Skip to content

DataViews: Add time field support - #80831

Closed
elazzabi wants to merge 2 commits into
trunkfrom
codex/dataviews-time-field
Closed

elazzabi wants to merge 2 commits into
trunkfrom
codex/dataviews-time-field

Conversation

@elazzabi

Copy link
Copy Markdown
Contributor

What?

Adds first-class support for time-only fields to DataViews and DataForm.

Field authors can now use type: 'time' to display and edit normalized time values such as 14:30, without attaching an artificial date or timezone.

Why?

DataViews currently supports date and datetime, but neither correctly represents a value that contains only a time. Otherwise, consumers have to use a generic text field or introduce date and time zone semantics that do not belong to the value.

How?

The new field type composes the existing DataViews field infrastructure:

  • Uses a native HTML time input through the shared validated-input control.
  • Preserves values as time-only strings without timezone conversion.
  • Supports equality and chronological comparison operators.
  • Sorts normalized time strings chronologically.
  • Reuses the existing required and element validation behavior.
  • Documents the public field type, control, and supported operators.
  • Adds a dedicated DataViews/FieldTypes/time Storybook story.

Multi-selection operators are intentionally excluded because the native time control represents a single scalar value.

Testing Instructions

Open Storybook locally and visit FieldTypes > All / time

CleanShot.2026-07-29.at.12.07.14.mp4

Use of AI Tools

Codex was used to investigate the existing DataViews field architecture, implement the change, add tests and documentation, and review the resulting diff. I reviewed the generated changes and take responsibility for the final implementation.

DataViews previously recognized date and datetime fields but could not model a time-only value without attaching a synthetic date or timezone.

Register a native time control and field definition that preserves normalized HTML time strings, supports scalar comparison and sorting, and is documented and exercised in Storybook and unit tests.
@elazzabi elazzabi self-assigned this Jul 29, 2026
@github-actions

github-actions Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

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: elazzabi <elazzabi@git.wordpress.org>
Co-authored-by: ntsekouras <ntsekouras@git.wordpress.org>

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

@github-actions github-actions Bot added the [Package] DataViews /packages/dataviews label Jul 29, 2026
@github-actions

Copy link
Copy Markdown

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Required label: Any label starting with [Type].
  • Labels found: [Package] DataViews.

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

@elazzabi
elazzabi requested review from Copilot and removed request for gigitux, ntsekouras and oandregal July 29, 2026 09:13
Associate the new time field enhancement with #80831 so the package changelog validation can verify its pull request reference.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds first-class time support to the DataViews field system and DataForm controls, allowing time-only values (e.g. 14:30) to be displayed, edited, filtered, and sorted without introducing date/timezone semantics.

Changes:

  • Adds a new time field type (operators, formatting, validation wiring) and registers it in the field-type registry and public type union.
  • Adds a dedicated DataForm time control built on the shared validated input control.
  • Updates docs, Storybook stories, and tests to cover normalization and editing for time fields.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/dataviews/src/types/field-api.ts Extends the public FieldTypeName union to include time.
packages/dataviews/src/field-types/time.tsx Introduces the time field type definition (render/edit/operators/sort/validation).
packages/dataviews/src/field-types/index.tsx Registers the new time field type in normalizeFields.
packages/dataviews/src/field-types/test/normalize-fields.ts Adds normalization expectations for time fields (formatting, operators, sorting).
packages/dataviews/src/components/dataform-controls/utils/validated-input.tsx Extends validated input typings to allow type="time".
packages/dataviews/src/components/dataform-controls/time.tsx Adds a new DataForm control that renders a native time input via validated input.
packages/dataviews/src/components/dataform-controls/index.tsx Registers the new time control in the bundled controls map.
packages/dataviews/src/dataform/test/dataform.tsx Adds a DataForm test ensuring time fields render as <input type="time"> and edit correctly.
packages/dataviews/src/field-types/stories/index.story.tsx Adds story data/field config and a dedicated Storybook story for time.
packages/dataviews/README.md Documents the new time type, the time control, and valid operators.
packages/dataviews/CHANGELOG.md Notes the enhancement in the package changelog.

Comment on lines +4 to +25
import type { FieldType } from '../types/private';
import {
OPERATOR_GREATER_THAN,
OPERATOR_GREATER_THAN_OR_EQUAL,
OPERATOR_IS,
OPERATOR_IS_NOT,
OPERATOR_LESS_THAN,
OPERATOR_LESS_THAN_OR_EQUAL,
} from '../constants';
import render from './utils/render-default';
import sort from './utils/sort-text';
import isValidRequired from './utils/is-valid-required';
import isValidElements from './utils/is-valid-elements';
import getValueFormatted from './utils/get-value-formatted-default';

export default {
type: 'time',
render,
Edit: 'time',
sort,
enableSorting: true,
enableGlobalSearch: false,
Comment on lines 6 to 9

- DataViews: Add a `time` field type and DataForm control.
- DataViews: Add Shift+Click range selection through a shared `useSelectionProps` hook that layouts can adopt, wired up in the table and grid layouts.[#80046](https://github.com/WordPress/gutenberg/pull/80046)
- DataViewsPicker: Add Shift+Click range selection to the `picker-table`, `picker-grid`, and `picker-activity` layouts. [#80413](https://github.com/WordPress/gutenberg/pull/80413)
@ntsekouras

Copy link
Copy Markdown
Contributor

That's a eerie coincidence 😄 . I had opened a similar PR about 10 minutes before yours.

Curious to see though the differences because mine is lot bigger.

@github-actions

Copy link
Copy Markdown

Size Change: +322 B (0%)

Total Size: 7.76 MB

📦 View Changed
Filename Size Change
build/modules/content-types/index.min.js 164 kB +55 B (+0.03%)
build/scripts/block-editor/index.min.js 428 kB +45 B (+0.01%)
build/scripts/edit-site/index.min.js 305 kB +58 B (+0.02%)
build/scripts/editor/index.min.js 500 kB +103 B (+0.02%)
build/scripts/media-utils/index.min.js 121 kB +61 B (+0.05%)

compressed-size-action

@elazzabi

Copy link
Copy Markdown
Contributor Author

Haha @ntsekouras, what a coincidence. It looks like yours supports more than mine; happy to close this one in favor of yours (or try to at least support the same features so we can compare both 😄 )

@ntsekouras

Copy link
Copy Markdown
Contributor

Haha @ntsekouras, what a coincidence. It looks like yours supports more than mine; happy to close this one in favor of yours (or try to at least support the same features so we can compare both 😄 )

It seems so, and based on yours though, it might be simplified in a few pieces. Wanna collaborate on mine?

@elazzabi

Copy link
Copy Markdown
Contributor Author

@ntsekouras sure! I'll leave this as is then 🙌

@github-actions

Copy link
Copy Markdown

Flaky tests detected in 590aa3f.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/30438919038
📝 Reported issues:

@elazzabi

Copy link
Copy Markdown
Contributor Author

Closing in favor of #80830

@elazzabi elazzabi closed this Jul 30, 2026
@oandregal
oandregal deleted the codex/dataviews-time-field branch August 4, 2026 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] DataViews /packages/dataviews

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants