Skip to content

Commit

Permalink
Update ws reference (#1697)
Browse files Browse the repository at this point in the history
* fix(workspace): update parent id reference

* feat(workspaces): add bulk select to workspaces table
  • Loading branch information
karelhala authored Nov 8, 2024
1 parent 71d4fe2 commit 49a1b89
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/redux/reducers/workspaces-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface Workspace {
name: string;
description: string;
children?: Workspace[];
parent_id?: string;
}
export interface WorkspacesStore {
isLoading: boolean;
Expand Down
30 changes: 23 additions & 7 deletions src/smart-components/workspaces/workspaces.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { useIntl } from 'react-intl';
import { useDispatch, useSelector } from 'react-redux';
import { fetchWorkspaces } from '../../redux/actions/workspaces-actions';
import messages from '../../Messages';
import { ContentHeader } from '@patternfly/react-component-groups';
import { BulkSelect, BulkSelectValue, ContentHeader } from '@patternfly/react-component-groups';
import { PageSection } from '@patternfly/react-core';
import { DataView, DataViewTable, DataViewTh, DataViewTrTree, useDataViewSelection } from '@patternfly/react-data-view';
import { DataView, DataViewTable, DataViewTh, DataViewToolbar, DataViewTrTree, useDataViewSelection } from '@patternfly/react-data-view';
import { Workspace } from '../../redux/reducers/workspaces-reducer';
import { RBACStore } from '../../redux/store';

Expand All @@ -22,12 +22,12 @@ const Workspaces = () => {
dispatch(fetchWorkspaces());
}, [dispatch]);

const mapWorkspacesToHierarchy = (workspaceData: any[]): Workspace[] => {
const mapWorkspacesToHierarchy = (workspaceData: Workspace[]): Workspace[] => {
const workspaceMap: { [key: string]: Workspace } = {};

workspaceData.forEach((ws) => {
workspaceMap[ws.uuid] = {
id: ws.uuid,
workspaceMap[ws.id] = {
id: ws.id,
name: ws.name,
description: ws.description,
children: [],
Expand All @@ -37,9 +37,9 @@ const Workspaces = () => {
const hierarchy: Workspace[] = [];
workspaceData.forEach((ws) => {
if (ws.parent_id) {
workspaceMap[ws.parent_id]?.children?.push(workspaceMap[ws.uuid]);
workspaceMap[ws.parent_id]?.children?.push(workspaceMap[ws.id]);
} else {
hierarchy.push(workspaceMap[ws.uuid]);
hierarchy.push(workspaceMap[ws.id]);
}
});

Expand Down Expand Up @@ -67,6 +67,11 @@ const Workspaces = () => {

const columns: DataViewTh[] = ['Name', 'Description'];

const handleBulkSelect = (value: BulkSelectValue) => {
value === BulkSelectValue.none && selection.onSelect(false);
value === BulkSelectValue.all && selection.onSelect(true, workspaces);
};

return (
<React.Fragment>
<ContentHeader
Expand All @@ -83,6 +88,17 @@ const Workspaces = () => {
{error && <p>Error: {error}</p>}
{!isLoading && !error && (
<DataView selection={selection}>
<DataViewToolbar
bulkSelect={
<BulkSelect
canSelectAll
isDataPaginated={false}
totalCount={workspaces.length}
selectedCount={selection.selected.length}
onSelect={handleBulkSelect}
/>
}
/>
<DataViewTable isTreeTable aria-label="Repositories table" ouiaId={'ouiaId'} columns={columns} rows={rows} />
</DataView>
)}
Expand Down

0 comments on commit 49a1b89

Please sign in to comment.