Skip to content

Conversation

chihsuan
Copy link
Member

@chihsuan chihsuan commented Jul 22, 2025

What?

This PR implements the Edit component for the Date field 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 the inThePast and over operators.

Why?

Provides a more user-friendly date selection experience

How?

  • Added a new date control component for single date selection and a date range control component.
  • Enhanced styles for date controls, including custom date picker styling.
  • Updated the date field type to support new operators for filtering.

Testing Instructions

  1. Run npm run storybook:dev
  2. Go to http://localhost:50240/?path=/story/dataviews-fieldtypes--date
  3. Test single date operators:
    • Select operators: on, before, after - verify calendar widget appears
    • Test preset buttons (Today, Yesterday, etc.) - verify selection state
  4. Test date range operator:
    • Select between operator - verify DateRangeCalendar appears
    • Test range presets (Last 7 days, Last 30 days) - verify full day ranges
    • Test manual From/To inputs - verify normalization

Screenshots or screencast

Screen.Recording.2025-07-22.at.18.02.32.mov

- 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.
@chihsuan chihsuan changed the title DataViews: Implement date Edit control DataViews: Implement Edit control for date field Jul 22, 2025
chihsuan added 2 commits July 22, 2025 17:39
- 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.
@chihsuan chihsuan marked this pull request as ready for review July 22, 2025 10:05
@chihsuan chihsuan requested a review from oandregal as a code owner July 22, 2025 10:05
@@ -33,72 +27,6 @@ const TIME_UNITS_OPTIONS = {
],
};

function RelativeDateControls( {
Copy link
Member Author

Choose a reason for hiding this comment

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

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;
Copy link
Member Author

Choose a reason for hiding this comment

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

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.

Before:
Screenshot 2025-07-22 at 17 34 37

After:
Screenshot 2025-07-22 at 17 34 59

Copy link

github-actions bot commented Jul 22, 2025

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: chihsuan <chihsuan@git.wordpress.org>
Co-authored-by: oandregal <oandregal@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@t-hamano t-hamano added [Type] Enhancement A suggestion for improvement. [Feature] DataViews Work surrounding upgrading and evolving views in the site editor and beyond [Package] DataViews /packages/dataviews labels Jul 23, 2025
@@ -28,6 +28,7 @@
- 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.
Copy link
Member

Choose a reason for hiding this comment

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

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` }
Copy link
Member

Choose a reason for hiding this comment

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

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, we can keep the same class names.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in 7101810

Screen.Recording.2025-07-29.at.13.58.56.mov

];

const DATE_RANGE_PRESETS = [
{
Copy link
Member

Choose a reason for hiding this comment

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

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)

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought the same initially, but Woo Analytics includes both "today" and "yesterday" as options in its range filter, so I kept them.

Screenshot 2025-07-29 at 13 20 25

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed in e884b14.

Screenshot 2025-07-29 at 13 57 34

OPERATOR_AFTER_INC,
OPERATOR_IN_THE_PAST,
OPERATOR_OVER,
OPERATOR_BETWEEN,
Copy link
Member

Choose a reason for hiding this comment

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

I don't mind reusing between for date ranges, but the display of date ranges in the filter chip is not clear:

Screenshot 2025-07-28 at 16 34 39

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

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.

} else if ( filterInView?.value !== undefined ) {
activeElements = [
{
value: filterInView.value,
label: filterInView.value,
},
];
}

Copy link
Member Author

@chihsuan chihsuan Jul 29, 2025

Choose a reason for hiding this comment

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

I attempted to use a space as the operator, but IMO it doesn't look quite right when dealing with integers.

Screenshot 2025-07-29 at 13 55 37

How about using a comma followed by a space for now instead? 8778eba

Screenshot 2025-07-29 at 13 56 39 Screenshot 2025-07-29 at 14 00 53

Copy link
Member Author

Choose a reason for hiding this comment

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

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. 🤔

Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Example: Field between: 1 and 2, Field between: 2024-01-01 and 2024-02-01.

That's a great suggestion! Changed in 6950184.

Screenshot 2025-07-30 at 13 00 48 Screenshot 2025-07-30 at 13 00 37

Copy link
Member

@oandregal oandregal left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! I've left some adjustments to address, other than it's ready to land.

@chihsuan chihsuan requested a review from oandregal July 29, 2025 06:04
@oandregal oandregal merged commit be4208b into WordPress:trunk Jul 30, 2025
62 checks passed
@github-actions github-actions bot added this to the Gutenberg 21.4 milestone Jul 30, 2025
adamsilverstein pushed a commit to adamsilverstein/gutenberg that referenced this pull request Jul 31, 2025
Co-authored-by: chihsuan <chihsuan@git.wordpress.org>
Co-authored-by: oandregal <oandregal@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] DataViews Work surrounding upgrading and evolving views in the site editor and beyond [Package] DataViews /packages/dataviews [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants