@patternfly/react-data-view 6.1.0 → 6.3.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 +2 -2
- package/dist/cjs/DataView/DataView.js +4 -7
- package/dist/cjs/DataView/DataView.test.js +3 -6
- package/dist/cjs/DataViewCheckboxFilter/DataViewCheckboxFilter.d.ts +2 -2
- package/dist/cjs/DataViewCheckboxFilter/DataViewCheckboxFilter.js +10 -15
- package/dist/cjs/DataViewCheckboxFilter/DataViewCheckboxFilter.test.js +3 -3
- package/dist/cjs/DataViewEventsContext/DataViewEventsContext.d.ts +3 -3
- package/dist/cjs/DataViewEventsContext/DataViewEventsContext.js +3 -25
- package/dist/cjs/DataViewEventsContext/DataViewEventsContext.test.js +11 -16
- package/dist/cjs/DataViewFilters/DataViewFilters.d.ts +2 -2
- package/dist/cjs/DataViewFilters/DataViewFilters.js +12 -40
- package/dist/cjs/DataViewFilters/DataViewFilters.test.js +11 -5
- package/dist/cjs/DataViewTable/DataViewTable.d.ts +2 -2
- package/dist/cjs/DataViewTable/DataViewTable.js +2 -5
- package/dist/cjs/DataViewTable/DataViewTable.test.js +4 -7
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.d.ts +2 -2
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.js +15 -41
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.test.js +6 -12
- package/dist/cjs/DataViewTableHead/DataViewTableHead.d.ts +2 -2
- package/dist/cjs/DataViewTableHead/DataViewTableHead.js +5 -28
- package/dist/cjs/DataViewTableHead/DataViewTableHead.test.js +5 -13
- package/dist/cjs/DataViewTableTree/DataViewTableTree.d.ts +2 -2
- package/dist/cjs/DataViewTableTree/DataViewTableTree.js +10 -34
- package/dist/cjs/DataViewTableTree/DataViewTableTree.test.js +6 -13
- package/dist/cjs/DataViewTextFilter/DataViewTextFilter.d.ts +2 -2
- package/dist/cjs/DataViewTextFilter/DataViewTextFilter.js +2 -6
- package/dist/cjs/DataViewTextFilter/DataViewTextFilter.test.js +3 -3
- package/dist/cjs/DataViewToolbar/DataViewToolbar.d.ts +4 -2
- package/dist/cjs/DataViewToolbar/DataViewToolbar.js +5 -34
- package/dist/cjs/DataViewToolbar/DataViewToolbar.test.js +3 -3
- package/dist/cjs/Hooks/filters.js +1 -1
- package/dist/cjs/Hooks/filters.test.js +25 -0
- package/dist/cjs/InternalContext/InternalContext.d.ts +3 -3
- package/dist/cjs/InternalContext/InternalContext.js +3 -25
- package/dist/cjs/InternalContext/InternalContext.test.js +9 -21
- package/dist/esm/DataView/DataView.d.ts +2 -2
- package/dist/esm/DataView/DataView.js +4 -4
- package/dist/esm/DataView/DataView.test.js +2 -5
- package/dist/esm/DataViewCheckboxFilter/DataViewCheckboxFilter.d.ts +2 -2
- package/dist/esm/DataViewCheckboxFilter/DataViewCheckboxFilter.js +10 -12
- package/dist/esm/DataViewCheckboxFilter/DataViewCheckboxFilter.test.js +2 -2
- package/dist/esm/DataViewEventsContext/DataViewEventsContext.d.ts +3 -3
- package/dist/esm/DataViewEventsContext/DataViewEventsContext.js +3 -2
- package/dist/esm/DataViewEventsContext/DataViewEventsContext.test.js +11 -13
- package/dist/esm/DataViewFilters/DataViewFilters.d.ts +2 -2
- package/dist/esm/DataViewFilters/DataViewFilters.js +12 -17
- package/dist/esm/DataViewFilters/DataViewFilters.test.js +11 -5
- package/dist/esm/DataViewTable/DataViewTable.d.ts +2 -2
- package/dist/esm/DataViewTable/DataViewTable.js +2 -2
- package/dist/esm/DataViewTable/DataViewTable.test.js +3 -3
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.d.ts +2 -2
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.js +15 -18
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.test.js +5 -8
- package/dist/esm/DataViewTableHead/DataViewTableHead.d.ts +2 -2
- package/dist/esm/DataViewTableHead/DataViewTableHead.js +5 -5
- package/dist/esm/DataViewTableHead/DataViewTableHead.test.js +4 -9
- package/dist/esm/DataViewTableTree/DataViewTableTree.d.ts +2 -2
- package/dist/esm/DataViewTableTree/DataViewTableTree.js +10 -11
- package/dist/esm/DataViewTableTree/DataViewTableTree.test.js +5 -9
- package/dist/esm/DataViewTextFilter/DataViewTextFilter.d.ts +2 -2
- package/dist/esm/DataViewTextFilter/DataViewTextFilter.js +2 -3
- package/dist/esm/DataViewTextFilter/DataViewTextFilter.test.js +2 -2
- package/dist/esm/DataViewToolbar/DataViewToolbar.d.ts +4 -2
- package/dist/esm/DataViewToolbar/DataViewToolbar.js +5 -11
- package/dist/esm/DataViewToolbar/DataViewToolbar.test.js +2 -2
- package/dist/esm/Hooks/filters.js +1 -1
- package/dist/esm/Hooks/filters.test.js +25 -0
- package/dist/esm/InternalContext/InternalContext.d.ts +3 -3
- package/dist/esm/InternalContext/InternalContext.js +3 -2
- package/dist/esm/InternalContext/InternalContext.test.js +7 -16
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -10
- package/patternfly-docs/content/extensions/data-view/examples/DataView/AbstractLayoutExample.tsx +3 -3
- package/patternfly-docs/content/extensions/data-view/examples/DataView/DataView.md +1 -1
- package/patternfly-docs/content/extensions/data-view/examples/DataView/EventsExample.tsx +4 -4
- package/patternfly-docs/content/extensions/data-view/examples/DataView/PredefinedLayoutFullExample.tsx +5 -5
- package/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableEmptyExample.tsx +6 -6
- package/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableErrorExample.tsx +2 -2
- package/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableExample.tsx +2 -2
- package/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableLoadingExample.tsx +4 -4
- package/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableTreeExample.tsx +2 -2
- package/patternfly-docs/content/extensions/data-view/examples/Table/SortingExample.tsx +3 -3
- package/patternfly-docs/content/extensions/data-view/examples/Table/Table.md +1 -1
- package/patternfly-docs/content/extensions/data-view/examples/Toolbar/AllSelectedExample.tsx +116 -0
- package/patternfly-docs/content/extensions/data-view/examples/Toolbar/Toolbar.md +13 -1
- package/patternfly-docs/pages/index.js +1 -0
- package/release.config.js +10 -2
- package/src/DataView/DataView.test.tsx +10 -8
- package/src/DataView/DataView.tsx +4 -4
- package/src/DataViewCheckboxFilter/DataViewCheckboxFilter.test.tsx +0 -1
- package/src/DataViewCheckboxFilter/DataViewCheckboxFilter.tsx +10 -10
- package/src/DataViewEventsContext/DataViewEventsContext.test.tsx +4 -4
- package/src/DataViewEventsContext/DataViewEventsContext.tsx +1 -1
- package/src/DataViewFilters/DataViewFilters.test.tsx +29 -10
- package/src/DataViewFilters/DataViewFilters.tsx +12 -12
- package/src/DataViewTable/DataViewTable.test.tsx +0 -1
- package/src/DataViewTable/DataViewTable.tsx +2 -2
- package/src/DataViewTableBasic/DataViewTableBasic.test.tsx +0 -1
- package/src/DataViewTableBasic/DataViewTableBasic.tsx +2 -2
- package/src/DataViewTableHead/DataViewTableHead.test.tsx +0 -1
- package/src/DataViewTableHead/DataViewTableHead.tsx +2 -2
- package/src/DataViewTableTree/DataViewTableTree.test.tsx +0 -1
- package/src/DataViewTableTree/DataViewTableTree.tsx +5 -5
- package/src/DataViewTextFilter/DataViewTextFilter.test.tsx +0 -1
- package/src/DataViewTextFilter/DataViewTextFilter.tsx +2 -2
- package/src/DataViewToolbar/DataViewToolbar.test.tsx +0 -1
- package/src/DataViewToolbar/DataViewToolbar.tsx +9 -2
- package/src/Hooks/filters.test.tsx +27 -0
- package/src/Hooks/filters.ts +1 -1
- package/src/InternalContext/InternalContext.test.tsx +0 -1
- package/src/InternalContext/InternalContext.tsx +2 -2
- package/tsconfig.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { FC } from 'react';
|
|
2
2
|
import { StackProps } from '@patternfly/react-core';
|
|
3
3
|
import { DataViewSelection } from '../InternalContext';
|
|
4
4
|
export declare const DataViewState: {
|
|
@@ -19,5 +19,5 @@ export interface DataViewProps extends StackProps {
|
|
|
19
19
|
activeState?: DataViewState | string;
|
|
20
20
|
}
|
|
21
21
|
export type DataViewImpementationProps = Omit<DataViewProps, 'onSelect' | 'isItemSelected' | 'isItemSelectDisabled'>;
|
|
22
|
-
export declare const DataView:
|
|
22
|
+
export declare const DataView: FC<DataViewProps>;
|
|
23
23
|
export default DataView;
|
|
@@ -9,7 +9,8 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
9
9
|
}
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
|
-
import
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import { Children } from 'react';
|
|
13
14
|
import { Stack, StackItem } from '@patternfly/react-core';
|
|
14
15
|
import { InternalContextProvider } from '../InternalContext';
|
|
15
16
|
export const DataViewState = {
|
|
@@ -19,11 +20,10 @@ export const DataViewState = {
|
|
|
19
20
|
};
|
|
20
21
|
const DataViewImplementation = (_a) => {
|
|
21
22
|
var { children, ouiaId = 'DataView' } = _a, props = __rest(_a, ["children", "ouiaId"]);
|
|
22
|
-
return (
|
|
23
|
+
return (_jsx(Stack, Object.assign({ "data-ouia-component-id": `${ouiaId}-stack` }, props, { children: Children.map(children, (child, index) => (_jsx(StackItem, { "data-ouia-component-id": `${ouiaId}-stack-item-${index}`, children: child }))) })));
|
|
23
24
|
};
|
|
24
25
|
export const DataView = (_a) => {
|
|
25
26
|
var { children, selection, activeState } = _a, props = __rest(_a, ["children", "selection", "activeState"]);
|
|
26
|
-
return (
|
|
27
|
-
React.createElement(DataViewImplementation, Object.assign({}, props), children)));
|
|
27
|
+
return (_jsx(InternalContextProvider, { selection: selection, activeState: activeState, children: _jsx(DataViewImplementation, Object.assign({}, props, { children: children })) }));
|
|
28
28
|
};
|
|
29
29
|
export default DataView;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { render } from '@testing-library/react';
|
|
3
3
|
import DataView from './DataView';
|
|
4
4
|
const layoutItemStyling = {
|
|
@@ -9,9 +9,6 @@ const layoutItemStyling = {
|
|
|
9
9
|
};
|
|
10
10
|
describe('DataView component', () => {
|
|
11
11
|
test('should render correctly', () => {
|
|
12
|
-
expect(render(
|
|
13
|
-
React.createElement("div", { style: layoutItemStyling }, "Header"),
|
|
14
|
-
React.createElement("div", { style: layoutItemStyling }, "Data representation"),
|
|
15
|
-
React.createElement("div", { style: layoutItemStyling }, "Footer")))).toMatchSnapshot();
|
|
12
|
+
expect(render(_jsxs(DataView, { children: [_jsx("div", { style: layoutItemStyling, children: "Header" }), _jsx("div", { style: layoutItemStyling, children: "Data representation" }), _jsx("div", { style: layoutItemStyling, children: "Footer" })] }))).toMatchSnapshot();
|
|
16
13
|
});
|
|
17
14
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { FC } from 'react';
|
|
2
2
|
import { MenuProps } from '@patternfly/react-core';
|
|
3
3
|
import { DataViewFilterOption } from '../DataViewFilters';
|
|
4
4
|
export declare const isDataViewFilterOption: (obj: unknown) => obj is DataViewFilterOption;
|
|
@@ -25,5 +25,5 @@ export interface DataViewCheckboxFilterProps extends Omit<MenuProps, 'onSelect'
|
|
|
25
25
|
/** Custom OUIA ID */
|
|
26
26
|
ouiaId?: string;
|
|
27
27
|
}
|
|
28
|
-
export declare const DataViewCheckboxFilter:
|
|
28
|
+
export declare const DataViewCheckboxFilter: FC<DataViewCheckboxFilterProps>;
|
|
29
29
|
export default DataViewCheckboxFilter;
|
|
@@ -9,7 +9,8 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
9
9
|
}
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
|
-
import
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import { useState, useRef, useMemo, useEffect } from 'react';
|
|
13
14
|
import { Badge, Menu, MenuContent, MenuItem, MenuList, MenuToggle, Popper, ToolbarFilter, } from '@patternfly/react-core';
|
|
14
15
|
import { FilterIcon } from '@patternfly/react-icons';
|
|
15
16
|
const isToolbarLabel = (label) => typeof label === 'object' && 'key' in label;
|
|
@@ -20,11 +21,11 @@ export const isDataViewFilterOption = (obj) => !!obj &&
|
|
|
20
21
|
typeof obj.value === 'string';
|
|
21
22
|
export const DataViewCheckboxFilter = (_a) => {
|
|
22
23
|
var { filterId, title, value = [], onChange, placeholder, options = [], showToolbarItem, showIcon = !placeholder, showBadge = !placeholder, ouiaId = 'DataViewCheckboxFilter' } = _a, props = __rest(_a, ["filterId", "title", "value", "onChange", "placeholder", "options", "showToolbarItem", "showIcon", "showBadge", "ouiaId"]);
|
|
23
|
-
const [isOpen, setIsOpen] =
|
|
24
|
-
const toggleRef =
|
|
25
|
-
const menuRef =
|
|
26
|
-
const containerRef =
|
|
27
|
-
const normalizeOptions =
|
|
24
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
25
|
+
const toggleRef = useRef(null);
|
|
26
|
+
const menuRef = useRef(null);
|
|
27
|
+
const containerRef = useRef(null);
|
|
28
|
+
const normalizeOptions = useMemo(() => options.map(option => typeof option === 'string'
|
|
28
29
|
? { label: option, value: option }
|
|
29
30
|
: option), [options]);
|
|
30
31
|
const handleToggleClick = (event) => {
|
|
@@ -45,18 +46,15 @@ export const DataViewCheckboxFilter = (_a) => {
|
|
|
45
46
|
menuRef.current && toggleRef.current &&
|
|
46
47
|
!menuRef.current.contains(event.target) && !toggleRef.current.contains(event.target)
|
|
47
48
|
&& setIsOpen(false);
|
|
48
|
-
|
|
49
|
+
useEffect(() => {
|
|
49
50
|
window.addEventListener('click', handleClickOutside);
|
|
50
51
|
return () => {
|
|
51
52
|
window.removeEventListener('click', handleClickOutside);
|
|
52
53
|
};
|
|
53
54
|
}, [isOpen]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
54
|
-
return (
|
|
55
|
+
return (_jsx(ToolbarFilter, { "data-ouia-component-id": ouiaId, labels: value.map(item => {
|
|
55
56
|
const activeOption = normalizeOptions.find(option => option.value === item);
|
|
56
57
|
return ({ key: activeOption === null || activeOption === void 0 ? void 0 : activeOption.value, node: activeOption === null || activeOption === void 0 ? void 0 : activeOption.label });
|
|
57
|
-
}), deleteLabel: (_, label) => onChange === null || onChange === void 0 ? void 0 : onChange(undefined, value.filter(item => item !== (isToolbarLabel(label) ? label.key : label))), categoryName: title, showToolbarItem: showToolbarItem },
|
|
58
|
-
React.createElement(Popper, { trigger: React.createElement(MenuToggle, { ouiaId: `${ouiaId}-toggle`, ref: toggleRef, onClick: handleToggleClick, isExpanded: isOpen, icon: showIcon ? React.createElement(FilterIcon, null) : undefined, badge: value.length > 0 && showBadge ? React.createElement(Badge, { "data-ouia-component-id": `${ouiaId}-badge`, isRead: true }, value.length) : undefined, style: { width: '200px' } }, placeholder !== null && placeholder !== void 0 ? placeholder : title), triggerRef: toggleRef, popper: React.createElement(Menu, Object.assign({ ref: menuRef, ouiaId: `${ouiaId}-menu`, onSelect: handleSelect, selected: value }, props),
|
|
59
|
-
React.createElement(MenuContent, null,
|
|
60
|
-
React.createElement(MenuList, null, normalizeOptions.map(option => (React.createElement(MenuItem, { "data-ouia-component-id": `${ouiaId}-filter-item-${option.value}`, key: option.value, itemId: option.value, isSelected: value.includes(option.value), hasCheckbox: true }, option.label)))))), popperRef: menuRef, appendTo: containerRef.current || undefined, "aria-label": `${title !== null && title !== void 0 ? title : filterId} filter`, isVisible: isOpen })));
|
|
58
|
+
}), deleteLabel: (_, label) => onChange === null || onChange === void 0 ? void 0 : onChange(undefined, value.filter(item => item !== (isToolbarLabel(label) ? label.key : label))), categoryName: title, showToolbarItem: showToolbarItem, children: _jsx(Popper, { trigger: _jsx(MenuToggle, { ouiaId: `${ouiaId}-toggle`, ref: toggleRef, onClick: handleToggleClick, isExpanded: isOpen, icon: showIcon ? _jsx(FilterIcon, {}) : undefined, badge: value.length > 0 && showBadge ? _jsx(Badge, { "data-ouia-component-id": `${ouiaId}-badge`, isRead: true, children: value.length }) : undefined, style: { width: '200px' }, children: placeholder !== null && placeholder !== void 0 ? placeholder : title }), triggerRef: toggleRef, popper: _jsx(Menu, Object.assign({ ref: menuRef, ouiaId: `${ouiaId}-menu`, onSelect: handleSelect, selected: value }, props, { children: _jsx(MenuContent, { children: _jsx(MenuList, { children: normalizeOptions.map(option => (_jsx(MenuItem, { "data-ouia-component-id": `${ouiaId}-filter-item-${option.value}`, itemId: option.value, isSelected: value.includes(option.value), hasCheckbox: true, children: option.label }, option.value))) }) }) })), popperRef: menuRef, appendTo: containerRef.current || undefined, "aria-label": `${title !== null && title !== void 0 ? title : filterId} filter`, isVisible: isOpen }) }, ouiaId));
|
|
61
59
|
};
|
|
62
60
|
export default DataViewCheckboxFilter;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { render } from '@testing-library/react';
|
|
3
3
|
import DataViewCheckboxFilter from './DataViewCheckboxFilter';
|
|
4
4
|
import DataViewToolbar from '../DataViewToolbar';
|
|
@@ -14,7 +14,7 @@ describe('DataViewCheckboxFilter component', () => {
|
|
|
14
14
|
],
|
|
15
15
|
};
|
|
16
16
|
it('should render correctly', () => {
|
|
17
|
-
const { container } = render(
|
|
17
|
+
const { container } = render(_jsx(DataViewToolbar, { filters: _jsx(DataViewCheckboxFilter, Object.assign({}, defaultProps)) }));
|
|
18
18
|
expect(container).toMatchSnapshot();
|
|
19
19
|
});
|
|
20
20
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { PropsWithChildren } from "react";
|
|
2
2
|
export declare const EventTypes: {
|
|
3
3
|
readonly rowClick: "rowClick";
|
|
4
4
|
};
|
|
@@ -10,7 +10,7 @@ export interface DataViewEventsContextValue {
|
|
|
10
10
|
subscribe: Subscribe;
|
|
11
11
|
trigger: Trigger;
|
|
12
12
|
}
|
|
13
|
-
export declare const DataViewEventsContext:
|
|
14
|
-
export declare const DataViewEventsProvider: ({ children }: PropsWithChildren) =>
|
|
13
|
+
export declare const DataViewEventsContext: import("react").Context<DataViewEventsContextValue>;
|
|
14
|
+
export declare const DataViewEventsProvider: ({ children }: PropsWithChildren) => import("react/jsx-runtime").JSX.Element;
|
|
15
15
|
export declare const useDataViewEventsContext: () => DataViewEventsContextValue;
|
|
16
16
|
export default DataViewEventsContext;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useCallback, useContext, useState } from "react";
|
|
2
3
|
export const EventTypes = {
|
|
3
4
|
rowClick: 'rowClick'
|
|
4
5
|
};
|
|
@@ -28,7 +29,7 @@ export const DataViewEventsProvider = ({ children }) => {
|
|
|
28
29
|
callback(...payload);
|
|
29
30
|
});
|
|
30
31
|
}, [subscriptions]);
|
|
31
|
-
return (
|
|
32
|
+
return (_jsx(DataViewEventsContext.Provider, { value: { subscribe, trigger }, children: children }));
|
|
32
33
|
};
|
|
33
34
|
export const useDataViewEventsContext = () => useContext(DataViewEventsContext);
|
|
34
35
|
export default DataViewEventsContext;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect } from 'react';
|
|
2
3
|
import { render, fireEvent } from '@testing-library/react';
|
|
3
4
|
import { useDataViewEventsContext, DataViewEventsProvider, EventTypes } from './DataViewEventsContext';
|
|
4
5
|
let id = 0;
|
|
@@ -14,15 +15,14 @@ describe('DataViewEventsContext', () => {
|
|
|
14
15
|
const callback = jest.fn();
|
|
15
16
|
const TestComponent = () => {
|
|
16
17
|
const { subscribe, trigger } = useDataViewEventsContext();
|
|
17
|
-
|
|
18
|
+
useEffect(() => {
|
|
18
19
|
const unsubscribe = subscribe(EventTypes.rowClick, callback);
|
|
19
20
|
return () => unsubscribe();
|
|
20
21
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
21
22
|
}, []);
|
|
22
|
-
return (
|
|
23
|
+
return (_jsx("button", { onClick: () => trigger(EventTypes.rowClick, 'some payload'), children: "Trigger" }));
|
|
23
24
|
};
|
|
24
|
-
const { getByText } = render(
|
|
25
|
-
React.createElement(TestComponent, null)));
|
|
25
|
+
const { getByText } = render(_jsx(DataViewEventsProvider, { children: _jsx(TestComponent, {}) }));
|
|
26
26
|
fireEvent.click(getByText('Trigger'));
|
|
27
27
|
expect(callback).toHaveBeenCalledWith('some payload');
|
|
28
28
|
});
|
|
@@ -30,15 +30,14 @@ describe('DataViewEventsContext', () => {
|
|
|
30
30
|
const callback = jest.fn();
|
|
31
31
|
const TestComponent = () => {
|
|
32
32
|
const { subscribe, trigger } = useDataViewEventsContext();
|
|
33
|
-
|
|
33
|
+
useEffect(() => {
|
|
34
34
|
const unsubscribe = subscribe(EventTypes.rowClick, callback);
|
|
35
35
|
unsubscribe();
|
|
36
36
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
37
37
|
}, []);
|
|
38
|
-
return (
|
|
38
|
+
return (_jsx("button", { onClick: () => trigger(EventTypes.rowClick, 'some payload'), children: "Trigger" }));
|
|
39
39
|
};
|
|
40
|
-
const { getByText } = render(
|
|
41
|
-
React.createElement(TestComponent, null)));
|
|
40
|
+
const { getByText } = render(_jsx(DataViewEventsProvider, { children: _jsx(TestComponent, {}) }));
|
|
42
41
|
fireEvent.click(getByText('Trigger'));
|
|
43
42
|
expect(callback).not.toHaveBeenCalled();
|
|
44
43
|
});
|
|
@@ -47,7 +46,7 @@ describe('DataViewEventsContext', () => {
|
|
|
47
46
|
const callback2 = jest.fn();
|
|
48
47
|
const TestComponent = () => {
|
|
49
48
|
const { subscribe, trigger } = useDataViewEventsContext();
|
|
50
|
-
|
|
49
|
+
useEffect(() => {
|
|
51
50
|
const unsubscribe1 = subscribe(EventTypes.rowClick, callback1);
|
|
52
51
|
const unsubscribe2 = subscribe(EventTypes.rowClick, callback2);
|
|
53
52
|
return () => {
|
|
@@ -56,10 +55,9 @@ describe('DataViewEventsContext', () => {
|
|
|
56
55
|
};
|
|
57
56
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
58
57
|
}, []);
|
|
59
|
-
return (
|
|
58
|
+
return (_jsx("button", { onClick: () => trigger(EventTypes.rowClick, 'some payload'), children: "Trigger" }));
|
|
60
59
|
};
|
|
61
|
-
const { getByText } = render(
|
|
62
|
-
React.createElement(TestComponent, null)));
|
|
60
|
+
const { getByText } = render(_jsx(DataViewEventsProvider, { children: _jsx(TestComponent, {}) }));
|
|
63
61
|
fireEvent.click(getByText('Trigger'));
|
|
64
62
|
expect(callback1).toHaveBeenCalledWith('some payload');
|
|
65
63
|
expect(callback2).toHaveBeenCalledWith('some payload');
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
2
|
import { ToolbarToggleGroupProps } from '@patternfly/react-core';
|
|
3
3
|
export interface DataViewFilterOption {
|
|
4
4
|
/** Filter option label */
|
|
@@ -21,5 +21,5 @@ export interface DataViewFiltersProps<T extends object> extends Omit<ToolbarTogg
|
|
|
21
21
|
/** Custom OUIA ID */
|
|
22
22
|
ouiaId?: string;
|
|
23
23
|
}
|
|
24
|
-
export declare const DataViewFilters: <T extends object>({ children, ouiaId, toggleIcon, breakpoint, onChange, values, ...props }: DataViewFiltersProps<T>) =>
|
|
24
|
+
export declare const DataViewFilters: <T extends object>({ children, ouiaId, toggleIcon, breakpoint, onChange, values, ...props }: DataViewFiltersProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
25
25
|
export default DataViewFilters;
|
|
@@ -9,20 +9,21 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
9
9
|
}
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
|
-
import
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { Children, isValidElement, cloneElement, useMemo, useState, useRef, useEffect } from 'react';
|
|
13
14
|
import { Menu, MenuContent, MenuItem, MenuList, MenuToggle, Popper, ToolbarGroup, ToolbarToggleGroup, } from '@patternfly/react-core';
|
|
14
15
|
import { FilterIcon } from '@patternfly/react-icons';
|
|
15
16
|
;
|
|
16
17
|
export const DataViewFilters = (_a) => {
|
|
17
|
-
var { children, ouiaId = 'DataViewFilters', toggleIcon =
|
|
18
|
+
var { children, ouiaId = 'DataViewFilters', toggleIcon = _jsx(FilterIcon, {}), breakpoint = 'xl', onChange, values } = _a, props = __rest(_a, ["children", "ouiaId", "toggleIcon", "breakpoint", "onChange", "values"]);
|
|
18
19
|
const [activeAttributeMenu, setActiveAttributeMenu] = useState('');
|
|
19
20
|
const [isAttributeMenuOpen, setIsAttributeMenuOpen] = useState(false);
|
|
20
21
|
const attributeToggleRef = useRef(null);
|
|
21
22
|
const attributeMenuRef = useRef(null);
|
|
22
23
|
const attributeContainerRef = useRef(null);
|
|
23
|
-
const childrenHash = useMemo(() => JSON.stringify(
|
|
24
|
-
const filterItems = useMemo(() =>
|
|
25
|
-
.map(child =>
|
|
24
|
+
const childrenHash = useMemo(() => JSON.stringify(Children.map(children, (child) => isValidElement(child) ? { type: child.type, key: child.key, props: child.props } : child)), [children]);
|
|
25
|
+
const filterItems = useMemo(() => Children.toArray(children)
|
|
26
|
+
.map(child => isValidElement(child) ? { filterId: String(child.props.filterId), title: String(child.props.title) } : undefined).filter((item) => !!item), [childrenHash]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
26
27
|
useEffect(() => {
|
|
27
28
|
filterItems.length > 0 && setActiveAttributeMenu(filterItems[0].title);
|
|
28
29
|
}, [filterItems]);
|
|
@@ -39,20 +40,14 @@ export const DataViewFilters = (_a) => {
|
|
|
39
40
|
window.removeEventListener('click', handleClickOutside);
|
|
40
41
|
};
|
|
41
42
|
}, [isAttributeMenuOpen]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
42
|
-
const attributeToggle = (
|
|
43
|
-
const attributeMenu = (
|
|
43
|
+
const attributeToggle = (_jsx(MenuToggle, { ref: attributeToggleRef, onClick: () => setIsAttributeMenuOpen(!isAttributeMenuOpen), isExpanded: isAttributeMenuOpen, icon: toggleIcon, children: activeAttributeMenu }));
|
|
44
|
+
const attributeMenu = (_jsx(Menu, { ref: attributeMenuRef, onSelect: (_ev, itemId) => {
|
|
44
45
|
const selectedItem = filterItems.find(item => item.filterId === itemId);
|
|
45
46
|
selectedItem && setActiveAttributeMenu(selectedItem.title);
|
|
46
47
|
setIsAttributeMenuOpen(false);
|
|
47
|
-
} },
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
React.createElement(ToolbarGroup, { variant: "filter-group" },
|
|
52
|
-
React.createElement("div", { ref: attributeContainerRef },
|
|
53
|
-
React.createElement(Popper, { trigger: attributeToggle, triggerRef: attributeToggleRef, popper: attributeMenu, popperRef: attributeMenuRef, appendTo: attributeContainerRef.current || undefined, isVisible: isAttributeMenuOpen })),
|
|
54
|
-
React.Children.map(children, (child) => React.isValidElement(child)
|
|
55
|
-
? React.cloneElement(child, Object.assign({ showToolbarItem: activeAttributeMenu === child.props.title, onChange: (event, value) => onChange === null || onChange === void 0 ? void 0 : onChange(event, { [child.props.filterId]: value }), value: values === null || values === void 0 ? void 0 : values[child.props.filterId] }, child.props))
|
|
56
|
-
: child))));
|
|
48
|
+
}, children: _jsx(MenuContent, { children: _jsx(MenuList, { children: filterItems.map(item => (_jsx(MenuItem, { itemId: item.filterId, children: item.title }, item.filterId))) }) }) }));
|
|
49
|
+
return (_jsx(ToolbarToggleGroup, Object.assign({ "data-ouia-component-id": ouiaId, toggleIcon: toggleIcon, breakpoint: breakpoint }, props, { children: _jsxs(ToolbarGroup, { variant: "filter-group", children: [_jsx("div", { ref: attributeContainerRef, children: _jsx(Popper, { trigger: attributeToggle, triggerRef: attributeToggleRef, popper: attributeMenu, popperRef: attributeMenuRef, appendTo: attributeContainerRef.current || undefined, isVisible: isAttributeMenuOpen }) }), Children.map(children, (child) => isValidElement(child)
|
|
50
|
+
? cloneElement(child, Object.assign({ showToolbarItem: activeAttributeMenu === child.props.title, onChange: (event, value) => onChange === null || onChange === void 0 ? void 0 : onChange(child.props.filterId, { [child.props.filterId]: value }), value: values === null || values === void 0 ? void 0 : values[child.props.filterId] }, child.props))
|
|
51
|
+
: child)] }) })));
|
|
57
52
|
};
|
|
58
53
|
export default DataViewFilters;
|
|
@@ -1,14 +1,20 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { render } from '@testing-library/react';
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { render, fireEvent } from '@testing-library/react';
|
|
3
3
|
import DataViewFilters from './DataViewFilters';
|
|
4
4
|
import DataViewToolbar from '../DataViewToolbar';
|
|
5
5
|
import DataViewTextFilter from '../DataViewTextFilter';
|
|
6
6
|
describe('DataViewFilters component', () => {
|
|
7
7
|
const mockOnChange = jest.fn();
|
|
8
8
|
it('should render correctly', () => {
|
|
9
|
-
const { container } = render(
|
|
10
|
-
React.createElement(DataViewTextFilter, { filterId: "one", title: "One" }),
|
|
11
|
-
React.createElement(DataViewTextFilter, { filterId: "two", title: "Two" })) }));
|
|
9
|
+
const { container } = render(_jsx(DataViewToolbar, { filters: _jsxs(DataViewFilters, { onChange: mockOnChange, values: {}, children: [_jsx(DataViewTextFilter, { filterId: "one", title: "One" }), _jsx(DataViewTextFilter, { filterId: "two", title: "Two" })] }) }));
|
|
12
10
|
expect(container).toMatchSnapshot();
|
|
13
11
|
});
|
|
12
|
+
it('should call onChange with correct key and value when filter changes', () => {
|
|
13
|
+
const mockOnChange = jest.fn();
|
|
14
|
+
const { getByLabelText } = render(_jsx(DataViewToolbar, { filters: _jsxs(DataViewFilters, { onChange: mockOnChange, values: {}, children: [_jsx(DataViewTextFilter, { filterId: "one", title: "One" }), _jsx(DataViewTextFilter, { filterId: "two", title: "Two" })] }) }));
|
|
15
|
+
const input = getByLabelText('One filter');
|
|
16
|
+
input.focus();
|
|
17
|
+
fireEvent.input(input, { target: { value: 'abc' } });
|
|
18
|
+
expect(mockOnChange).toHaveBeenCalledWith('one', { one: 'abc' });
|
|
19
|
+
});
|
|
14
20
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { FC, ReactNode } from 'react';
|
|
2
2
|
import { TdProps, ThProps, TrProps } from '@patternfly/react-table';
|
|
3
3
|
import { DataViewTableTreeProps } from '../DataViewTableTree';
|
|
4
4
|
import { DataViewTableBasicProps } from '../DataViewTableBasic';
|
|
@@ -45,5 +45,5 @@ export type DataViewTableProps = ({
|
|
|
45
45
|
} & DataViewTableTreeProps) | ({
|
|
46
46
|
isTreeTable?: false;
|
|
47
47
|
} & DataViewTableBasicProps);
|
|
48
|
-
export declare const DataViewTable:
|
|
48
|
+
export declare const DataViewTable: FC<DataViewTableProps>;
|
|
49
49
|
export default DataViewTable;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { DataViewTableTree } from '../DataViewTableTree';
|
|
3
3
|
import { DataViewTableBasic } from '../DataViewTableBasic';
|
|
4
4
|
export const isDataViewThObject = (value) => value != null && typeof value === 'object' && 'cell' in value;
|
|
5
5
|
export const isDataViewTdObject = (value) => value != null && typeof value === 'object' && 'cell' in value;
|
|
6
6
|
export const isDataViewTrObject = (value) => value != null && typeof value === 'object' && 'row' in value;
|
|
7
|
-
export const DataViewTable = (props) => (props.isTreeTable ?
|
|
7
|
+
export const DataViewTable = (props) => (props.isTreeTable ? _jsx(DataViewTableTree, Object.assign({}, props)) : _jsx(DataViewTableBasic, Object.assign({}, props)));
|
|
8
8
|
export default DataViewTable;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { render } from '@testing-library/react';
|
|
3
3
|
import { DataViewTable } from './DataViewTable';
|
|
4
4
|
const repositories = [
|
|
@@ -42,11 +42,11 @@ const columns = ['Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Las
|
|
|
42
42
|
const ouiaId = 'TableExample';
|
|
43
43
|
describe('DataViewTable component', () => {
|
|
44
44
|
test('should render a basic table correctly', () => {
|
|
45
|
-
const { container } = render(
|
|
45
|
+
const { container } = render(_jsx(DataViewTable, { "aria-label": 'Repositories table', ouiaId: ouiaId, columns: columns, rows: rows }));
|
|
46
46
|
expect(container).toMatchSnapshot();
|
|
47
47
|
});
|
|
48
48
|
test('should render a tree table correctly', () => {
|
|
49
|
-
const { container } = render(
|
|
49
|
+
const { container } = render(_jsx(DataViewTable, { isTreeTable: true, "aria-label": 'Repositories table', ouiaId: ouiaId, columns: columns, rows: treeRows }));
|
|
50
50
|
expect(container).toMatchSnapshot();
|
|
51
51
|
});
|
|
52
52
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { FC } from 'react';
|
|
2
2
|
import { TableProps } from '@patternfly/react-table';
|
|
3
3
|
import { DataViewTh, DataViewTr } from '../DataViewTable';
|
|
4
4
|
import { DataViewState } from '../DataView/DataView';
|
|
@@ -15,5 +15,5 @@ export interface DataViewTableBasicProps extends Omit<TableProps, 'onSelect' | '
|
|
|
15
15
|
/** Custom OUIA ID */
|
|
16
16
|
ouiaId?: string;
|
|
17
17
|
}
|
|
18
|
-
export declare const DataViewTableBasic:
|
|
18
|
+
export declare const DataViewTableBasic: FC<DataViewTableBasicProps>;
|
|
19
19
|
export default DataViewTableBasic;
|
|
@@ -9,7 +9,8 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
9
9
|
}
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
|
-
import
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { useMemo } from 'react';
|
|
13
14
|
import { Table, Tbody, Td, Tr, } from '@patternfly/react-table';
|
|
14
15
|
import { useInternalContext } from '../InternalContext';
|
|
15
16
|
import { DataViewTableHead } from '../DataViewTableHead';
|
|
@@ -22,23 +23,19 @@ export const DataViewTableBasic = (_a) => {
|
|
|
22
23
|
const activeBodyState = useMemo(() => activeState ? bodyStates === null || bodyStates === void 0 ? void 0 : bodyStates[activeState] : undefined, [activeState, bodyStates]);
|
|
23
24
|
const renderedRows = useMemo(() => rows.map((row, rowIndex) => {
|
|
24
25
|
const rowIsObject = isDataViewTrObject(row);
|
|
25
|
-
return (
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return (React.createElement(Td, Object.assign({ key: colIndex }, (cellIsObject && ((_a = cell === null || cell === void 0 ? void 0 : cell.props) !== null && _a !== void 0 ? _a : {})), { "data-ouia-component-id": `${ouiaId}-td-${rowIndex}-${colIndex}` }), cellIsObject ? cell.cell : cell));
|
|
38
|
-
})));
|
|
26
|
+
return (_jsxs(Tr, Object.assign({ ouiaId: `${ouiaId}-tr-${rowIndex}` }, (rowIsObject && (row === null || row === void 0 ? void 0 : row.props)), { children: [isSelectable && (_jsx(Td, { select: {
|
|
27
|
+
rowIndex,
|
|
28
|
+
onSelect: (_event, isSelecting) => {
|
|
29
|
+
onSelect === null || onSelect === void 0 ? void 0 : onSelect(isSelecting, rowIsObject ? row : [row]);
|
|
30
|
+
},
|
|
31
|
+
isSelected: (isSelected === null || isSelected === void 0 ? void 0 : isSelected(row)) || false,
|
|
32
|
+
isDisabled: (isSelectDisabled === null || isSelectDisabled === void 0 ? void 0 : isSelectDisabled(row)) || false,
|
|
33
|
+
} }, `select-${rowIndex}`)), (rowIsObject ? row.row : row).map((cell, colIndex) => {
|
|
34
|
+
var _a;
|
|
35
|
+
const cellIsObject = isDataViewTdObject(cell);
|
|
36
|
+
return (_jsx(Td, Object.assign({}, (cellIsObject && ((_a = cell === null || cell === void 0 ? void 0 : cell.props) !== null && _a !== void 0 ? _a : {})), { "data-ouia-component-id": `${ouiaId}-td-${rowIndex}-${colIndex}`, children: cellIsObject ? cell.cell : cell }), colIndex));
|
|
37
|
+
})] }), rowIndex));
|
|
39
38
|
}), [rows, isSelectable, isSelected, isSelectDisabled, onSelect, ouiaId]);
|
|
40
|
-
return (
|
|
41
|
-
activeHeadState || React.createElement(DataViewTableHead, { columns: columns, ouiaId: ouiaId }),
|
|
42
|
-
activeBodyState || React.createElement(Tbody, null, renderedRows)));
|
|
39
|
+
return (_jsxs(Table, Object.assign({ "aria-label": "Data table", ouiaId: ouiaId }, props, { children: [activeHeadState || _jsx(DataViewTableHead, { columns: columns, ouiaId: ouiaId }), activeBodyState || _jsx(Tbody, { children: renderedRows })] })));
|
|
43
40
|
};
|
|
44
41
|
export default DataViewTableBasic;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { render } from '@testing-library/react';
|
|
3
3
|
import { DataView } from '../DataView';
|
|
4
4
|
import { DataViewTableBasic } from './DataViewTableBasic';
|
|
@@ -17,22 +17,19 @@ const columns = ['Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Las
|
|
|
17
17
|
const ouiaId = 'TableExample';
|
|
18
18
|
describe('DataViewTable component', () => {
|
|
19
19
|
test('should render correctly', () => {
|
|
20
|
-
const { container } = render(
|
|
20
|
+
const { container } = render(_jsx(DataViewTableBasic, { "aria-label": 'Repositories table', ouiaId: ouiaId, columns: columns, rows: rows }));
|
|
21
21
|
expect(container).toMatchSnapshot();
|
|
22
22
|
});
|
|
23
23
|
test('should render with an empty state', () => {
|
|
24
|
-
const { container } = render(
|
|
25
|
-
React.createElement(DataViewTableBasic, { "aria-label": 'Repositories table', ouiaId: ouiaId, columns: columns, bodyStates: { empty: "No data found" }, rows: [] })));
|
|
24
|
+
const { container } = render(_jsx(DataView, { activeState: "empty", children: _jsx(DataViewTableBasic, { "aria-label": 'Repositories table', ouiaId: ouiaId, columns: columns, bodyStates: { empty: "No data found" }, rows: [] }) }));
|
|
26
25
|
expect(container).toMatchSnapshot();
|
|
27
26
|
});
|
|
28
27
|
test('should render with an error state', () => {
|
|
29
|
-
const { container } = render(
|
|
30
|
-
React.createElement(DataViewTableBasic, { "aria-label": 'Repositories table', ouiaId: ouiaId, columns: columns, bodyStates: { error: "Some error" }, rows: [] })));
|
|
28
|
+
const { container } = render(_jsx(DataView, { activeState: "error", children: _jsx(DataViewTableBasic, { "aria-label": 'Repositories table', ouiaId: ouiaId, columns: columns, bodyStates: { error: "Some error" }, rows: [] }) }));
|
|
31
29
|
expect(container).toMatchSnapshot();
|
|
32
30
|
});
|
|
33
31
|
test('should render with a loading state', () => {
|
|
34
|
-
const { container } = render(
|
|
35
|
-
React.createElement(DataViewTableBasic, { "aria-label": 'Repositories table', ouiaId: ouiaId, columns: columns, bodyStates: { loading: "Data is loading" }, rows: [] })));
|
|
32
|
+
const { container } = render(_jsx(DataView, { activeState: "loading", children: _jsx(DataViewTableBasic, { "aria-label": 'Repositories table', ouiaId: ouiaId, columns: columns, bodyStates: { loading: "Data is loading" }, rows: [] }) }));
|
|
36
33
|
expect(container).toMatchSnapshot();
|
|
37
34
|
});
|
|
38
35
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { FC } from 'react';
|
|
2
2
|
import { TheadProps } from '@patternfly/react-table';
|
|
3
3
|
import { DataViewTh } from '../DataViewTable';
|
|
4
4
|
/** extends TheadProps */
|
|
@@ -10,5 +10,5 @@ export interface DataViewTableHeadProps extends TheadProps {
|
|
|
10
10
|
/** Custom OUIA ID */
|
|
11
11
|
ouiaId?: string;
|
|
12
12
|
}
|
|
13
|
-
export declare const DataViewTableHead:
|
|
13
|
+
export declare const DataViewTableHead: FC<DataViewTableHeadProps>;
|
|
14
14
|
export default DataViewTableHead;
|
|
@@ -9,7 +9,8 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
9
9
|
}
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
|
-
import
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import { useMemo } from 'react';
|
|
13
14
|
import { Th, Thead, Tr } from '@patternfly/react-table';
|
|
14
15
|
import { useInternalContext } from '../InternalContext';
|
|
15
16
|
import { isDataViewThObject } from '../DataViewTable';
|
|
@@ -18,13 +19,12 @@ export const DataViewTableHead = (_a) => {
|
|
|
18
19
|
const { selection } = useInternalContext();
|
|
19
20
|
const { onSelect, isSelected } = selection !== null && selection !== void 0 ? selection : {};
|
|
20
21
|
const cells = useMemo(() => [
|
|
21
|
-
onSelect && isSelected && !isTreeTable ? (
|
|
22
|
+
onSelect && isSelected && !isTreeTable ? (_jsx(Th, { screenReaderText: 'Data selection table head cell' }, "row-select")) : null,
|
|
22
23
|
...columns.map((column, index) => {
|
|
23
24
|
var _a;
|
|
24
|
-
return (
|
|
25
|
+
return (_jsx(Th, Object.assign({}, (isDataViewThObject(column) && ((_a = column === null || column === void 0 ? void 0 : column.props) !== null && _a !== void 0 ? _a : {})), { "data-ouia-component-id": `${ouiaId}-th-${index}`, children: isDataViewThObject(column) ? column.cell : column }), index));
|
|
25
26
|
})
|
|
26
27
|
], [columns, ouiaId, onSelect, isSelected, isTreeTable]);
|
|
27
|
-
return (
|
|
28
|
-
React.createElement(Tr, { ouiaId: `${ouiaId}-tr-head` }, cells)));
|
|
28
|
+
return (_jsx(Thead, Object.assign({ "data-ouia-component-id": `${ouiaId}-thead` }, props, { children: _jsx(Tr, { ouiaId: `${ouiaId}-tr-head`, children: cells }) })));
|
|
29
29
|
};
|
|
30
30
|
export default DataViewTableHead;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { render } from '@testing-library/react';
|
|
3
3
|
import { Table } from '@patternfly/react-table';
|
|
4
4
|
import { DataViewTableHead } from './DataViewTableHead';
|
|
@@ -12,20 +12,15 @@ describe('DataViewTableHead component', () => {
|
|
|
12
12
|
isSelectDisabled: jest.fn(),
|
|
13
13
|
};
|
|
14
14
|
test('should render correctly', () => {
|
|
15
|
-
const { container } = render(
|
|
16
|
-
React.createElement(DataViewTableHead, { columns: columns, ouiaId: ouiaId })));
|
|
15
|
+
const { container } = render(_jsx(Table, { children: _jsx(DataViewTableHead, { columns: columns, ouiaId: ouiaId }) }));
|
|
17
16
|
expect(container).toMatchSnapshot();
|
|
18
17
|
});
|
|
19
18
|
test('should render the tree table correctly when isTreeTable is true', () => {
|
|
20
|
-
const { container } = render(
|
|
21
|
-
React.createElement(Table, null,
|
|
22
|
-
React.createElement(DataViewTableHead, { isTreeTable: true, columns: columns, ouiaId: ouiaId }))));
|
|
19
|
+
const { container } = render(_jsx(DataView, { selection: mockSelection, children: _jsx(Table, { children: _jsx(DataViewTableHead, { isTreeTable: true, columns: columns, ouiaId: ouiaId }) }) }));
|
|
23
20
|
expect(container).toMatchSnapshot();
|
|
24
21
|
});
|
|
25
22
|
test('should render selection column when selection is provided', () => {
|
|
26
|
-
const { container } = render(
|
|
27
|
-
React.createElement(Table, null,
|
|
28
|
-
React.createElement(DataViewTableHead, { columns: columns, ouiaId: ouiaId }))));
|
|
23
|
+
const { container } = render(_jsx(DataView, { selection: mockSelection, children: _jsx(Table, { children: _jsx(DataViewTableHead, { columns: columns, ouiaId: ouiaId }) }) }));
|
|
29
24
|
expect(container).toMatchSnapshot();
|
|
30
25
|
});
|
|
31
26
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { FC } from 'react';
|
|
2
2
|
import { TableProps } from '@patternfly/react-table';
|
|
3
3
|
import { DataViewTh, DataViewTrTree } from '../DataViewTable';
|
|
4
4
|
import { DataViewState } from '../DataView/DataView';
|
|
@@ -21,5 +21,5 @@ export interface DataViewTableTreeProps extends Omit<TableProps, 'onSelect' | 'r
|
|
|
21
21
|
/** Custom OUIA ID */
|
|
22
22
|
ouiaId?: string;
|
|
23
23
|
}
|
|
24
|
-
export declare const DataViewTableTree:
|
|
24
|
+
export declare const DataViewTableTree: FC<DataViewTableTreeProps>;
|
|
25
25
|
export default DataViewTableTree;
|