-
Notifications
You must be signed in to change notification settings - Fork 83
feat(webui): Modify time range input to show presets in date time inputs. #1676
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
base: main
Are you sure you want to change the base?
Changes from all commits
df714b5
e8dd34e
595b655
ccc1667
9a128a1
f36e665
6ae47c1
8bb7b7d
2159042
e2da61d
f59e33b
6dac345
d789c35
06a1944
2786aea
11c45e8
6289b47
16ccad1
dcf17e3
e4d9784
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import useSearchStore from "../../SearchState/index"; | ||
| import { | ||
| DATE_RANGE_POSITION, | ||
| DATE_RANGE_PROP_KEY, | ||
| TIME_RANGE_DISPLAY_TEXT_MAP, | ||
| TIME_RANGE_OPTION, | ||
| } from "./utils"; | ||
|
|
||
|
|
||
| interface TimeDateInputProps { | ||
| value: string; | ||
| [DATE_RANGE_PROP_KEY]: DATE_RANGE_POSITION; | ||
| } | ||
|
|
||
| /** | ||
| * Input component for DatePicker that displays custom text for preset time ranges. | ||
| * | ||
| * @param props | ||
| * @return | ||
| */ | ||
| const TimeDateInput = (props: TimeDateInputProps) => { | ||
| const {value, [DATE_RANGE_PROP_KEY]: dateRange} = props; | ||
| const timeRangeOption = useSearchStore((state) => state.timeRangeOption); | ||
|
|
||
| const displayText = timeRangeOption === TIME_RANGE_OPTION.CUSTOM ? | ||
| value : | ||
| TIME_RANGE_DISPLAY_TEXT_MAP[timeRangeOption][dateRange]; | ||
|
|
||
| return ( | ||
| <input | ||
| {...props} | ||
| readOnly={true} | ||
| value={displayText}/> | ||
| ); | ||
| }; | ||
|
|
||
|
|
||
| export default TimeDateInput; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,10 @@ | |
| display: inline-flex; | ||
| } | ||
|
|
||
| .timeRangeInputContainer :global(.ant-select) { | ||
| min-width: 150px; | ||
| } | ||
|
|
||
| /* Makes border flush with range picker */ | ||
| .customSelected :global(.ant-select-selector) { | ||
| border-top-right-radius: 0 !important; | ||
|
|
@@ -11,6 +15,5 @@ | |
| .rangePicker { | ||
| border-top-left-radius: 0; | ||
| border-bottom-left-radius: 0; | ||
| min-width: 200px; | ||
| max-width: 220px; | ||
| min-width: 350px; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Verify 350px min-width on smaller layouts Bumping the range picker 🤖 Prompt for AI Agents |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -122,11 +122,83 @@ const isValidDateRange = ( | |
| return null !== dates && null !== dates[0] && null !== dates[1]; | ||
| }; | ||
|
|
||
| /** | ||
| * AntD date range position. | ||
| */ | ||
| enum DATE_RANGE_POSITION { | ||
| START = "start", | ||
| END = "end", | ||
| } | ||
|
|
||
| /** | ||
| * AntD RangePicker prop key for date range position. | ||
| */ | ||
| const DATE_RANGE_PROP_KEY = "date-range"; | ||
|
|
||
| /** | ||
| * Map of time range options to their display text | ||
| */ | ||
| const TIME_RANGE_DISPLAY_TEXT_MAP: Record< | ||
| TIME_RANGE_OPTION, | ||
| Record<DATE_RANGE_POSITION, string> | ||
| > = { | ||
| [TIME_RANGE_OPTION.LAST_15_MINUTES]: { | ||
| [DATE_RANGE_POSITION.START]: "15 minutes ago", | ||
| [DATE_RANGE_POSITION.END]: "Now", | ||
| }, | ||
| [TIME_RANGE_OPTION.LAST_HOUR]: { | ||
| [DATE_RANGE_POSITION.START]: "1 hour ago", | ||
| [DATE_RANGE_POSITION.END]: "Now", | ||
| }, | ||
| [TIME_RANGE_OPTION.TODAY]: { | ||
| [DATE_RANGE_POSITION.START]: "Start of today", | ||
| [DATE_RANGE_POSITION.END]: "End of today", | ||
| }, | ||
| [TIME_RANGE_OPTION.YESTERDAY]: { | ||
| [DATE_RANGE_POSITION.START]: "Start of yesterday", | ||
| [DATE_RANGE_POSITION.END]: "End of yesterday", | ||
| }, | ||
| [TIME_RANGE_OPTION.LAST_7_DAYS]: { | ||
| [DATE_RANGE_POSITION.START]: "7 days ago", | ||
| [DATE_RANGE_POSITION.END]: "Now", | ||
| }, | ||
| [TIME_RANGE_OPTION.LAST_30_DAYS]: { | ||
| [DATE_RANGE_POSITION.START]: "30 days ago", | ||
| [DATE_RANGE_POSITION.END]: "Now", | ||
| }, | ||
| [TIME_RANGE_OPTION.LAST_12_MONTHS]: { | ||
| [DATE_RANGE_POSITION.START]: "12 months ago", | ||
| [DATE_RANGE_POSITION.END]: "Now", | ||
| }, | ||
| [TIME_RANGE_OPTION.MONTH_TO_DATE]: { | ||
| [DATE_RANGE_POSITION.START]: "Start of month", | ||
| [DATE_RANGE_POSITION.END]: "Now", | ||
| }, | ||
| [TIME_RANGE_OPTION.YEAR_TO_DATE]: { | ||
| [DATE_RANGE_POSITION.START]: "Start of year", | ||
| [DATE_RANGE_POSITION.END]: "Now", | ||
| }, | ||
| [TIME_RANGE_OPTION.ALL_TIME]: { | ||
| [DATE_RANGE_POSITION.START]: "First timestamp", | ||
| [DATE_RANGE_POSITION.END]: "Last timestamp", | ||
| }, | ||
|
|
||
| // Custom option is just a placeholder for typing purposes, its values should not | ||
| // be used. | ||
| [TIME_RANGE_OPTION.CUSTOM]: { | ||
| [DATE_RANGE_POSITION.START]: "Start date", | ||
| [DATE_RANGE_POSITION.END]: "End date", | ||
| }, | ||
| }; | ||
|
Comment on lines
+125
to
+192
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Display text mapping is consistent and well-typed The DATE_RANGE_POSITION enum, DATE_RANGE_PROP_KEY, and TIME_RANGE_DISPLAY_TEXT_MAP are cleanly modelled: every TIME_RANGE_OPTION is covered, and the nested Record keeps START/END text in sync with the logical ranges (e.g., “7 days ago”/“Now”). This should make the UI text easy to maintain. Consider adding a small unit test tying TIME_RANGE_DISPLAY_TEXT_MAP to TIME_RANGE_OPTION_DAYJS_MAP so future edits do not drift in meaning. Also applies to: 195-205 🤖 Prompt for AI Agents |
||
|
|
||
|
|
||
| export { | ||
| DATE_RANGE_POSITION, | ||
| DATE_RANGE_PROP_KEY, | ||
| DEFAULT_TIME_RANGE, | ||
| DEFAULT_TIME_RANGE_OPTION, | ||
| isValidDateRange, | ||
| TIME_RANGE_DISPLAY_TEXT_MAP, | ||
| TIME_RANGE_OPTION, | ||
| TIME_RANGE_OPTION_DAYJS_MAP, | ||
| TIME_RANGE_OPTION_NAMES, | ||
|
|
||
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.
this style isn't actually used?
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.
its used. It forces the size of the select for timestamp presets