-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #506 from noi-techpark/fix-table-filter
Fix table filter
- Loading branch information
Showing
19 changed files
with
442 additions
and
481 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
databrowser/src/domain/datasets/ui/tableView/filter/builder/filterBuilder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// SPDX-FileCopyrightText: NOI Techpark <[email protected]> | ||
// | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
import { DatasetDomain } from '../../../../config/types'; | ||
import { BaseFilter } from '../types'; | ||
import { buildMobilityFilterValues } from './mobilityFilterBuilder'; | ||
import { buildTourismFilterValues } from './tourismFilterBuilder'; | ||
|
||
export const buildFilterValues = ( | ||
datasetDomain: DatasetDomain | undefined, | ||
updatedFilters: BaseFilter[] | ||
): string[] => { | ||
if (datasetDomain === 'tourism') { | ||
return buildTourismFilterValues(updatedFilters); | ||
} | ||
if (datasetDomain === 'mobility') { | ||
return buildMobilityFilterValues(updatedFilters); | ||
} | ||
console.debug( | ||
`Can not build filter values for unknown dataset domain "${datasetDomain}", returning empty list` | ||
); | ||
return []; | ||
}; | ||
|
||
export const buildFilterValuesString = ( | ||
datasetDomain: DatasetDomain | undefined, | ||
updatedFilters: BaseFilter[] | ||
): string | undefined => { | ||
const filterValues = buildFilterValues(datasetDomain, updatedFilters); | ||
return filterValues.length > 0 ? `and(${filterValues.join(',')})` : undefined; | ||
}; |
76 changes: 76 additions & 0 deletions
76
databrowser/src/domain/datasets/ui/tableView/filter/builder/mobilityFilterBuilder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// SPDX-FileCopyrightText: NOI Techpark <[email protected]> | ||
// | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
import { BaseFilter } from '../types'; | ||
|
||
export const buildMobilityFilterValues = (updatedFilters: BaseFilter[]) => | ||
updatedFilters.reduce<string[]>((prev, curr) => { | ||
if (curr.value === '' || curr.value == null) { | ||
return prev; | ||
} | ||
|
||
const value = toMobilityFilterValue(curr); | ||
|
||
if (value === '' || value == null) { | ||
return prev; | ||
} | ||
|
||
switch (curr.operator) { | ||
case 'eq': | ||
return [...prev, `${curr.propertyPath}.eq.${value}`]; | ||
case 'neq': | ||
return [...prev, `${curr.propertyPath}.neq.${value}`]; | ||
case 'gt': | ||
return [...prev, `${curr.propertyPath}.gt.${value}`]; | ||
case 'gteq': | ||
return [...prev, `${curr.propertyPath}.gteq.${value}`]; | ||
case 'lt': | ||
return [...prev, `${curr.propertyPath}.lt.${value}`]; | ||
case 'lteq': | ||
return [...prev, `${curr.propertyPath}.lteq.${value}`]; | ||
case 'in': | ||
return [...prev, `${curr.propertyPath}.in.(${value})`]; | ||
case 'nin': | ||
return [...prev, `${curr.propertyPath}.nin.(${value})`]; | ||
case 're': | ||
return [...prev, `${curr.propertyPath}.re.${value}`]; | ||
case 'ire': | ||
return [...prev, `${curr.propertyPath}.ire.${value}`]; | ||
case 'nre': | ||
return [...prev, `${curr.propertyPath}.nre.${value}`]; | ||
case 'nire': | ||
return [...prev, `${curr.propertyPath}.nire.${value}`]; | ||
case 'bbi': | ||
return [...prev, `${curr.propertyPath}.bbi.(${value})`]; | ||
case 'bbc': | ||
return [...prev, `${curr.propertyPath}.bbc.(${value})`]; | ||
default: | ||
return prev; | ||
} | ||
}, []); | ||
|
||
// We need to surround the filter value with double quotes only if it is a string. | ||
// If its a string, we need to further check if it can be converted to a number | ||
// or boolean. If so, no double quotes must be added. | ||
const toMobilityFilterValue = ({ operator, value }: BaseFilter) => { | ||
if (typeof value !== 'string') { | ||
return value; | ||
} | ||
|
||
const number = Number(value); | ||
if (!isNaN(number)) { | ||
return number; | ||
} | ||
|
||
const lowerCasedValue = value.toLowerCase(); | ||
if (lowerCasedValue === 'true' || lowerCasedValue === 'false') { | ||
return value; | ||
} | ||
|
||
if (operator === 'bbi' || operator === 'bbc') { | ||
return `${value}`; | ||
} | ||
|
||
return `"${value}"`; | ||
}; |
45 changes: 45 additions & 0 deletions
45
databrowser/src/domain/datasets/ui/tableView/filter/builder/tourismFilterBuilder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// SPDX-FileCopyrightText: NOI Techpark <[email protected]> | ||
// | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
import { BaseFilter } from '../types'; | ||
|
||
export const buildTourismFilterValues = (updatedFilters: BaseFilter[]) => | ||
updatedFilters.reduce<string[]>((prev, curr) => { | ||
if ( | ||
curr.operator !== 'isnull' && | ||
curr.operator !== 'isnotnull' && | ||
(curr.value === '' || curr.value == null) | ||
) { | ||
return prev; | ||
} | ||
|
||
switch (curr.operator) { | ||
case 'eq': | ||
return [...prev, `eq(${curr.propertyPath},'${curr.value}')`]; | ||
case 'ne': | ||
return [...prev, `ne(${curr.propertyPath},'${curr.value}')`]; | ||
case 'gt': | ||
return [...prev, `gt(${curr.propertyPath},'${curr.value}')`]; | ||
case 'ge': | ||
return [...prev, `ge(${curr.propertyPath},'${curr.value}')`]; | ||
case 'lt': | ||
return [...prev, `lt(${curr.propertyPath},'${curr.value}')`]; | ||
case 'le': | ||
return [...prev, `le(${curr.propertyPath},'${curr.value}')`]; | ||
case 'isnull': | ||
return [...prev, `isnull(${curr.propertyPath})`]; | ||
case 'isnotnull': | ||
return [...prev, `isnotnull(${curr.propertyPath})`]; | ||
case 'in': | ||
return [...prev, `in(${curr.propertyPath}.[*],'${curr.value}')`]; | ||
case 'nin': | ||
return [...prev, `nin(${curr.propertyPath}.[*],'${curr.value}')`]; | ||
case 'like': | ||
return [...prev, `like(${curr.propertyPath},'${curr.value}')`]; | ||
case 'likein': | ||
return [...prev, `likein(${curr.propertyPath}.[*],'${curr.value}')`]; | ||
default: | ||
return prev; | ||
} | ||
}, []); |
45 changes: 45 additions & 0 deletions
45
databrowser/src/domain/datasets/ui/tableView/filter/datasetFilterStore.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// SPDX-FileCopyrightText: NOI Techpark <[email protected]> | ||
// | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
import { acceptHMRUpdate, defineStore, storeToRefs } from 'pinia'; | ||
import { computed } from 'vue'; | ||
import { useDatasetBaseInfoStore } from '../../../config/store/datasetBaseInfoStore'; | ||
import { useDatasetQueryStore } from '../../../location/store/datasetQueryStore'; | ||
import { buildFilterValuesString } from './builder/filterBuilder'; | ||
import { parseFilterWithRegex } from './parser/filterParser'; | ||
import { BaseFilter } from './types'; | ||
|
||
export const useDatasetFilterStore = defineStore('datasetFilterStore', () => { | ||
const { datasetDomain } = storeToRefs(useDatasetBaseInfoStore()); | ||
|
||
const urlFilterParamName = computed(() => { | ||
if (datasetDomain.value === 'tourism') { | ||
return 'rawfilter'; | ||
} | ||
if (datasetDomain.value === 'mobility') { | ||
return 'where'; | ||
} | ||
return ''; | ||
}); | ||
|
||
const urlFilter = useDatasetQueryStore().handle(urlFilterParamName); | ||
|
||
const datasetFilters = computed<BaseFilter[]>({ | ||
get: () => parseFilterWithRegex(datasetDomain.value, urlFilter.value), | ||
set: (updatedFilters) => | ||
(urlFilter.value = buildFilterValuesString( | ||
datasetDomain.value, | ||
updatedFilters | ||
)), | ||
}); | ||
|
||
return { datasetFilters }; | ||
}); | ||
|
||
// Add support for hot-module-reload | ||
if (import.meta.hot) { | ||
import.meta.hot.accept( | ||
acceptHMRUpdate(useDatasetFilterStore, import.meta.hot) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
databrowser/src/domain/datasets/ui/tableView/filter/parser/filterParser.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// SPDX-FileCopyrightText: NOI Techpark <[email protected]> | ||
// | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
import { DatasetDomain } from '../../../../config/types'; | ||
import { BaseFilter } from '../types'; | ||
import { mobilityParseFilterWithRegex } from './mobilityFilterParserWithRegex'; | ||
import { tourismParseFilterWithRegex } from './tourismFilterParserWithRegex'; | ||
|
||
export const parseFilterWithRegex = ( | ||
datasetDomain: DatasetDomain | undefined, | ||
filterString?: string | ||
): BaseFilter[] => { | ||
if (datasetDomain === 'tourism') { | ||
return tourismParseFilterWithRegex(filterString); | ||
} | ||
if (datasetDomain === 'mobility') { | ||
return mobilityParseFilterWithRegex(filterString); | ||
} | ||
console.debug( | ||
`Can not parse filters for unknown dataset domain "${datasetDomain}", returning empty list` | ||
); | ||
return []; | ||
}; |
Oops, something went wrong.