Skip to content
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

Show if dag page filters are active #38080

Merged
merged 4 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
72 changes: 58 additions & 14 deletions airflow/www/static/js/dag/nav/FilterBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,18 @@ declare const filtersOptions: {
taskStates: TaskState[];
};

const now = new Date();

const FilterBar = () => {
const {
filters,
filters: {
baseDate,
numRuns,
runState,
runStateOptions,
runType,
runTypeOptions,
},
onBaseDateChange,
onNumRunsChange,
onRunTypeChange,
Expand All @@ -49,9 +58,16 @@ const FilterBar = () => {
transformArrayToMultiSelectOptions,
} = useFilters();

// @ts-ignore
const isBaseDateDefault = moment(now).isSame(baseDate, "minute");
const isRunStateDefault = !runState || !runState.length;
const isRunTypeDefault = !runType || !runType.length;
const areFiltersDefault =
isBaseDateDefault && isRunTypeDefault && isRunStateDefault;

const { timezone } = useTimezone();
// @ts-ignore
const time = moment(filters.baseDate);
const time = moment(baseDate);
// @ts-ignore
const formattedTime = time.tz(timezone).format(isoFormatWithoutTZ);

Expand All @@ -61,17 +77,45 @@ const FilterBar = () => {
};

const multiSelectBoxStyle = { minWidth: "160px", zIndex: 3 };
const multiSelectStyles = useChakraSelectProps({
...inputStyles,

const multiSelectStyles: Record<string, any> = {
size: "lg",
isMulti: true,
tagVariant: "solid",
hideSelectedOptions: false,
isClearable: false,
selectedOptionStyle: "check",
};

const filteredStyles = {
borderColor: "blue.400",
borderWidth: 2,
};

const runTypeStyles = useChakraSelectProps({
...multiSelectStyles,
chakraStyles: {
control: (provided) => ({
...provided,
bg: "white",
...(isRunTypeDefault ? {} : filteredStyles),
_hover: {
...(isRunTypeDefault ? {} : filteredStyles),
},
}),
},
});

const runStateStyles = useChakraSelectProps({
...multiSelectStyles,
chakraStyles: {
container: (provided) => ({
control: (provided) => ({
...provided,
bg: "white",
...(isRunStateDefault ? {} : filteredStyles),
_hover: {
...(isRunStateDefault ? {} : filteredStyles),
},
}),
},
});
Expand All @@ -90,13 +134,14 @@ const FilterBar = () => {
type="datetime-local"
value={formattedTime || ""}
onChange={(e) => onBaseDateChange(e.target.value)}
{...(isBaseDateDefault ? {} : filteredStyles)}
/>
</Box>
<Box px={2}>
<Select
{...inputStyles}
placeholder="Runs"
value={filters.numRuns || ""}
value={numRuns || ""}
onChange={(e) => onNumRunsChange(e.target.value)}
>
{filtersOptions.numRuns.map((value) => (
Expand All @@ -108,8 +153,8 @@ const FilterBar = () => {
</Box>
<Box px={2} style={multiSelectBoxStyle}>
<MultiSelect
{...multiSelectStyles}
value={transformArrayToMultiSelectOptions(filters.runType)}
{...runTypeStyles}
value={transformArrayToMultiSelectOptions(runType)}
onChange={(typeOptions) => {
if (
Array.isArray(typeOptions) &&
Expand All @@ -120,15 +165,15 @@ const FilterBar = () => {
);
}
}}
options={transformArrayToMultiSelectOptions(filters.runTypeOptions)}
options={transformArrayToMultiSelectOptions(runTypeOptions)}
placeholder="All Run Types"
/>
</Box>
<Box />
<Box px={2} style={multiSelectBoxStyle}>
<MultiSelect
{...multiSelectStyles}
value={transformArrayToMultiSelectOptions(filters.runState)}
{...runStateStyles}
value={transformArrayToMultiSelectOptions(runState)}
onChange={(stateOptions) => {
if (
Array.isArray(stateOptions) &&
Expand All @@ -139,9 +184,7 @@ const FilterBar = () => {
);
}
}}
options={transformArrayToMultiSelectOptions(
filters.runStateOptions
)}
options={transformArrayToMultiSelectOptions(runStateOptions)}
placeholder="All Run States"
/>
</Box>
Expand All @@ -152,6 +195,7 @@ const FilterBar = () => {
background="white"
variant="outline"
onClick={clearFilters}
disabled={areFiltersDefault}
bbovenzi marked this conversation as resolved.
Show resolved Hide resolved
size="lg"
>
Clear Filters
Expand Down
1 change: 0 additions & 1 deletion airflow/www/static/js/dag/useFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ const useFilters = (): FilterHookReturn => {

const clearFilters = () => {
searchParams.delete(BASE_DATE_PARAM);
searchParams.delete(NUM_RUNS_PARAM);
searchParams.delete(RUN_TYPE_PARAM);
searchParams.delete(RUN_STATE_PARAM);
setSearchParams(searchParams);
Expand Down