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

Update ws reference #1697

Open
wants to merge 2 commits into
base: master
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
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