From 38d09c8aa2a86e092113f738a272c5d77ea63e7c Mon Sep 17 00:00:00 2001 From: Stefanos Date: Mon, 19 Apr 2021 16:51:08 +0300 Subject: [PATCH] feat: add filter sector vocab for transaction --- .../datadisplay/Lists/ListControls/index.tsx | 30 +++++++++++++++---- .../state/utils/getSectorVocabs.ts | 4 ++- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/app/components/datadisplay/Lists/ListControls/index.tsx b/src/app/components/datadisplay/Lists/ListControls/index.tsx index f2a670e7..e51c5fe1 100644 --- a/src/app/components/datadisplay/Lists/ListControls/index.tsx +++ b/src/app/components/datadisplay/Lists/ListControls/index.tsx @@ -4,6 +4,7 @@ import List from '@material-ui/core/List'; import ListItem from '@material-ui/core/ListItem'; import ListItemIcon from '@material-ui/core/ListItemIcon'; import ListItemText from '@material-ui/core/ListItemText'; +import { ModuleStore } from 'app/modules/querybuilder-module/state/store'; import styled from 'styled-components/macro'; import { Palette } from 'app/theme'; import Typography from '@material-ui/core/Typography'; @@ -67,19 +68,36 @@ const ListCategory = styled((props) => )` //todo: look into virtualized lists https://material-ui.com/components/lists/ export const ListControls = (props: Props) => { + const store = ModuleStore.useStore(); const [checked, setChecked] = React.useState(props.addedFilterOptions || []); const handleToggle = (value) => () => { const currentIndex = checked.indexOf(value as never); const newChecked = [...checked]; - // eslint-disable-next-line no-unused-expressions - currentIndex === -1 - ? newChecked.push(value as never) - : newChecked.splice(currentIndex, 1); + if (currentIndex === -1) { + newChecked.push(value as never); + } else { + newChecked.splice(currentIndex, 1); + const filterKey = + value === 'Default language' + ? 'language' + : value + .split(' ') + .map( + (key: string, index: number) => + `${ + index === 0 ? key[0].toLowerCase() : key[0].toUpperCase() + }${key.substr(1)}` + ) + .join(''); + store.set(filterKey)([]); + } + + if (props.onCheckChange) { + props.onCheckChange(newChecked); + } - // eslint-disable-next-line no-unused-expressions - props.onCheckChange && props.onCheckChange(newChecked); setChecked(newChecked); }; diff --git a/src/app/modules/querybuilder-module/state/utils/getSectorVocabs.ts b/src/app/modules/querybuilder-module/state/utils/getSectorVocabs.ts index 30b4be75..d1d751b1 100644 --- a/src/app/modules/querybuilder-module/state/utils/getSectorVocabs.ts +++ b/src/app/modules/querybuilder-module/state/utils/getSectorVocabs.ts @@ -4,7 +4,9 @@ export function getSectorVocabs(data: any, rowFormat: string) { } switch (rowFormat) { case 'activity': - return `sector_vocabulary:(${data.join(' ')})`; + return `(transaction_sector_vocabulary:(${data.join( + ' ' + )}) OR sector_vocabulary:(${data.join(' ')}))`; case 'transaction': return `(transaction_sector_vocabulary:(${data.join( ' '