@patternfly/react-data-view 1.0.0-prerelease.3 → 1.0.0-prerelease.5

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.
Files changed (60) hide show
  1. package/dist/cjs/DataView/DataView.test.d.ts +1 -1
  2. package/dist/cjs/DataView/DataView.test.js +12 -6
  3. package/dist/cjs/DataViewToolbar/DataViewToolbar.d.ts +5 -3
  4. package/dist/cjs/DataViewToolbar/DataViewToolbar.js +3 -2
  5. package/dist/cjs/DataViewToolbar/DataViewToolbar.test.js +14 -0
  6. package/dist/cjs/Hooks/index.d.ts +2 -1
  7. package/dist/cjs/Hooks/index.js +2 -1
  8. package/dist/cjs/Hooks/pagination.d.ts +16 -0
  9. package/dist/cjs/Hooks/pagination.js +16 -0
  10. package/dist/cjs/Hooks/pagination.test.d.ts +1 -0
  11. package/dist/cjs/Hooks/pagination.test.js +49 -0
  12. package/dist/cjs/Hooks/selection.d.ts +11 -0
  13. package/dist/cjs/Hooks/selection.js +26 -0
  14. package/dist/cjs/Hooks/selection.test.d.ts +1 -0
  15. package/dist/cjs/Hooks/selection.test.js +55 -0
  16. package/dist/esm/DataView/DataView.test.d.ts +1 -1
  17. package/dist/esm/DataView/DataView.test.js +13 -7
  18. package/dist/esm/DataViewToolbar/DataViewToolbar.d.ts +5 -3
  19. package/dist/esm/DataViewToolbar/DataViewToolbar.js +3 -2
  20. package/dist/esm/DataViewToolbar/DataViewToolbar.test.d.ts +1 -0
  21. package/dist/esm/DataViewToolbar/DataViewToolbar.test.js +9 -0
  22. package/dist/esm/Hooks/index.d.ts +2 -1
  23. package/dist/esm/Hooks/index.js +2 -1
  24. package/dist/esm/Hooks/pagination.d.ts +16 -0
  25. package/dist/esm/Hooks/pagination.js +12 -0
  26. package/dist/esm/Hooks/pagination.test.d.ts +1 -0
  27. package/dist/esm/Hooks/pagination.test.js +47 -0
  28. package/dist/esm/Hooks/selection.d.ts +11 -0
  29. package/dist/esm/Hooks/selection.js +22 -0
  30. package/dist/esm/Hooks/selection.test.d.ts +1 -0
  31. package/dist/esm/Hooks/selection.test.js +53 -0
  32. package/generate-fed-package-json.js +7 -8
  33. package/generate-index.js +2 -2
  34. package/package.json +7 -6
  35. package/patternfly-docs/content/extensions/data-view/examples/{DataViewToolbar/DataViewToolbar.md → Components/Components.md} +9 -5
  36. package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewToolbarExample.tsx +20 -0
  37. package/patternfly-docs/content/extensions/data-view/examples/Functionality/Functionality.md +77 -0
  38. package/patternfly-docs/content/extensions/data-view/examples/Functionality/PaginationExample.tsx +65 -0
  39. package/patternfly-docs/content/extensions/data-view/examples/Functionality/SelectionExample.tsx +88 -0
  40. package/patternfly-docs/content/extensions/data-view/examples/{DataView/DataView.md → Layout/Layout.md} +9 -6
  41. package/patternfly-docs/content/extensions/data-view/examples/Layout/PredefinedLayoutExample.tsx +120 -0
  42. package/src/DataView/DataView.test.tsx +16 -8
  43. package/src/DataView/__snapshots__/DataView.test.tsx.snap +134 -0
  44. package/src/DataViewToolbar/DataViewToolbar.test.tsx +11 -0
  45. package/src/DataViewToolbar/DataViewToolbar.tsx +12 -5
  46. package/src/DataViewToolbar/__snapshots__/DataViewToolbar.test.tsx.snap +538 -0
  47. package/src/Hooks/index.ts +2 -1
  48. package/src/Hooks/pagination.test.tsx +57 -0
  49. package/src/Hooks/pagination.ts +31 -0
  50. package/src/Hooks/selection.test.tsx +52 -0
  51. package/src/Hooks/selection.ts +32 -0
  52. package/dist/cjs/Hooks/useDataViewPagination.d.ts +0 -4
  53. package/dist/cjs/Hooks/useDataViewPagination.js +0 -2
  54. package/dist/esm/Hooks/useDataViewPagination.d.ts +0 -4
  55. package/patternfly-docs/content/extensions/data-view/examples/DataView/DataViewPredefinedLayoutExample.tsx +0 -24
  56. package/patternfly-docs/content/extensions/data-view/examples/DataViewToolbar/DataViewToolbarExample.tsx +0 -7
  57. package/patternfly-docs/content/extensions/data-view/examples/Hooks/Hooks.md +0 -23
  58. package/src/Hooks/useDataViewPagination.ts +0 -4
  59. /package/dist/{esm/Hooks/useDataViewPagination.js → cjs/DataViewToolbar/DataViewToolbar.test.d.ts} +0 -0
  60. /package/patternfly-docs/content/extensions/data-view/examples/{DataView/DataViewLayoutExample.tsx → Layout/AbstractLayoutExample.tsx} +0 -0
@@ -1 +1 @@
1
- import '@testing-library/jest-dom';
1
+ export {};
@@ -5,12 +5,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const react_1 = __importDefault(require("react"));
7
7
  const react_2 = require("@testing-library/react");
8
- require("@testing-library/jest-dom");
9
8
  const DataView_1 = __importDefault(require("./DataView"));
10
- describe('DataView', () => {
11
- it('should render data view', () => {
12
- (0, react_2.render)(react_1.default.createElement(DataView_1.default, null,
13
- react_1.default.createElement(react_1.default.Fragment, null, "Data view content")));
14
- expect(react_2.screen.getByText('Data view content')).toBeInTheDocument();
9
+ const layoutItemStyling = {
10
+ width: '100%',
11
+ height: '5rem',
12
+ padding: 'var(--pf-t--global--spacer--md)',
13
+ border: 'var(--pf-t--global--border--width--box--default) dashed var(--pf-t--global--border--color--default)'
14
+ };
15
+ describe('DataView component', () => {
16
+ test('should render correctly', () => {
17
+ expect((0, react_2.render)(react_1.default.createElement(DataView_1.default, null,
18
+ react_1.default.createElement("div", { style: layoutItemStyling }, "Header"),
19
+ react_1.default.createElement("div", { style: layoutItemStyling }, "Data representation"),
20
+ react_1.default.createElement("div", { style: layoutItemStyling }, "Footer")))).toMatchSnapshot();
15
21
  });
16
22
  });
@@ -1,11 +1,13 @@
1
- import React from 'react';
2
- export interface DataViewToolbarProps {
1
+ import React, { PropsWithChildren } from 'react';
2
+ export interface DataViewToolbarProps extends PropsWithChildren {
3
3
  /** Toolbar className */
4
4
  className?: string;
5
5
  /** Custom OUIA ID */
6
6
  ouiaId?: string;
7
+ /** React component to display bulk select */
8
+ bulkSelect?: React.ReactNode;
7
9
  /** React component to display pagination */
8
10
  pagination?: React.ReactNode;
9
11
  }
10
- export declare const DataViewToolbar: React.FC<React.PropsWithChildren<DataViewToolbarProps>>;
12
+ export declare const DataViewToolbar: React.FC<DataViewToolbarProps>;
11
13
  export default DataViewToolbar;
@@ -18,10 +18,11 @@ exports.DataViewToolbar = void 0;
18
18
  const react_1 = __importDefault(require("react"));
19
19
  const react_core_1 = require("@patternfly/react-core");
20
20
  const DataViewToolbar = (_a) => {
21
- var { className, ouiaId = 'DataViewToolbar', pagination, children } = _a, props = __rest(_a, ["className", "ouiaId", "pagination", "children"]);
21
+ var { className, ouiaId = 'DataViewToolbar', bulkSelect, pagination, children } = _a, props = __rest(_a, ["className", "ouiaId", "bulkSelect", "pagination", "children"]);
22
22
  return (react_1.default.createElement(react_core_1.Toolbar, Object.assign({ ouiaId: ouiaId, className: className }, props),
23
23
  react_1.default.createElement(react_core_1.ToolbarContent, null,
24
- pagination && (react_1.default.createElement(react_core_1.ToolbarItem, { variant: react_core_1.ToolbarItemVariant.pagination }, pagination)),
24
+ bulkSelect && (react_1.default.createElement(react_core_1.ToolbarItem, { "data-ouia-component-id": `${ouiaId}-bulk-select` }, bulkSelect)),
25
+ pagination && (react_1.default.createElement(react_core_1.ToolbarItem, { variant: react_core_1.ToolbarItemVariant.pagination, "data-ouia-component-id": `${ouiaId}-pagination` }, pagination)),
25
26
  children)));
26
27
  };
27
28
  exports.DataViewToolbar = DataViewToolbar;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const react_1 = __importDefault(require("react"));
7
+ const react_2 = require("@testing-library/react");
8
+ const DataViewToolbar_1 = __importDefault(require("./DataViewToolbar"));
9
+ const react_core_1 = require("@patternfly/react-core");
10
+ describe('DataViewToolbar component', () => {
11
+ test('should render correctly', () => {
12
+ expect((0, react_2.render)(react_1.default.createElement(DataViewToolbar_1.default, { pagination: react_1.default.createElement(react_core_1.Pagination, { page: 1, perPage: 10 }) }))).toMatchSnapshot();
13
+ });
14
+ });
@@ -1 +1,2 @@
1
- export * from './useDataViewPagination';
1
+ export * from './pagination';
2
+ export * from './selection';
@@ -14,4 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./useDataViewPagination"), exports);
17
+ __exportStar(require("./pagination"), exports);
18
+ __exportStar(require("./selection"), exports);
@@ -0,0 +1,16 @@
1
+ export interface UseDataViewPaginationProps {
2
+ /** Initial page */
3
+ page?: number;
4
+ /** Items per page */
5
+ perPage: number;
6
+ }
7
+ export interface DataViewPaginationProps extends UseDataViewPaginationProps {
8
+ /** Current page number */
9
+ page: number;
10
+ }
11
+ export declare const useDataViewPagination: ({ page, perPage }: UseDataViewPaginationProps) => {
12
+ onPerPageSelect: (_event: React.MouseEvent | React.KeyboardEvent | MouseEvent | undefined, newPerPage: number) => void;
13
+ onSetPage: (_event: React.MouseEvent | React.KeyboardEvent | MouseEvent | undefined, newPage: number) => void;
14
+ page: number;
15
+ perPage: number;
16
+ };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useDataViewPagination = void 0;
4
+ const react_1 = require("react");
5
+ const useDataViewPagination = ({ page = 1, perPage }) => {
6
+ const [state, setState] = (0, react_1.useState)({ page, perPage });
7
+ const onPerPageSelect = (_event, newPerPage) => {
8
+ setState(prev => (Object.assign(Object.assign({}, prev), { perPage: newPerPage })));
9
+ };
10
+ const onSetPage = (_event, newPage) => {
11
+ setState(prev => (Object.assign(Object.assign({}, prev), { page: newPage })));
12
+ };
13
+ return Object.assign(Object.assign({}, state), { onPerPageSelect,
14
+ onSetPage });
15
+ };
16
+ exports.useDataViewPagination = useDataViewPagination;
@@ -0,0 +1 @@
1
+ import '@testing-library/jest-dom';
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("@testing-library/jest-dom");
4
+ const react_1 = require("@testing-library/react");
5
+ const pagination_1 = require("./pagination");
6
+ describe('useDataViewPagination', () => {
7
+ it('should get initial state correctly - no page', () => {
8
+ const { result } = (0, react_1.renderHook)(() => (0, pagination_1.useDataViewPagination)({ perPage: 7 }));
9
+ expect(result.current).toEqual({
10
+ onPerPageSelect: expect.any(Function),
11
+ onSetPage: expect.any(Function),
12
+ page: 1,
13
+ perPage: 7
14
+ });
15
+ });
16
+ it('should get initial state correctly - page set', () => {
17
+ const { result } = (0, react_1.renderHook)(() => (0, pagination_1.useDataViewPagination)({ page: 3, perPage: 5 }));
18
+ expect(result.current).toEqual({
19
+ onPerPageSelect: expect.any(Function),
20
+ onSetPage: expect.any(Function),
21
+ page: 3,
22
+ perPage: 5
23
+ });
24
+ });
25
+ it('should set page correctly', () => {
26
+ const { result } = (0, react_1.renderHook)(() => (0, pagination_1.useDataViewPagination)({ page: 3, perPage: 5 }));
27
+ (0, react_1.act)(() => {
28
+ result.current.onSetPage(undefined, 8);
29
+ });
30
+ expect(result.current).toEqual({
31
+ onPerPageSelect: expect.any(Function),
32
+ onSetPage: expect.any(Function),
33
+ page: 8,
34
+ perPage: 5
35
+ });
36
+ });
37
+ it('should set perPage correctly', () => {
38
+ const { result } = (0, react_1.renderHook)(() => (0, pagination_1.useDataViewPagination)({ page: 3, perPage: 5 }));
39
+ (0, react_1.act)(() => {
40
+ result.current.onPerPageSelect(undefined, 50);
41
+ });
42
+ expect(result.current).toEqual({
43
+ onPerPageSelect: expect.any(Function),
44
+ onSetPage: expect.any(Function),
45
+ page: 3,
46
+ perPage: 50
47
+ });
48
+ });
49
+ });
@@ -0,0 +1,11 @@
1
+ export interface UseDataViewSelectionProps {
2
+ /** Array of initially selected entries */
3
+ initialSelected?: (any)[];
4
+ /** Function to compare items when checking if entry is selected */
5
+ matchOption?: (item: any, another: any) => boolean;
6
+ }
7
+ export declare const useDataViewSelection: (props: UseDataViewSelectionProps) => {
8
+ selected: any[];
9
+ onSelect: (isSelecting: boolean, items?: any[] | any) => void;
10
+ isSelected: (item: any) => boolean;
11
+ };
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useDataViewSelection = void 0;
4
+ /* eslint-disable @typescript-eslint/no-explicit-any */
5
+ const react_1 = require("react");
6
+ const useDataViewSelection = (props) => {
7
+ var _a;
8
+ const [selected, setSelected] = (0, react_1.useState)((_a = props.initialSelected) !== null && _a !== void 0 ? _a : []);
9
+ const matchOption = props.matchOption ? props.matchOption : (option, another) => (option === another);
10
+ const onSelect = (isSelecting, items) => {
11
+ isSelecting ?
12
+ setSelected(prev => {
13
+ const newSelectedItems = [...prev];
14
+ (Array.isArray(items) ? items : [items]).forEach(newItem => !prev.some(prevItem => matchOption(prevItem, newItem)) && newSelectedItems.push(newItem));
15
+ return newSelectedItems;
16
+ })
17
+ : setSelected(items ? prev => prev.filter(prevSelected => !(Array.isArray(items) ? items : [items]).some(item => matchOption(item, prevSelected))) : []);
18
+ };
19
+ const isSelected = (item) => (props === null || props === void 0 ? void 0 : props.matchOption) ? Boolean(selected.find(selected => matchOption(selected, item))) : selected.includes(item);
20
+ return {
21
+ selected,
22
+ onSelect,
23
+ isSelected
24
+ };
25
+ };
26
+ exports.useDataViewSelection = useDataViewSelection;
@@ -0,0 +1 @@
1
+ import '@testing-library/jest-dom';
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ require("@testing-library/jest-dom");
13
+ const react_1 = require("@testing-library/react");
14
+ const selection_1 = require("./selection");
15
+ describe('useDataViewSelection', () => {
16
+ it('should get initial state correctly - no initialSelected', () => {
17
+ const { result } = (0, react_1.renderHook)(() => (0, selection_1.useDataViewSelection)({}));
18
+ expect(result.current).toEqual({
19
+ selected: [],
20
+ onSelect: expect.any(Function),
21
+ isSelected: expect.any(Function),
22
+ });
23
+ });
24
+ it('should get initial state correctly - with initialSelected', () => {
25
+ const initialSelected = [{ id: 1, name: 'test1' }];
26
+ const { result } = (0, react_1.renderHook)(() => (0, selection_1.useDataViewSelection)({ initialSelected }));
27
+ expect(result.current).toEqual({
28
+ selected: initialSelected,
29
+ onSelect: expect.any(Function),
30
+ isSelected: expect.any(Function),
31
+ });
32
+ });
33
+ it('should select items correctly - objects', () => __awaiter(void 0, void 0, void 0, function* () {
34
+ const initialSelected = [{ id: 1, name: 'test1' }];
35
+ const { result } = (0, react_1.renderHook)(() => (0, selection_1.useDataViewSelection)({ initialSelected }));
36
+ yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
37
+ result.current.onSelect(true, { id: 2, name: 'test2' });
38
+ }));
39
+ expect(result.current.selected).toEqual([...initialSelected, { id: 2, name: 'test2' }]);
40
+ }));
41
+ it('should deselect items correctly - strings', () => __awaiter(void 0, void 0, void 0, function* () {
42
+ const initialSelected = ['test1', 'test2'];
43
+ const { result } = (0, react_1.renderHook)(() => (0, selection_1.useDataViewSelection)({ initialSelected }));
44
+ yield (0, react_1.act)(() => __awaiter(void 0, void 0, void 0, function* () {
45
+ result.current.onSelect(false, 'test2');
46
+ }));
47
+ expect(result.current.selected).toEqual(['test1']);
48
+ }));
49
+ it('should check if item is selected correctly - objects', () => {
50
+ const initialSelected = [{ id: 1, name: 'test1' }, { id: 2, name: 'test2' }];
51
+ const { result } = (0, react_1.renderHook)(() => (0, selection_1.useDataViewSelection)({ initialSelected, matchOption: (a, b) => a.id === b.id }));
52
+ expect(result.current.isSelected({ id: 1, name: 'test1' })).toBe(true);
53
+ expect(result.current.isSelected({ id: 3, name: 'test2' })).toBe(false);
54
+ });
55
+ });
@@ -1 +1 @@
1
- import '@testing-library/jest-dom';
1
+ export {};
@@ -1,11 +1,17 @@
1
1
  import React from 'react';
2
- import { render, screen } from '@testing-library/react';
3
- import '@testing-library/jest-dom';
2
+ import { render } from '@testing-library/react';
4
3
  import DataView from './DataView';
5
- describe('DataView', () => {
6
- it('should render data view', () => {
7
- render(React.createElement(DataView, null,
8
- React.createElement(React.Fragment, null, "Data view content")));
9
- expect(screen.getByText('Data view content')).toBeInTheDocument();
4
+ const layoutItemStyling = {
5
+ width: '100%',
6
+ height: '5rem',
7
+ padding: 'var(--pf-t--global--spacer--md)',
8
+ border: 'var(--pf-t--global--border--width--box--default) dashed var(--pf-t--global--border--color--default)'
9
+ };
10
+ describe('DataView component', () => {
11
+ test('should render correctly', () => {
12
+ expect(render(React.createElement(DataView, null,
13
+ React.createElement("div", { style: layoutItemStyling }, "Header"),
14
+ React.createElement("div", { style: layoutItemStyling }, "Data representation"),
15
+ React.createElement("div", { style: layoutItemStyling }, "Footer")))).toMatchSnapshot();
10
16
  });
11
17
  });
@@ -1,11 +1,13 @@
1
- import React from 'react';
2
- export interface DataViewToolbarProps {
1
+ import React, { PropsWithChildren } from 'react';
2
+ export interface DataViewToolbarProps extends PropsWithChildren {
3
3
  /** Toolbar className */
4
4
  className?: string;
5
5
  /** Custom OUIA ID */
6
6
  ouiaId?: string;
7
+ /** React component to display bulk select */
8
+ bulkSelect?: React.ReactNode;
7
9
  /** React component to display pagination */
8
10
  pagination?: React.ReactNode;
9
11
  }
10
- export declare const DataViewToolbar: React.FC<React.PropsWithChildren<DataViewToolbarProps>>;
12
+ export declare const DataViewToolbar: React.FC<DataViewToolbarProps>;
11
13
  export default DataViewToolbar;
@@ -12,10 +12,11 @@ var __rest = (this && this.__rest) || function (s, e) {
12
12
  import React from 'react';
13
13
  import { Toolbar, ToolbarContent, ToolbarItem, ToolbarItemVariant } from '@patternfly/react-core';
14
14
  export const DataViewToolbar = (_a) => {
15
- var { className, ouiaId = 'DataViewToolbar', pagination, children } = _a, props = __rest(_a, ["className", "ouiaId", "pagination", "children"]);
15
+ var { className, ouiaId = 'DataViewToolbar', bulkSelect, pagination, children } = _a, props = __rest(_a, ["className", "ouiaId", "bulkSelect", "pagination", "children"]);
16
16
  return (React.createElement(Toolbar, Object.assign({ ouiaId: ouiaId, className: className }, props),
17
17
  React.createElement(ToolbarContent, null,
18
- pagination && (React.createElement(ToolbarItem, { variant: ToolbarItemVariant.pagination }, pagination)),
18
+ bulkSelect && (React.createElement(ToolbarItem, { "data-ouia-component-id": `${ouiaId}-bulk-select` }, bulkSelect)),
19
+ pagination && (React.createElement(ToolbarItem, { variant: ToolbarItemVariant.pagination, "data-ouia-component-id": `${ouiaId}-pagination` }, pagination)),
19
20
  children)));
20
21
  };
21
22
  export default DataViewToolbar;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ import { render } from '@testing-library/react';
3
+ import DataViewToolbar from './DataViewToolbar';
4
+ import { Pagination } from '@patternfly/react-core';
5
+ describe('DataViewToolbar component', () => {
6
+ test('should render correctly', () => {
7
+ expect(render(React.createElement(DataViewToolbar, { pagination: React.createElement(Pagination, { page: 1, perPage: 10 }) }))).toMatchSnapshot();
8
+ });
9
+ });
@@ -1 +1,2 @@
1
- export * from './useDataViewPagination';
1
+ export * from './pagination';
2
+ export * from './selection';
@@ -1 +1,2 @@
1
- export * from './useDataViewPagination';
1
+ export * from './pagination';
2
+ export * from './selection';
@@ -0,0 +1,16 @@
1
+ export interface UseDataViewPaginationProps {
2
+ /** Initial page */
3
+ page?: number;
4
+ /** Items per page */
5
+ perPage: number;
6
+ }
7
+ export interface DataViewPaginationProps extends UseDataViewPaginationProps {
8
+ /** Current page number */
9
+ page: number;
10
+ }
11
+ export declare const useDataViewPagination: ({ page, perPage }: UseDataViewPaginationProps) => {
12
+ onPerPageSelect: (_event: React.MouseEvent | React.KeyboardEvent | MouseEvent | undefined, newPerPage: number) => void;
13
+ onSetPage: (_event: React.MouseEvent | React.KeyboardEvent | MouseEvent | undefined, newPage: number) => void;
14
+ page: number;
15
+ perPage: number;
16
+ };
@@ -0,0 +1,12 @@
1
+ import { useState } from "react";
2
+ export const useDataViewPagination = ({ page = 1, perPage }) => {
3
+ const [state, setState] = useState({ page, perPage });
4
+ const onPerPageSelect = (_event, newPerPage) => {
5
+ setState(prev => (Object.assign(Object.assign({}, prev), { perPage: newPerPage })));
6
+ };
7
+ const onSetPage = (_event, newPage) => {
8
+ setState(prev => (Object.assign(Object.assign({}, prev), { page: newPage })));
9
+ };
10
+ return Object.assign(Object.assign({}, state), { onPerPageSelect,
11
+ onSetPage });
12
+ };
@@ -0,0 +1 @@
1
+ import '@testing-library/jest-dom';
@@ -0,0 +1,47 @@
1
+ import '@testing-library/jest-dom';
2
+ import { renderHook, act } from '@testing-library/react';
3
+ import { useDataViewPagination } from './pagination';
4
+ describe('useDataViewPagination', () => {
5
+ it('should get initial state correctly - no page', () => {
6
+ const { result } = renderHook(() => useDataViewPagination({ perPage: 7 }));
7
+ expect(result.current).toEqual({
8
+ onPerPageSelect: expect.any(Function),
9
+ onSetPage: expect.any(Function),
10
+ page: 1,
11
+ perPage: 7
12
+ });
13
+ });
14
+ it('should get initial state correctly - page set', () => {
15
+ const { result } = renderHook(() => useDataViewPagination({ page: 3, perPage: 5 }));
16
+ expect(result.current).toEqual({
17
+ onPerPageSelect: expect.any(Function),
18
+ onSetPage: expect.any(Function),
19
+ page: 3,
20
+ perPage: 5
21
+ });
22
+ });
23
+ it('should set page correctly', () => {
24
+ const { result } = renderHook(() => useDataViewPagination({ page: 3, perPage: 5 }));
25
+ act(() => {
26
+ result.current.onSetPage(undefined, 8);
27
+ });
28
+ expect(result.current).toEqual({
29
+ onPerPageSelect: expect.any(Function),
30
+ onSetPage: expect.any(Function),
31
+ page: 8,
32
+ perPage: 5
33
+ });
34
+ });
35
+ it('should set perPage correctly', () => {
36
+ const { result } = renderHook(() => useDataViewPagination({ page: 3, perPage: 5 }));
37
+ act(() => {
38
+ result.current.onPerPageSelect(undefined, 50);
39
+ });
40
+ expect(result.current).toEqual({
41
+ onPerPageSelect: expect.any(Function),
42
+ onSetPage: expect.any(Function),
43
+ page: 3,
44
+ perPage: 50
45
+ });
46
+ });
47
+ });
@@ -0,0 +1,11 @@
1
+ export interface UseDataViewSelectionProps {
2
+ /** Array of initially selected entries */
3
+ initialSelected?: (any)[];
4
+ /** Function to compare items when checking if entry is selected */
5
+ matchOption?: (item: any, another: any) => boolean;
6
+ }
7
+ export declare const useDataViewSelection: (props: UseDataViewSelectionProps) => {
8
+ selected: any[];
9
+ onSelect: (isSelecting: boolean, items?: any[] | any) => void;
10
+ isSelected: (item: any) => boolean;
11
+ };
@@ -0,0 +1,22 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { useState } from "react";
3
+ export const useDataViewSelection = (props) => {
4
+ var _a;
5
+ const [selected, setSelected] = useState((_a = props.initialSelected) !== null && _a !== void 0 ? _a : []);
6
+ const matchOption = props.matchOption ? props.matchOption : (option, another) => (option === another);
7
+ const onSelect = (isSelecting, items) => {
8
+ isSelecting ?
9
+ setSelected(prev => {
10
+ const newSelectedItems = [...prev];
11
+ (Array.isArray(items) ? items : [items]).forEach(newItem => !prev.some(prevItem => matchOption(prevItem, newItem)) && newSelectedItems.push(newItem));
12
+ return newSelectedItems;
13
+ })
14
+ : setSelected(items ? prev => prev.filter(prevSelected => !(Array.isArray(items) ? items : [items]).some(item => matchOption(item, prevSelected))) : []);
15
+ };
16
+ const isSelected = (item) => (props === null || props === void 0 ? void 0 : props.matchOption) ? Boolean(selected.find(selected => matchOption(selected, item))) : selected.includes(item);
17
+ return {
18
+ selected,
19
+ onSelect,
20
+ isSelected
21
+ };
22
+ };
@@ -0,0 +1 @@
1
+ import '@testing-library/jest-dom';
@@ -0,0 +1,53 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import '@testing-library/jest-dom';
11
+ import { renderHook, act } from '@testing-library/react';
12
+ import { useDataViewSelection } from './selection';
13
+ describe('useDataViewSelection', () => {
14
+ it('should get initial state correctly - no initialSelected', () => {
15
+ const { result } = renderHook(() => useDataViewSelection({}));
16
+ expect(result.current).toEqual({
17
+ selected: [],
18
+ onSelect: expect.any(Function),
19
+ isSelected: expect.any(Function),
20
+ });
21
+ });
22
+ it('should get initial state correctly - with initialSelected', () => {
23
+ const initialSelected = [{ id: 1, name: 'test1' }];
24
+ const { result } = renderHook(() => useDataViewSelection({ initialSelected }));
25
+ expect(result.current).toEqual({
26
+ selected: initialSelected,
27
+ onSelect: expect.any(Function),
28
+ isSelected: expect.any(Function),
29
+ });
30
+ });
31
+ it('should select items correctly - objects', () => __awaiter(void 0, void 0, void 0, function* () {
32
+ const initialSelected = [{ id: 1, name: 'test1' }];
33
+ const { result } = renderHook(() => useDataViewSelection({ initialSelected }));
34
+ yield act(() => __awaiter(void 0, void 0, void 0, function* () {
35
+ result.current.onSelect(true, { id: 2, name: 'test2' });
36
+ }));
37
+ expect(result.current.selected).toEqual([...initialSelected, { id: 2, name: 'test2' }]);
38
+ }));
39
+ it('should deselect items correctly - strings', () => __awaiter(void 0, void 0, void 0, function* () {
40
+ const initialSelected = ['test1', 'test2'];
41
+ const { result } = renderHook(() => useDataViewSelection({ initialSelected }));
42
+ yield act(() => __awaiter(void 0, void 0, void 0, function* () {
43
+ result.current.onSelect(false, 'test2');
44
+ }));
45
+ expect(result.current.selected).toEqual(['test1']);
46
+ }));
47
+ it('should check if item is selected correctly - objects', () => {
48
+ const initialSelected = [{ id: 1, name: 'test1' }, { id: 2, name: 'test2' }];
49
+ const { result } = renderHook(() => useDataViewSelection({ initialSelected, matchOption: (a, b) => a.id === b.id }));
50
+ expect(result.current.isSelected({ id: 1, name: 'test1' })).toBe(true);
51
+ expect(result.current.isSelected({ id: 3, name: 'test2' })).toBe(false);
52
+ });
53
+ });
@@ -1,14 +1,13 @@
1
1
  const fse = require('fs-extra');
2
- const glob = require('glob');
2
+ const { globSync } = require('glob');
3
3
  const path = require('path');
4
4
 
5
5
  const root = process.cwd();
6
6
 
7
- const sourceFiles = glob
8
- .sync(`${root}/src/*/`)
7
+ const sourceFiles = globSync(`${root}/src/*/`)
9
8
  .map((name) => name.replace(/\/$/, ''));
10
9
 
11
- const indexTypings = glob.sync(`${root}/src/index.d.ts`);
10
+ const indexTypings = globSync(`${root}/src/index.d.ts`);
12
11
 
13
12
  const ENV_AGNOSTIC_ROOT = `${root}/dist/dynamic`
14
13
 
@@ -23,9 +22,9 @@ async function copyTypings(files, dest) {
23
22
 
24
23
  async function createPackage(file) {
25
24
  const fileName = file.split('/').pop();
26
- const esmSource = glob.sync(`${root}/dist/esm/${fileName}/**/index.js`)[0];
27
- const cjsSource = glob.sync(`${root}/dist/cjs/${fileName}/**/index.js`)[0];
28
- const typingsSource = glob.sync(`${root}/dist/esm/${fileName}/**/index.d.ts`)[0]
25
+ const esmSource = globSync(`${root}/dist/esm/${fileName}/**/index.js`)[0];
26
+ const cjsSource = globSync(`${root}/dist/cjs/${fileName}/**/index.js`)[0];
27
+ const typingsSource = globSync(`${root}/dist/esm/${fileName}/**/index.d.ts`)[0]
29
28
  /**
30
29
  * Prevent creating package.json for directories with no JS files (like CSS directories)
31
30
  */
@@ -46,7 +45,7 @@ async function createPackage(file) {
46
45
  main: cjsRelative,
47
46
  module: esmRelative,
48
47
  };
49
- const typings = glob.sync(`${root}/src/${fileName}/*.d.ts`);
48
+ const typings = globSync(`${root}/src/${fileName}/*.d.ts`);
50
49
  const cmds = [];
51
50
  content.typings = tsRelative;
52
51
  cmds.push(copyTypings(typings, `${root}/dist/${fileName}`));
package/generate-index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  const fse = require('fs-extra');
2
- const glob = require('glob');
2
+ const { globSync } = require('glob');
3
3
  const path = require('path');
4
4
 
5
5
  const root = process.cwd();
6
6
 
7
7
  const ENV_AGNOSTIC_ROOT = `${root}/src`
8
8
 
9
- const sourceFiles = glob.sync(path.resolve(__dirname, './src/*/index.ts'))
9
+ const sourceFiles = globSync(path.resolve(__dirname, './src/*/index.ts'))
10
10
 
11
11
  async function generateIndex(files) {
12
12
  // ensure the dynamic root exists
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/react-data-view",
3
- "version": "1.0.0-prerelease.3",
3
+ "version": "1.0.0-prerelease.5",
4
4
  "description": "Data view used for Red Hat projects.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -31,9 +31,10 @@
31
31
  "tag": "prerelease"
32
32
  },
33
33
  "dependencies": {
34
- "@patternfly/react-core": "^6.0.0-alpha.55",
35
- "@patternfly/react-icons": "^6.0.0-alpha.20",
36
- "@patternfly/react-table": "^6.0.0-alpha.55",
34
+ "@patternfly/react-core": "^6.0.0-alpha.69",
35
+ "@patternfly/react-icons": "^6.0.0-alpha.24",
36
+ "@patternfly/react-table": "^6.0.0-alpha.69",
37
+ "@patternfly/react-component-groups": "^6.0.0-alpha.2",
37
38
  "react-jss": "^10.10.0",
38
39
  "clsx": "^2.1.1"
39
40
  },
@@ -43,8 +44,8 @@
43
44
  },
44
45
  "devDependencies": {
45
46
  "@patternfly/patternfly-a11y": "^4.3.1",
46
- "@patternfly/documentation-framework": "^6.0.0-alpha.22",
47
- "@patternfly/patternfly": "^6.0.0-alpha.117",
47
+ "@patternfly/documentation-framework": "^6.0.0-alpha.49",
48
+ "@patternfly/patternfly": "6.0.0-alpha.139",
48
49
  "@types/react": "^18.3.1",
49
50
  "@types/react-dom": "^18.3.0",
50
51
  "@types/react-router-dom": "^5.3.3",