1- import { Spinner } from '@plone/components' ;
1+ import { Spinner , Table , Button } from '@plone/components' ;
22import Toolbar from '@plone/volto/components/manage/Toolbar/Toolbar' ;
33import Icon from '@plone/volto/components/theme/Icon/Icon' ;
4- import { useEffect } from 'react' ;
4+ import { useEffect , useState } from 'react' ;
55import { createPortal } from 'react-dom' ;
66import { useDispatch } from 'react-redux' ;
77import { getParentUrl } from '@plone/volto/helpers/Url/Url' ;
88import { useSelector } from 'react-redux' ;
99import { Link , useParams } from 'react-router-dom' ;
10- import { getKeywords } from 'volto-keywordmanager /actions/keywords ' ;
10+ import { searchContent } from '@plone/ volto/actions/search/search ' ;
1111import Error from '@plone/volto/components/theme/Error/Error' ;
1212import { defineMessages , FormattedMessage , useIntl } from 'react-intl' ;
1313import { useClient } from '@plone/volto/hooks' ;
14+ import { deleteKeywords } from 'volto-keywordmanager/actions/keywords' ;
1415
1516import backSVG from '@plone/volto/icons/back.svg' ;
17+ import trashSVG from '@plone/volto/icons/delete.svg' ;
1618
1719const messages = defineMessages ( {
1820 back : {
@@ -23,9 +25,17 @@ const messages = defineMessages({
2325 id : 'loading' ,
2426 defaultMessage : 'Loading' ,
2527 } ,
26- keyword : {
27- id : 'Keyword' ,
28- defaultMessage : 'Keyword' ,
28+ title : {
29+ id : 'title' ,
30+ defaultMessage : 'Title' ,
31+ } ,
32+ path : {
33+ id : 'path' ,
34+ defaultMessage : 'Path' ,
35+ } ,
36+ actions : {
37+ id : 'actions' ,
38+ defaultMessage : 'Actions' ,
2939 } ,
3040} ) ;
3141
@@ -34,19 +44,27 @@ const KeywordView = (props) => {
3444 const params = useParams < { id : string } > ( ) ;
3545 const id = params . id ;
3646 const intl = useIntl ( ) ;
37- const keywords = useSelector ( ( state ) => state . keywords ) ;
47+ const keywords = useSelector ( ( state ) => state . search . subrequests . keywords ) ;
3848 const dispatch = useDispatch ( ) ;
3949 const isClient = useClient ( ) ;
4050 const pathname = location . pathname ;
41- const options = {
42- id : id ,
43- } ;
51+ const [ selectedKeys , setSelectedKeys ] = useState < string | Set < string > > (
52+ new Set ( ) ,
53+ ) ;
4454
4555 useEffect ( ( ) => {
46- dispatch ( getKeywords ( options ) ) ;
56+ dispatch ( searchContent ( '/' , { Subject : [ id ] } , 'keywords' ) ) ;
4757 } , [ ] ) ;
4858
49- if ( keywords . loading ) {
59+ const handleDeleteKeywords = async ( kw : string | string [ ] ) => {
60+ if ( typeof kw == 'string' ) {
61+ kw = [ kw ] ;
62+ }
63+ await dispatch ( deleteKeywords ( { items : kw } ) ) ;
64+ await dispatch ( searchContent ( '/' , { Subject : [ id ] } , 'keywords' ) ) ;
65+ } ;
66+
67+ if ( keywords ?. loading ) {
5068 return < Spinner label = { intl . formatMessage ( messages . loading ) } /> ;
5169 }
5270
@@ -55,8 +73,42 @@ const KeywordView = (props) => {
5573 }
5674
5775 return (
58- < >
76+ < div
77+ id = "page-keyword_manager"
78+ className = "ui container controlpanel-keyword-manager"
79+ >
5980 < h1 > Hello world</ h1 >
81+ < Table
82+ className = "react-aria-Table cmsui-table"
83+ columns = { [
84+ {
85+ id : 'title' ,
86+ name : intl . formatMessage ( messages . title ) ,
87+ isRowHeader : true ,
88+ } ,
89+ {
90+ id : 'path' ,
91+ name : intl . formatMessage ( messages . path ) ,
92+ } ,
93+ {
94+ id : 'actions' ,
95+ name : intl . formatMessage ( messages . actions ) ,
96+ } ,
97+ ] }
98+ rows = { keywords ?. items ?. map ( ( item ) => ( {
99+ id : item [ '@id' ] ,
100+ textValue : item . title ,
101+ title : < p > { item . title } </ p > ,
102+ path : < p > { item [ '@id' ] } </ p > ,
103+ actions : (
104+ < Button onPress = { ( ) => handleDeleteKeywords ( item [ '@id' ] ) } >
105+ < Icon name = { trashSVG } size = "20px" />
106+ </ Button >
107+ ) ,
108+ } ) ) }
109+ selectionMode = "multiple"
110+ onSelectionChange = { setSelectedKeys }
111+ />
60112 { isClient &&
61113 createPortal (
62114 < Toolbar
@@ -75,7 +127,7 @@ const KeywordView = (props) => {
75127 /> ,
76128 document . getElementById ( 'toolbar' ) as HTMLElement ,
77129 ) }
78- </ >
130+ </ div >
79131 ) ;
80132} ;
81133
0 commit comments