Skip to content

Commit

Permalink
JNG-3980 filter empty values (#449)
Browse files Browse the repository at this point in the history
  • Loading branch information
noherczeg authored Aug 22, 2024
1 parent f812018 commit bb8390d
Show file tree
Hide file tree
Showing 11 changed files with 198 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,10 @@ export function EagerTable<T extends GridValidRowModel, TStored extends T, S ext
setFilterModel(newModel);
setItemStringified(filterModelKey, newModel);

if (newModel.items.every((i: any) => i.value !== undefined)) {
const newFilters: Filter[] = mapFilterModelToFilters(newModel, filterOptions);
const newFilters: Filter[] = mapFilterModelToFilters(newModel, filterOptions);

if (Array.isArray(newFilters)) {
handleFiltersChange(newFilters);
}
if (Array.isArray(newFilters)) {
handleFiltersChange(newFilters);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,10 @@ export function LazyTable<T extends GridValidRowModel, TStored extends T, S exte
setFilterModel(newModel);
setItemStringified(filterModelKey, newModel);

if (newModel.items.every((i: any) => i.value !== undefined)) {
const newFilters: Filter[] = mapFilterModelToFilters(newModel, filterOptions);
const newFilters: Filter[] = mapFilterModelToFilters(newModel, filterOptions);

if (Array.isArray(newFilters)) {
handleFiltersChange(newFilters);
}
if (Array.isArray(newFilters)) {
handleFiltersChange(newFilters);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,18 @@
"judo.component.Table.ContextMenu.excludeBy": "Exclude based on the selected value",
"judo.applications.available_applications": "Available applications",
"judo.applications.change": "Switch Application",
"judo.modal.filter.lessThan": "lessThan",
"judo.modal.filter.greaterThan": "greaterThan",
"judo.modal.filter.lessOrEqual": "lessOrEqual",
"judo.modal.filter.greaterOrEqual": "greaterOrEqual",
"judo.modal.filter.equal": "equal",
"judo.modal.filter.notEqual": "notEqual",
"judo.modal.filter.matches": "matches",
"judo.modal.filter.like": "like",
"judo.modal.filter.equals": "equals",
"judo.modal.filter.notEquals": "notEquals",
"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 @@ -113,16 +113,18 @@
"judo.component.Table.ContextMenu.excludeBy": "Exclude based on the selected value",
"judo.applications.available_applications": "Available applications",
"judo.applications.change": "Switch Application",
"judo.modal.filter.lessThan": "lessThan",
"judo.modal.filter.greaterThan": "greaterThan",
"judo.modal.filter.lessOrEqual": "lessOrEqual",
"judo.modal.filter.greaterOrEqual": "greaterOrEqual",
"judo.modal.filter.equal": "equal",
"judo.modal.filter.notEqual": "notEqual",
"judo.modal.filter.matches": "matches",
"judo.modal.filter.like": "like",
"judo.modal.filter.equals": "equals",
"judo.modal.filter.notEquals": "notEquals",
"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,6 +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.confirm.confirm": "Igen",
"judo.modal.confirm.cancel": "Nem",
"judo.modal.confirm.confirm-title": "Megerősítés szükséges",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,76 +30,12 @@ import type {
Operation,
} from '../../components-api';
import { FilterType } from '../../components-api';
import { exists } from '../../utilities';
import { exists, getOperationEnumValue, getOperatorsByFilter, getDefaultOperator, isFilterWithoutValue } from '../../utilities';
import { mainContainerPadding } from '../../theme';
import { _BooleanOperation, _EnumerationOperation, _NumericOperation, _StringOperation } from '~/services/data-api/common/operations';
import { DropdownButton } from '../DropdownButton';
import { TrinaryLogicCombobox } from '../widgets/TrinaryLogicCombobox';
import { MdiIcon } from '../MdiIcon';

const getDefaultOperator = (filterType: FilterType) => {
switch (filterType) {
case FilterType.boolean:
return _BooleanOperation['equals'];
case FilterType.date:
return _NumericOperation['equal'];
case FilterType.dateTime:
return _NumericOperation['equal'];
// case FilterType.time:
// return _NumericOperation['equal'];
case FilterType.enumeration:
return _EnumerationOperation['equals'];
case FilterType.numeric:
return _NumericOperation['equal'];
case FilterType.string:
return _StringOperation['like'];
case FilterType.trinaryLogic:
return _BooleanOperation['equals'];
}
};

const getOperationEnumValue = (filter: Filter, operator: string) => {
switch (filter.filterOption.filterType) {
case FilterType.boolean:
return _BooleanOperation[operator as keyof typeof _BooleanOperation];
case FilterType.date:
return _NumericOperation[operator as keyof typeof _NumericOperation];
case FilterType.dateTime:
return _NumericOperation[operator as keyof typeof _NumericOperation];
// case FilterType.time:
// return _NumericOperation[operator as keyof typeof _NumericOperation];
case FilterType.enumeration:
return _EnumerationOperation[operator as keyof typeof _BooleanOperation];
case FilterType.numeric:
return _NumericOperation[operator as keyof typeof _NumericOperation];
case FilterType.string:
return _StringOperation[operator as keyof typeof _StringOperation];
case FilterType.trinaryLogic:
return _BooleanOperation[operator as keyof typeof _BooleanOperation];
}
};

const getOperatorsByFilter = (filter: Filter): string[] => {
switch (filter.filterOption.filterType) {
case FilterType.boolean:
return Object.values(_BooleanOperation);
case FilterType.date:
return Object.values(_NumericOperation);
case FilterType.dateTime:
return Object.values(_NumericOperation);
// case FilterType.time:
// return Object.values(_NumericOperation);
case FilterType.enumeration:
return Object.values(_EnumerationOperation);
case FilterType.numeric:
return Object.values(_NumericOperation);
case FilterType.string:
return Object.values(_StringOperation);
case FilterType.trinaryLogic:
return Object.values(_BooleanOperation);
}
};

const FilterOperator = ({ filter, operatorId, valueId, setFilterOperator }: FilterOperatorProps) => {
const { t } = useTranslation();

Expand All @@ -126,8 +62,6 @@ const FilterOperator = ({ filter, operatorId, valueId, setFilterOperator }: Filt
};

const FilterInput = ({ filter, setFilterValue, valueId }: FilterInputProps) => {
const { t } = useTranslation();

if (filter.filterOption.filterType === FilterType.enumeration && !exists(filter.filterOption.enumValues)) {
throw new Error(`Missing enumValues from FilterOptions of "${filter.filterOption.attributeName}"`);
}
Expand Down Expand Up @@ -280,7 +214,7 @@ const FilterRow = ({ id, filter, closeHandler, setFilterOperator, setFilterValue
{filter && <FilterOperator operatorId={`${id}-operator`} valueId={`${id}-value`} filter={filter} setFilterOperator={setFilterOperator} />}
</Grid>
<Grid item xs={7}>
{filter && <FilterInput operatorId={`${id}-operator`} valueId={`${id}-value`} filter={filter} setFilterValue={setFilterValue} />}
{filter && !isFilterWithoutValue(filter) && <FilterInput operatorId={`${id}-operator`} valueId={`${id}-value`} filter={filter} setFilterValue={setFilterValue} />}
</Grid>
<Grid item xs={1}>
<IconButton id={`${id}-close`} onClick={() => closeHandler(filter)}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,10 @@ export function EagerTable<T extends GridValidRowModel, TStored extends T, S ext
setFilterModel(newModel);
setItemStringified(filterModelKey, newModel);

if (newModel.items.every((i: any) => i.value !== undefined)) {
const newFilters: Filter[] = mapFilterModelToFilters(newModel, filterOptions);
const newFilters: Filter[] = mapFilterModelToFilters(newModel, filterOptions);

if (Array.isArray(newFilters)) {
handleFiltersChange(newFilters);
}
if (Array.isArray(newFilters)) {
handleFiltersChange(newFilters);
}
}
{{/ if }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,10 @@ export function LazyTable<T extends GridValidRowModel, TStored extends T, S exte
setFilterModel(newModel);
setItemStringified(filterModelKey, newModel);

if (newModel.items.every((i: any) => i.value !== undefined)) {
const newFilters: Filter[] = mapFilterModelToFilters(newModel, filterOptions);
const newFilters: Filter[] = mapFilterModelToFilters(newModel, filterOptions);

if (Array.isArray(newFilters)) {
handleFiltersChange(newFilters);
}
if (Array.isArray(newFilters)) {
handleFiltersChange(newFilters);
}
}
{{/ if }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,28 @@ import {
import type { GridFilterOperator } from '@mui/x-data-grid{{ getMUIDataGridPlanSuffix }}';

function filterStringColumnOperators(operator: GridFilterOperator): boolean {
// https://github.com/mui/mui-x/blob/master/packages/grid/x-data-grid/src/colDef/gridStringOperators.ts
// https://github.com/mui/mui-x/blob/master/packages/x-data-grid/src/colDef/gridStringOperators.ts
// startsWith and endsWith is filtered out because they'd need complex value mapping...
return !(['startsWith', 'endsWith', 'isEmpty', 'isNotEmpty', 'isAnyOf'].includes(operator.value));
return !(['startsWith', 'endsWith', 'isAnyOf'].includes(operator.value));
}

function filterNumericColumnOperators(operator: GridFilterOperator): boolean {
// https://github.com/mui/mui-x/blob/master/packages/grid/x-data-grid/src/colDef/gridNumericOperators.ts
return !(['isEmpty', 'isNotEmpty', 'isAnyOf'].includes(operator.value));
// https://github.com/mui/mui-x/blob/master/packages/x-data-grid/src/colDef/gridNumericOperators.ts
return !(['isAnyOf'].includes(operator.value));
}

function filterDateColumnOperators(operator: GridFilterOperator): boolean {
// https://github.com/mui/mui-x/blob/master/packages/grid/x-data-grid/src/colDef/gridDateOperators.ts
return !(['isEmpty', 'isNotEmpty'].includes(operator.value));
// https://github.com/mui/mui-x/blob/master/packages/x-data-grid/src/colDef/gridDateOperators.ts
return true;
}

function filterDateTimeColumnOperators(operator: GridFilterOperator): boolean {
// https://github.com/mui/mui-x/blob/master/packages/grid/x-data-grid/src/colDef/gridDateOperators.ts
return !['isEmpty', 'isNotEmpty'].includes(operator.value);
// https://github.com/mui/mui-x/blob/master/packages/x-data-grid/src/colDef/gridDateOperators.ts
return true;
}

function filterBooleanColumnOperators(operator: GridFilterOperator): boolean {
// https://github.com/mui/mui-x/blob/master/packages/grid/x-data-grid/src/colDef/gridBooleanOperators.ts
// https://github.com/mui/mui-x/blob/master/packages/x-data-grid/src/colDef/gridBooleanColDef.tsx
return true;
}

Expand Down
Loading

0 comments on commit bb8390d

Please sign in to comment.