Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Use RAC table instead #16

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 backSVG from '@plone/volto/icons/back.svg';
import { Icon, Toolbar, UniversalLink } from '@plone/volto/components';

import {
Cell,

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

View workflow job for this annotation

GitHub Actions / frontend / code-analysis

'Cell' is defined but never used
Column,

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

View workflow job for this annotation

GitHub Actions / frontend / code-analysis

'Column' is defined but never used
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,

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

View workflow job for this annotation

GitHub Actions / frontend / code-analysis

'Row' is defined but never used
Table,

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

View workflow job for this annotation

GitHub Actions / frontend / code-analysis

'Table' is defined but never used
TableBody,

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

View workflow job for this annotation

GitHub Actions / frontend / code-analysis

'TableBody' is defined but never used
TableHeader,

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

View workflow job for this annotation

GitHub Actions / frontend / code-analysis

'TableHeader' is defined but never used
} 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 @@ -77,10 +92,9 @@
state.direction === 'ascending' ? 'descending' : 'ascending',
};
}

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 +143,44 @@
? intl.formatMessage(messages.registrationManagementAll)
: intl.formatMessage(messages.registrationManagement);

let list = useAsyncList({

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

View workflow job for this annotation

GitHub Actions / frontend / code-analysis

'list' is assigned a value but never used
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 }) {
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,14 +200,48 @@
/>
</Segment>
<Segment secondary>{pageTitle}</Segment>
<Table className={'sortable'}>
{/* @sneridagh: Commenting the RAC alternative for now */}
{/* <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
sorted={column === 'training' ? direction : null}
onClick={() =>
sortDispatch({ type: 'CHANGE_SORT', column: 'training' })
sortDispatch({
type: 'CHANGE_SORT',
column: 'training.title',
})
}
>
<FormattedMessage
Expand All @@ -167,7 +253,7 @@
<TableHeaderCell
sorted={column === 'name' ? direction : null}
onClick={() =>
sortDispatch({ type: 'CHANGE_SORT', column: 'name' })
sortDispatch({ type: 'CHANGE_SORT', column: 'user_id' })
}
>
<FormattedMessage id={'Name'} defaultMessage={'Name'} />
Expand All @@ -189,8 +275,8 @@
</TableHeaderCell>
)}
</TableRow>
</TableHeader>
<TableBody>
</SemanticTableHeader>
<SemanticTableBody>
{isClient && (
<RegistrationsList
intl={intl}
Expand All @@ -200,8 +286,8 @@
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.

Loading