@patternfly/react-data-view 7.0.0-prerelease.1 → 7.0.0-prerelease.3
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 +12 -0
- package/dist/cjs/DataView/DataView.js +14 -3
- package/dist/cjs/DataView/DataView.test.js +3 -4
- 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 +18 -0
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.js +71 -0
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.test.d.ts +1 -0
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.test.js +43 -0
- package/dist/cjs/DataViewTableBasic/index.d.ts +2 -0
- package/dist/cjs/DataViewTableBasic/index.js +23 -0
- package/dist/cjs/DataViewTableHead/DataViewTableHead.d.ts +13 -0
- package/dist/cjs/DataViewTableHead/DataViewTableHead.js +57 -0
- package/dist/cjs/DataViewTableHead/DataViewTableHead.test.d.ts +1 -0
- package/dist/cjs/DataViewTableHead/DataViewTableHead.test.js +36 -0
- package/dist/cjs/DataViewTableHead/index.d.ts +2 -0
- package/dist/cjs/DataViewTableHead/index.js +23 -0
- package/dist/cjs/DataViewTableTree/DataViewTableTree.d.ts +24 -0
- package/dist/cjs/DataViewTableTree/DataViewTableTree.js +132 -0
- package/dist/cjs/DataViewTableTree/DataViewTableTree.test.d.ts +1 -0
- package/dist/cjs/DataViewTableTree/DataViewTableTree.test.js +90 -0
- package/dist/cjs/DataViewTableTree/index.d.ts +2 -0
- package/dist/cjs/DataViewTableTree/index.js +23 -0
- package/dist/cjs/DataViewToolbar/DataViewToolbar.d.ts +2 -0
- package/dist/cjs/DataViewToolbar/DataViewToolbar.js +2 -1
- package/dist/cjs/Hooks/pagination.d.ts +9 -5
- package/dist/cjs/Hooks/pagination.js +8 -8
- package/dist/cjs/Hooks/pagination.test.js +0 -52
- 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 +25 -0
- package/dist/cjs/InternalContext/InternalContext.js +40 -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/DataViewTableHead/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 +12 -0
- package/dist/esm/DataView/DataView.js +13 -2
- package/dist/esm/DataView/DataView.test.js +3 -4
- 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 +18 -0
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.js +44 -0
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.test.d.ts +1 -0
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.test.js +38 -0
- package/dist/esm/DataViewTableBasic/index.d.ts +2 -0
- package/dist/esm/DataViewTableBasic/index.js +2 -0
- package/dist/esm/DataViewTableHead/DataViewTableHead.d.ts +13 -0
- package/dist/esm/DataViewTableHead/DataViewTableHead.js +30 -0
- package/dist/esm/DataViewTableHead/DataViewTableHead.test.d.ts +1 -0
- package/dist/esm/DataViewTableHead/DataViewTableHead.test.js +31 -0
- package/dist/esm/DataViewTableHead/index.d.ts +2 -0
- package/dist/esm/DataViewTableHead/index.js +2 -0
- package/dist/esm/DataViewTableTree/DataViewTableTree.d.ts +24 -0
- package/dist/esm/DataViewTableTree/DataViewTableTree.js +105 -0
- package/dist/esm/DataViewTableTree/DataViewTableTree.test.d.ts +1 -0
- package/dist/esm/DataViewTableTree/DataViewTableTree.test.js +85 -0
- package/dist/esm/DataViewTableTree/index.d.ts +2 -0
- package/dist/esm/DataViewTableTree/index.js +2 -0
- package/dist/esm/DataViewToolbar/DataViewToolbar.d.ts +2 -0
- package/dist/esm/DataViewToolbar/DataViewToolbar.js +2 -1
- package/dist/esm/Hooks/pagination.d.ts +9 -5
- package/dist/esm/Hooks/pagination.js +9 -9
- package/dist/esm/Hooks/pagination.test.js +0 -52
- 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 +25 -0
- package/dist/esm/InternalContext/InternalContext.js +12 -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/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +11 -10
- package/patternfly-docs/content/extensions/data-view/examples/Components/Components.md +80 -5
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableEmptyExample.tsx +57 -0
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableErrorExample.tsx +45 -0
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableExample.tsx +67 -0
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableLoadingExample.tsx +27 -0
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableTreeExample.tsx +71 -0
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewToolbarActionsExample.tsx +27 -0
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewToolbarExample.tsx +4 -4
- 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 +12 -11
- package/patternfly-docs/content/extensions/data-view/examples/Functionality/PaginationExample.tsx +20 -37
- package/patternfly-docs/content/extensions/data-view/examples/Functionality/SelectionExample.tsx +15 -46
- package/patternfly-docs/content/extensions/data-view/examples/Layout/AbstractLayoutExample.tsx +3 -4
- package/patternfly-docs/content/extensions/data-view/examples/Layout/Layout.md +2 -1
- package/patternfly-docs/content/extensions/data-view/examples/Layout/PredefinedLayoutExample.tsx +20 -51
- package/patternfly-docs/pages/index.js +1 -1
- package/release.config.js +1 -5
- package/src/DataView/DataView.test.tsx +3 -4
- package/src/DataView/DataView.tsx +25 -3
- package/src/DataView/__snapshots__/DataView.test.tsx.snap +16 -16
- 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 +1042 -0
- package/src/DataViewTable/index.ts +2 -0
- package/src/DataViewTableBasic/DataViewTableBasic.test.tsx +65 -0
- package/src/DataViewTableBasic/DataViewTableBasic.tsx +82 -0
- package/src/DataViewTableBasic/__snapshots__/DataViewTableBasic.test.tsx.snap +555 -0
- package/src/DataViewTableBasic/index.ts +2 -0
- package/src/DataViewTableHead/DataViewTableHead.test.tsx +50 -0
- package/src/DataViewTableHead/DataViewTableHead.tsx +53 -0
- package/src/DataViewTableHead/__snapshots__/DataViewTableHead.test.tsx.snap +227 -0
- package/src/DataViewTableHead/index.ts +2 -0
- package/src/DataViewTableTree/DataViewTableTree.test.tsx +113 -0
- package/src/DataViewTableTree/DataViewTableTree.tsx +164 -0
- package/src/DataViewTableTree/__snapshots__/DataViewTableTree.test.tsx.snap +1200 -0
- package/src/DataViewTableTree/index.ts +2 -0
- package/src/DataViewToolbar/DataViewToolbar.tsx +9 -2
- package/src/DataViewToolbar/__snapshots__/DataViewToolbar.test.tsx.snap +208 -166
- package/src/Hooks/pagination.test.tsx +0 -80
- package/src/Hooks/pagination.ts +22 -16
- 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 +51 -0
- package/src/InternalContext/index.ts +2 -0
- package/src/index.ts +18 -0
|
@@ -6,35 +6,35 @@ exports[`DataView component should render correctly 1`] = `
|
|
|
6
6
|
"baseElement": <body>
|
|
7
7
|
<div>
|
|
8
8
|
<div
|
|
9
|
-
class="pf-
|
|
10
|
-
data-ouia-component-id="DataView-stack
|
|
9
|
+
class="pf-v6-l-stack"
|
|
10
|
+
data-ouia-component-id="DataView-stack"
|
|
11
11
|
>
|
|
12
12
|
<div
|
|
13
|
-
class="pf-
|
|
13
|
+
class="pf-v6-l-stack__item"
|
|
14
14
|
data-ouia-component-id="DataView-stack-item-0"
|
|
15
15
|
>
|
|
16
16
|
<div
|
|
17
|
-
style="width: 100%; height: 5rem;
|
|
17
|
+
style="width: 100%; height: 5rem;"
|
|
18
18
|
>
|
|
19
19
|
Header
|
|
20
20
|
</div>
|
|
21
21
|
</div>
|
|
22
22
|
<div
|
|
23
|
-
class="pf-
|
|
23
|
+
class="pf-v6-l-stack__item"
|
|
24
24
|
data-ouia-component-id="DataView-stack-item-1"
|
|
25
25
|
>
|
|
26
26
|
<div
|
|
27
|
-
style="width: 100%; height: 5rem;
|
|
27
|
+
style="width: 100%; height: 5rem;"
|
|
28
28
|
>
|
|
29
29
|
Data representation
|
|
30
30
|
</div>
|
|
31
31
|
</div>
|
|
32
32
|
<div
|
|
33
|
-
class="pf-
|
|
33
|
+
class="pf-v6-l-stack__item"
|
|
34
34
|
data-ouia-component-id="DataView-stack-item-2"
|
|
35
35
|
>
|
|
36
36
|
<div
|
|
37
|
-
style="width: 100%; height: 5rem;
|
|
37
|
+
style="width: 100%; height: 5rem;"
|
|
38
38
|
>
|
|
39
39
|
Footer
|
|
40
40
|
</div>
|
|
@@ -44,35 +44,35 @@ exports[`DataView component should render correctly 1`] = `
|
|
|
44
44
|
</body>,
|
|
45
45
|
"container": <div>
|
|
46
46
|
<div
|
|
47
|
-
class="pf-
|
|
48
|
-
data-ouia-component-id="DataView-stack
|
|
47
|
+
class="pf-v6-l-stack"
|
|
48
|
+
data-ouia-component-id="DataView-stack"
|
|
49
49
|
>
|
|
50
50
|
<div
|
|
51
|
-
class="pf-
|
|
51
|
+
class="pf-v6-l-stack__item"
|
|
52
52
|
data-ouia-component-id="DataView-stack-item-0"
|
|
53
53
|
>
|
|
54
54
|
<div
|
|
55
|
-
style="width: 100%; height: 5rem;
|
|
55
|
+
style="width: 100%; height: 5rem;"
|
|
56
56
|
>
|
|
57
57
|
Header
|
|
58
58
|
</div>
|
|
59
59
|
</div>
|
|
60
60
|
<div
|
|
61
|
-
class="pf-
|
|
61
|
+
class="pf-v6-l-stack__item"
|
|
62
62
|
data-ouia-component-id="DataView-stack-item-1"
|
|
63
63
|
>
|
|
64
64
|
<div
|
|
65
|
-
style="width: 100%; height: 5rem;
|
|
65
|
+
style="width: 100%; height: 5rem;"
|
|
66
66
|
>
|
|
67
67
|
Data representation
|
|
68
68
|
</div>
|
|
69
69
|
</div>
|
|
70
70
|
<div
|
|
71
|
-
class="pf-
|
|
71
|
+
class="pf-v6-l-stack__item"
|
|
72
72
|
data-ouia-component-id="DataView-stack-item-2"
|
|
73
73
|
>
|
|
74
74
|
<div
|
|
75
|
-
style="width: 100%; height: 5rem;
|
|
75
|
+
style="width: 100%; height: 5rem;"
|
|
76
76
|
>
|
|
77
77
|
Footer
|
|
78
78
|
</div>
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, fireEvent } from '@testing-library/react';
|
|
3
|
+
import { useDataViewEventsContext, DataViewEventsProvider, EventTypes } from './DataViewEventsContext';
|
|
4
|
+
|
|
5
|
+
let id = 0;
|
|
6
|
+
|
|
7
|
+
beforeAll(() => {
|
|
8
|
+
Object.defineProperty(global, 'crypto', {
|
|
9
|
+
value: {
|
|
10
|
+
randomUUID: jest.fn(() => `mocked-uuid-${id++}`),
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describe('DataViewEventsContext', () => {
|
|
16
|
+
test('should provide context value and allow subscriptions', () => {
|
|
17
|
+
const callback = jest.fn();
|
|
18
|
+
|
|
19
|
+
const TestComponent = () => {
|
|
20
|
+
const { subscribe, trigger } = useDataViewEventsContext();
|
|
21
|
+
|
|
22
|
+
React.useEffect(() => {
|
|
23
|
+
const unsubscribe = subscribe(EventTypes.rowClick, callback);
|
|
24
|
+
return () => unsubscribe();
|
|
25
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
26
|
+
}, []);
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<button onClick={() => trigger(EventTypes.rowClick, 'some payload')}>Trigger</button>
|
|
30
|
+
);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const { getByText } = render(
|
|
34
|
+
<DataViewEventsProvider>
|
|
35
|
+
<TestComponent />
|
|
36
|
+
</DataViewEventsProvider>
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
fireEvent.click(getByText('Trigger'));
|
|
40
|
+
expect(callback).toHaveBeenCalledWith('some payload');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('should handle unsubscribing correctly', () => {
|
|
44
|
+
const callback = jest.fn();
|
|
45
|
+
|
|
46
|
+
const TestComponent = () => {
|
|
47
|
+
const { subscribe, trigger } = useDataViewEventsContext();
|
|
48
|
+
|
|
49
|
+
React.useEffect(() => {
|
|
50
|
+
const unsubscribe = subscribe(EventTypes.rowClick, callback);
|
|
51
|
+
unsubscribe();
|
|
52
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
53
|
+
}, []);
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<button onClick={() => trigger(EventTypes.rowClick, 'some payload')}>Trigger</button>
|
|
57
|
+
);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const { getByText } = render(
|
|
61
|
+
<DataViewEventsProvider>
|
|
62
|
+
<TestComponent />
|
|
63
|
+
</DataViewEventsProvider>
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
fireEvent.click(getByText('Trigger'));
|
|
67
|
+
|
|
68
|
+
expect(callback).not.toHaveBeenCalled();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('should handle multiple subscriptions and trigger events correctly', () => {
|
|
72
|
+
const callback1 = jest.fn();
|
|
73
|
+
const callback2 = jest.fn();
|
|
74
|
+
|
|
75
|
+
const TestComponent = () => {
|
|
76
|
+
const { subscribe, trigger } = useDataViewEventsContext();
|
|
77
|
+
|
|
78
|
+
React.useEffect(() => {
|
|
79
|
+
const unsubscribe1 = subscribe(EventTypes.rowClick, callback1);
|
|
80
|
+
const unsubscribe2 = subscribe(EventTypes.rowClick, callback2);
|
|
81
|
+
|
|
82
|
+
return () => {
|
|
83
|
+
unsubscribe1();
|
|
84
|
+
unsubscribe2();
|
|
85
|
+
};
|
|
86
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
87
|
+
}, []);
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<button onClick={() => trigger(EventTypes.rowClick, 'some payload')}>Trigger</button>
|
|
91
|
+
);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const { getByText } = render(
|
|
95
|
+
<DataViewEventsProvider>
|
|
96
|
+
<TestComponent />
|
|
97
|
+
</DataViewEventsProvider>
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
fireEvent.click(getByText('Trigger'));
|
|
101
|
+
|
|
102
|
+
expect(callback1).toHaveBeenCalledWith('some payload');
|
|
103
|
+
expect(callback2).toHaveBeenCalledWith('some payload');
|
|
104
|
+
});
|
|
105
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
PropsWithChildren,
|
|
3
|
+
createContext,
|
|
4
|
+
useCallback,
|
|
5
|
+
useContext,
|
|
6
|
+
useState
|
|
7
|
+
} from "react";
|
|
8
|
+
|
|
9
|
+
export const EventTypes = {
|
|
10
|
+
rowClick: 'rowClick'
|
|
11
|
+
} as const;
|
|
12
|
+
|
|
13
|
+
export type DataViewEvent = typeof EventTypes[keyof typeof EventTypes];
|
|
14
|
+
|
|
15
|
+
type Callback = (...args: any[]) => void; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
16
|
+
interface Subscriptions { [id: string]: Callback }
|
|
17
|
+
type EventSubscriptions = { [event in DataViewEvent]: Subscriptions };
|
|
18
|
+
type Subscribe = (event: DataViewEvent, callback: Callback) => () => void;
|
|
19
|
+
type Trigger = (event: DataViewEvent, ...payload: any[]) => void; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
20
|
+
|
|
21
|
+
export interface DataViewEventsContextValue {
|
|
22
|
+
subscribe: Subscribe;
|
|
23
|
+
trigger: Trigger;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const DataViewEventsContext = createContext<DataViewEventsContextValue>({
|
|
27
|
+
subscribe: () => () => null,
|
|
28
|
+
trigger: () => null
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export const DataViewEventsProvider = ({ children }: PropsWithChildren) => {
|
|
32
|
+
const [ subscriptions, setSubscriptions ] = useState<EventSubscriptions>({
|
|
33
|
+
[EventTypes.rowClick]: {}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const subscribe: Subscribe = (event, callback) => {
|
|
37
|
+
const id = crypto.randomUUID();
|
|
38
|
+
|
|
39
|
+
// set new subscription
|
|
40
|
+
setSubscriptions(prevSubscriptions => ({
|
|
41
|
+
...prevSubscriptions,
|
|
42
|
+
[event]: { ...prevSubscriptions[event], [id]: callback }
|
|
43
|
+
}));
|
|
44
|
+
|
|
45
|
+
// return unsubscribe function
|
|
46
|
+
return () => {
|
|
47
|
+
setSubscriptions(prevSubscriptions => {
|
|
48
|
+
const updatedSubscriptions = { ...prevSubscriptions };
|
|
49
|
+
delete updatedSubscriptions[event][id];
|
|
50
|
+
return updatedSubscriptions;
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const trigger = useCallback((event: DataViewEvent, ...payload: unknown[]) => {
|
|
56
|
+
Object.values(subscriptions[event]).forEach(callback => {
|
|
57
|
+
callback(...payload);
|
|
58
|
+
});
|
|
59
|
+
}, [ subscriptions ]);
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<DataViewEventsContext.Provider value={{ subscribe, trigger }}>
|
|
63
|
+
{children}
|
|
64
|
+
</DataViewEventsContext.Provider>
|
|
65
|
+
);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const useDataViewEventsContext = () => useContext(DataViewEventsContext);
|
|
69
|
+
|
|
70
|
+
export default DataViewEventsContext;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
import { DataViewTable, DataViewTrTree } from './DataViewTable';
|
|
4
|
+
|
|
5
|
+
interface Repository {
|
|
6
|
+
name: string;
|
|
7
|
+
branches: string | null;
|
|
8
|
+
prs: string | null;
|
|
9
|
+
workspaces: string;
|
|
10
|
+
lastCommit: string;
|
|
11
|
+
children?: Repository[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const repositories: Repository[] = [
|
|
15
|
+
{ name: 'Repository one', branches: 'Branch one', prs: 'Pull request one', workspaces: 'Workspace one', lastCommit: 'Timestamp one' },
|
|
16
|
+
{ name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
|
|
17
|
+
{ name: 'Repository three', branches: 'Branch three', prs: 'Pull request three', workspaces: 'Workspace three', lastCommit: 'Timestamp three' },
|
|
18
|
+
{ name: 'Repository four', branches: 'Branch four', prs: 'Pull request four', workspaces: 'Workspace four', lastCommit: 'Timestamp four' },
|
|
19
|
+
{ name: 'Repository five', branches: 'Branch five', prs: 'Pull request five', workspaces: 'Workspace five', lastCommit: 'Timestamp five' },
|
|
20
|
+
{ name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six' }
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
const rows = repositories.map(repo => ({ row: Object.values(repo) }));
|
|
24
|
+
|
|
25
|
+
const repositoriesTree: Repository[] = [
|
|
26
|
+
{
|
|
27
|
+
name: 'Repository one',
|
|
28
|
+
branches: 'Branch one',
|
|
29
|
+
prs: 'Pull request one',
|
|
30
|
+
workspaces: 'Workspace one',
|
|
31
|
+
lastCommit: 'Timestamp one',
|
|
32
|
+
children: [
|
|
33
|
+
{ name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
|
|
34
|
+
{ name: 'Repository three', branches: 'Branch three', prs: 'Pull request three', workspaces: 'Workspace three', lastCommit: 'Timestamp three' },
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: 'Repository four',
|
|
39
|
+
branches: 'Branch four',
|
|
40
|
+
prs: 'Pull request four',
|
|
41
|
+
workspaces: 'Workspace four',
|
|
42
|
+
lastCommit: 'Timestamp four',
|
|
43
|
+
children: [ { name: 'Repository five', branches: 'Branch five', prs: 'Pull request five', workspaces: 'Workspace five', lastCommit: 'Timestamp five' } ]
|
|
44
|
+
},
|
|
45
|
+
{ name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six' }
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
const buildRows = (repositories: Repository[]): DataViewTrTree[] => repositories.map((repo) => ({
|
|
51
|
+
row: [ repo.name, repo.branches, repo.prs, repo.workspaces, repo.lastCommit ],
|
|
52
|
+
id: repo.name, // unique ID for each row
|
|
53
|
+
...(repo.children
|
|
54
|
+
? {
|
|
55
|
+
children: buildRows(repo.children) // build rows for children
|
|
56
|
+
}
|
|
57
|
+
: {})
|
|
58
|
+
}));
|
|
59
|
+
|
|
60
|
+
const treeRows = buildRows(repositoriesTree);
|
|
61
|
+
|
|
62
|
+
const columns = [ 'Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit' ];
|
|
63
|
+
|
|
64
|
+
const ouiaId = 'TableExample';
|
|
65
|
+
|
|
66
|
+
describe('DataViewTable component', () => {
|
|
67
|
+
test('should render a basic table correctly', () => {
|
|
68
|
+
const { container } = render(
|
|
69
|
+
<DataViewTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} rows={rows} />
|
|
70
|
+
);
|
|
71
|
+
expect(container).toMatchSnapshot();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('should render a tree table correctly', () => {
|
|
75
|
+
const { container } = render(
|
|
76
|
+
<DataViewTable isTreeTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} rows={treeRows} />
|
|
77
|
+
);
|
|
78
|
+
expect(container).toMatchSnapshot();
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
TdProps,
|
|
4
|
+
ThProps,
|
|
5
|
+
TrProps
|
|
6
|
+
} from '@patternfly/react-table';
|
|
7
|
+
import { DataViewTableTree, DataViewTableTreeProps } from '../DataViewTableTree';
|
|
8
|
+
import { DataViewTableBasic, DataViewTableBasicProps } from '../DataViewTableBasic';
|
|
9
|
+
|
|
10
|
+
// Table head typings
|
|
11
|
+
export type DataViewTh = ReactNode | { cell: ReactNode; props?: ThProps };
|
|
12
|
+
export const isDataViewThObject = (value: DataViewTh): value is { cell: ReactNode; props?: ThProps } => value != null && typeof value === 'object' && 'cell' in value;
|
|
13
|
+
|
|
14
|
+
// Basic table typings
|
|
15
|
+
export interface DataViewTrObject { row: DataViewTd[], id?: string, props?: TrProps }
|
|
16
|
+
export type DataViewTd = ReactNode | { cell: ReactNode; props?: TdProps };
|
|
17
|
+
export type DataViewTr = DataViewTd[] | DataViewTrObject;
|
|
18
|
+
|
|
19
|
+
export const isDataViewTdObject = (value: DataViewTd): value is { cell: ReactNode; props?: TdProps } => value != null && typeof value === 'object' && 'cell' in value;
|
|
20
|
+
export const isDataViewTrObject = (value: DataViewTr): value is { row: DataViewTd[], id?: string } => value != null && typeof value === 'object' && 'row' in value;
|
|
21
|
+
|
|
22
|
+
// Tree table typings
|
|
23
|
+
export interface DataViewTrTree extends DataViewTrObject { id: string, children?: DataViewTrTree[] }
|
|
24
|
+
|
|
25
|
+
export type DataViewTableProps =
|
|
26
|
+
| ({
|
|
27
|
+
isTreeTable: true;
|
|
28
|
+
} & DataViewTableTreeProps)
|
|
29
|
+
| ({
|
|
30
|
+
isTreeTable?: false;
|
|
31
|
+
} & DataViewTableBasicProps);
|
|
32
|
+
|
|
33
|
+
export const DataViewTable: React.FC<DataViewTableProps> = (props) => (
|
|
34
|
+
props.isTreeTable ? <DataViewTableTree {...props} /> : <DataViewTableBasic {...props} />
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
export default DataViewTable;
|