rowyio / rowy

Low-code backend platform. Manage database on spreadsheet-like UI and build cloud functions workflows in JS/TS, all in your browser.
http://rowy.io
Other
5.88k stars 479 forks source link

Fix datetime filters crash table page #1526

Closed bofeiw closed 7 months ago

bofeiw commented 7 months ago

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: https://github.com/rowyio/rowy/discussions/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.

vercel[bot] commented 7 months ago

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](https://vercel.com/rowy/rowy-typedoc/67qaZM3zJV6YJvF4SYenEwFdEsVS)) | | | Jan 21, 2024 9:36pm |