Skip to content

Commit

Permalink
JNG-5993 fix card filter lifecycle, add missing translations
Browse files Browse the repository at this point in the history
  • Loading branch information
noherczeg committed Nov 17, 2024
1 parent f9bac01 commit 95e4962
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@
"judo.component.TrinaryLogic.unknown": "Unknown",
"judo.component.TrinaryLogic.true": "Yes",
"judo.component.TrinaryLogic.false": "No",
"judo.component.CardsContainer.Filter.filter": "Filter",
"judo.component.CardsContainer.Filter.clearAll": "Filter",
"judo.component.Table.error.remove": "Could not remove element!",
"judo.component.Table.error.add": "Could not add element!",
"judo.component.Table.error.clear": "Could not clear table!",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@
"judo.component.TrinaryLogic.unknown": "Unknown",
"judo.component.TrinaryLogic.true": "Yes",
"judo.component.TrinaryLogic.false": "No",
"judo.component.CardsContainer.Filter.filter": "Filter",
"judo.component.CardsContainer.Filter.clearAll": "Filter",
"judo.component.Table.error.remove": "Could not remove element!",
"judo.component.Table.error.add": "Could not add element!",
"judo.component.Table.error.clear": "Could not clear table!",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@
"judo.component.TrinaryLogic.unknown": "Ismeretlen",
"judo.component.TrinaryLogic.true": "Igen",
"judo.component.TrinaryLogic.false": "Nem",
"judo.component.CardsContainer.Filter.filter": "Szűrő",
"judo.component.CardsContainer.Filter.clearAll": "Az összes törlése",
"judo.component.Table.error.remove": "Nem sikerült eltávolítani a kiválasztott elemet!",
"judo.component.Table.error.add": "Nem sikerült hozzáadni a kiválasztott elemet!",
"judo.component.Table.error.claer": "Nem sikerült kiüríteni a táblát!",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { useTranslation } from 'react-i18next';

export interface CardsFilterDefinition<T> {
type: FilterType;
operator?: any;
field: keyof T;
label: string;
values: { value: any, label: string }[];
Expand All @@ -31,20 +32,28 @@ export const CardsFilter: FC<{ filterDefinitions: CardsFilterDefinition<any>[],
};
setValues(newValues);
onFiltersChanged?.(newValues);
}, [values]);
}, [values, onFiltersChanged]);

const clearFilters = useCallback(() => {
setValues({});
onFiltersChanged?.({});
// We need to explicitly null out values because our filter may refer to Transfer fields which are not in the list
// of columns. Other framework features rely on column info for e.g. queryCustomizer cleanup.
const newValues: Record<string, any> = {};
for (const key in values) {
newValues[key] = null;
}
setValues(newValues);
onFiltersChanged?.(newValues);
}, [values]);

return (
<Grid container direction="row" spacing={2}>
<Grid item xs={12}>
<Typography variant="h4">
Filters
{t('judo.component.CardsContainer.Filter.filter', { defaultValue: 'Filter' })}
</Typography>
<Button variant={'text'} onClick={clearFilters} >Clear all</Button>
<Button variant={'text'} onClick={clearFilters}>
{t('judo.component.CardsContainer.Filter.clearAll', { defaultValue: 'Filter' })}
</Button>
</Grid>
{filterDefinitions.map(d => (
<Grid item xs={12} key={d.field as string}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ export function mapCardsFiltersToFilters<T>(cardsFilters: CardsFilterDefinition<
},
filterBy: {
value: values[key],
operator: def.type === FilterType.boolean ? _BooleanOperation.equals : _StringOperation.equal,
operator: def.operator ? def.operator : (def.type === FilterType.boolean ? _BooleanOperation.equals : _StringOperation.equal),
},
});
}
Expand Down

0 comments on commit 95e4962

Please sign in to comment.