Skip to content

Commit 17644ec

Browse files
committed
[DOP-22530] Fix lineage & list filters messing with each other
1 parent dded2b3 commit 17644ec

File tree

3 files changed

+58
-12
lines changed

3 files changed

+58
-12
lines changed

src/components/lineage/LineageFilters.tsx

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ type LineageFilterValues = {
2727
granularity?: string;
2828
include_column_lineage?: boolean;
2929
};
30+
type LineageFilterKeys = keyof LineageFilterValues;
31+
const lineageFilterKeys: LineageFilterKeys[] = [
32+
"since",
33+
"until",
34+
"depth",
35+
"direction",
36+
"granularity",
37+
"include_column_lineage",
38+
];
3039

3140
type LineageFiltersProps = {
3241
onSubmit: (values: LineageFilterValues) => void;
@@ -76,10 +85,20 @@ const LineageFilters = ({
7685
granularities.includes(choice.id),
7786
);
7887

79-
const submit = form.handleSubmit((formValues: LineageFilterValues) => {
80-
listParamsActions.setFilters(formValues);
81-
onSubmit(formValues);
82-
});
88+
const submit = form.handleSubmit(
89+
(formValues: LineageFilterValues & { [key: string]: any }) => {
90+
const keys = Object.keys(formValues);
91+
const validKeys = lineageFilterKeys.filter((key) =>
92+
keys.includes(key),
93+
);
94+
const validValues = validKeys.reduce(
95+
(acc, key) => ({ ...acc, [key]: formValues[key] }),
96+
{},
97+
);
98+
listParamsActions.setFilters(validValues);
99+
onSubmit(validValues);
100+
},
101+
);
83102

84103
// draw lineage just after opening the page
85104
useEffect(() => {

src/components/operation/OperationRaListFilters.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,24 @@ type OperationRaListFilterValues = {
99
since?: string;
1010
until?: string;
1111
};
12+
type OperationRaListFilterKeys = keyof OperationRaListFilterValues;
13+
const filterKeys: OperationRaListFilterKeys[] = ["since", "until"];
1214

1315
const OperationRaListFilters = () => {
1416
const translate = useTranslate();
1517
const { filterValues, setFilters } = useListContext();
1618
const form = useForm({ defaultValues: filterValues });
1719

1820
const submit = form.handleSubmit(
19-
(formValues: OperationRaListFilterValues) => {
20-
if (Object.keys(formValues).length > 0) {
21-
setFilters(formValues);
21+
(formValues: OperationRaListFilterValues & { [key: string]: any }) => {
22+
const keys = Object.keys(formValues);
23+
const validKeys = filterKeys.filter((key) => keys.includes(key));
24+
if (validKeys.length > 0) {
25+
const validValues = validKeys.reduce(
26+
(acc, key) => ({ ...acc, [key]: formValues[key] }),
27+
{},
28+
);
29+
setFilters(validValues);
2230
}
2331
},
2432
);

src/components/run/RunRaListFilters.tsx

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,38 @@ const weekAgo = (): Date => {
1818
type RunRaListFilterValues = {
1919
since?: string;
2020
until?: string;
21+
status?: string;
22+
job_type?: string;
23+
started_by_user?: string;
2124
search_query?: string;
2225
};
26+
type RunRaListFilterKeys = keyof RunRaListFilterValues;
27+
const filterKeys: RunRaListFilterKeys[] = [
28+
"since",
29+
"until",
30+
"status",
31+
"job_type",
32+
"started_by_user",
33+
];
2334

2435
const RunRaListFilters = () => {
2536
const translate = useTranslate();
2637
const { filterValues, setFilters } = useListContext();
2738
const form = useForm({ defaultValues: filterValues });
2839

29-
const submit = form.handleSubmit((formValues: RunRaListFilterValues) => {
30-
if (Object.keys(formValues).length > 0) {
31-
setFilters(formValues);
32-
}
33-
});
40+
const submit = form.handleSubmit(
41+
(formValues: RunRaListFilterValues & { [key: string]: any }) => {
42+
const keys = Object.keys(formValues);
43+
const validKeys = filterKeys.filter((key) => keys.includes(key));
44+
if (validKeys.length > 0) {
45+
const validValues = validKeys.reduce(
46+
(acc, key) => ({ ...acc, [key]: formValues[key] }),
47+
{},
48+
);
49+
setFilters(validValues);
50+
}
51+
},
52+
);
3453

3554
// fill up filters just after opening the page
3655
useEffect(() => {

0 commit comments

Comments
 (0)