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
Changes from 2 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
85 changes: 71 additions & 14 deletions airflow/www/static/js/dag/nav/FilterBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,30 @@ import { useTimezone } from "src/context/timezone";
import { isoFormatWithoutTZ } from "src/datetime_utils";
import useFilters from "src/dag/useFilters";

declare const defaultDagRunDisplayNumber: number;

declare const filtersOptions: {
dagStates: RunState[];
numRuns: number[];
runTypes: DagRun["runType"][];
taskStates: TaskState[];
};

const now = new Date();

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

// @ts-ignore
const isBaseDateDefault = moment(now).isSame(baseDate, "minute");
const isNumRunsDefault = numRuns === defaultDagRunDisplayNumber.toString();
const isRunStateDefault = !runState || !runState.length;
const isRunTypeDefault = !runType || !runType.length;
const areFiltersDefault =
isBaseDateDefault &&
isNumRunsDefault &&
bbovenzi marked this conversation as resolved.
Show resolved Hide resolved
!root &&
!filterUpstream &&
!filterDownstream &&
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 +89,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,14 +146,16 @@ 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)}
{...(isNumRunsDefault ? {} : filteredStyles)}
>
{filtersOptions.numRuns.map((value) => (
<option value={value} key={value}>
Expand All @@ -108,8 +166,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 +178,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 +197,7 @@ const FilterBar = () => {
);
}
}}
options={transformArrayToMultiSelectOptions(
filters.runStateOptions
)}
options={transformArrayToMultiSelectOptions(runStateOptions)}
placeholder="All Run States"
/>
</Box>
Expand All @@ -152,6 +208,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