@patternfly/react-data-view 5.1.0 → 5.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/DataView/DataView.d.ts +4 -0
- package/dist/cjs/DataView/DataView.js +7 -1
- package/dist/cjs/DataViewEventsContext/DataViewEventsContext.d.ts +16 -0
- package/dist/cjs/DataViewEventsContext/DataViewEventsContext.js +62 -0
- package/dist/cjs/DataViewEventsContext/DataViewEventsContext.test.d.ts +1 -0
- package/dist/cjs/DataViewEventsContext/DataViewEventsContext.test.js +72 -0
- package/dist/cjs/DataViewEventsContext/index.d.ts +2 -0
- package/dist/cjs/DataViewEventsContext/index.js +23 -0
- package/dist/cjs/DataViewTable/DataViewTable.d.ts +41 -0
- package/dist/cjs/DataViewTable/DataViewTable.js +18 -0
- package/dist/cjs/DataViewTable/DataViewTable.test.d.ts +1 -0
- package/dist/cjs/DataViewTable/DataViewTable.test.js +57 -0
- package/dist/cjs/DataViewTable/index.d.ts +2 -0
- package/dist/cjs/DataViewTable/index.js +23 -0
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.d.ts +13 -0
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.js +49 -0
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.test.d.ts +1 -0
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.test.js +27 -0
- package/dist/cjs/DataViewTableBasic/index.d.ts +2 -0
- package/dist/cjs/DataViewTableBasic/index.js +23 -0
- package/dist/cjs/DataViewTableHeader/DataViewTableHeader.d.ts +13 -0
- package/dist/cjs/DataViewTableHeader/DataViewTableHeader.js +57 -0
- package/dist/cjs/DataViewTableHeader/DataViewTableHeader.test.d.ts +1 -0
- package/dist/cjs/DataViewTableHeader/DataViewTableHeader.test.js +36 -0
- package/dist/cjs/DataViewTableHeader/index.d.ts +2 -0
- package/dist/cjs/DataViewTableHeader/index.js +23 -0
- package/dist/cjs/DataViewTableTree/DataViewTableTree.d.ts +19 -0
- package/dist/cjs/DataViewTableTree/DataViewTableTree.js +120 -0
- package/dist/cjs/DataViewTableTree/DataViewTableTree.test.d.ts +1 -0
- package/dist/cjs/DataViewTableTree/DataViewTableTree.test.js +75 -0
- package/dist/cjs/DataViewTableTree/index.d.ts +2 -0
- package/dist/cjs/DataViewTableTree/index.js +23 -0
- package/dist/cjs/Hooks/selection.d.ts +3 -3
- package/dist/cjs/Hooks/selection.js +4 -6
- package/dist/cjs/Hooks/selection.test.js +4 -4
- package/dist/cjs/InternalContext/InternalContext.d.ts +17 -0
- package/dist/cjs/InternalContext/InternalContext.js +35 -0
- package/dist/cjs/InternalContext/InternalContext.test.d.ts +1 -0
- package/dist/cjs/InternalContext/InternalContext.test.js +56 -0
- package/dist/cjs/InternalContext/index.d.ts +2 -0
- package/dist/cjs/InternalContext/index.js +23 -0
- package/dist/cjs/index.d.ts +12 -0
- package/dist/cjs/index.js +20 -2
- package/dist/dynamic/DataViewEventsContext/package.json +1 -0
- package/dist/dynamic/DataViewTable/package.json +1 -0
- package/dist/dynamic/DataViewTableBasic/package.json +1 -0
- package/dist/dynamic/DataViewTableHeader/package.json +1 -0
- package/dist/dynamic/DataViewTableTree/package.json +1 -0
- package/dist/dynamic/InternalContext/package.json +1 -0
- package/dist/esm/DataView/DataView.d.ts +4 -0
- package/dist/esm/DataView/DataView.js +7 -1
- package/dist/esm/DataViewEventsContext/DataViewEventsContext.d.ts +16 -0
- package/dist/esm/DataViewEventsContext/DataViewEventsContext.js +34 -0
- package/dist/esm/DataViewEventsContext/DataViewEventsContext.test.d.ts +1 -0
- package/dist/esm/DataViewEventsContext/DataViewEventsContext.test.js +67 -0
- package/dist/esm/DataViewEventsContext/index.d.ts +2 -0
- package/dist/esm/DataViewEventsContext/index.js +2 -0
- package/dist/esm/DataViewTable/DataViewTable.d.ts +41 -0
- package/dist/esm/DataViewTable/DataViewTable.js +8 -0
- package/dist/esm/DataViewTable/DataViewTable.test.d.ts +1 -0
- package/dist/esm/DataViewTable/DataViewTable.test.js +52 -0
- package/dist/esm/DataViewTable/index.d.ts +2 -0
- package/dist/esm/DataViewTable/index.js +2 -0
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.d.ts +13 -0
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.js +42 -0
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.test.d.ts +1 -0
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.test.js +22 -0
- package/dist/esm/DataViewTableBasic/index.d.ts +2 -0
- package/dist/esm/DataViewTableBasic/index.js +2 -0
- package/dist/esm/DataViewTableHeader/DataViewTableHeader.d.ts +13 -0
- package/dist/esm/DataViewTableHeader/DataViewTableHeader.js +30 -0
- package/dist/esm/DataViewTableHeader/DataViewTableHeader.test.d.ts +1 -0
- package/dist/esm/DataViewTableHeader/DataViewTableHeader.test.js +31 -0
- package/dist/esm/DataViewTableHeader/index.d.ts +2 -0
- package/dist/esm/DataViewTableHeader/index.js +2 -0
- package/dist/esm/DataViewTableTree/DataViewTableTree.d.ts +19 -0
- package/dist/esm/DataViewTableTree/DataViewTableTree.js +93 -0
- package/dist/esm/DataViewTableTree/DataViewTableTree.test.d.ts +1 -0
- package/dist/esm/DataViewTableTree/DataViewTableTree.test.js +70 -0
- package/dist/esm/DataViewTableTree/index.d.ts +2 -0
- package/dist/esm/DataViewTableTree/index.js +2 -0
- package/dist/esm/Hooks/selection.d.ts +3 -3
- package/dist/esm/Hooks/selection.js +4 -6
- package/dist/esm/Hooks/selection.test.js +4 -4
- package/dist/esm/InternalContext/InternalContext.d.ts +17 -0
- package/dist/esm/InternalContext/InternalContext.js +7 -0
- package/dist/esm/InternalContext/InternalContext.test.d.ts +1 -0
- package/dist/esm/InternalContext/InternalContext.test.js +51 -0
- package/dist/esm/InternalContext/index.d.ts +2 -0
- package/dist/esm/InternalContext/index.js +2 -0
- package/dist/esm/index.d.ts +12 -0
- package/dist/esm/index.js +12 -0
- package/package.json +1 -1
- package/patternfly-docs/content/extensions/data-view/examples/Components/Components.md +45 -3
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableExample.tsx +47 -0
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableTreeExample.tsx +69 -0
- package/patternfly-docs/content/extensions/data-view/examples/EventsContext/EventsContext.md +32 -0
- package/patternfly-docs/content/extensions/data-view/examples/EventsContext/EventsExample.tsx +108 -0
- package/patternfly-docs/content/extensions/data-view/examples/Functionality/Functionality.md +6 -5
- package/patternfly-docs/content/extensions/data-view/examples/Functionality/PaginationExample.tsx +15 -32
- package/patternfly-docs/content/extensions/data-view/examples/Functionality/SelectionExample.tsx +15 -46
- package/patternfly-docs/content/extensions/data-view/examples/Layout/Layout.md +1 -0
- package/patternfly-docs/content/extensions/data-view/examples/Layout/PredefinedLayoutExample.tsx +20 -51
- package/src/DataView/DataView.tsx +14 -2
- package/src/DataViewEventsContext/DataViewEventsContext.test.tsx +105 -0
- package/src/DataViewEventsContext/DataViewEventsContext.tsx +70 -0
- package/src/DataViewEventsContext/index.ts +2 -0
- package/src/DataViewTable/DataViewTable.test.tsx +80 -0
- package/src/DataViewTable/DataViewTable.tsx +37 -0
- package/src/DataViewTable/__snapshots__/DataViewTable.test.tsx.snap +1010 -0
- package/src/DataViewTable/index.ts +2 -0
- package/src/DataViewTableBasic/DataViewTableBasic.test.tsx +37 -0
- package/src/DataViewTableBasic/DataViewTableBasic.tsx +71 -0
- package/src/DataViewTableBasic/__snapshots__/DataViewTableBasic.test.tsx.snap +324 -0
- package/src/DataViewTableBasic/index.ts +2 -0
- package/src/DataViewTableHeader/DataViewTableHeader.test.tsx +52 -0
- package/src/DataViewTableHeader/DataViewTableHeader.tsx +53 -0
- package/src/DataViewTableHeader/__snapshots__/DataViewTableHeader.test.tsx.snap +227 -0
- package/src/DataViewTableHeader/index.ts +2 -0
- package/src/DataViewTableTree/DataViewTableTree.test.tsx +85 -0
- package/src/DataViewTableTree/DataViewTableTree.tsx +144 -0
- package/src/DataViewTableTree/__snapshots__/DataViewTableTree.test.tsx.snap +937 -0
- package/src/DataViewTableTree/index.ts +2 -0
- package/src/Hooks/selection.test.tsx +5 -5
- package/src/Hooks/selection.ts +6 -7
- package/src/InternalContext/InternalContext.test.tsx +89 -0
- package/src/InternalContext/InternalContext.tsx +35 -0
- package/src/InternalContext/index.ts +2 -0
- package/src/index.ts +18 -0
|
@@ -12,7 +12,7 @@ import { renderHook, act } from '@testing-library/react';
|
|
|
12
12
|
import { useDataViewSelection } from './selection';
|
|
13
13
|
describe('useDataViewSelection', () => {
|
|
14
14
|
it('should get initial state correctly - no initialSelected', () => {
|
|
15
|
-
const { result } = renderHook(() => useDataViewSelection({}));
|
|
15
|
+
const { result } = renderHook(() => useDataViewSelection({ matchOption: (a, b) => a.id === b.id }));
|
|
16
16
|
expect(result.current).toEqual({
|
|
17
17
|
selected: [],
|
|
18
18
|
onSelect: expect.any(Function),
|
|
@@ -21,7 +21,7 @@ describe('useDataViewSelection', () => {
|
|
|
21
21
|
});
|
|
22
22
|
it('should get initial state correctly - with initialSelected', () => {
|
|
23
23
|
const initialSelected = [{ id: 1, name: 'test1' }];
|
|
24
|
-
const { result } = renderHook(() => useDataViewSelection({ initialSelected }));
|
|
24
|
+
const { result } = renderHook(() => useDataViewSelection({ initialSelected, matchOption: (a, b) => a.id === b.id }));
|
|
25
25
|
expect(result.current).toEqual({
|
|
26
26
|
selected: initialSelected,
|
|
27
27
|
onSelect: expect.any(Function),
|
|
@@ -30,7 +30,7 @@ describe('useDataViewSelection', () => {
|
|
|
30
30
|
});
|
|
31
31
|
it('should select items correctly - objects', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
32
|
const initialSelected = [{ id: 1, name: 'test1' }];
|
|
33
|
-
const { result } = renderHook(() => useDataViewSelection({ initialSelected }));
|
|
33
|
+
const { result } = renderHook(() => useDataViewSelection({ initialSelected, matchOption: (a, b) => a.id === b.id }));
|
|
34
34
|
yield act(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
35
|
result.current.onSelect(true, { id: 2, name: 'test2' });
|
|
36
36
|
}));
|
|
@@ -38,7 +38,7 @@ describe('useDataViewSelection', () => {
|
|
|
38
38
|
}));
|
|
39
39
|
it('should deselect items correctly - strings', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
40
|
const initialSelected = ['test1', 'test2'];
|
|
41
|
-
const { result } = renderHook(() => useDataViewSelection({ initialSelected }));
|
|
41
|
+
const { result } = renderHook(() => useDataViewSelection({ initialSelected, matchOption: (a, b) => a === b }));
|
|
42
42
|
yield act(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
43
|
result.current.onSelect(false, 'test2');
|
|
44
44
|
}));
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React, { PropsWithChildren } from 'react';
|
|
2
|
+
export interface DataViewSelection {
|
|
3
|
+
/** Called when the selection of items changes */
|
|
4
|
+
onSelect: (isSelecting: boolean, items?: any[] | any) => void;
|
|
5
|
+
/** Checks if a specific item is currently selected */
|
|
6
|
+
isSelected: (item: any) => boolean;
|
|
7
|
+
/** Determines if selection is disabled for a given item */
|
|
8
|
+
isSelectDisabled?: (item: any) => boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface InternalContextValue {
|
|
11
|
+
selection?: DataViewSelection;
|
|
12
|
+
}
|
|
13
|
+
export declare const InternalContext: React.Context<InternalContextValue>;
|
|
14
|
+
export type InternalProviderProps = PropsWithChildren<InternalContextValue>;
|
|
15
|
+
export declare const InternalContextProvider: React.FC<InternalProviderProps>;
|
|
16
|
+
export declare const useInternalContext: () => InternalContextValue;
|
|
17
|
+
export default InternalContext;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React, { createContext, useContext } from 'react';
|
|
2
|
+
export const InternalContext = createContext({
|
|
3
|
+
selection: undefined
|
|
4
|
+
});
|
|
5
|
+
export const InternalContextProvider = ({ children, selection }) => (React.createElement(InternalContext.Provider, { value: { selection } }, children));
|
|
6
|
+
export const useInternalContext = () => useContext(InternalContext);
|
|
7
|
+
export default InternalContext;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, fireEvent } from '@testing-library/react';
|
|
3
|
+
import '@testing-library/jest-dom';
|
|
4
|
+
import { useInternalContext } from './InternalContext';
|
|
5
|
+
import { DataView } from '../DataView';
|
|
6
|
+
describe('InternalContext', () => {
|
|
7
|
+
const mockSelection = {
|
|
8
|
+
onSelect: jest.fn(),
|
|
9
|
+
isSelected: jest.fn(),
|
|
10
|
+
isSelectDisabled: jest.fn(),
|
|
11
|
+
};
|
|
12
|
+
test('should provide context value and allow consuming it', () => {
|
|
13
|
+
const TestComponent = () => {
|
|
14
|
+
const { selection } = useInternalContext();
|
|
15
|
+
return (React.createElement("div", null,
|
|
16
|
+
React.createElement("button", { onClick: () => selection === null || selection === void 0 ? void 0 : selection.onSelect(true, ['item1']) }, "Select item"),
|
|
17
|
+
React.createElement("span", null, (selection === null || selection === void 0 ? void 0 : selection.isSelected('item1')) ? 'Selected' : 'Not selected')));
|
|
18
|
+
};
|
|
19
|
+
const { getByText } = render(React.createElement(DataView, { selection: mockSelection },
|
|
20
|
+
React.createElement(TestComponent, null)));
|
|
21
|
+
fireEvent.click(getByText('Select item'));
|
|
22
|
+
expect(mockSelection.onSelect).toHaveBeenCalledWith(true, ['item1']);
|
|
23
|
+
});
|
|
24
|
+
test('should handle selection state correctly', () => {
|
|
25
|
+
const mockSelectionState = Object.assign(Object.assign({}, mockSelection), { isSelected: jest.fn((item) => item === 'item1') });
|
|
26
|
+
const TestComponent = () => {
|
|
27
|
+
const { selection } = useInternalContext();
|
|
28
|
+
return (React.createElement("div", null,
|
|
29
|
+
React.createElement("span", null, (selection === null || selection === void 0 ? void 0 : selection.isSelected('item1')) ? 'Item 1 is selected' : 'Item 1 is not selected'),
|
|
30
|
+
React.createElement("span", null, (selection === null || selection === void 0 ? void 0 : selection.isSelected('item2')) ? 'Item 2 is selected' : 'Item 2 is not selected')));
|
|
31
|
+
};
|
|
32
|
+
const { getByText } = render(React.createElement(DataView, { selection: mockSelectionState },
|
|
33
|
+
React.createElement(TestComponent, null)));
|
|
34
|
+
expect(getByText('Item 1 is selected')).toBeInTheDocument();
|
|
35
|
+
expect(getByText('Item 2 is not selected')).toBeInTheDocument();
|
|
36
|
+
});
|
|
37
|
+
test('should handle selection disabled correctly', () => {
|
|
38
|
+
const mockSelectionWithDisabled = Object.assign(Object.assign({}, mockSelection), { isSelectDisabled: jest.fn((item) => item === 'item3') });
|
|
39
|
+
const TestComponent = () => {
|
|
40
|
+
var _a, _b;
|
|
41
|
+
const { selection } = useInternalContext();
|
|
42
|
+
return (React.createElement("div", null,
|
|
43
|
+
React.createElement("span", null, ((_a = selection === null || selection === void 0 ? void 0 : selection.isSelectDisabled) === null || _a === void 0 ? void 0 : _a.call(selection, 'item3')) ? 'Item 3 is disabled' : 'Item 3 is enabled'),
|
|
44
|
+
React.createElement("span", null, ((_b = selection === null || selection === void 0 ? void 0 : selection.isSelectDisabled) === null || _b === void 0 ? void 0 : _b.call(selection, 'item1')) ? 'Item 1 is disabled' : 'Item 1 is enabled')));
|
|
45
|
+
};
|
|
46
|
+
const { getByText } = render(React.createElement(DataView, { selection: mockSelectionWithDisabled },
|
|
47
|
+
React.createElement(TestComponent, null)));
|
|
48
|
+
expect(getByText('Item 3 is disabled')).toBeInTheDocument();
|
|
49
|
+
expect(getByText('Item 1 is enabled')).toBeInTheDocument();
|
|
50
|
+
});
|
|
51
|
+
});
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
|
+
export { default as InternalContext } from './InternalContext';
|
|
2
|
+
export * from './InternalContext';
|
|
1
3
|
export * from './Hooks';
|
|
2
4
|
export { default as DataViewToolbar } from './DataViewToolbar';
|
|
3
5
|
export * from './DataViewToolbar';
|
|
6
|
+
export { default as DataViewTableTree } from './DataViewTableTree';
|
|
7
|
+
export * from './DataViewTableTree';
|
|
8
|
+
export { default as DataViewTableHeader } from './DataViewTableHeader';
|
|
9
|
+
export * from './DataViewTableHeader';
|
|
10
|
+
export { default as DataViewTableBasic } from './DataViewTableBasic';
|
|
11
|
+
export * from './DataViewTableBasic';
|
|
12
|
+
export { default as DataViewTable } from './DataViewTable';
|
|
13
|
+
export * from './DataViewTable';
|
|
14
|
+
export { default as DataViewEventsContext } from './DataViewEventsContext';
|
|
15
|
+
export * from './DataViewEventsContext';
|
|
4
16
|
export { default as DataView } from './DataView';
|
|
5
17
|
export * from './DataView';
|
package/dist/esm/index.js
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
// this file is autogenerated by generate-index.js, modifying it manually will have no effect
|
|
2
|
+
export { default as InternalContext } from './InternalContext';
|
|
3
|
+
export * from './InternalContext';
|
|
2
4
|
export * from './Hooks';
|
|
3
5
|
export { default as DataViewToolbar } from './DataViewToolbar';
|
|
4
6
|
export * from './DataViewToolbar';
|
|
7
|
+
export { default as DataViewTableTree } from './DataViewTableTree';
|
|
8
|
+
export * from './DataViewTableTree';
|
|
9
|
+
export { default as DataViewTableHeader } from './DataViewTableHeader';
|
|
10
|
+
export * from './DataViewTableHeader';
|
|
11
|
+
export { default as DataViewTableBasic } from './DataViewTableBasic';
|
|
12
|
+
export * from './DataViewTableBasic';
|
|
13
|
+
export { default as DataViewTable } from './DataViewTable';
|
|
14
|
+
export * from './DataViewTable';
|
|
15
|
+
export { default as DataViewEventsContext } from './DataViewEventsContext';
|
|
16
|
+
export * from './DataViewEventsContext';
|
|
5
17
|
export { default as DataView } from './DataView';
|
|
6
18
|
export * from './DataView';
|
package/package.json
CHANGED
|
@@ -11,11 +11,15 @@ source: react
|
|
|
11
11
|
# If you use typescript, the name of the interface to display props for
|
|
12
12
|
# These are found through the sourceProps function provided in patternfly-docs.source.js
|
|
13
13
|
sortValue: 4
|
|
14
|
-
propComponents: ['DataViewToolbar']
|
|
14
|
+
propComponents: ['DataViewToolbar', 'DataViewTableBasic', 'DataViewTableTree']
|
|
15
15
|
sourceLink: https://github.com/patternfly/react-data-view/blob/main/packages/module/patternfly-docs/content/extensions/data-view/examples/Components/Components.md
|
|
16
16
|
---
|
|
17
|
+
import { FolderIcon, FolderOpenIcon, LeafIcon, ExclamationCircleIcon } from '@patternfly/react-icons';
|
|
17
18
|
import { BulkSelect } from '@patternfly/react-component-groups';
|
|
18
|
-
import DataViewToolbar from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
|
|
19
|
+
import { DataViewToolbar } from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
|
|
20
|
+
import { DataViewTable } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
|
|
21
|
+
import { useDataViewSelection } from '@patternfly/react-data-view/dist/dynamic/Hooks';
|
|
22
|
+
import { DataView } from '@patternfly/react-data-view/dist/dynamic/DataView';
|
|
19
23
|
|
|
20
24
|
## Data view toolbar
|
|
21
25
|
|
|
@@ -23,9 +27,47 @@ The **data view toolbar** component renders a default opinionated data view tool
|
|
|
23
27
|
|
|
24
28
|
Data view toolbar can contain a `pagination`, `bulkSelect` or any other children content passed. The preffered way of passing children toolbar items is using the [toolbar item](/components/toolbar#toolbar-items) component.
|
|
25
29
|
|
|
26
|
-
### Basic example
|
|
30
|
+
### Basic toolbar example
|
|
27
31
|
|
|
28
32
|
```js file="./DataViewToolbarExample.tsx"
|
|
29
33
|
|
|
30
34
|
```
|
|
31
35
|
|
|
36
|
+
## Data view table
|
|
37
|
+
|
|
38
|
+
The **data view table** component renders your columns and rows definition into a [table](/components/table) component.
|
|
39
|
+
|
|
40
|
+
### Rows and columns customization
|
|
41
|
+
|
|
42
|
+
This example shows possible formats of `rows` and `columns` passed to the `DataViewTable` which allow you various customizations of the table header and body.
|
|
43
|
+
|
|
44
|
+
```js file="./DataViewTableExample.tsx"
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The `DataViewTable` component accepts the following props:
|
|
49
|
+
|
|
50
|
+
- `columns` defining the column headers of the table. Each item in the array can be a `ReactNode` (for simple headers) or an object with the following properties:
|
|
51
|
+
- `cell` (`ReactNode`) content to display in the column header.
|
|
52
|
+
- optional `props` (`ThProps`) to pass to the `<Th>` component, such as `width`, `sort`, and other table header cell properties.
|
|
53
|
+
|
|
54
|
+
- `rows` defining the rows to be displayed in the table. Each item in the array can be either an array of `DataViewTd` (for simple rows) or an object with the following properties:
|
|
55
|
+
- `row` (`DataViewTd[]`) defining the content for each cell in the row.
|
|
56
|
+
- optional `id` (`string`) for the row (can be used to match items in selection).
|
|
57
|
+
- optional `props` (`TrProps`) to pass to the `<Tr>` component, such as `isHoverable`, `isRowSelected`, and other table row properties.
|
|
58
|
+
|
|
59
|
+
- optional `ouiaId`
|
|
60
|
+
|
|
61
|
+
- optional `props` (`TableProps`) that are passed down to the `<Table>` component, except for `onSelect`, which is managed internally.
|
|
62
|
+
|
|
63
|
+
### Tree table example
|
|
64
|
+
This example shows the tree table variant with expandable rows, custom icons for leaf and parent nodes. Tree table is turned on by passing `isTreeTable` flag to the `DataViewTable` component. You can pass `collapsedIcon`, `expandedIcon` or `leafIcon` to be displayen rows with given status. The tree table rows have to be defined in a format of object with following keys:
|
|
65
|
+
- `row` (`DataViewTd[]`) defining the content for each cell in the row.
|
|
66
|
+
- `id` (`string`) for the row (used to match items in selection end expand the rows).
|
|
67
|
+
- optional `children` (`DataViewTrTree[]`) defining the children rows.
|
|
68
|
+
|
|
69
|
+
It is also possible to disable row selection using the `isSelectDisabled` function passed to the wrapping data view component.
|
|
70
|
+
|
|
71
|
+
```js file="./DataViewTableTreeExample.tsx"
|
|
72
|
+
|
|
73
|
+
```
|
package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableExample.tsx
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { DataViewTable, DataViewTr, DataViewTh } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
|
|
3
|
+
import { ExclamationCircleIcon } from '@patternfly/react-icons';
|
|
4
|
+
import { Button } from '@patternfly/react-core';
|
|
5
|
+
|
|
6
|
+
interface Repository {
|
|
7
|
+
id: number;
|
|
8
|
+
name: string;
|
|
9
|
+
branches: string | null;
|
|
10
|
+
prs: string | null;
|
|
11
|
+
workspaces: string;
|
|
12
|
+
lastCommit: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const repositories: Repository[] = [
|
|
16
|
+
{ id: 1, name: 'Repository one', branches: 'Branch one', prs: 'Pull request one', workspaces: 'Workspace one', lastCommit: 'Timestamp one' },
|
|
17
|
+
{ id: 2, name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
|
|
18
|
+
{ id: 3, name: 'Repository three', branches: 'Branch three', prs: 'Pull request three', workspaces: 'Workspace three', lastCommit: 'Timestamp three' },
|
|
19
|
+
{ id: 4, name: 'Repository four', branches: 'Branch four', prs: 'Pull request four', workspaces: 'Workspace four', lastCommit: 'Timestamp four' },
|
|
20
|
+
{ id: 5, name: 'Repository five', branches: 'Branch five', prs: 'Pull request five', workspaces: 'Workspace five', lastCommit: 'Timestamp five' },
|
|
21
|
+
{ id: 6, name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six' }
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
// you can also pass props to Tr by returning { row: DataViewTd[], props: TrProps } }
|
|
25
|
+
const rows: DataViewTr[] = repositories.map(({ id, name, branches, prs, workspaces, lastCommit }) => [
|
|
26
|
+
{ id, cell: workspaces, props: { favorites: { isFavorited: true } } },
|
|
27
|
+
{ cell: <Button href='#' variant='link' isInline>{name}</Button> },
|
|
28
|
+
branches,
|
|
29
|
+
prs,
|
|
30
|
+
workspaces,
|
|
31
|
+
lastCommit
|
|
32
|
+
]);
|
|
33
|
+
|
|
34
|
+
const columns: DataViewTh[] = [
|
|
35
|
+
null,
|
|
36
|
+
'Repositories',
|
|
37
|
+
{ cell: <>Branches<ExclamationCircleIcon className='pf-v5-u-ml-sm' color='var(--pf-v5-global--danger-color--100)'/></> },
|
|
38
|
+
'Pull requests',
|
|
39
|
+
{ cell: 'Workspaces', props: { info: { tooltip: 'More information' } } },
|
|
40
|
+
{ cell: 'Last commit', props: { sort: { sortBy: {}, columnIndex: 4 } } }
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
const ouiaId = 'TableExample';
|
|
44
|
+
|
|
45
|
+
export const BasicExample: React.FunctionComponent = () => (
|
|
46
|
+
<DataViewTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} rows={rows} />
|
|
47
|
+
);
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { DataView } from '@patternfly/react-data-view/dist/dynamic/DataView';
|
|
3
|
+
import { DataViewTable, DataViewTh, DataViewTrTree } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
|
|
4
|
+
import { useDataViewSelection } from '@patternfly/react-data-view/dist/dynamic/Hooks';
|
|
5
|
+
import { FolderIcon, FolderOpenIcon, LeafIcon } from '@patternfly/react-icons';
|
|
6
|
+
|
|
7
|
+
interface Repository {
|
|
8
|
+
name: string;
|
|
9
|
+
branches: string | null;
|
|
10
|
+
prs: string | null;
|
|
11
|
+
workspaces: string;
|
|
12
|
+
lastCommit: string;
|
|
13
|
+
children?: Repository[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const repositories: Repository[] = [
|
|
17
|
+
{
|
|
18
|
+
name: 'Repository one',
|
|
19
|
+
branches: 'Branch one',
|
|
20
|
+
prs: 'Pull request one',
|
|
21
|
+
workspaces: 'Workspace one',
|
|
22
|
+
lastCommit: 'Timestamp one',
|
|
23
|
+
children: [
|
|
24
|
+
{ name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
|
|
25
|
+
{ name: 'Repository three', branches: 'Branch three', prs: 'Pull request three', workspaces: 'Workspace three', lastCommit: 'Timestamp three' },
|
|
26
|
+
]
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: 'Repository four',
|
|
30
|
+
branches: 'Branch four',
|
|
31
|
+
prs: 'Pull request four',
|
|
32
|
+
workspaces: 'Workspace four',
|
|
33
|
+
lastCommit: 'Timestamp four',
|
|
34
|
+
children: [ { name: 'Repository five', branches: 'Branch five', prs: 'Pull request five', workspaces: 'Workspace five', lastCommit: 'Timestamp five' } ]
|
|
35
|
+
},
|
|
36
|
+
{ name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six' }
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
const buildRows = (repositories: Repository[]): DataViewTrTree[] => repositories.map((repo) => ({
|
|
40
|
+
row: [ repo.name, repo.branches, repo.prs, repo.workspaces, repo.lastCommit ],
|
|
41
|
+
id: repo.name, // unique ID for each row
|
|
42
|
+
...(repo.children
|
|
43
|
+
? {
|
|
44
|
+
children: buildRows(repo.children) // build rows for children
|
|
45
|
+
}
|
|
46
|
+
: {})
|
|
47
|
+
}));
|
|
48
|
+
|
|
49
|
+
const rows: DataViewTrTree[] = buildRows(repositories);
|
|
50
|
+
|
|
51
|
+
const columns: DataViewTh[] = [
|
|
52
|
+
'Repositories',
|
|
53
|
+
'Branches',
|
|
54
|
+
'Pull requests',
|
|
55
|
+
'Workspaces',
|
|
56
|
+
'Last commit'
|
|
57
|
+
];
|
|
58
|
+
|
|
59
|
+
const ouiaId = 'TreeTableExample';
|
|
60
|
+
|
|
61
|
+
export const BasicExample: React.FunctionComponent = () => {
|
|
62
|
+
const selection = useDataViewSelection({ matchOption: (a, b) => a.id === b.id });
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<DataView selection={selection}>
|
|
66
|
+
<DataViewTable isTreeTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} rows={rows} leafIcon={<LeafIcon/>} expandedIcon={<FolderOpenIcon aria-hidden />} collapsedIcon={<FolderIcon aria-hidden />} />
|
|
67
|
+
</DataView>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
---
|
|
2
|
+
# Sidenav top-level section
|
|
3
|
+
# should be the same for all markdown files
|
|
4
|
+
section: extensions
|
|
5
|
+
subsection: Data view
|
|
6
|
+
# Sidenav secondary level section
|
|
7
|
+
# should be the same for all markdown files
|
|
8
|
+
id: Events context
|
|
9
|
+
# Tab (react | react-demos | html | html-demos | design-guidelines | accessibility)
|
|
10
|
+
source: react
|
|
11
|
+
# If you use typescript, the name of the interface to display props for
|
|
12
|
+
# These are found through the sourceProps function provided in patternfly-docs.source.js
|
|
13
|
+
sortValue: 3
|
|
14
|
+
sourceLink: https://github.com/patternfly/react-data-view/blob/main/packages/module/patternfly-docs/content/extensions/data-view/examples/EventsContext/EventsContext.md
|
|
15
|
+
---
|
|
16
|
+
import { useState, useEffect, useRef, useMemo } from 'react';
|
|
17
|
+
import { Table, Tbody, Th, Thead, Tr, Td } from '@patternfly/react-table';
|
|
18
|
+
import { DataView } from '@patternfly/react-data-view/dist/dynamic/DataView';
|
|
19
|
+
import { DataViewTable } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
|
|
20
|
+
import { useDataViewEventsContext, DataViewEventsContext, DataViewEventsProvider, EventTypes } from '@patternfly/react-data-view/dist/dynamic/DataViewEventsContext';
|
|
21
|
+
import { Drawer, DrawerContent, DrawerContentBody } from '@patternfly/react-core';
|
|
22
|
+
|
|
23
|
+
The **data view events context** provides a way of listening to the data view events from the outside of the component.
|
|
24
|
+
|
|
25
|
+
### Row click subscription example
|
|
26
|
+
The following example demonstrates how to use the `DataViewEventsContext` to manage shared state and handle events. The `DataViewEventsProvider` is used to wrap components that need access to the shared context. This example illustrates how to set up a layout that listens for data view row click events and displays detailed information about the selected row in a [drawer component](/components/drawer).
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
```js file="./EventsExample.tsx"
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import React, { useEffect, useState, useRef, useMemo } from 'react';
|
|
2
|
+
import { Drawer, DrawerActions, DrawerCloseButton, DrawerContent, DrawerContentBody, DrawerHead, DrawerPanelContent, Title, Text } from '@patternfly/react-core';
|
|
3
|
+
import { DataView } from '@patternfly/react-data-view/dist/dynamic/DataView';
|
|
4
|
+
import { DataViewTable } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
|
|
5
|
+
import { DataViewEventsProvider, EventTypes, useDataViewEventsContext } from '@patternfly/react-data-view/dist/dynamic/DataViewEventsContext';
|
|
6
|
+
|
|
7
|
+
interface Repository {
|
|
8
|
+
name: string;
|
|
9
|
+
branches: string | null;
|
|
10
|
+
prs: string | null;
|
|
11
|
+
workspaces: string;
|
|
12
|
+
lastCommit: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const repositories: Repository[] = [
|
|
16
|
+
{ name: 'Repository one', branches: 'Branch one', prs: 'Pull request one', workspaces: 'Workspace one', lastCommit: 'Timestamp one' },
|
|
17
|
+
{ name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
|
|
18
|
+
{ name: 'Repository three', branches: 'Branch three', prs: 'Pull request three', workspaces: 'Workspace three', lastCommit: 'Timestamp three' },
|
|
19
|
+
{ name: 'Repository four', branches: 'Branch four', prs: 'Pull request four', workspaces: 'Workspace four', lastCommit: 'Timestamp four' },
|
|
20
|
+
{ name: 'Repository five', branches: 'Branch five', prs: 'Pull request five', workspaces: 'Workspace five', lastCommit: 'Timestamp five' },
|
|
21
|
+
{ name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six' }
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
const columns = [ 'Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit' ];
|
|
25
|
+
|
|
26
|
+
const ouiaId = 'ContextExample';
|
|
27
|
+
|
|
28
|
+
interface RepositoryDetailProps {
|
|
29
|
+
selectedRepo?: Repository;
|
|
30
|
+
setSelectedRepo: React.Dispatch<React.SetStateAction<Repository | undefined>>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const RepositoryDetail: React.FunctionComponent<RepositoryDetailProps> = ({ selectedRepo, setSelectedRepo }) => {
|
|
34
|
+
const context = useDataViewEventsContext();
|
|
35
|
+
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
const unsubscribe = context.subscribe(EventTypes.rowClick, (repo: Repository) => {
|
|
38
|
+
setSelectedRepo(repo);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
return () => unsubscribe();
|
|
42
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
43
|
+
}, []);
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<DrawerPanelContent>
|
|
47
|
+
<DrawerHead>
|
|
48
|
+
<Title className="pf-v5-u-mb-md" headingLevel="h2" ouiaId="detail-drawer-title">
|
|
49
|
+
Detail of {selectedRepo?.name}
|
|
50
|
+
</Title>
|
|
51
|
+
<Text>Branches: {selectedRepo?.branches}</Text>
|
|
52
|
+
<Text>Pull requests: {selectedRepo?.prs}</Text>
|
|
53
|
+
<Text>Workspaces: {selectedRepo?.workspaces}</Text>
|
|
54
|
+
<Text>Last commit: {selectedRepo?.lastCommit}</Text>
|
|
55
|
+
<DrawerActions>
|
|
56
|
+
<DrawerCloseButton onClick={() => setSelectedRepo(undefined)} data-ouia-component-id="detail-drawer-close-btn"/>
|
|
57
|
+
</DrawerActions>
|
|
58
|
+
</DrawerHead>
|
|
59
|
+
</DrawerPanelContent>
|
|
60
|
+
);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
interface RepositoriesTableProps {
|
|
64
|
+
selectedRepo?: Repository;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const RepositoriesTable: React.FunctionComponent<RepositoriesTableProps> = ({ selectedRepo = undefined }) => {
|
|
68
|
+
const { trigger } = useDataViewEventsContext();
|
|
69
|
+
const rows = useMemo(() => {
|
|
70
|
+
const handleRowClick = (repo: Repository | undefined) => {
|
|
71
|
+
trigger(EventTypes.rowClick, repo);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
return repositories.map(repo => ({
|
|
75
|
+
row: Object.values(repo),
|
|
76
|
+
props: {
|
|
77
|
+
isClickable: true,
|
|
78
|
+
onRowClick: () => handleRowClick(selectedRepo?.name === repo.name ? undefined : repo),
|
|
79
|
+
isRowSelected: selectedRepo?.name === repo.name
|
|
80
|
+
}
|
|
81
|
+
}));
|
|
82
|
+
}, [ selectedRepo?.name, trigger ]);
|
|
83
|
+
|
|
84
|
+
return (
|
|
85
|
+
<DataView>
|
|
86
|
+
<DataViewTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} rows={rows} />
|
|
87
|
+
</DataView>
|
|
88
|
+
);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export const BasicExample: React.FunctionComponent = () => {
|
|
92
|
+
const [ selectedRepo, setSelectedRepo ] = useState<Repository>();
|
|
93
|
+
const drawerRef = useRef<HTMLDivElement>(null);
|
|
94
|
+
|
|
95
|
+
return (
|
|
96
|
+
<DataViewEventsProvider>
|
|
97
|
+
<Drawer isExpanded={Boolean(selectedRepo)} onExpand={() => drawerRef.current?.focus()} data-ouia-component-id="detail-drawer" >
|
|
98
|
+
<DrawerContent
|
|
99
|
+
panelContent={<RepositoryDetail selectedRepo={selectedRepo} setSelectedRepo={setSelectedRepo} />}
|
|
100
|
+
>
|
|
101
|
+
<DrawerContentBody>
|
|
102
|
+
<RepositoriesTable selectedRepo={selectedRepo} />
|
|
103
|
+
</DrawerContentBody>
|
|
104
|
+
</DrawerContent>
|
|
105
|
+
</Drawer>
|
|
106
|
+
</DataViewEventsProvider>
|
|
107
|
+
);
|
|
108
|
+
};
|
package/patternfly-docs/content/extensions/data-view/examples/Functionality/Functionality.md
CHANGED
|
@@ -18,6 +18,7 @@ import { useDataViewPagination, useDataViewSelection } from '@patternfly/react-d
|
|
|
18
18
|
import { DataView } from '@patternfly/react-data-view/dist/dynamic/DataView';
|
|
19
19
|
import { BulkSelect, BulkSelectValue } from '@patternfly/react-component-groups/dist/dynamic/BulkSelect';
|
|
20
20
|
import { DataViewToolbar } from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
|
|
21
|
+
import { DataViewTable } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
|
|
21
22
|
import { BrowserRouter, useSearchParams } from 'react-router-dom';
|
|
22
23
|
|
|
23
24
|
This is a list of functionality you can use to manage data displayed in the **data view**.
|
|
@@ -34,9 +35,9 @@ The `useDataViewPagination` hook manages the pagination state of the data view.
|
|
|
34
35
|
|
|
35
36
|
**Initial values:**
|
|
36
37
|
- `perPage` initial value
|
|
37
|
-
-
|
|
38
|
-
-
|
|
39
|
-
-
|
|
38
|
+
- optional `page` initial value
|
|
39
|
+
- optional `searchParams` object
|
|
40
|
+
- optional `setSearchParams` function
|
|
40
41
|
|
|
41
42
|
While the hook works seamlessly with React Router library, you do not need to use it to take advantage of URL persistence. The `searchParams` and `setSearchParams` props can be managed using native browser APIs (`URLSearchParams` and `window.history.pushState`) or any other routing library of your choice. If you don't pass these two props, the pagination state will be stored internally without the URL usage.
|
|
42
43
|
|
|
@@ -68,8 +69,8 @@ Data view toolbar can display a bulk selection component using the `bulkSelect`
|
|
|
68
69
|
The `useDataViewSelection` hook manages the selection state of the data view.
|
|
69
70
|
|
|
70
71
|
**Initial values:**
|
|
71
|
-
-
|
|
72
|
-
-
|
|
72
|
+
- optional `initialSelected` array of record's identifiers selected by default
|
|
73
|
+
- `matchOption` function to check if given record is selected
|
|
73
74
|
|
|
74
75
|
*When no `matchOption` is passed, the `Array.prototype.includes()` operation is performed on the `selected` array.*
|
|
75
76
|
|
package/patternfly-docs/content/extensions/data-view/examples/Functionality/PaginationExample.tsx
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React, { useMemo } from 'react';
|
|
2
2
|
import { Pagination } from '@patternfly/react-core';
|
|
3
|
-
import { Table, Tbody, Th, Thead, Tr, Td } from '@patternfly/react-table';
|
|
4
|
-
import { useDataViewPagination } from '@patternfly/react-data-view/dist/dynamic/Hooks';
|
|
5
|
-
import DataView from '@patternfly/react-data-view/dist/dynamic/DataView';
|
|
6
|
-
import DataViewToolbar from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
|
|
7
3
|
import { BrowserRouter, useSearchParams } from 'react-router-dom';
|
|
4
|
+
import { useDataViewPagination } from '@patternfly/react-data-view/dist/dynamic/Hooks';
|
|
5
|
+
import { DataView } from '@patternfly/react-data-view/dist/dynamic/DataView';
|
|
6
|
+
import { DataViewToolbar } from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
|
|
7
|
+
import { DataViewTable } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
|
|
8
8
|
|
|
9
9
|
const perPageOptions = [
|
|
10
10
|
{ title: '5', value: 5 },
|
|
@@ -20,21 +20,17 @@ interface Repository {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
const repositories: Repository[] = [
|
|
23
|
-
{ name: 'one', branches: '
|
|
24
|
-
{ name: '
|
|
25
|
-
{ name: '
|
|
26
|
-
{ name: '
|
|
27
|
-
{ name: '
|
|
28
|
-
{ name: '
|
|
23
|
+
{ name: 'Repository one', branches: 'Branch one', prs: 'Pull request one', workspaces: 'Workspace one', lastCommit: 'Timestamp one' },
|
|
24
|
+
{ name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
|
|
25
|
+
{ name: 'Repository three', branches: 'Branch three', prs: 'Pull request three', workspaces: 'Workspace three', lastCommit: 'Timestamp three' },
|
|
26
|
+
{ name: 'Repository four', branches: 'Branch four', prs: 'Pull request four', workspaces: 'Workspace four', lastCommit: 'Timestamp four' },
|
|
27
|
+
{ name: 'Repository five', branches: 'Branch five', prs: 'Pull request five', workspaces: 'Workspace five', lastCommit: 'Timestamp five' },
|
|
28
|
+
{ name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six' }
|
|
29
29
|
];
|
|
30
30
|
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
prs: 'Pull requests',
|
|
35
|
-
workspaces: 'Workspaces',
|
|
36
|
-
lastCommit: 'Last commit'
|
|
37
|
-
};
|
|
31
|
+
const rows = repositories.map(item => Object.values(item));
|
|
32
|
+
|
|
33
|
+
const columns = [ 'Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit' ];
|
|
38
34
|
|
|
39
35
|
const ouiaId = 'LayoutExample';
|
|
40
36
|
|
|
@@ -43,24 +39,11 @@ const MyTable: React.FunctionComponent = () => {
|
|
|
43
39
|
const pagination = useDataViewPagination({ perPage: 5, searchParams, setSearchParams });
|
|
44
40
|
const { page, perPage } = pagination;
|
|
45
41
|
|
|
46
|
-
const
|
|
42
|
+
const pageRows = useMemo(() => rows.slice((page - 1) * perPage, ((page - 1) * perPage) + perPage), [ page, perPage ]);
|
|
47
43
|
return (
|
|
48
44
|
<DataView>
|
|
49
45
|
<DataViewToolbar ouiaId='DataViewHeader' pagination={<Pagination perPageOptions={perPageOptions} itemCount={repositories.length} {...pagination} />} />
|
|
50
|
-
<
|
|
51
|
-
<Thead data-ouia-component-id={`${ouiaId}-thead`}>
|
|
52
|
-
<Tr ouiaId={`${ouiaId}-tr-head`}>
|
|
53
|
-
{Object.values(cols).map((column, index) => <Th key={index} data-ouia-component-id={`${ouiaId}-th-${index}`}>{column}</Th>)}
|
|
54
|
-
</Tr>
|
|
55
|
-
</Thead>
|
|
56
|
-
<Tbody>
|
|
57
|
-
{data.map((repo, rowIndex) => (
|
|
58
|
-
<Tr key={repo.name} ouiaId={`${ouiaId}-tr-${rowIndex}`}>
|
|
59
|
-
{Object.keys(cols).map((column, colIndex) => <Td key={colIndex} data-ouia-component-id={`${ouiaId}-td-${rowIndex}-${colIndex}`}>{repo[column]}</Td>)}
|
|
60
|
-
</Tr>
|
|
61
|
-
))}
|
|
62
|
-
</Tbody>
|
|
63
|
-
</Table>
|
|
46
|
+
<DataViewTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} rows={pageRows} />
|
|
64
47
|
<DataViewToolbar ouiaId='DataViewFooter' pagination={<Pagination isCompact perPageOptions={perPageOptions} itemCount={repositories.length} {...pagination} />} />
|
|
65
48
|
</DataView>
|
|
66
49
|
)
|