Repository navigation
Fix date range filter updating on each keystroke #69955
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -39,6 +39,7 @@ export const DateRangeFilter = ({ filter, onChange, onRemove }: FilterPluginProp | |
| const hasValue = isValidFilterValue(filter.config.type, filter.value); | ||
|
|
||
| const { | ||
| applyDateRange, | ||
| editingState, | ||
| endDateValue, | ||
| formatDisplayValue, | ||
|
|
@@ -64,6 +65,12 @@ export const DateRangeFilter = ({ filter, onChange, onRemove }: FilterPluginProp | |
| defaultOpen={!hasValue} | ||
| key={filter.id} | ||
| lazyMount | ||
| onOpenChange={(details) => { | ||
| if (!details.open) { | ||
| // Submit the current editing state when the popover closes | ||
| applyDateRange(); | ||
| } | ||
| }} | ||
|
Comment on lines
+68
to
+73
Member
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. applyDateRange fires on every popover close. (Even when no edit has been done, a cheap check on the value could prevent this) |
||
| positioning={{ placement: "bottom-start" }} | ||
| unmountOnExit | ||
| > | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -260,20 +260,6 @@ export const useDateRangeFilter = ({ onChange, translate, value }: UseDateRangeF | |
| const newInputs = { ...prev.inputs, [inputKey]: inputValue }; | ||
| const validationErrors = validateInputs(newInputs); | ||
|
|
||
| const dateStr = field === "start" ? newInputs.start : newInputs.end; | ||
| const timeStr = field === "start" ? newInputs.startTime : newInputs.endTime; | ||
|
|
||
| if (dayjs(dateStr, DATE_INPUT_FORMAT, true).isValid()) { | ||
| const combinedDateTime = combineDateAndTime(dateStr, timeStr, selectedTimezone); | ||
|
|
||
| if (Boolean(combinedDateTime)) { | ||
| onChange({ | ||
| ...value, | ||
| [field === "start" ? "startDate" : "endDate"]: combinedDateTime, | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| ...prev, | ||
| inputs: newInputs, | ||
|
|
@@ -318,7 +304,31 @@ export const useDateRangeFilter = ({ onChange, translate, value }: UseDateRangeF | |
|
|
||
| const hasValidationErrors = editingState.validationErrors.length > 0; | ||
|
|
||
| const applyDateRange = () => { | ||
| const { inputs } = editingState; | ||
| const errors = validateInputs(inputs); | ||
|
|
||
| // Don't apply if there are validation errors | ||
| if (errors.length > 0) { | ||
| return; | ||
|
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. Can we double check that this return doesn't close the dateinput when there is an error? |
||
| } | ||
|
|
||
| const startDateTime = inputs.start | ||
| ? combineDateAndTime(inputs.start, inputs.startTime, selectedTimezone) | ||
| : undefined; | ||
| const endDateTime = inputs.end | ||
| ? combineDateAndTime(inputs.end, inputs.endTime, selectedTimezone) | ||
| : undefined; | ||
|
|
||
| onChange({ | ||
| ...value, | ||
| endDate: endDateTime, | ||
| startDate: startDateTime, | ||
| }); | ||
| }; | ||
|
|
||
| return { | ||
| applyDateRange, | ||
| editingState, | ||
| endDateValue, | ||
| formatDisplayValue, | ||
|
|
||
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 prop seems like dead code, it's never passed.