Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix datetime filters crash table page #1526

Merged
merged 1 commit into from
Jan 26, 2024
Merged

Conversation

bofeiw
Copy link
Contributor

@bofeiw bofeiw commented Jan 21, 2024

Issue

Applying any date or datetime filters will cause the whole table page to crash, and the crash persists until user manually visit debug page and reset filters.

Example: #1513

Cause

We expect toDate to be present in the filter value because it is supposed to be a Firestore Timestamp object.

const filterDate =
        "toDate" in filter.value ? filter.value.toDate() : filter.value;

This used to hold true, however, the recent shareable filter url feature slightly changed the way filters are passed - it uses JSON.stringify on filters and set it in the url. When the values are parsed, we no longer get Timestamp. Instead, we get { nanoseconds: number; seconds: number }, the Timestamp object without toDate() method. The above code would no longer work, causing the table page to crash.

Fix

Without changing how the shareable filter url works, adding a parser on the date values would fix the issue.

...
if (date.seconds) {
    return new Date(date.seconds * 1000 + date.nanoseconds / 1_000_000);
...

An alternative way to fix the issue is to make use of toDate() method of Timestamp with the filter values in the url, however I think this will introduce more lines of code and complexity, and the parser solution would be simpler.

Copy link

vercel bot commented Jan 21, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
rowy-os ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 21, 2024 9:36pm
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
rowy-typedoc ⬜️ Ignored (Inspect) Jan 21, 2024 9:36pm

@bofeiw bofeiw changed the title Fix datetime filters crashes table page Fix datetime filters crash table page Jan 21, 2024
@shamsmosowi shamsmosowi merged commit 1857314 into develop Jan 26, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants