From 222a578fbdb8658ec994488a7fc1d654ed8fc888 Mon Sep 17 00:00:00 2001 From: winzlieb Date: Thu, 17 Mar 2022 15:29:45 +0100 Subject: [PATCH] allow change of default operator in row definition --- .../search/components/config/defaultColumnRawDefinition.ts | 7 ++++++- frontend/search/components/ngo/HostOfferLookupTable.tsx | 6 +++--- frontend/search/components/util/datagrid/columnRaw.ts | 3 +++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/frontend/search/components/config/defaultColumnRawDefinition.ts b/frontend/search/components/config/defaultColumnRawDefinition.ts index 8d390b8..1adf503 100644 --- a/frontend/search/components/config/defaultColumnRawDefinition.ts +++ b/frontend/search/components/config/defaultColumnRawDefinition.ts @@ -37,7 +37,12 @@ const columnsRaw: ColumnRaw[] = [ "group": "distance", "header": "km", "type": "number", - "defaultWidth": 105 + "defaultWidth": 105, + "options": { + "filter": { + "operator": "lte" + } + } }, { "name": "place_country", diff --git a/frontend/search/components/ngo/HostOfferLookupTable.tsx b/frontend/search/components/ngo/HostOfferLookupTable.tsx index 9e1f4b1..fa79d6e 100644 --- a/frontend/search/components/ngo/HostOfferLookupTable.tsx +++ b/frontend/search/components/ngo/HostOfferLookupTable.tsx @@ -112,14 +112,14 @@ const columns: TypeColumn[] = defaultColumnRawDefinition editor: editorMappings[c.type as 'string' | 'number' | 'boolean' | 'date'] })) -const defaultFilterValue: TypeFilterValue = columns +const defaultFilterValue: TypeFilterValue = defaultColumnRawDefinition .filter(({type}) => type && ['string', 'number', 'boolean', 'date'].includes(type)) - .map(({name, type}) => { + .map(({name, type, options}) => { return { name, type, value: null, - operator: operatorsForType[type as 'string' | 'number' | 'date' | 'boolean'] + operator: options?.filter?.operator || operatorsForType[type as 'string' | 'number' | 'date' | 'boolean'] } as unknown as TypeSingleFilterValue }) diff --git a/frontend/search/components/util/datagrid/columnRaw.ts b/frontend/search/components/util/datagrid/columnRaw.ts index 2d25789..16ed0f1 100644 --- a/frontend/search/components/util/datagrid/columnRaw.ts +++ b/frontend/search/components/util/datagrid/columnRaw.ts @@ -2,6 +2,9 @@ import {Array2StringTransformOptions, DateToISOTransformOptions} from "../tableV export type ColumnOptions = { dateFormat?: string + filter?: { + operator?: string + } transform?: { array2string?: Array2StringTransformOptions date2Iso?: DateToISOTransformOptions