Skip to content

Commit

Permalink
Use RAC table instead
Browse files Browse the repository at this point in the history
  • Loading branch information
sneridagh committed Nov 21, 2024
1 parent 4514f3c commit 49c6b62
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 16 deletions.
5 changes: 3 additions & 2 deletions frontend/packages/volto-ploneconf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"@eeacms/volto-matomo"
],
"dependencies": {
"@plone/components": "workspace:*",
"@eeacms/volto-accordion-block": "11.0.0",
"@eeacms/volto-matomo": "^5.0.0",
"@eeacms/volto-statistic-block": "4.1.0",
Expand All @@ -54,19 +53,21 @@
"@mbarde/volto-image-crop-widget": "0.5.1",
"@plone-collective/volto-authomatic": "2.0.1",
"@plone-collective/volto-eventbrite-block": "^1.0.0-alpha.2",
"@plone/components": "workspace:*",
"@plonegovbr/volto-network-block": "^1.0.0",
"classnames": "2.2.6",
"embla-carousel-autoplay": "^8.0.0",
"embla-carousel-react": "^8.0.0",
"react-lazy-load-image-component": "^1.6.2",
"react-stately": "^3.33.0",
"volto-form-block": "^3.9.1",
"volto-subblocks": "^2.1.0"
},
"peerDependencies": {
"react": "18.2.0",
"react-aria-components": "^1.4.1",
"react-dom": "18.2.0",
"react-intl": "^3.12.1",
"react-aria-components": "^1.4.1",
"semantic-ui-react": "^2.1.5"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import _ from 'lodash';
import sortBy from 'lodash/sortBy';
import cloneDeep from 'lodash/cloneDeep';
import React, { useEffect, useState } from 'react';
import { Container } from '@plone/components';
import { defineMessages, useIntl, FormattedMessage } from 'react-intl';
import { useDispatch, useSelector } from 'react-redux';
import { useLocation } from 'react-router-dom';
import {
Table,
TableBody,
TableHeader,
Table as SemanticTable,
TableBody as SemanticTableBody,
TableHeader as SemanticTableHeader,
TableRow,
TableHeaderCell,
Segment,
Expand All @@ -17,12 +18,26 @@ import { Helmet } from '@plone/volto/helpers';
import backSVG from '@plone/volto/icons/back.svg';
import { Icon, Toolbar, UniversalLink } from '@plone/volto/components';

import {
Cell,
Column,
ColumnResizer,

Check warning on line 24 in frontend/packages/volto-ploneconf/src/components/Registrations/RegistrationsManagement.jsx

View workflow job for this annotation

GitHub Actions / frontend / code-analysis

'ColumnResizer' is defined but never used
ResizableTableContainer,

Check warning on line 25 in frontend/packages/volto-ploneconf/src/components/Registrations/RegistrationsManagement.jsx

View workflow job for this annotation

GitHub Actions / frontend / code-analysis

'ResizableTableContainer' is defined but never used
Row,
Table,
TableBody,
TableHeader,
} from 'react-aria-components';

import {
getAllRegistrations,
getRegistrations,
} from '../../actions/registrations/registrations';

import RegistrationItem from './RegistrationItem';
import { useListData, useAsyncList } from 'react-stately';

Check warning on line 38 in frontend/packages/volto-ploneconf/src/components/Registrations/RegistrationsManagement.jsx

View workflow job for this annotation

GitHub Actions / frontend / code-analysis

'useListData' is defined but never used

import '@plone/components/src/styles/basic/Table.css';

const messages = defineMessages({
back: {
Expand Down Expand Up @@ -80,7 +95,7 @@ const sortReducer = (state, action) => {

return {
column: action.column,
data: _.sortBy(state.data, [action.column]),
data: sortBy(state.data, [action.column]),
direction: 'ascending',
};
default:
Expand Down Expand Up @@ -129,6 +144,46 @@ const RegistrationsManagement = () => {
? intl.formatMessage(messages.registrationManagementAll)
: intl.formatMessage(messages.registrationManagement);

let list = useAsyncList({
async load({ signal }) {
// let res = await fetch(`https://swapi.py4e.com/api/people/?search`, {
// signal,
// });
// let json = await res.json();
const func =
portal_type === 'Training' ? getRegistrations : getAllRegistrations;

let registrations = await dispatch(func(pathname, uuid));
const result = cloneDeep(registrations.registrations.items);
result.forEach((registration) => {
registration.training = registration.training.title;
});
return {
items: result,
};
},
// async getKey(item) {
// debugger;
// return item.uid;
// },
async sort({ items, sortDescriptor }) {
console.log(items);

Check warning on line 170 in frontend/packages/volto-ploneconf/src/components/Registrations/RegistrationsManagement.jsx

View workflow job for this annotation

GitHub Actions / frontend / code-analysis

Unexpected console statement
console.log(sortDescriptor.column);

Check warning on line 171 in frontend/packages/volto-ploneconf/src/components/Registrations/RegistrationsManagement.jsx

View workflow job for this annotation

GitHub Actions / frontend / code-analysis

Unexpected console statement
return {
items: items.sort((a, b) => {
let first = a[sortDescriptor.column];
let second = b[sortDescriptor.column];
let cmp =
(parseInt(first) || first) < (parseInt(second) || second) ? -1 : 1;
if (sortDescriptor.direction === 'descending') {
cmp *= -1;
}
return cmp;
}),
};
},
});

return (
<>
<Helmet title={pageTitle} />
Expand All @@ -148,8 +203,38 @@ const RegistrationsManagement = () => {
/>
</Segment>
<Segment secondary>{pageTitle}</Segment>
<Table className={'sortable'}>
<Table
aria-label="Example table with client side sorting"
sortDescriptor={list.sortDescriptor}
onSortChange={list.sort}
>
<TableHeader>
<Column id="training" isRowHeader allowsSorting>
Training
</Column>
<Column id="user_id" allowsSorting>
Name
</Column>
<Column id="created" allowsSorting>
Date
</Column>
<Column id="state" allowsSorting>
State
</Column>
</TableHeader>
<TableBody items={list.items}>
{(item) => (
<Row id={item.uid}>
<Cell>{item.training}</Cell>
<Cell>{item.user_id}</Cell>
<Cell>{item.created}</Cell>
<Cell>{item.state}</Cell>
</Row>
)}
</TableBody>
</Table>
<SemanticTable className={'sortable'}>
<SemanticTableHeader>
<TableRow>
{allTrainings && (
<TableHeaderCell
Expand Down Expand Up @@ -189,8 +274,8 @@ const RegistrationsManagement = () => {
</TableHeaderCell>
)}
</TableRow>
</TableHeader>
<TableBody>
</SemanticTableHeader>
<SemanticTableBody>
{isClient && (
<RegistrationsList
intl={intl}
Expand All @@ -200,8 +285,8 @@ const RegistrationsManagement = () => {
allTrainings={allTrainings}
/>
)}
</TableBody>
</Table>
</SemanticTableBody>
</SemanticTable>
</Segment.Group>
{isClient &&
createPortal(
Expand Down
23 changes: 19 additions & 4 deletions frontend/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 49c6b62

Please sign in to comment.