Skip to content

Conversation

@willhuang1997
Copy link
Contributor

Hi,

I am a software engineer at Streamlit working with Lukas Masuch. I am attempting to add date, datetime, and time support but it looks like the current implementation doesn't fully work and there are some edge cases that aren't necessary kept.

I left comments as to why most changes are specifically there. I didn't necessarily see any tests that would be implemented but I have tested this custom cell in Streamlit, in glide-data-grid, and also had Lukas look over some of the code as a review (obviously doesn't count as a review but just saying).

I would love to work with anyone who would like to help me get this in and any requests to make this work!

William Huang
SWE at Streamlit / Snowflake

@jassmith
Copy link
Contributor

jassmith commented Feb 1, 2023

Most polite PR ever

@jassmith
Copy link
Contributor

jassmith commented Feb 1, 2023

Did you run prettier over these files? The formatting feels off. I should have a check for that...

@willhuang1997
Copy link
Contributor Author

Did you run prettier over these files? The formatting feels off. I should have a check for that...

Hm... I ran:

yarn prettier --write packages/

and then committed...?

@jassmith
Copy link
Contributor

jassmith commented Feb 1, 2023

No problem

jassmith
jassmith previously approved these changes Feb 1, 2023
Copy link
Contributor

@jassmith jassmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything else looks great. Will try to get test support stood up ASAP so Im not blocking you.

@jassmith
Copy link
Contributor

jassmith commented Feb 1, 2023

5.2.2 now has a test framework in place for cells. Please rebase your branch onto 5.2.2 and retarget.

@willhuang1997 willhuang1997 changed the base branch from main to 5.2.2 February 1, 2023 07:04
@willhuang1997 willhuang1997 dismissed jassmith’s stale review February 1, 2023 07:04

The base branch was changed.

@lukasmasuch
Copy link
Collaborator

lukasmasuch commented Feb 1, 2023

Another more optional feature (does not need to be part of this PR): Make the min (string), max (string), and step (number) attributes accessible through the cell props. These parameters are supported in the same way by the time, date, and datetime-local inputs, so I think this should be very trivial to support.

@willhuang1997
Copy link
Contributor Author

Hi @jassmith ,

Do you have any recommendations as to how to render the editor and then somehow call the onChange method? I tried looking at cells.test.tsx and copying this code but it didn't end up working properly on my VSCode with error along the lines that Editor is not a React Component:

        const Editor = renderer.provideEditor?.(MOCK_DATE_CELL)
        const target = getMockEditorTarget();
        assert(Editor !== undefined)
        assert(!isObjectEditorCallbackResult(Editor));

        assert(Editor !== undefined);
        const result = render(
            <Editor
                onChange={noop}
                onFinishedEditing={noop}
                isHighlighted={false}
                value={MOCK_DATE_CELL}
                target={target}
                forceEditMode={false}
            />
        );

However, would this be able to get merged otherwise? I do have some TODOs that I do plan to get to but the implementation itself might be good to go after meeting with Lukas?

cc: @lukasmasuch just to sign off too

@jassmith
Copy link
Contributor

jassmith commented Feb 5, 2023

I probably wont have time for about 7 days to debug what is going on there. If you can get it working I will have time to review however.

@willhuang1997
Copy link
Contributor Author

Hi @jassmith ! I know you're busy but will you have time to review it anytime soon? Is it possible to get a date as to when this will be reviewed?

Thanks,

William

@jassmith
Copy link
Contributor

jassmith commented Feb 9, 2023

I will review it tonight after dinner

Copy link
Contributor

@jassmith jassmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall. I am curious about the 1970 choice.

if (d.format === "time" && Number.isNaN(parseDateTimestamp)) {
// The pasted value was not a valid date string
// Try to interpret value as time string instead (HH:mm:ss)
parseDateTimestamp = Date.parse(`1970-01-01T${v}Z`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not interpret it as "today" instead of 1970? Today at least feels more likely to be expected.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume we could also use today's date here... both are probably semi-optimal solutions here. The general problem here is that there isn't really a native format for time in javascript.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thinking a bit more here. Probably today has slightly more advantages 👍 @willhuang1997 would you be fine as well with changing that?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One argument for keeping 1970-01-01: It is consistent with how the time input converts the time back into a date. Calling valueAsDate on the time input event will return the time based on 1970-01-01. valueAsNumber is also the UNIX timestamp from 1970-01-01 and not today.

image

@willhuang1997
Copy link
Contributor Author

willhuang1997 commented Feb 10, 2023

Looks good overall. I am curious about the 1970 choice.

Thanks! I think any day can be used for the sort to properly work but 1970 is used just because it's the Unix epoch. Is it possible to merge it? Only those with write access can merge :)

@lukasmasuch
Copy link
Collaborator

lukasmasuch commented Feb 10, 2023

Oh, I think the tests are not yet running as part of the CI 😬 Let me quickly add that

Update: Done ✅

@jassmith
Copy link
Contributor

Thank you both for your excellent work. I got this one from here. This looks great.

@willhuang1997
Copy link
Contributor Author

Since the build was broken, I removed the failing tests because they were based off of local time zone and causing flakiness.

@lukasmasuch
Copy link
Collaborator

It would be great if we could make the DatePickerCell to also adapt to the content when it's automatically sized. We would need to add this to the renderer:

  measure: (ctx, cell) => {
    const { displayDate } = cell.data
    return ctx.measureText(displayDate).width + 16
  },

But in order to have that work, we need to remove this check (see the issue here):

if (cell.kind === GridCellKind.Custom) return defaultSize;

* Fix unit tests

* Fix tests

* Remove min / max
@lukasmasuch
Copy link
Collaborator

I added a couple of small refinements and improvements to the PR:

  • Add support for null as date value.
  • Use defaultValue instead of value. Using value can lead to some strange issues.
  • Check if valueAsNumber is NaN instead of empty value to determine that the created value by the user is not valid since we are using valueAsNumber and not value.
  • Add measure to allow auto-resizing of the cell.
  • Allow providing a timezoneOffset. This allows to let the user to edit a datetime object in the date & time of the timezone, but still get back the actual UTC date adjusted by the timezone.
  • Adjust paste tests to only use strings, since pasting will always use strings anyways.

@msdrigg
Copy link

msdrigg commented Mar 16, 2023

Is anything blocking this? This feature set looks great!

jassmith and others added 2 commits August 16, 2023 19:10
* Fix unit tests

* Fix tests

* Remove min / max

* Add support for date in min/max
@jassmith jassmith merged commit 9495a25 into glideapps:5.2.2 Aug 18, 2023
jassmith added a commit that referenced this pull request Aug 19, 2023
* 5.2.2-beta1

* Fix unable to select last col

* Find better react-laag fix

* Fix build error

* Prevent crash

* Ensure click off container properly supports touches

* 5.2.2-beta2

* Improve error messages

* Offer increased control over search

* Add dumb filter example

* Fix import

* Export GetRowThemeCallback

* Ensure canvas is in proper ltr/rtl mode

* Don't accidentally exclude final col when copying rows

* Make sure to support RTL in column headers

* Load up testing framework

* Fix build

* Add row marker stories

* Add more type exports

* Fix padding with wrapped text

* 5.2.2-beta3

* Fix copy pasta discovered during merge

* Bump to 5.2.2-beta5

* feat: pass through middle mouse click event to onCellClicked (#693)

* pass through middle mouse click event to onCellClicked

* Add tests and prevent werid behavior

* Add more tests and fixes

* Oops

* Fix build

---------

Co-authored-by: Jason Smith <jason@heyglide.com>

* Fix issue with missing ts distribution (#673)

* feat: expose the cell location in keyboard event (#664)

* feat: expose the cell location in keyboard event

* Add test

* Fix API

---------

Co-authored-by: Alex Corrado <alex.corrado@heyglide.com>
Co-authored-by: Jason Smith <jason@heyglide.com>

* DatePickerCell Implementation (#627)

* DatePickerCell Implementation with prettier

* Suggestions. Note, I do need to add more unit tests

* Actually remove the unit test beacuse infra does not support this as of yet.

* Rename variable to dateKind

* Add support.ts duplicate method into cells packagea and refactor import

* Put back try and catch. oops

* readd format parameter to support backwards compat and incorporate Lukas Feedback

* Adding basic unit test

* Add todos for myself

* lint

* Add max, min, step, readonly, and change cached displayDate behavior to undefined behavior

* Add more tests and dataid for date-picker-cell

* Add tests

* Add date, time, datetime tests

* cleanup

* Remove console.log

* Add more test cases for onPaste

* Add time test case for onPaste

* Add implementation for time in onPaste

* Cleanup tests a bit

* Add additional columns to storybook

* Apply correct formatting

* Apply correct formatting

* Clean up with correct prettier file

* Remove need for support functions

* Clean imports

* Revert "Clean up with correct prettier file"

This reverts commit 32e5b93.

* Add assert method

* Fix paste issue

* Delete support ts

* Fix cell stories display

* Add styling to apply gdg theme

* Fix tests

* Use outside read-only

* Remove theme

* Add cell tests to CI workflow

* Fix tests and remove extra test

* Remove tests because they're failing based on timezone

* Update date picker cell (#5)

* Fix unit tests

* Fix tests

* Remove min / max

* Add support for Date as min / max value (#6)

* Fix unit tests

* Fix tests

* Remove min / max

* Add support for date in min/max

---------

Co-authored-by: lukasmasuch <lukas.masuch@gmail.com>
Co-authored-by: Jason Smith <jassmith@gmail.com>

* 5.2.2-beta6

* Add obstructed playground

* Cleanup events a little more

* Bump to 5.3.0

---------

Co-authored-by: Alex Corrado <alex.corrado@heyglide.com>
Co-authored-by: Caleb Hoyoul Kang <caleb.kang@hpe.com>
Co-authored-by: Lukas Masuch <Lukas.Masuch@gmail.com>
Co-authored-by: Vigen <95758873+vabrahamyanadobe@users.noreply.github.com>
Co-authored-by: willhuang1997 <willhuang1997@gmail.com>
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.

4 participants