|
1 | | -import { Button, SearchField, Select, Spinner, Table } from '@plone/components'; |
| 1 | +import { Button, SearchField, Select, Spinner } from '@plone/components'; |
| 2 | +import { Table, TableHeader, TableBody, Row } from 'react-aria-components'; |
| 3 | +import { Column, Collection, Cell } from 'react-aria-components'; |
| 4 | +import { Checkbox } from '@plone/components'; |
2 | 5 | import { searchContent } from '@plone/volto/actions/search/search'; |
3 | 6 | import Toolbar from '@plone/volto/components/manage/Toolbar/Toolbar'; |
4 | 7 | import Icon from '@plone/volto/components/theme/Icon/Icon'; |
@@ -125,6 +128,46 @@ const KeywordView = (props) => { |
125 | 128 | ); |
126 | 129 | }, [dispatch, options]); |
127 | 130 |
|
| 131 | + const columns = [ |
| 132 | + { |
| 133 | + id: 'title', |
| 134 | + name: intl.formatMessage(messages.title), |
| 135 | + isRowHeader: true, |
| 136 | + }, |
| 137 | + { |
| 138 | + id: 'type', |
| 139 | + name: intl.formatMessage(messages.type), |
| 140 | + }, |
| 141 | + { id: 'state', name: intl.formatMessage(messages.state) }, |
| 142 | + ]; |
| 143 | + |
| 144 | + const rows = keywords?.items?.map((obj) => ({ |
| 145 | + id: obj['@id'], |
| 146 | + textValue: obj.title, |
| 147 | + title: ( |
| 148 | + <> |
| 149 | + <UniversalLink href={obj['@id'] || '/'}>{obj.title}</UniversalLink> |
| 150 | + <br /> |
| 151 | + <span hidden>Path: </span> |
| 152 | + <span>{flattenToAppURL(obj['@id']) || '/'}</span> |
| 153 | + <KeywordList |
| 154 | + keywords={obj[keywordIndex]} |
| 155 | + currentId={id} |
| 156 | + onDelete={(item) => handleDeleteKeywords(item, obj['@id'])} |
| 157 | + /> |
| 158 | + </> |
| 159 | + ), |
| 160 | + type: obj.type_title, |
| 161 | + state: ( |
| 162 | + <FormattedMessage |
| 163 | + id={ |
| 164 | + states?.items?.find((item) => item.value === obj.review_state) |
| 165 | + ?.label ?? 'no workflow state' |
| 166 | + } |
| 167 | + /> |
| 168 | + ), |
| 169 | + })); |
| 170 | + |
128 | 171 | const handleDeleteKeywords = async (kw: string | string[], id?: string) => { |
129 | 172 | if (typeof kw == 'string') { |
130 | 173 | kw = [kw]; |
@@ -239,59 +282,45 @@ const KeywordView = (props) => { |
239 | 282 | </div> |
240 | 283 | </div> |
241 | 284 | </div> |
242 | | - {keywords?.loaded && keywords?.items.length > 0 ? ( |
243 | | - <Table |
244 | | - id="keywords" |
245 | | - className="react-aria-Table cmsui-table" |
246 | | - columns={[ |
247 | | - { |
248 | | - id: 'title', |
249 | | - name: intl.formatMessage(messages.title), |
250 | | - isRowHeader: true, |
251 | | - }, |
252 | | - { |
253 | | - id: 'type', |
254 | | - name: intl.formatMessage(messages.type), |
255 | | - }, |
256 | | - { id: 'state', name: intl.formatMessage(messages.state) }, |
257 | | - ]} |
258 | | - rows={keywords?.items?.map((obj) => ({ |
259 | | - id: obj['@id'], |
260 | | - textValue: obj.title, |
261 | | - title: ( |
262 | | - <> |
263 | | - <UniversalLink href={obj['@id'] || '/'}> |
264 | | - {obj.title} |
265 | | - </UniversalLink> |
266 | | - <br /> |
267 | | - <span hidden>Path: </span> |
268 | | - <span>{flattenToAppURL(obj['@id']) || '/'}</span> |
269 | | - <KeywordList |
270 | | - keywords={obj[keywordIndex]} |
271 | | - currentId={id} |
272 | | - onDelete={(item) => handleDeleteKeywords(item, obj['@id'])} |
273 | | - /> |
274 | | - </> |
275 | | - ), |
276 | | - type: obj.type_title, |
277 | | - state: ( |
278 | | - <FormattedMessage |
279 | | - id={ |
280 | | - states?.items?.find((item) => item.value === obj.review_state) |
281 | | - ?.label ?? 'no workflow state' |
282 | | - } |
283 | | - /> |
284 | | - ), |
285 | | - }))} |
286 | | - selectionMode="multiple" |
287 | | - onSelectionChange={setSelectedKeys} |
288 | | - /> |
289 | | - ) : keywords?.loading ? ( |
290 | | - <Spinner aria-label={intl.formatMessage(messages.loading)} /> |
291 | | - ) : ( |
292 | | - <div>No results.</div> |
293 | | - )} |
294 | | - {keywords?.total > pageSize && ( |
| 285 | + <Table |
| 286 | + className="react-aria-Table cmsui-table" |
| 287 | + selectionMode="multiple" |
| 288 | + selectedKeys={selectedKeys} |
| 289 | + onSelectionChange={setSelectedKeys} |
| 290 | + > |
| 291 | + <TableHeader columns={columns}> |
| 292 | + <Column> |
| 293 | + <Checkbox slot="selection" /> |
| 294 | + </Column> |
| 295 | + <Collection items={columns}> |
| 296 | + {(column) => ( |
| 297 | + <Column isRowHeader={column.isRowHeader}>{column.name}</Column> |
| 298 | + )} |
| 299 | + </Collection> |
| 300 | + </TableHeader> |
| 301 | + <TableBody |
| 302 | + items={rows} |
| 303 | + renderEmptyState={() => |
| 304 | + keywords?.loading ? ( |
| 305 | + <Spinner aria-label={intl.formatMessage(messages.loading)} /> |
| 306 | + ) : ( |
| 307 | + 'No results found.' |
| 308 | + ) |
| 309 | + } |
| 310 | + > |
| 311 | + {(item) => ( |
| 312 | + <Row columns={columns} textValue={item.textValue}> |
| 313 | + <Cell> |
| 314 | + <Checkbox slot="selection" /> |
| 315 | + </Cell> |
| 316 | + <Collection items={columns}> |
| 317 | + {(column) => <Cell>{item[column.id]}</Cell>} |
| 318 | + </Collection> |
| 319 | + </Row> |
| 320 | + )} |
| 321 | + </TableBody> |
| 322 | + </Table> |
| 323 | + {totalPages > 1 && ( |
295 | 324 | <Pagination |
296 | 325 | activePage={currentPage} |
297 | 326 | totalPages={totalPages} |
|
0 commit comments