Skip to content

Commit df09bdb

Browse files
committed
add filtering options in keyword view
1 parent 5b0910f commit df09bdb

1 file changed

Lines changed: 57 additions & 12 deletions

File tree

frontend/packages/volto-keywordmanager/src/components/KeywordView.tsx

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Spinner, Table, Button, SearchField } from '@plone/components';
1+
import { Spinner, Table, Button, SearchField, Select } from '@plone/components';
22
import { DialogTrigger } from 'react-aria-components';
33
import Toolbar from '@plone/volto/components/manage/Toolbar/Toolbar';
44
import Icon from '@plone/volto/components/theme/Icon/Icon';
@@ -15,12 +15,13 @@ import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
1515
import { useClient } from '@plone/volto/hooks';
1616
import { deleteKeywords } from 'volto-keywordmanager/actions/keywords';
1717
import DeleteModal from './DeleteModal';
18+
import { getTypes } from '@plone/volto/actions/types/types';
19+
import { getBaseUrl } from '@plone/volto/helpers/Url/Url';
1820

1921
import backSVG from '@plone/volto/icons/back.svg';
2022
import trashSVG from '@plone/volto/icons/delete.svg';
2123
import searchSVG from '@plone/volto/icons/zoom.svg';
22-
import { Select } from '@plone/components';
23-
import { getTypes } from '@plone/volto/actions/types/types';
24+
import { getVocabulary } from '@plone/volto/actions/vocabularies/vocabularies';
2425

2526
const messages = defineMessages({
2627
back: {
@@ -47,6 +48,14 @@ const messages = defineMessages({
4748
id: 'actions',
4849
defaultMessage: 'Actions',
4950
},
51+
selectTypePlaceholder: {
52+
id: 'All types',
53+
defaultMessage: 'All types',
54+
},
55+
selectStatePlaceholder: {
56+
id: 'All states',
57+
defaultMessage: 'All states',
58+
},
5059
searchFieldPlaceholder: {
5160
id: 'search',
5261
defaultMessage: 'Search',
@@ -58,7 +67,13 @@ const KeywordView = (props) => {
5867
const { id } = useParams<{ id: string }>();
5968
const intl = useIntl();
6069
const keywords = useSelector((state) => state.search.subrequests.keywords);
61-
const types = useSelector((state) => state.types);
70+
const types = useSelector(
71+
(state) =>
72+
state.vocabularies['plone.app.vocabularies.ReallyUserFriendlyTypes'],
73+
);
74+
const states = useSelector(
75+
(state) => state.vocabularies['plone.app.vocabularies.WorkflowStates'],
76+
);
6277
const dispatch = useDispatch();
6378
const isClient = useClient();
6479
const pathname = location.pathname;
@@ -72,19 +87,33 @@ const KeywordView = (props) => {
7287
const [pageSize, setPageSize] = useState<number>(25);
7388
const pageSizes = [25, 50, 100];
7489
const [selectedTypes, setSelectedTypes] = useState<[]>([]);
90+
const [selectedStates, setSelectedStates] = useState<[]>([]);
91+
const [search, setSearch] = useState<string>('');
7592

7693
const options = useMemo(
7794
() => ({
7895
Subject: [id],
7996
...(selectedTypes.length > 0 && { portal_type: selectedTypes }),
97+
...(selectedStates.length > 0 && { review_state: selectedStates }),
98+
...(search && { SearchableText: search }),
8099
...(pageSize !== 25 && { b_size: pageSize }),
81100
...(currentPage !== 0 && { b_start: currentPage }),
82101
}),
83-
[id, selectedTypes, pageSize, currentPage],
102+
[id, selectedTypes, selectedStates, search, pageSize, currentPage],
84103
);
85104

86105
useEffect(() => {
87106
dispatch(searchContent('/', options, 'keywords'));
107+
dispatch(
108+
getVocabulary({
109+
vocabNameOrURL: 'plone.app.vocabularies.ReallyUserFriendlyTypes',
110+
}),
111+
);
112+
dispatch(
113+
getVocabulary({
114+
vocabNameOrURL: 'plone.app.vocabularies.WorkflowStates',
115+
}),
116+
);
88117
}, [dispatch, options]);
89118

90119
const handleDeleteKeywords = async (kw: string | string[]) => {
@@ -153,25 +182,41 @@ const KeywordView = (props) => {
153182
/>
154183
</DialogTrigger>
155184
</div>
156-
<div>
185+
<div className="select-portal_type">
157186
<Select
158187
selectionMode="multiple"
188+
placeholder={intl.formatMessage(messages.selectTypePlaceholder)}
159189
onChange={setSelectedTypes}
160-
items={types?.types.map((type) => ({
161-
label: type.title,
162-
value: type.title,
190+
items={types?.items?.map((item) => ({
191+
label: item.value,
192+
value: <FormattedMessage id={item.label} />,
193+
}))}
194+
/>
195+
</div>
196+
<div className="select-review_state">
197+
<Select
198+
selectionMode="multiple"
199+
placeholder={intl.formatMessage(messages.selectStatePlaceholder)}
200+
onChange={setSelectedStates}
201+
items={states?.items?.map((item) => ({
202+
label: item.value,
203+
value: item.label,
163204
}))}
164205
/>
165206
</div>
166207
<div className="search">
167208
<SearchField
168209
placeholder={intl.formatMessage(messages.searchFieldPlaceholder)}
169-
/>
170-
<Icon name={searchSVG} size="20px" />
210+
onSubmit={setSearch}
211+
>
212+
<Button>
213+
<Icon name={searchSVG} size="20px" />
214+
</Button>
215+
</SearchField>
171216
</div>
172217
</div>
173218
</div>
174-
{keywords?.loaded ? (
219+
{keywords?.loaded && keywords?.items.length > 0 ? (
175220
<Table
176221
className="react-aria-Table cmsui-table"
177222
columns={[

0 commit comments

Comments
 (0)