-
Notifications
You must be signed in to change notification settings - Fork 19
Add datetime filter for Workflows Page #693
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fernandol-nvidia
wants to merge
5
commits into
main
Choose a base branch
from
fernandol/workflow-date-filter
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+944
−175
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
219 changes: 219 additions & 0 deletions
219
src/ui/src/components/filter-bar/filter-bar-date-picker.tsx
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,219 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION. All rights reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| /** | ||
| * FilterBarDatePicker - Date/range picker panel rendered inside the FilterBar dropdown. | ||
| * | ||
| * B1 "Split Rail" layout: preset list on the left with active indicator, | ||
| * stacked From/To date inputs on the right. | ||
| * | ||
| * Selecting a preset or applying custom dates calls onCommit(value) where value | ||
| * is either a preset label ("last 7 days"), a single ISO date ("2026-03-11"), | ||
| * or an ISO range ("2026-03-01..2026-03-11"). | ||
| */ | ||
|
|
||
| "use client"; | ||
|
|
||
| import { useState, useCallback, useMemo, memo, useRef, useEffect } from "react"; | ||
| import { DATE_RANGE_PRESETS } from "@/lib/date-range-utils"; | ||
| import { DATE_CUSTOM_FROM, DATE_CUSTOM_TO, DATE_CUSTOM_APPLY } from "@/components/filter-bar/lib/types"; | ||
| import { MONTHS_SHORT } from "@/lib/format-date"; | ||
|
|
||
| interface FilterBarDatePickerProps { | ||
| /** Called when a date or range is committed. Value is preset label, ISO date, or ISO range. */ | ||
| onCommit: (value: string) => void; | ||
| /** Preset label currently highlighted via keyboard navigation (shows active indicator). */ | ||
| highlightedLabel?: string; | ||
| /** Called when Tab/Shift-Tab should wrap the cycle (e.g. Tab past Apply, Shift-Tab on From). */ | ||
| onCycleStep?: (direction: "forward" | "backward", fromValue: string) => void; | ||
| } | ||
|
|
||
| /** Format a UTC YYYY-MM-DD string as "Mar 4" or "Mar 4 '25" (if year differs from currentYear). */ | ||
| function fmtUtcDate(isoDate: string, currentYear: number): string { | ||
| const d = new Date(`${isoDate}T00:00:00Z`); | ||
| const mon = MONTHS_SHORT[d.getUTCMonth()]; | ||
| const day = d.getUTCDate(); | ||
| const year = d.getUTCFullYear(); | ||
| return year !== currentYear ? `${mon} ${day} '${String(year).slice(2)}` : `${mon} ${day}`; | ||
| } | ||
|
|
||
| /** | ||
| * Build hint text from the raw preset value (before next-midnight adjustment). | ||
| * Single date → "Mar 11"; range → "Mar 4 – Mar 11". | ||
| */ | ||
| function buildPresetHint(rawValue: string, currentYear: number): string { | ||
| if (rawValue.includes("..")) { | ||
| const sep = rawValue.indexOf(".."); | ||
| return `${fmtUtcDate(rawValue.slice(0, sep), currentYear)} – ${fmtUtcDate(rawValue.slice(sep + 2), currentYear)}`; | ||
| } | ||
| return fmtUtcDate(rawValue, currentYear); | ||
| } | ||
|
|
||
| export const FilterBarDatePicker = memo(function FilterBarDatePicker({ | ||
| onCommit, | ||
| highlightedLabel, | ||
| onCycleStep, | ||
| }: FilterBarDatePickerProps) { | ||
| const [fromDate, setFromDate] = useState(""); | ||
| const [toDate, setToDate] = useState(""); | ||
|
|
||
| const fromRef = useRef<HTMLInputElement>(null); | ||
| const toRef = useRef<HTMLInputElement>(null); | ||
| const applyRef = useRef<HTMLButtonElement>(null); | ||
|
|
||
| // When keyboard navigation highlights a custom input sentinel, move DOM focus there. | ||
| // For the To input, also open the calendar picker — programmatic focus() always lands | ||
| // at the first sub-field (MM), but entering backward should start at the calendar end. | ||
| useEffect(() => { | ||
| if (highlightedLabel === DATE_CUSTOM_FROM) { | ||
| fromRef.current?.focus(); | ||
| } else if (highlightedLabel === DATE_CUSTOM_TO) { | ||
| toRef.current?.focus(); | ||
| } else if (highlightedLabel === DATE_CUSTOM_APPLY) { | ||
| applyRef.current?.focus(); | ||
| } | ||
| }, [highlightedLabel]); | ||
|
|
||
| // Compute once per render (client-only component, only mounted on interaction). | ||
| const currentYear = useMemo(() => new Date().getUTCFullYear(), []); | ||
|
|
||
| const presetHints = useMemo( | ||
| () => Object.fromEntries(DATE_RANGE_PRESETS.map((p) => [p.label, buildPresetHint(p.getValue(), currentYear)])), | ||
| [currentYear], | ||
| ); | ||
|
|
||
| // toDate must be strictly after fromDate (same minute = zero-second window after +1min adjustment) | ||
| const rangeError = !!fromDate && !!toDate && toDate <= fromDate; | ||
|
|
||
| const handleApply = useCallback(() => { | ||
| if (!fromDate || rangeError) return; | ||
| if (toDate) { | ||
| onCommit(`${fromDate}..${toDate}`); | ||
| } else { | ||
| onCommit(fromDate); | ||
| } | ||
| }, [fromDate, toDate, rangeError, onCommit]); | ||
|
|
||
| const handleFromChange = useCallback((value: string) => { | ||
| setFromDate(value); | ||
| // Clear "to" if it's now at or before "from" (equal = invalid range after +1min adjustment) | ||
| setToDate((prev) => (prev && prev <= value ? "" : prev)); | ||
| }, []); | ||
|
|
||
| return ( | ||
| <div | ||
| className="fb-date-picker" | ||
| role="none" | ||
| onKeyDown={(e) => e.stopPropagation()} | ||
| > | ||
| <div className="fb-date-split"> | ||
| {/* Left rail: presets with right-aligned date hints */} | ||
| <div className="fb-date-rail"> | ||
| <div className="fb-date-section-label">Presets</div> | ||
| {DATE_RANGE_PRESETS.map((preset) => ( | ||
| <button | ||
| key={preset.label} | ||
| type="button" | ||
| tabIndex={-1} | ||
| className="fb-date-preset-row" | ||
| data-active={highlightedLabel === preset.label ? "" : undefined} | ||
| onClick={() => onCommit(preset.label)} | ||
| > | ||
| <span className="fb-date-preset-label">{preset.label}</span> | ||
| <span className="fb-date-preset-hint">{presetHints[preset.label]}</span> | ||
| </button> | ||
| ))} | ||
| </div> | ||
|
|
||
| {/* Right: custom range */} | ||
| <div className="fb-date-custom"> | ||
| <div className="fb-date-section-label">Custom range</div> | ||
| <div className="fb-date-field"> | ||
| <label | ||
| className="fb-date-label" | ||
| htmlFor="fb-date-from" | ||
| > | ||
| From | ||
| </label> | ||
| <input | ||
| ref={fromRef} | ||
| id="fb-date-from" | ||
| type="datetime-local" | ||
| value={fromDate} | ||
| onChange={(e) => handleFromChange(e.target.value)} | ||
| className="fb-date-input" | ||
| /> | ||
| </div> | ||
| <div className="fb-date-field"> | ||
| <label | ||
| className="fb-date-label" | ||
| htmlFor="fb-date-to" | ||
| > | ||
| To | ||
| </label> | ||
| <input | ||
| ref={toRef} | ||
| id="fb-date-to" | ||
| type="datetime-local" | ||
| value={toDate} | ||
| onChange={(e) => setToDate(e.target.value)} | ||
| min={fromDate || undefined} | ||
| className="fb-date-input" | ||
| data-error={rangeError ? "" : undefined} | ||
| aria-invalid={rangeError} | ||
| aria-describedby={rangeError ? "fb-date-range-error" : undefined} | ||
| /> | ||
| {rangeError && ( | ||
| <span | ||
| id="fb-date-range-error" | ||
| className="fb-date-error" | ||
| role="alert" | ||
| > | ||
| “To” must be after “From” | ||
| </span> | ||
| )} | ||
| </div> | ||
| <button | ||
| ref={applyRef} | ||
| type="button" | ||
| onClick={handleApply} | ||
| disabled={!fromDate || rangeError} | ||
| onKeyDown={(e) => { | ||
| if (e.key === "Tab" && !e.shiftKey) { | ||
| e.preventDefault(); | ||
| onCycleStep?.("forward", DATE_CUSTOM_APPLY); | ||
| } | ||
| }} | ||
| className="fb-date-apply" | ||
| > | ||
| Apply → | ||
| </button> | ||
| </div> | ||
| </div> | ||
| {/* Focus sentinel: the last focusable element inside the picker. | ||
| When Tab exits Apply (or To when Apply is disabled), the browser naturally | ||
| focuses this sentinel. onFocus immediately redirects back into the cycle, | ||
| keeping focus trapped inside the filter bar. It must live inside the picker | ||
| (inside the container) so handleBlur sees relatedTarget as within-container. */} | ||
| <span | ||
| tabIndex={0} | ||
| aria-hidden="true" | ||
| className="sr-only" | ||
| onFocus={() => onCycleStep?.("forward", DATE_CUSTOM_APPLY)} | ||
| /> | ||
| </div> | ||
| ); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: NVIDIA/OSMO
Length of output: 82
🏁 Script executed:
Repository: NVIDIA/OSMO
Length of output: 10776
🏁 Script executed:
Repository: NVIDIA/OSMO
Length of output: 1180
🏁 Script executed:
Repository: NVIDIA/OSMO
Length of output: 118
🏁 Script executed:
Repository: NVIDIA/OSMO
Length of output: 9873
🏁 Script executed:
Repository: NVIDIA/OSMO
Length of output: 1020
🏁 Script executed:
Repository: NVIDIA/OSMO
Length of output: 674
🏁 Script executed:
Repository: NVIDIA/OSMO
Length of output: 5741
🏁 Script executed:
Repository: NVIDIA/OSMO
Length of output: 567
🏁 Script executed:
Repository: NVIDIA/OSMO
Length of output: 37
🏁 Script executed:
Repository: NVIDIA/OSMO
Length of output: 830
🏁 Script executed:
Repository: NVIDIA/OSMO
Length of output: 7204
🏁 Script executed:
Repository: NVIDIA/OSMO
Length of output: 394
Remove
stopPropagation()or allow Escape to bubble to parent's keyboard handler.The
onKeyDown={(e) => e.stopPropagation()}blocks all keyboard events, including Escape, from bubbling to the parent's keyboard navigation system. The parent'sonEscapehandler expects Escape to propagate and callscloseDropdown()to close the date picker. Since the date picker does not handle Escape itself, pressing Escape has no effect. Only Tab has custom handling on the Apply button (intentional), so consider replacing the blanketstopPropagation()with a selective check:if (e.key !== "Escape") e.stopPropagation().🤖 Prompt for AI Agents