@patternfly/react-data-view 1.0.0-prerelease.2 → 1.0.0-prerelease.4
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 +5 -3
- package/dist/cjs/DataView/DataView.js +15 -1
- package/dist/cjs/DataViewToolbar/DataViewToolbar.d.ts +11 -0
- package/dist/cjs/DataViewToolbar/DataViewToolbar.js +28 -0
- package/dist/cjs/DataViewToolbar/index.d.ts +2 -0
- package/dist/cjs/DataViewToolbar/index.js +23 -0
- package/dist/cjs/Hooks/index.d.ts +1 -0
- package/dist/cjs/Hooks/index.js +17 -0
- package/dist/cjs/Hooks/pagination.d.ts +13 -0
- package/dist/cjs/Hooks/pagination.js +16 -0
- package/dist/cjs/Hooks/pagination.test.js +49 -0
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.js +6 -2
- package/dist/dynamic/DataViewToolbar/package.json +1 -0
- package/dist/dynamic/Hooks/package.json +1 -0
- package/dist/esm/DataView/DataView.d.ts +5 -3
- package/dist/esm/DataView/DataView.js +16 -2
- package/dist/esm/DataViewToolbar/DataViewToolbar.d.ts +11 -0
- package/dist/esm/DataViewToolbar/DataViewToolbar.js +21 -0
- package/dist/esm/DataViewToolbar/index.d.ts +2 -0
- package/dist/esm/DataViewToolbar/index.js +2 -0
- package/dist/esm/Hooks/index.d.ts +1 -0
- package/dist/esm/Hooks/index.js +1 -0
- package/dist/esm/Hooks/pagination.d.ts +13 -0
- package/dist/esm/Hooks/pagination.js +12 -0
- package/dist/esm/Hooks/pagination.test.js +47 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +3 -0
- package/generate-index.js +2 -1
- package/package.json +15 -14
- package/patternfly-a11y.config.js +2 -1
- package/patternfly-docs/content/extensions/data-view/examples/DataView/DataView.md +15 -5
- package/patternfly-docs/content/extensions/data-view/examples/DataView/DataViewLayoutExample.tsx +17 -0
- package/patternfly-docs/content/extensions/data-view/examples/DataView/DataViewPredefinedLayoutExample.tsx +65 -0
- package/patternfly-docs/content/extensions/data-view/examples/DataViewToolbar/DataViewToolbar.md +27 -0
- package/patternfly-docs/content/extensions/data-view/examples/DataViewToolbar/DataViewToolbarExample.tsx +7 -0
- package/patternfly-docs/content/extensions/data-view/examples/Hooks/Hooks.md +20 -0
- package/patternfly-docs/pages/index.js +1 -1
- package/src/DataView/DataView.tsx +15 -8
- package/src/DataViewToolbar/DataViewToolbar.tsx +27 -0
- package/src/DataViewToolbar/index.ts +2 -0
- package/src/Hooks/index.ts +1 -0
- package/src/Hooks/pagination.test.tsx +57 -0
- package/src/Hooks/pagination.ts +28 -0
- package/src/index.ts +4 -0
- package/dist/cjs/DataView/DataView.test.js +0 -15
- package/dist/esm/DataView/DataView.test.js +0 -10
- package/patternfly-docs/content/extensions/data-view/examples/DataView/DataViewExample.tsx +0 -6
- package/patternfly-docs/generated/extensions/data-view/about-data-view/extensions.js +0 -54
- package/patternfly-docs/generated/extensions/data-view/data-view/react.js +0 -66
- package/patternfly-docs/generated/index.js +0 -24
- package/src/DataView/DataView.test.tsx +0 -13
- /package/dist/cjs/{DataView/DataView.test.d.ts → Hooks/pagination.test.d.ts} +0 -0
- /package/dist/esm/{DataView/DataView.test.d.ts → Hooks/pagination.test.d.ts} +0 -0
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
export interface DataViewProps {
|
|
3
|
-
/**
|
|
4
|
-
|
|
3
|
+
/** Content rendered inside the data view */
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
/** Custom OUIA ID */
|
|
6
|
+
ouiaId?: string;
|
|
5
7
|
}
|
|
6
|
-
export declare const DataView: React.
|
|
8
|
+
export declare const DataView: React.FC<DataViewProps>;
|
|
7
9
|
export default DataView;
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
2
13
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
15
|
};
|
|
@@ -6,6 +17,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
17
|
exports.DataView = void 0;
|
|
7
18
|
const react_1 = __importDefault(require("react"));
|
|
8
19
|
const react_core_1 = require("@patternfly/react-core");
|
|
9
|
-
const DataView = (
|
|
20
|
+
const DataView = (_a) => {
|
|
21
|
+
var { children, ouiaId = 'DataView' } = _a, props = __rest(_a, ["children", "ouiaId"]);
|
|
22
|
+
return (react_1.default.createElement(react_core_1.Stack, Object.assign({ "data-ouia-component-id": `${ouiaId}-stack}` }, props), react_1.default.Children.map(children, (child, index) => (react_1.default.createElement(react_core_1.StackItem, { "data-ouia-component-id": `${ouiaId}-stack-item-${index}` }, child)))));
|
|
23
|
+
};
|
|
10
24
|
exports.DataView = DataView;
|
|
11
25
|
exports.default = exports.DataView;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface DataViewToolbarProps {
|
|
3
|
+
/** Toolbar className */
|
|
4
|
+
className?: string;
|
|
5
|
+
/** Custom OUIA ID */
|
|
6
|
+
ouiaId?: string;
|
|
7
|
+
/** React component to display pagination */
|
|
8
|
+
pagination?: React.ReactNode;
|
|
9
|
+
}
|
|
10
|
+
export declare const DataViewToolbar: React.FC<React.PropsWithChildren<DataViewToolbarProps>>;
|
|
11
|
+
export default DataViewToolbar;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.DataViewToolbar = void 0;
|
|
18
|
+
const react_1 = __importDefault(require("react"));
|
|
19
|
+
const react_core_1 = require("@patternfly/react-core");
|
|
20
|
+
const DataViewToolbar = (_a) => {
|
|
21
|
+
var { className, ouiaId = 'DataViewToolbar', pagination, children } = _a, props = __rest(_a, ["className", "ouiaId", "pagination", "children"]);
|
|
22
|
+
return (react_1.default.createElement(react_core_1.Toolbar, Object.assign({ ouiaId: ouiaId, className: className }, props),
|
|
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)),
|
|
25
|
+
children)));
|
|
26
|
+
};
|
|
27
|
+
exports.DataViewToolbar = DataViewToolbar;
|
|
28
|
+
exports.default = exports.DataViewToolbar;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.default = void 0;
|
|
21
|
+
var DataViewToolbar_1 = require("./DataViewToolbar");
|
|
22
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(DataViewToolbar_1).default; } });
|
|
23
|
+
__exportStar(require("./DataViewToolbar"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './pagination';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./pagination"), exports);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface UseDataViewPaginationProps {
|
|
2
|
+
page?: number;
|
|
3
|
+
perPage: number;
|
|
4
|
+
}
|
|
5
|
+
export interface DataViewPaginationProps extends UseDataViewPaginationProps {
|
|
6
|
+
page: number;
|
|
7
|
+
}
|
|
8
|
+
export declare const useDataViewPagination: ({ page, perPage }: UseDataViewPaginationProps) => {
|
|
9
|
+
onPerPageSelect: (_event: React.MouseEvent | React.KeyboardEvent | MouseEvent | undefined, newPerPage: number) => void;
|
|
10
|
+
onSetPage: (_event: React.MouseEvent | React.KeyboardEvent | MouseEvent | undefined, newPage: number) => void;
|
|
11
|
+
page: number;
|
|
12
|
+
perPage: number;
|
|
13
|
+
};
|
|
@@ -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,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
|
+
});
|
package/dist/cjs/index.d.ts
CHANGED
package/dist/cjs/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// this file is autogenerated by generate-index.js, modifying it manually will have no effect
|
|
3
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
3
|
if (k2 === undefined) k2 = k;
|
|
5
4
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -18,7 +17,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
18
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
18
|
};
|
|
20
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.DataView = void 0;
|
|
20
|
+
exports.DataView = exports.DataViewToolbar = void 0;
|
|
21
|
+
// this file is autogenerated by generate-index.js, modifying it manually will have no effect
|
|
22
|
+
__exportStar(require("./Hooks"), exports);
|
|
23
|
+
var DataViewToolbar_1 = require("./DataViewToolbar");
|
|
24
|
+
Object.defineProperty(exports, "DataViewToolbar", { enumerable: true, get: function () { return __importDefault(DataViewToolbar_1).default; } });
|
|
25
|
+
__exportStar(require("./DataViewToolbar"), exports);
|
|
22
26
|
var DataView_1 = require("./DataView");
|
|
23
27
|
Object.defineProperty(exports, "DataView", { enumerable: true, get: function () { return __importDefault(DataView_1).default; } });
|
|
24
28
|
__exportStar(require("./DataView"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"main":"../../cjs/DataViewToolbar/index.js","module":"../../esm/DataViewToolbar/index.js","typings":"../../esm/DataViewToolbar/index.d.ts"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"main":"../../cjs/Hooks/index.js","module":"../../esm/Hooks/index.js","typings":"../../esm/Hooks/index.d.ts"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
export interface DataViewProps {
|
|
3
|
-
/**
|
|
4
|
-
|
|
3
|
+
/** Content rendered inside the data view */
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
/** Custom OUIA ID */
|
|
6
|
+
ouiaId?: string;
|
|
5
7
|
}
|
|
6
|
-
export declare const DataView: React.
|
|
8
|
+
export declare const DataView: React.FC<DataViewProps>;
|
|
7
9
|
export default DataView;
|
|
@@ -1,4 +1,18 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
1
12
|
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
export const DataView = (
|
|
13
|
+
import { Stack, StackItem } from '@patternfly/react-core';
|
|
14
|
+
export const DataView = (_a) => {
|
|
15
|
+
var { children, ouiaId = 'DataView' } = _a, props = __rest(_a, ["children", "ouiaId"]);
|
|
16
|
+
return (React.createElement(Stack, Object.assign({ "data-ouia-component-id": `${ouiaId}-stack}` }, props), React.Children.map(children, (child, index) => (React.createElement(StackItem, { "data-ouia-component-id": `${ouiaId}-stack-item-${index}` }, child)))));
|
|
17
|
+
};
|
|
4
18
|
export default DataView;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface DataViewToolbarProps {
|
|
3
|
+
/** Toolbar className */
|
|
4
|
+
className?: string;
|
|
5
|
+
/** Custom OUIA ID */
|
|
6
|
+
ouiaId?: string;
|
|
7
|
+
/** React component to display pagination */
|
|
8
|
+
pagination?: React.ReactNode;
|
|
9
|
+
}
|
|
10
|
+
export declare const DataViewToolbar: React.FC<React.PropsWithChildren<DataViewToolbarProps>>;
|
|
11
|
+
export default DataViewToolbar;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import React from 'react';
|
|
13
|
+
import { Toolbar, ToolbarContent, ToolbarItem, ToolbarItemVariant } from '@patternfly/react-core';
|
|
14
|
+
export const DataViewToolbar = (_a) => {
|
|
15
|
+
var { className, ouiaId = 'DataViewToolbar', pagination, children } = _a, props = __rest(_a, ["className", "ouiaId", "pagination", "children"]);
|
|
16
|
+
return (React.createElement(Toolbar, Object.assign({ ouiaId: ouiaId, className: className }, props),
|
|
17
|
+
React.createElement(ToolbarContent, null,
|
|
18
|
+
pagination && (React.createElement(ToolbarItem, { variant: ToolbarItemVariant.pagination }, pagination)),
|
|
19
|
+
children)));
|
|
20
|
+
};
|
|
21
|
+
export default DataViewToolbar;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './pagination';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './pagination';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface UseDataViewPaginationProps {
|
|
2
|
+
page?: number;
|
|
3
|
+
perPage: number;
|
|
4
|
+
}
|
|
5
|
+
export interface DataViewPaginationProps extends UseDataViewPaginationProps {
|
|
6
|
+
page: number;
|
|
7
|
+
}
|
|
8
|
+
export declare const useDataViewPagination: ({ page, perPage }: UseDataViewPaginationProps) => {
|
|
9
|
+
onPerPageSelect: (_event: React.MouseEvent | React.KeyboardEvent | MouseEvent | undefined, newPerPage: number) => void;
|
|
10
|
+
onSetPage: (_event: React.MouseEvent | React.KeyboardEvent | MouseEvent | undefined, newPage: number) => void;
|
|
11
|
+
page: number;
|
|
12
|
+
perPage: number;
|
|
13
|
+
};
|
|
@@ -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,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
|
+
});
|
package/dist/esm/index.d.ts
CHANGED
package/dist/esm/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
// this file is autogenerated by generate-index.js, modifying it manually will have no effect
|
|
2
|
+
export * from './Hooks';
|
|
3
|
+
export { default as DataViewToolbar } from './DataViewToolbar';
|
|
4
|
+
export * from './DataViewToolbar';
|
|
2
5
|
export { default as DataView } from './DataView';
|
|
3
6
|
export * from './DataView';
|
package/generate-index.js
CHANGED
|
@@ -20,7 +20,8 @@ async function generateIndex(files) {
|
|
|
20
20
|
|
|
21
21
|
files.forEach(file => {
|
|
22
22
|
const name = file.replace('/index.ts', '').split('/').pop();
|
|
23
|
-
|
|
23
|
+
// do not generate default exports for Hooks/
|
|
24
|
+
name !== 'Hooks' && stream.write(`\nexport { default as ${name} } from './${name}';\n`);
|
|
24
25
|
stream.write(`export * from './${name}';\n`);
|
|
25
26
|
});
|
|
26
27
|
stream.end();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@patternfly/react-data-view",
|
|
3
|
-
"version": "1.0.0-prerelease.
|
|
3
|
+
"version": "1.0.0-prerelease.4",
|
|
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,10 +31,11 @@
|
|
|
31
31
|
"tag": "prerelease"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@patternfly/react-core": "^
|
|
35
|
-
"@patternfly/react-icons": "^
|
|
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",
|
|
36
37
|
"react-jss": "^10.10.0",
|
|
37
|
-
"clsx": "^2.1.
|
|
38
|
+
"clsx": "^2.1.1"
|
|
38
39
|
},
|
|
39
40
|
"peerDependencies": {
|
|
40
41
|
"react": "^17 || ^18",
|
|
@@ -42,16 +43,16 @@
|
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
44
45
|
"@patternfly/patternfly-a11y": "^4.3.1",
|
|
45
|
-
"@patternfly/documentation-framework": "^
|
|
46
|
-
"@patternfly/patternfly": "^
|
|
47
|
-
"@types/react": "^18.
|
|
48
|
-
"@types/react-dom": "^18.
|
|
46
|
+
"@patternfly/documentation-framework": "^6.0.0-alpha.22",
|
|
47
|
+
"@patternfly/patternfly": "^6.0.0-alpha.117",
|
|
48
|
+
"@types/react": "^18.3.1",
|
|
49
|
+
"@types/react-dom": "^18.3.0",
|
|
49
50
|
"@types/react-router-dom": "^5.3.3",
|
|
50
|
-
"react": "^18.
|
|
51
|
-
"react-dom": "^18.
|
|
52
|
-
"react-router": "^6.
|
|
53
|
-
"react-router-dom": "^6.
|
|
54
|
-
"rimraf": "^
|
|
55
|
-
"typescript": "^5.
|
|
51
|
+
"react": "^18.3.1",
|
|
52
|
+
"react-dom": "^18.3.1",
|
|
53
|
+
"react-router": "^6.23.0",
|
|
54
|
+
"react-router-dom": "^6.23.0",
|
|
55
|
+
"rimraf": "^5.0.5",
|
|
56
|
+
"typescript": "^5.4.5"
|
|
56
57
|
}
|
|
57
58
|
}
|
|
@@ -5,7 +5,7 @@ section: extensions
|
|
|
5
5
|
subsection: Data view
|
|
6
6
|
# Sidenav secondary level section
|
|
7
7
|
# should be the same for all markdown files
|
|
8
|
-
id: Data view
|
|
8
|
+
id: Data view layout
|
|
9
9
|
# Tab (react | react-demos | html | html-demos | design-guidelines | accessibility)
|
|
10
10
|
source: react
|
|
11
11
|
# If you use typescript, the name of the interface to display props for
|
|
@@ -13,15 +13,25 @@ source: react
|
|
|
13
13
|
propComponents: ['DataView']
|
|
14
14
|
sourceLink: https://github.com/patternfly/react-data-view/blob/main/packages/module/patternfly-docs/content/extensions/data-view/examples/DataView/DataView.md
|
|
15
15
|
---
|
|
16
|
-
|
|
16
|
+
import { useMemo } from 'react';
|
|
17
|
+
import { useDataViewPagination } from '@patternfly/react-data-view/dist/dynamic/Hooks';
|
|
17
18
|
import DataView from '@patternfly/react-data-view/dist/dynamic/DataView';
|
|
19
|
+
import DataViewToolbar from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
|
|
18
20
|
|
|
19
21
|
The **data view** component renders record data in a configured layout.
|
|
20
22
|
|
|
21
|
-
###
|
|
23
|
+
### Layout example
|
|
24
|
+
|
|
25
|
+
Data view is expected to consist of header, data part and footer stacked below each other and passed as `children`.
|
|
26
|
+
|
|
27
|
+
```js file="./DataViewLayoutExample.tsx"
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Predefined layout components
|
|
22
32
|
|
|
23
|
-
|
|
33
|
+
You can make use of the predefined layout components to display a default header and footer. See [data view toolbar](/data-view/data-view-toolbar) for more information
|
|
24
34
|
|
|
25
|
-
```js file="./
|
|
35
|
+
```js file="./DataViewPredefinedLayoutExample.tsx"
|
|
26
36
|
|
|
27
37
|
```
|
package/patternfly-docs/content/extensions/data-view/examples/DataView/DataViewLayoutExample.tsx
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import DataView from '@patternfly/react-data-view/dist/dynamic/DataView';
|
|
3
|
+
|
|
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
|
+
|
|
11
|
+
export const BasicExample: React.FunctionComponent = () => (
|
|
12
|
+
<DataView>
|
|
13
|
+
<div style={layoutItemStyling}>Header</div>
|
|
14
|
+
<div style={layoutItemStyling}>Data representation</div>
|
|
15
|
+
<div style={layoutItemStyling}>Footer</div>
|
|
16
|
+
</DataView>
|
|
17
|
+
)
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import { Pagination } from '@patternfly/react-core';
|
|
3
|
+
import { Table, Tbody, Th, Thead, Tr, Td } from '@patternfly/react-table';
|
|
4
|
+
import { useDataViewPagination } from '@patternfly/react-data-view/dist/dynamic/Hooks';
|
|
5
|
+
import DataView from '@patternfly/react-data-view/dist/dynamic/DataView';
|
|
6
|
+
import DataViewToolbar from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
|
|
7
|
+
|
|
8
|
+
const perPageOptions = [
|
|
9
|
+
{ title: '5', value: 5 },
|
|
10
|
+
{ title: '10', value: 10 }
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
interface Repository {
|
|
14
|
+
name: string;
|
|
15
|
+
branches: string | null;
|
|
16
|
+
prs: string | null;
|
|
17
|
+
workspaces: string;
|
|
18
|
+
lastCommit: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const repositories: Repository[] = [
|
|
22
|
+
{ name: 'one', branches: 'two', prs: 'three', workspaces: 'four', lastCommit: 'five' },
|
|
23
|
+
{ name: 'one - 2', branches: null, prs: null, workspaces: 'four - 2', lastCommit: 'five - 2' },
|
|
24
|
+
{ name: 'one - 3', branches: 'two - 3', prs: 'three - 3', workspaces: 'four - 3', lastCommit: 'five - 3' },
|
|
25
|
+
{ name: 'one - 4', branches: 'two - 4', prs: 'null', workspaces: 'four - 4', lastCommit: 'five - 4' },
|
|
26
|
+
{ name: 'one - 5', branches: 'two - 5', prs: 'three - 5', workspaces: 'four - 5', lastCommit: 'five - 5' },
|
|
27
|
+
{ name: 'one - 6', branches: 'two - 6', prs: 'three - 6', workspaces: 'four - 6', lastCommit: 'five - 6' }
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
const cols = {
|
|
31
|
+
name: 'Repositories',
|
|
32
|
+
branches: 'Branches',
|
|
33
|
+
prs: 'Pull requests',
|
|
34
|
+
workspaces: 'Workspaces',
|
|
35
|
+
lastCommit: 'Last commit'
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const ouiaId = 'LayoutExample';
|
|
39
|
+
|
|
40
|
+
export const BasicExample: React.FunctionComponent = () => {
|
|
41
|
+
const pagination = useDataViewPagination({ perPage: 5 });
|
|
42
|
+
const { page, perPage } = pagination;
|
|
43
|
+
|
|
44
|
+
const data = useMemo(() => repositories.slice((page - 1) * perPage, ((page - 1) * perPage) + perPage), [ page, perPage ]);
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<DataView>
|
|
48
|
+
<DataViewToolbar pagination={<Pagination ouiaId={`${ouiaId}Header-pagination`} perPageOptions={perPageOptions} itemCount={repositories.length} {...pagination} />} />
|
|
49
|
+
<Table aria-label="Repositories table" ouiaId={ouiaId}>
|
|
50
|
+
<Thead data-ouia-component-id={`${ouiaId}-thead`}>
|
|
51
|
+
<Tr ouiaId={`${ouiaId}-tr-head`}>
|
|
52
|
+
{Object.values(cols).map((column, index) => <Th key={index} data-ouia-component-id={`${ouiaId}-th-${index}`}>{column}</Th>)}
|
|
53
|
+
</Tr>
|
|
54
|
+
</Thead>
|
|
55
|
+
<Tbody>
|
|
56
|
+
{data.map((repo, rowIndex) => (
|
|
57
|
+
<Tr key={repo.name} ouiaId={`${ouiaId}-tr-${rowIndex}`}>
|
|
58
|
+
{Object.keys(cols).map((column, colIndex) => <Td key={colIndex} data-ouia-component-id={`${ouiaId}-td-${rowIndex}-${colIndex}`}>{repo[column]}</Td>)}
|
|
59
|
+
</Tr>
|
|
60
|
+
))}
|
|
61
|
+
</Tbody>
|
|
62
|
+
</Table>
|
|
63
|
+
<DataViewToolbar pagination={<Pagination isCompact ouiaId={`${ouiaId}Footer-pagination`} perPageOptions={perPageOptions} itemCount={repositories.length} {...pagination} />} />
|
|
64
|
+
</DataView>
|
|
65
|
+
)}
|
package/patternfly-docs/content/extensions/data-view/examples/DataViewToolbar/DataViewToolbar.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
---
|
|
2
|
+
# Sidenav top-level section
|
|
3
|
+
# should be the same for all markdown files
|
|
4
|
+
section: extensions
|
|
5
|
+
subsection: Data view
|
|
6
|
+
# Sidenav secondary level section
|
|
7
|
+
# should be the same for all markdown files
|
|
8
|
+
id: Data view toolbar
|
|
9
|
+
# Tab (react | react-demos | html | html-demos | design-guidelines | accessibility)
|
|
10
|
+
source: react
|
|
11
|
+
# If you use typescript, the name of the interface to display props for
|
|
12
|
+
# These are found through the sourceProps function provided in patternfly-docs.source.js
|
|
13
|
+
propComponents: ['DataViewToolbar']
|
|
14
|
+
sourceLink: https://github.com/patternfly/react-data-view/blob/main/packages/module/patternfly-docs/content/extensions/data-view/examples/DataViewToolbar/DataViewToolbar.md
|
|
15
|
+
---
|
|
16
|
+
import DataViewToolbar from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
|
|
17
|
+
|
|
18
|
+
The **data view toolbar** component renders a default opinionated data view toolbar.
|
|
19
|
+
|
|
20
|
+
### Basic example
|
|
21
|
+
|
|
22
|
+
Data view toolbar can display a pagination using the `pagination` property accepting a React node. You can also pass a custom `ouiaId` for testing purposes.
|
|
23
|
+
|
|
24
|
+
```js file="./DataViewToolbarExample.tsx"
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Pagination } from '@patternfly/react-core';
|
|
3
|
+
import DataViewToolbar from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
|
|
4
|
+
|
|
5
|
+
export const BasicExample: React.FunctionComponent = () => (
|
|
6
|
+
<DataViewToolbar pagination={<Pagination page={1} perPage={10} />} />
|
|
7
|
+
)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
---
|
|
2
|
+
# Sidenav top-level section
|
|
3
|
+
# should be the same for all markdown files
|
|
4
|
+
section: extensions
|
|
5
|
+
subsection: Data view
|
|
6
|
+
# Sidenav secondary level section
|
|
7
|
+
# should be the same for all markdown files
|
|
8
|
+
id: Hooks
|
|
9
|
+
# Tab (react | react-demos | html | html-demos | design-guidelines | accessibility)
|
|
10
|
+
source: react
|
|
11
|
+
# If you use typescript, the name of the interface to display props for
|
|
12
|
+
# These are found through the sourceProps function provided in patternfly-docs.source.js
|
|
13
|
+
propComponents: []
|
|
14
|
+
sourceLink: https://github.com/patternfly/react-data-view/blob/main/packages/module/patternfly-docs/content/extensions/data-view/examples/Hooks/Hooks.md
|
|
15
|
+
---
|
|
16
|
+
Data view hooks provide a predefined solution to manage state of the data view. This modular approach allows them to be easily replaced with a custom implementation in case of more specific needs.
|
|
17
|
+
|
|
18
|
+
### useDataViewPagination()
|
|
19
|
+
|
|
20
|
+
The `useDataViewPagination` hook manages the pagination state of the data view. It retrieves the current `page` and `perPage` values together with functions to set them (`onSetPage`, `onPerPageSelect`). You can easily spread the retrieved values to the PatternFly [pagination](/components/pagination) component and make it live.
|
|
@@ -10,7 +10,7 @@ const centerStyle = {
|
|
|
10
10
|
|
|
11
11
|
const IndexPage = () => {
|
|
12
12
|
return (
|
|
13
|
-
<PageSection
|
|
13
|
+
<PageSection style={centerStyle}>
|
|
14
14
|
<div style={{ flex: 'none', textAlign: 'center' }}>
|
|
15
15
|
<Title size="4xl" headingLevel="h1">
|
|
16
16
|
My extension docs
|
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { Stack, StackItem } from '@patternfly/react-core';
|
|
4
3
|
export interface DataViewProps {
|
|
5
|
-
/**
|
|
6
|
-
|
|
4
|
+
/** Content rendered inside the data view */
|
|
5
|
+
children: React.ReactNode;
|
|
6
|
+
/** Custom OUIA ID */
|
|
7
|
+
ouiaId?: string;
|
|
7
8
|
}
|
|
8
9
|
|
|
9
|
-
export const DataView: React.
|
|
10
|
-
|
|
10
|
+
export const DataView: React.FC<DataViewProps> = ({
|
|
11
|
+
children, ouiaId = 'DataView', ...props
|
|
11
12
|
}: DataViewProps) => (
|
|
12
|
-
<
|
|
13
|
-
)
|
|
13
|
+
<Stack data-ouia-component-id={`${ouiaId}-stack}`} {...props}>
|
|
14
|
+
{React.Children.map(children, (child, index) => (
|
|
15
|
+
<StackItem data-ouia-component-id={`${ouiaId}-stack-item-${index}`}>
|
|
16
|
+
{child}
|
|
17
|
+
</StackItem>
|
|
18
|
+
))}
|
|
19
|
+
</Stack>
|
|
20
|
+
)
|
|
14
21
|
|
|
15
22
|
export default DataView;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Toolbar, ToolbarContent, ToolbarItem, ToolbarItemVariant } from '@patternfly/react-core';
|
|
3
|
+
|
|
4
|
+
export interface DataViewToolbarProps {
|
|
5
|
+
/** Toolbar className */
|
|
6
|
+
className?: string;
|
|
7
|
+
/** Custom OUIA ID */
|
|
8
|
+
ouiaId?: string;
|
|
9
|
+
/** React component to display pagination */
|
|
10
|
+
pagination?: React.ReactNode;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const DataViewToolbar: React.FC<React.PropsWithChildren<DataViewToolbarProps>> = ({ className, ouiaId = 'DataViewToolbar', pagination, children, ...props }: React.PropsWithChildren<DataViewToolbarProps>) => (
|
|
14
|
+
<Toolbar ouiaId={ouiaId} className={className} {...props}>
|
|
15
|
+
<ToolbarContent>
|
|
16
|
+
{pagination && (
|
|
17
|
+
<ToolbarItem variant={ToolbarItemVariant.pagination}>
|
|
18
|
+
{ /* TO DO: Make the pagination work later */ }
|
|
19
|
+
{pagination}
|
|
20
|
+
</ToolbarItem>
|
|
21
|
+
)}
|
|
22
|
+
{children}
|
|
23
|
+
</ToolbarContent>
|
|
24
|
+
</Toolbar>
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
export default DataViewToolbar;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './pagination';
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
2
|
+
import { renderHook, act } from '@testing-library/react';
|
|
3
|
+
import { useDataViewPagination } from './pagination';
|
|
4
|
+
|
|
5
|
+
describe('useDataViewPagination', () => {
|
|
6
|
+
|
|
7
|
+
it('should get initial state correctly - no page', () => {
|
|
8
|
+
const { result } = renderHook(() => 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
|
+
|
|
17
|
+
it('should get initial state correctly - page set', () => {
|
|
18
|
+
const { result } = renderHook(() => useDataViewPagination({ page: 3, perPage: 5 }))
|
|
19
|
+
expect(result.current).toEqual({
|
|
20
|
+
onPerPageSelect: expect.any(Function),
|
|
21
|
+
onSetPage: expect.any(Function),
|
|
22
|
+
page: 3,
|
|
23
|
+
perPage: 5
|
|
24
|
+
})
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('should set page correctly', () => {
|
|
28
|
+
const { result } = renderHook(() => useDataViewPagination({ page: 3, perPage: 5 }))
|
|
29
|
+
|
|
30
|
+
act(() => {
|
|
31
|
+
result.current.onSetPage(undefined, 8);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
expect(result.current).toEqual({
|
|
35
|
+
onPerPageSelect: expect.any(Function),
|
|
36
|
+
onSetPage: expect.any(Function),
|
|
37
|
+
page: 8,
|
|
38
|
+
perPage: 5
|
|
39
|
+
})
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should set perPage correctly', () => {
|
|
43
|
+
const { result } = renderHook(() => useDataViewPagination({ page: 3, perPage: 5 }))
|
|
44
|
+
|
|
45
|
+
act(() => {
|
|
46
|
+
result.current.onPerPageSelect(undefined, 50);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
expect(result.current).toEqual({
|
|
50
|
+
onPerPageSelect: expect.any(Function),
|
|
51
|
+
onSetPage: expect.any(Function),
|
|
52
|
+
page: 3,
|
|
53
|
+
perPage: 50
|
|
54
|
+
})
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
|
|
3
|
+
export interface UseDataViewPaginationProps {
|
|
4
|
+
page?: number;
|
|
5
|
+
perPage: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface DataViewPaginationProps extends UseDataViewPaginationProps {
|
|
9
|
+
page: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const useDataViewPagination = ({ page = 1, perPage }: UseDataViewPaginationProps) => {
|
|
13
|
+
const [ state, setState ] = useState({ page, perPage });
|
|
14
|
+
|
|
15
|
+
const onPerPageSelect = (_event: React.MouseEvent | React.KeyboardEvent | MouseEvent | undefined, newPerPage: number) => {
|
|
16
|
+
setState(prev => ({ ...prev, perPage: newPerPage }));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const onSetPage = (_event: React.MouseEvent | React.KeyboardEvent | MouseEvent | undefined, newPage: number) => {
|
|
20
|
+
setState(prev => ({ ...prev, page: newPage }));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
...state,
|
|
25
|
+
onPerPageSelect,
|
|
26
|
+
onSetPage
|
|
27
|
+
}
|
|
28
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
// this file is autogenerated by generate-index.js, modifying it manually will have no effect
|
|
2
|
+
export * from './Hooks';
|
|
3
|
+
|
|
4
|
+
export { default as DataViewToolbar } from './DataViewToolbar';
|
|
5
|
+
export * from './DataViewToolbar';
|
|
2
6
|
|
|
3
7
|
export { default as DataView } from './DataView';
|
|
4
8
|
export * from './DataView';
|
|
@@ -1,15 +0,0 @@
|
|
|
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
|
-
require("@testing-library/jest-dom");
|
|
9
|
-
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
|
-
expect(react_2.screen.getByText('This is Data view')).toBeInTheDocument();
|
|
14
|
-
});
|
|
15
|
-
});
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { render, screen } from '@testing-library/react';
|
|
3
|
-
import '@testing-library/jest-dom';
|
|
4
|
-
import DataView from './DataView';
|
|
5
|
-
describe('DataView', () => {
|
|
6
|
-
it('should render data view', () => {
|
|
7
|
-
render(React.createElement(DataView, null));
|
|
8
|
-
expect(screen.getByText('This is Data view')).toBeInTheDocument();
|
|
9
|
-
});
|
|
10
|
-
});
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { AutoLinkHeader, Example, Link as PatternflyThemeLink } from '@patternfly/documentation-framework/components';
|
|
3
|
-
|
|
4
|
-
const pageData = {
|
|
5
|
-
"id": "About data view",
|
|
6
|
-
"section": "extensions",
|
|
7
|
-
"subsection": "Data view",
|
|
8
|
-
"deprecated": false,
|
|
9
|
-
"beta": false,
|
|
10
|
-
"demo": false,
|
|
11
|
-
"newImplementationLink": false,
|
|
12
|
-
"source": "extensions",
|
|
13
|
-
"tabName": null,
|
|
14
|
-
"slug": "/extensions/data-view/about-data-view/extensions",
|
|
15
|
-
"sourceLink": "https://github.com/patternfly/patternfly-org/blob/main/packages/module/patternfly-docs/content/extensions/data-view/about-data-view.md",
|
|
16
|
-
"relPath": "packages/module/patternfly-docs/content/extensions/data-view/about-data-view.md",
|
|
17
|
-
"sortValue": 1
|
|
18
|
-
};
|
|
19
|
-
pageData.relativeImports = {
|
|
20
|
-
|
|
21
|
-
};
|
|
22
|
-
pageData.examples = {
|
|
23
|
-
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const Component = () => (
|
|
27
|
-
<React.Fragment>
|
|
28
|
-
<p {...{"className":"ws-p"}}>
|
|
29
|
-
{`Data view lives in its own package `}
|
|
30
|
-
<PatternflyThemeLink {...{"to":"https://www.npmjs.com/package/@patternfly/react-data-view"}}>
|
|
31
|
-
<code {...{"className":"ws-code"}}>
|
|
32
|
-
{`@patternfly/react-data-view`}
|
|
33
|
-
</code>
|
|
34
|
-
</PatternflyThemeLink>
|
|
35
|
-
</p>
|
|
36
|
-
<AutoLinkHeader {...{"id":"data-view","size":"h1","className":"ws-title ws-h1"}}>
|
|
37
|
-
{`Data view`}
|
|
38
|
-
</AutoLinkHeader>
|
|
39
|
-
<p {...{"className":"ws-p"}}>
|
|
40
|
-
{`The data view extension contains implementation of the data view component allowing to display record data in a configured layout.`}
|
|
41
|
-
</p>
|
|
42
|
-
<p {...{"className":"ws-p"}}>
|
|
43
|
-
{`If you notice a bug or have a suggestion for the data view, feel free to file an issue in our `}
|
|
44
|
-
<PatternflyThemeLink {...{"to":"https://github.com/patternfly/react-data-view/issues"}}>
|
|
45
|
-
{`GitHub repository`}
|
|
46
|
-
</PatternflyThemeLink>
|
|
47
|
-
{`! Please make sure to check if there is already a pre-existing issue before creating a new issue.`}
|
|
48
|
-
</p>
|
|
49
|
-
</React.Fragment>
|
|
50
|
-
);
|
|
51
|
-
Component.displayName = 'ExtensionsDataViewAboutDataViewExtensionsDocs';
|
|
52
|
-
Component.pageData = pageData;
|
|
53
|
-
|
|
54
|
-
export default Component;
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { AutoLinkHeader, Example, Link as PatternflyThemeLink } from '@patternfly/documentation-framework/components';
|
|
3
|
-
import DataView from '@patternfly/react-data-view/dist/dynamic/DataView';
|
|
4
|
-
const pageData = {
|
|
5
|
-
"id": "Data view",
|
|
6
|
-
"section": "extensions",
|
|
7
|
-
"subsection": "Data view",
|
|
8
|
-
"deprecated": false,
|
|
9
|
-
"beta": false,
|
|
10
|
-
"demo": false,
|
|
11
|
-
"newImplementationLink": false,
|
|
12
|
-
"source": "react",
|
|
13
|
-
"tabName": null,
|
|
14
|
-
"slug": "/extensions/data-view/data-view/react",
|
|
15
|
-
"sourceLink": "https://github.com/patternfly/react-data-view/blob/main/packages/module/patternfly-docs/content/extensions/data-view/examples/DataView/DataView.md",
|
|
16
|
-
"relPath": "packages/module/patternfly-docs/content/extensions/data-view/examples/DataView/DataView.md",
|
|
17
|
-
"propComponents": [
|
|
18
|
-
{
|
|
19
|
-
"name": "DataView",
|
|
20
|
-
"description": "",
|
|
21
|
-
"props": [
|
|
22
|
-
{
|
|
23
|
-
"name": "text",
|
|
24
|
-
"type": "string",
|
|
25
|
-
"description": "Example prop",
|
|
26
|
-
"defaultValue": "'This is Data view'"
|
|
27
|
-
}
|
|
28
|
-
]
|
|
29
|
-
}
|
|
30
|
-
],
|
|
31
|
-
"examples": [
|
|
32
|
-
"Basic example"
|
|
33
|
-
]
|
|
34
|
-
};
|
|
35
|
-
pageData.liveContext = {
|
|
36
|
-
DataView
|
|
37
|
-
};
|
|
38
|
-
pageData.relativeImports = {
|
|
39
|
-
|
|
40
|
-
};
|
|
41
|
-
pageData.examples = {
|
|
42
|
-
'Basic example': props =>
|
|
43
|
-
<Example {...pageData} {...props} {...{"code":"import React from 'react';\nimport DataView from '@patternfly/react-data-view/dist/dynamic/DataView';\n\nexport const BasicExample: React.FunctionComponent = () => (\n <DataView />\n);\n","title":"Basic example","lang":"js"}}>
|
|
44
|
-
|
|
45
|
-
<p {...{"className":"ws-p"}}>
|
|
46
|
-
{`A blank example of the data view layout.`}
|
|
47
|
-
</p>
|
|
48
|
-
</Example>
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const Component = () => (
|
|
52
|
-
<React.Fragment>
|
|
53
|
-
<p {...{"className":"ws-p"}}>
|
|
54
|
-
{`The `}
|
|
55
|
-
<strong>
|
|
56
|
-
{`data view`}
|
|
57
|
-
</strong>
|
|
58
|
-
{` component renders record data in a configured layout.`}
|
|
59
|
-
</p>
|
|
60
|
-
{React.createElement(pageData.examples["Basic example"])}
|
|
61
|
-
</React.Fragment>
|
|
62
|
-
);
|
|
63
|
-
Component.displayName = 'ExtensionsDataViewDataViewReactDocs';
|
|
64
|
-
Component.pageData = pageData;
|
|
65
|
-
|
|
66
|
-
export default Component;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
'/extensions/data-view/about-data-view/extensions': {
|
|
3
|
-
id: "About data view",
|
|
4
|
-
title: "About data view",
|
|
5
|
-
toc: [],
|
|
6
|
-
section: "extensions",
|
|
7
|
-
subsection: "Data view",
|
|
8
|
-
source: "extensions",
|
|
9
|
-
tabName: null,
|
|
10
|
-
sortValue: 1,
|
|
11
|
-
Component: () => import(/* webpackChunkName: "extensions/data-view/about-data-view/extensions/index" */ './extensions/data-view/about-data-view/extensions')
|
|
12
|
-
},
|
|
13
|
-
'/extensions/data-view/data-view/react': {
|
|
14
|
-
id: "Data view",
|
|
15
|
-
title: "Data view",
|
|
16
|
-
toc: [[{"text":"Basic example"}]],
|
|
17
|
-
examples: ["Basic example"],
|
|
18
|
-
section: "extensions",
|
|
19
|
-
subsection: "Data view",
|
|
20
|
-
source: "react",
|
|
21
|
-
tabName: null,
|
|
22
|
-
Component: () => import(/* webpackChunkName: "extensions/data-view/data-view/react/index" */ './extensions/data-view/data-view/react')
|
|
23
|
-
}
|
|
24
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { render, screen } from '@testing-library/react';
|
|
3
|
-
import '@testing-library/jest-dom'
|
|
4
|
-
import DataView from './DataView';
|
|
5
|
-
|
|
6
|
-
describe('DataView', () => {
|
|
7
|
-
|
|
8
|
-
it('should render data view', () => {
|
|
9
|
-
render(<DataView />);
|
|
10
|
-
expect(screen.getByText('This is Data view')).toBeInTheDocument();
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
});
|
|
File without changes
|
|
File without changes
|