feat(datagrid): add native date/time picker for date columns (#1405)#1410
Merged
Conversation
9b94169 to
04338c8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a native date/time picker for
DATE,DATETIME,TIMESTAMP, andTIMEcells in the data grid. Click the chevron on a date cell to open anNSDatePickercalendar/clock popover and pick a value visually.The picker augments inline editing, it does not replace it:
NOW()/CURRENT_TIMESTAMP/CURRENT_DATE/CURRENT_TIME/NULL.This is the capability removed in #1233. That picker was removed because it blocked text editing and was the only way to edit a date cell. This one sits alongside the inline editor, so it adds the visual picker back without that regression.
How it works
NSDatePicker, style.clockAndCalendar, mode.single, wrapped in anNSViewRepresentable, shown via the existingPopoverPresenter(.semitransient, like every other cell picker). OK commits; Cancel or click-away commits nothing.DATEshows the calendar only,TIMEthe clock only,DATETIME/TIMESTAMPboth.DateEditingServicedecomposes the cell string into date, time, fractional-seconds, and timezone-offset parts, lets the picker edit only the calendar/clock fields, and re-emits the fraction and offset verbatim. Naive types are pinned to UTC so the digits shown match the digits stored (no local-zone drift). NULL or unparseable cells start at the current date/time and write the column's default format.ColumnType.isTimeOnlynow strips a precision suffix, soTIME(6)is treated as time-only. This also fixes display formatting for those columns.Files
New:
DateEditingService.swiftfor the parse/format round-tripDateTimePickerContentView.swiftfor the SwiftUI popover and NSDatePicker wrapperChanged:
DataGridCellKind(new.datecase),DataGridCellView(chevron rendering, hit-test, click),DataGridCellRegistry.resolveKind,DataGridView+Click(chevron dispatch),DataGridView+Popovers(showDateTimePickerPopover),ColumnType.isTimeOnly,CHANGELOG.md, and the staledocs/features/data-grid.mdxsection.Tests
DateEditingServiceTestscovers MySQL / ISO /Z/ offset round-trips, fractional-second preservation, fraction and offset together, date-only, time-only, the edit-then-format path, NULL / empty / whitespace, unparseable input, and the per-type default format.ColumnTypeTestsgainsTIME(6),TIMESTAMP(6), andTIMESTAMPTZprecision cases.Test plan
DATETIMEcell. Calendar and clock popover opens at the current value. Pick a date and time, OK. Cell shows the new value, row is marked modified, Save emits the right UPDATE.DATEcell shows calendar only;TIMEcell shows clock only.TIMESTAMPvalue with fractional seconds keeps them after editing.timestamptzvalue keeps its offset after editing.Closes #1405