Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type DateInputProps = {
readonly onClear: () => void;
readonly onDateBlur?: () => void;
readonly onFocus?: () => void;
readonly onKeyDown?: (event: React.KeyboardEvent) => void;
readonly placeholder: string;
};

Expand All @@ -51,6 +52,7 @@ export const DateInput = ({
onClear,
onDateBlur,
onFocus,
onKeyDown,

Copy link
Copy Markdown
Member

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.

placeholder,
}: DateInputProps) => {
const fieldName = inputType === "date" ? field : (`${field}Time` as const);
Expand All @@ -69,6 +71,7 @@ export const DateInput = ({
onBlur={onDateBlur}
onChange={handleInputChange(field, inputType)}
onFocus={onFocus}
onKeyDown={onKeyDown}
placeholder={placeholder}
value={inputValue}
w="full"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const DateRangeFilter = ({ filter, onChange, onRemove }: FilterPluginProp
const hasValue = isValidFilterValue(filter.config.type, filter.value);

const {
applyDateRange,
editingState,
endDateValue,
formatDisplayValue,
Expand All @@ -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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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
>
Expand Down
38 changes: 24 additions & 14 deletions airflow-core/src/airflow/ui/src/hooks/useDateRangeFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}

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,
Expand Down
Loading