DataViews: Implement Edit control for date field#70836
Conversation
- Added a new date control component for single date selection and a date range control component. - Introduced a relative date control for handling relative date inputs. - Updated the datetime control to utilize the new relative date control. - Enhanced styles for date controls, including custom date picker styling. - Registered the new date control in the dataform controls index. - Updated the date field type to support new operators for filtering.
…call to unlock private APIs.
- Added date presets for quick selection of common dates (e.g., today, yesterday, past week, past month). - Introduced date range presets for easier selection of date ranges. - Refactored date formatting and selection logic for improved clarity and maintainability. - Updated the relative date control to include time unit options directly within its module.
| ], | ||
| }; | ||
|
|
||
| function RelativeDateControls( { |
There was a problem hiding this comment.
This component was relocated to its own file to enable reuse in both the date and datetime contexts.
| width: 230px; | ||
| width: 100%; | ||
| min-width: 230px; | ||
| max-width: 250px; |
There was a problem hiding this comment.
I changed the popover width to have a minimum of 230px and a maximum of 250px, since 230px alone was too narrow for the widget. cc @jameskoster for review/suggestions.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
| - Allow readonly fields in DataForm when `readOnly` is set to `true`. | ||
| - Adjust the padding when the component is placed inside a `Card`. | ||
| - Introduce `perPageSizes` to control the available sizes of the items per page | ||
| - Add support for the `Edit` control on the date field type. |
There was a problem hiding this comment.
Small note: this needs to be moved to the unreleased section of the changelog. I think we should also start to consistently add links to the PRs, so changes are easier to track.
| <HStack spacing={ 2.5 }> | ||
| <NumberControl | ||
| __next40pxDefaultSize | ||
| className={ `${ className }-number` } |
There was a problem hiding this comment.
Can this and the selectcontrol's class below still be dataviews-controls__relative-date-number and *-unit? There's also some CSS rules we need to update (check for .dataviews-controls__datetime-number and .dataviews-controls__datetime-unit).
Additionally, I've noticed over and in the past render slightly different widths for the number control:
Screen.Recording.2025-07-28.at.15.35.44.mov
There was a problem hiding this comment.
Yes, we can keep the same class names.
There was a problem hiding this comment.
Fixed in 7101810
Screen.Recording.2025-07-29.at.13.58.56.mov
| ]; | ||
|
|
||
| const DATE_RANGE_PRESETS = [ | ||
| { |
There was a problem hiding this comment.
today and yesterday are weird presets for a range. What about these for ranges:
- last 7 days
- last 30 days
- month to date (this is: from the 1st of the month to the current date)
- last year
- year to date (this is: from the 1st of the year to the current date)
There was a problem hiding this comment.
I thought the same initially, but Woo Analytics includes both "today" and "yesterday" as options in its range filter, so I kept them.
On further reflection, I agree that including these options in the Between operator could be confusing for users. If someone wants to filter for today or yesterday, they can use the On operator instead.
I'll make the changes.
| OPERATOR_AFTER_INC, | ||
| OPERATOR_IN_THE_PAST, | ||
| OPERATOR_OVER, | ||
| OPERATOR_BETWEEN, |
There was a problem hiding this comment.
I don't mind reusing between for date ranges, but the display of date ranges in the filter chip is not clear:
Throwing some ideas: perhaps the - separator would work if we render human-like dates ("Jul 31st" instead of "2025-07-31")? Or changing the separator to a space so it works across integers and dates?
There was a problem hiding this comment.
Using human-like dates sounds like a good idea! However, we'll need to update the way the input widget assigns the Filter label, which might require some refactoring. I'll change the separator to a space for now, as it's simple and looks better for both integers and dates.
gutenberg/packages/dataviews/src/components/dataviews-filters/filter.tsx
Lines 490 to 498 in 8a8da8a
There was a problem hiding this comment.
I attempted to use a space as the operator, but IMO it doesn't look quite right when dealing with integers.
How about using a comma followed by a space for now instead? 8778eba
There was a problem hiding this comment.
perhaps the - separator would work if we render human-like dates ("Jul 31st" instead of "2025-07-31")?
Upon closer examination, perhaps we could use field.render for this. 🤔
There was a problem hiding this comment.
Upon closer examination, perhaps we could use field.render for this. 🤔
That's probably going to cause issues because this is a React component and can be anything.
I attempted to use a space as the operator, but IMO it doesn't look quite right when dealing with integers.
How about using a comma followed by a space for now instead?
Agree space doesn't look good. For me, comma is weird as well. Perhaps go with the clearer, even if longer, and until we can actually render human-like dates? Example: Field between: 1 and 2, Field between: 2024-01-01 and 2024-02-01.
There was a problem hiding this comment.
Example: Field between: 1 and 2, Field between: 2024-01-01 and 2024-02-01.
That's a great suggestion! Changed in 6950184.
oandregal
left a comment
There was a problem hiding this comment.
Thanks for the PR! I've left some adjustments to address, other than it's ready to land.
Co-authored-by: chihsuan <chihsuan@git.wordpress.org> Co-authored-by: oandregal <oandregal@git.wordpress.org>



What?
This PR implements the
Editcomponent for theDatefield type in the DataViews using the Calendar widget.The calendar widget is used for the following operators:
on,notOn,before,after,beforeInc,afterInc,between, as well as for the default render. The relative date control is used for theinThePastandoveroperators.Why?
Provides a more user-friendly date selection experience
How?
Testing Instructions
npm run storybook:devScreenshots or screencast
Screen.Recording.2025-07-22.at.18.02.32.mov