Skip to content

Commit

Permalink
JNG-5888 filter context
Browse files Browse the repository at this point in the history
  • Loading branch information
noherczeg committed Aug 23, 2024
1 parent 0f43d84 commit d382513
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -536,12 +536,6 @@ export function EagerTable<T extends GridValidRowModel, TStored extends T, S ext
items: [...filterModel.items, mapFilterToFilterModel(filter)],
});
}}
onExcludeByCell={(filter: Filter) => {
handleFilterModelChange({
...filterModel,
items: [...filterModel.items, mapFilterToFilterModel(filter)],
});
}}
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -731,12 +731,6 @@ export function LazyTable<T extends GridValidRowModel, TStored extends T, S exte
items: [...filterModel.items, mapFilterToFilterModel(filter)],
});
}}
onExcludeByCell={(filter: Filter) => {
handleFilterModelChange({
...filterModel,
items: [...filterModel.items, mapFilterToFilterModel(filter)],
});
}}
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@
"judo.modal.filter.apply": "Apply",
"judo.modal.filter.clear-all": "Clear all",
"judo.modal.filter.operation": "Operation",
"judo.modal.filter.lessThan": "Less than",
"judo.modal.filter.greaterThan": "Greater than",
"judo.modal.filter.lessOrEqual": "Less or equal",
"judo.modal.filter.greaterOrEqual": "Greater or equal",
"judo.modal.filter.equal": "Equal",
"judo.modal.filter.notEqual": "Not equal",
"judo.modal.filter.matches": "Matches",
"judo.modal.filter.like": "Like",
"judo.modal.filter.equals": "Equals",
"judo.modal.filter.notEquals": "Not equals",
"judo.modal.filter.isNotEmpty": "Is not empty",
"judo.modal.filter.isEmpty": "Is empty",
"judo.modal.confirm.confirm": "Yes",
"judo.modal.confirm.cancel": "No",
"judo.modal.confirm.confirm-title": "Confirm action",
Expand Down Expand Up @@ -111,20 +123,10 @@
"judo.component.Table.ContextMenu.copyText": "Copy text",
"judo.component.Table.ContextMenu.filterBy": "Filter based on the selected value",
"judo.component.Table.ContextMenu.excludeBy": "Exclude based on the selected value",
"judo.component.Table.ContextMenu.filterByEmpty": "Filter by empty values",
"judo.component.Table.ContextMenu.filterByNonEmpty": "Filter by non-empty values",
"judo.applications.available_applications": "Available applications",
"judo.applications.change": "Switch Application",
"judo.modal.filter.lessThan": "Less than",
"judo.modal.filter.greaterThan": "Greater than",
"judo.modal.filter.lessOrEqual": "Less or equal",
"judo.modal.filter.greaterOrEqual": "Greater or equal",
"judo.modal.filter.equal": "Equal",
"judo.modal.filter.notEqual": "Not equal",
"judo.modal.filter.matches": "Matches",
"judo.modal.filter.like": "Like",
"judo.modal.filter.equals": "Equals",
"judo.modal.filter.notEquals": "Not equals",
"judo.modal.filter.isDefined": "Is defined",
"judo.modal.filter.isUndefined": "Is undefined",
"judo.error.error": "Error",
"judo.error.unhandled": "An unhandled error occurred.",
"judo.error.unmappable": "An error occurred, but we could not display the error info.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@
"judo.modal.filter.apply": "Apply",
"judo.modal.filter.clear-all": "Clear all",
"judo.modal.filter.operation": "Operation",
"judo.modal.filter.lessThan": "Less than",
"judo.modal.filter.greaterThan": "Greater than",
"judo.modal.filter.lessOrEqual": "Less or equal",
"judo.modal.filter.greaterOrEqual": "Greater or equal",
"judo.modal.filter.equal": "Equal",
"judo.modal.filter.notEqual": "Not equal",
"judo.modal.filter.matches": "Matches",
"judo.modal.filter.like": "Like",
"judo.modal.filter.equals": "Equals",
"judo.modal.filter.notEquals": "Not equals",
"judo.modal.filter.isNotEmpty": "Is not empty",
"judo.modal.filter.isEmpty": "Is empty",
"judo.modal.confirm.confirm": "Yes",
"judo.modal.confirm.cancel": "No",
"judo.modal.confirm.confirm-title": "Confirm action",
Expand Down Expand Up @@ -111,20 +123,10 @@
"judo.component.Table.ContextMenu.copyText": "Copy text",
"judo.component.Table.ContextMenu.filterBy": "Filter based on the selected value",
"judo.component.Table.ContextMenu.excludeBy": "Exclude based on the selected value",
"judo.component.Table.ContextMenu.filterByEmpty": "Filter by empty values",
"judo.component.Table.ContextMenu.filterByNonEmpty": "Filter by non-empty values",
"judo.applications.available_applications": "Available applications",
"judo.applications.change": "Switch Application",
"judo.modal.filter.lessThan": "Less than",
"judo.modal.filter.greaterThan": "Greater than",
"judo.modal.filter.lessOrEqual": "Less or equal",
"judo.modal.filter.greaterOrEqual": "Greater or equal",
"judo.modal.filter.equal": "Equal",
"judo.modal.filter.notEqual": "Not equal",
"judo.modal.filter.matches": "Matches",
"judo.modal.filter.like": "Like",
"judo.modal.filter.equals": "Equals",
"judo.modal.filter.notEquals": "Not equals",
"judo.modal.filter.isDefined": "Is defined",
"judo.modal.filter.isUndefined": "Is undefined",
"judo.error.error": "Error",
"judo.error.unhandled": "An unhandled error occurred.",
"judo.error.unmappable": "An error occurred, but we could not display the error info.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@
"judo.modal.filter.like": "Tartalmazza",
"judo.modal.filter.equals": "Egyenlő",
"judo.modal.filter.notEquals": "Nem egyenlő",
"judo.modal.filter.isDefined": "Létezik",
"judo.modal.filter.isUndefined": "Nem létezik",
"judo.modal.filter.isNotEmpty": "Létezik",
"judo.modal.filter.isEmpty": "Nem létezik",
"judo.modal.confirm.confirm": "Igen",
"judo.modal.confirm.cancel": "Nem",
"judo.modal.confirm.confirm-title": "Megerősítés szükséges",
Expand Down Expand Up @@ -123,6 +123,8 @@
"judo.component.Table.ContextMenu.copyText": "Szöveg másolása",
"judo.component.Table.ContextMenu.filterBy": "Szűrés a kiválasztott érték alapján",
"judo.component.Table.ContextMenu.excludeBy": "Kizárás a kiválasztott érték alapján",
"judo.component.Table.ContextMenu.filterByEmpty": "Szűrés üres mezőre",
"judo.component.Table.ContextMenu.filterByNonEmpty": "Szűrés nem üres mezőre",
"judo.applications.available_applications": "Választható alkalmazások",
"judo.applications.change": "Alkalmazás váltás",
"judo.error.error": "Hiba",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export interface ContextMenuProps<T, P extends JudoStored<T>> {
filterOptions: FilterOption[];
data: P[];
onFilterByCell: (filter: Filter) => void;
onExcludeByCell: (filter: Filter) => void;
}

export interface ContextMenuApi {
Expand All @@ -25,7 +24,7 @@ export interface ContextMenuApi {

export const ContextMenu = forwardRef<ContextMenuApi, ContextMenuProps<any, any>>(<T, P extends JudoStored<T>>(props: ContextMenuProps<T, P>, ref: ForwardedRef<ContextMenuApi>) => {
const { t } = useTranslation();
const { filters, data, onFilterByCell, onExcludeByCell, filterOptions, columns } = props;
const { filters, data, onFilterByCell, filterOptions, columns } = props;
const [selectedColumn, setSelectedColumn] = useState<GridColDef<P> | undefined>();
const [selectedRow, setSelectedRow] = useState<string | undefined>();
const [selectedRowData, setSelectedRowData] = useState<P | undefined>();
Expand Down Expand Up @@ -114,7 +113,7 @@ export const ContextMenu = forwardRef<ContextMenuApi, ContextMenuProps<any, any>
const filterOption = filterOptions.find((f) => f.attributeName === field)!;
const filterType: FilterType = filterOption.filterType;

onExcludeByCell({
onFilterByCell({
valueId: `${field as string}-value-${new Date().toISOString()}`,
operationId: `${field as string}-operation-${new Date().toISOString()}`,
id: field as string,
Expand All @@ -141,6 +140,61 @@ export const ContextMenu = forwardRef<ContextMenuApi, ContextMenuProps<any, any>
closeContextMenu();
};

const filterByEmpty = () => {
if (field) {
const filterOption = filterOptions.find((f) => f.attributeName === field)!;
const filterType: FilterType = filterOption.filterType;
onFilterByCell({
valueId: `${field as string}-value-${new Date().toISOString()}`,
operationId: `${field as string}-operation-${new Date().toISOString()}`,
id: field as string,
filterOption: {
id: `${field as string}-option-${new Date().toISOString()}`,
attributeName: field as string,
filterType: filterType,
...(filterType === FilterType.enumeration
? {
enumValues: filterOption.enumValues,
}
: {}),
},
filterBy: {
value: null,
operator: 'isEmpty' as Operation,
},
});
}
closeContextMenu();
};

const filterByNonEmpty = () => {
if (field) {
const filterOption = filterOptions.find((f) => f.attributeName === field)!;
const filterType: FilterType = filterOption.filterType;

onFilterByCell({
valueId: `${field as string}-value-${new Date().toISOString()}`,
operationId: `${field as string}-operation-${new Date().toISOString()}`,
id: field as string,
filterOption: {
id: `${field as string}-option-${new Date().toISOString()}`,
attributeName: field as string,
filterType: filterType,
...(filterType === FilterType.enumeration
? {
enumValues: filterOption.enumValues,
}
: {}),
},
filterBy: {
value: null,
operator: 'isNotEmpty' as Operation,
},
});
}
closeContextMenu();
};

return (
<Menu
open={contextMenu !== null}
Expand Down Expand Up @@ -175,6 +229,18 @@ export const ContextMenu = forwardRef<ContextMenuApi, ContextMenuProps<any, any>
{t('judo.component.Table.ContextMenu.excludeBy', { defaultValue: 'Exclude based on the selected value', columnName: selectedColumn?.headerName, field: field, value: selectedValue }) as string}
</Typography>
</MenuItem>)}
<MenuItem onClick={filterByEmpty}>
<MdiIcon path="file-hidden" sx={ { mr: 1 } } />
<Typography variant="inherit">
{t('judo.component.Table.ContextMenu.filterByEmpty', { defaultValue: 'Filter by empty values', columnName: selectedColumn?.headerName, field: field, value: selectedValue }) as string}
</Typography>
</MenuItem>
<MenuItem onClick={filterByNonEmpty}>
<MdiIcon path="file-document-outline" sx={ { mr: 1 } } />
<Typography variant="inherit">
{t('judo.component.Table.ContextMenu.filterByNonEmpty', { defaultValue: 'Filter by non-empty values', columnName: selectedColumn?.headerName, field: field, value: selectedValue }) as string}
</Typography>
</MenuItem>
</Menu>
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -565,16 +565,6 @@ export function EagerTable<T extends GridValidRowModel, TStored extends T, S ext
handleFiltersChange([...filters, filter]);
{{/ if }}
} }
onExcludeByCell={ (filter: Filter) => {
{{# if isUseInlineColumnFilters }}
handleFilterModelChange({
...filterModel,
items: [...filterModel.items, mapFilterToFilterModel(filter)],
});
{{ else }}
handleFiltersChange([...filters, filter]);
{{/ if }}
} }
/>
{{/ if }}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -739,16 +739,6 @@ export function LazyTable<T extends GridValidRowModel, TStored extends T, S exte
handleFiltersChange([...filters, filter]);
{{/ if }}
} }
onExcludeByCell={ (filter: Filter) => {
{{# if isUseInlineColumnFilters }}
handleFilterModelChange({
...filterModel,
items: [...filterModel.items, mapFilterToFilterModel(filter)],
});
{{ else }}
handleFiltersChange([...filters, filter]);
{{/ if }}
} }
/>
{{/ if }}
</>
Expand Down
Loading

0 comments on commit d382513

Please sign in to comment.