@ansible/ansible-ui-framework 0.0.258 → 0.0.260

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. package/{mjs → cjs}/BulkActionDialog.d.ts +0 -0
  2. package/{mjs → cjs}/BulkProgressDialog.d.ts +0 -0
  3. package/{mjs → cjs}/FilterDrawer.d.ts +0 -0
  4. package/{mjs → cjs}/PageAlertToaster.d.ts +0 -0
  5. package/{mjs → cjs}/PageBody.d.ts +0 -0
  6. package/{mjs → cjs}/PageCells.d.ts +0 -0
  7. package/{mjs → cjs}/PageColumnModal.d.ts +0 -0
  8. package/{mjs → cjs}/PageDataList.d.ts +0 -0
  9. package/{mjs → cjs}/PageDialog.d.ts +0 -0
  10. package/{mjs → cjs}/PageForm.d.ts +0 -0
  11. package/{mjs → cjs}/PageFramework.d.ts +0 -0
  12. package/{mjs → cjs}/PageHeader.d.ts +0 -0
  13. package/{mjs → cjs}/PageLayout.d.ts +0 -0
  14. package/{mjs → cjs}/PagePagination.d.ts +0 -0
  15. package/{mjs → cjs}/PageTable.d.ts +0 -0
  16. package/{mjs → cjs}/PageTableCard.d.ts +0 -0
  17. package/{mjs → cjs}/PageTableCards.d.ts +0 -0
  18. package/{mjs → cjs}/PageTableDetails.d.ts +0 -0
  19. package/{mjs → cjs}/PageTableList.d.ts +0 -0
  20. package/{mjs → cjs}/PageTableViewType.d.ts +0 -0
  21. package/{mjs → cjs}/PageTabs.d.ts +0 -0
  22. package/{mjs → cjs}/PageToolbar.d.ts +0 -0
  23. package/{mjs → cjs}/Settings.d.ts +0 -0
  24. package/{mjs → cjs}/TypedActions/TypedActions.d.ts +0 -0
  25. package/{mjs → cjs}/TypedActions/TypedActionsButtons.d.ts +0 -0
  26. package/{mjs → cjs}/TypedActions/index.d.ts +0 -0
  27. package/{mjs → cjs}/components/BulkSelector.d.ts +0 -0
  28. package/{mjs → cjs}/components/Collapse.d.ts +0 -0
  29. package/{mjs → cjs}/components/DetailInfo.d.ts +0 -0
  30. package/{mjs → cjs}/components/Details.d.ts +0 -0
  31. package/{mjs → cjs}/components/Dotted.d.ts +0 -0
  32. package/{mjs → cjs}/components/DropdownControlled.d.ts +0 -0
  33. package/{mjs → cjs}/components/ErrorBoundary.d.ts +0 -0
  34. package/{mjs → cjs}/components/Grid.d.ts +0 -0
  35. package/{mjs → cjs}/components/Help.d.ts +0 -0
  36. package/{mjs → cjs}/components/IconWrapper.d.ts +0 -0
  37. package/{mjs → cjs}/components/LoadingPage.d.ts +0 -0
  38. package/{mjs → cjs}/components/Masonry.d.ts +0 -0
  39. package/{mjs → cjs}/components/Scrollable.d.ts +0 -0
  40. package/{mjs → cjs}/components/SingleSelect.d.ts +0 -0
  41. package/{mjs → cjs}/components/patternfly-colors.d.ts +0 -0
  42. package/{mjs → cjs}/components/useBreakPoint.d.ts +0 -0
  43. package/{mjs → cjs}/components/useOpen.d.ts +0 -0
  44. package/{mjs → cjs}/components/useWindowLocation.d.ts +0 -0
  45. package/{mjs → cjs}/index.d.ts +1 -0
  46. package/cjs/index.js +1 -0
  47. package/{mjs → cjs}/useFrameworkTranslations.d.ts +0 -0
  48. package/{mjs → cjs}/useInMemoryView.d.ts +0 -0
  49. package/{mjs → cjs}/useSelectDialog.d.ts +0 -0
  50. package/{mjs → cjs}/useSelectMultipleDialog.d.ts +0 -0
  51. package/{mjs → cjs}/useTableItems.d.ts +0 -0
  52. package/{mjs → cjs}/useView.d.ts +0 -0
  53. package/{mjs → cjs}/utils/compare.d.ts +0 -0
  54. package/{mjs → cjs}/utils/download-file.d.ts +0 -0
  55. package/{mjs → cjs}/utils/random-string.d.ts +0 -0
  56. package/package.json +3 -11
  57. package/mjs/BulkActionDialog.js +0 -104
  58. package/mjs/BulkProgressDialog.js +0 -131
  59. package/mjs/FilterDrawer.js +0 -24
  60. package/mjs/PageAlertToaster.js +0 -48
  61. package/mjs/PageBody.js +0 -29
  62. package/mjs/PageCells.js +0 -102
  63. package/mjs/PageColumnModal.js +0 -64
  64. package/mjs/PageDataList.js +0 -44
  65. package/mjs/PageDialog.js +0 -12
  66. package/mjs/PageForm.js +0 -316
  67. package/mjs/PageFramework.js +0 -8
  68. package/mjs/PageHeader.js +0 -86
  69. package/mjs/PageLayout.js +0 -23
  70. package/mjs/PagePagination.js +0 -22
  71. package/mjs/PageTable.js +0 -191
  72. package/mjs/PageTableCard.js +0 -69
  73. package/mjs/PageTableCards.js +0 -23
  74. package/mjs/PageTableDetails.js +0 -11
  75. package/mjs/PageTableList.js +0 -62
  76. package/mjs/PageTableViewType.js +0 -6
  77. package/mjs/PageTabs.js +0 -45
  78. package/mjs/PageToolbar.js +0 -172
  79. package/mjs/Settings.js +0 -87
  80. package/mjs/TypedActions/TypedActions.js +0 -190
  81. package/mjs/TypedActions/TypedActionsButtons.js +0 -87
  82. package/mjs/TypedActions/index.js +0 -2
  83. package/mjs/components/BulkSelector.js +0 -56
  84. package/mjs/components/Collapse.js +0 -7
  85. package/mjs/components/DetailInfo.js +0 -8
  86. package/mjs/components/Details.js +0 -68
  87. package/mjs/components/Dotted.js +0 -4
  88. package/mjs/components/DropdownControlled.js +0 -8
  89. package/mjs/components/ErrorBoundary.js +0 -25
  90. package/mjs/components/Grid.js +0 -27
  91. package/mjs/components/Help.js +0 -9
  92. package/mjs/components/IconWrapper.js +0 -40
  93. package/mjs/components/LoadingPage.js +0 -9
  94. package/mjs/components/Masonry.js +0 -69
  95. package/mjs/components/Scrollable.js +0 -60
  96. package/mjs/components/SingleSelect.js +0 -37
  97. package/mjs/components/patternfly-colors.js +0 -38
  98. package/mjs/components/useBreakPoint.js +0 -118
  99. package/mjs/components/useOpen.js +0 -16
  100. package/mjs/components/useWindowLocation.js +0 -48
  101. package/mjs/index.js +0 -23
  102. package/mjs/useFrameworkTranslations.js +0 -22
  103. package/mjs/useInMemoryView.js +0 -60
  104. package/mjs/useSelectDialog.js +0 -49
  105. package/mjs/useSelectMultipleDialog.js +0 -29
  106. package/mjs/useTableItems.js +0 -378
  107. package/mjs/useView.js +0 -108
  108. package/mjs/utils/compare.js +0 -53
  109. package/mjs/utils/download-file.js +0 -18
  110. package/mjs/utils/random-string.js +0 -12
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -18,6 +18,7 @@ export * from './PageTableCards';
18
18
  export * from './PageTabs';
19
19
  export * from './PageToolbar';
20
20
  export * from './TypedActions';
21
+ export * from './useInMemoryView';
21
22
  export * from './useSelectDialog';
22
23
  export * from './useTableItems';
23
24
  export * from './utils/compare';
package/cjs/index.js CHANGED
@@ -34,6 +34,7 @@ __exportStar(require("./PageTableCards"), exports);
34
34
  __exportStar(require("./PageTabs"), exports);
35
35
  __exportStar(require("./PageToolbar"), exports);
36
36
  __exportStar(require("./TypedActions"), exports);
37
+ __exportStar(require("./useInMemoryView"), exports);
37
38
  __exportStar(require("./useSelectDialog"), exports);
38
39
  __exportStar(require("./useTableItems"), exports);
39
40
  __exportStar(require("./utils/compare"), exports);
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ansible/ansible-ui-framework",
3
3
  "description": "Framework for building consistent responsive web applications using PatternFly.",
4
- "version": "0.0.258",
4
+ "version": "0.0.260",
5
5
  "author": "Red Hat",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -9,16 +9,8 @@
9
9
  "url": "https://github.com/ansible/ansible-ui.git"
10
10
  },
11
11
  "homepage": "https://github.com/ansible/ansible-ui/tree/main/framework#readme",
12
- "type": "module",
13
- "exports": {
14
- ".": {
15
- "types": "./mjs/index.d.ts",
16
- "import": "./mjs/index.js",
17
- "require": "./cjs/index.cjs"
18
- }
19
- },
20
- "main": "mjs/index.js",
21
- "types": "mjs/index.d.ts",
12
+ "main": "cjs/index.js",
13
+ "types": "cjs/index.d.ts",
22
14
  "peerDependencies": {
23
15
  "@hookform/resolvers": "^2.0.0",
24
16
  "@patternfly/patternfly": "^4.0.0",
@@ -1,104 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Button, Checkbox, Modal, ModalBoxBody, ModalVariant, Progress, ProgressMeasureLocation, ProgressSize, ProgressVariant, } from '@patternfly/react-core';
3
- import { CheckCircleIcon, ExclamationCircleIcon, PendingIcon } from '@patternfly/react-icons';
4
- import pLimit from 'p-limit';
5
- import { useCallback, useState } from 'react';
6
- import { Collapse } from './components/Collapse';
7
- import { usePageDialog } from './PageDialog';
8
- import { PageTable } from './PageTable';
9
- import { useFrameworkTranslations } from './useFrameworkTranslations';
10
- import { usePaged } from './useTableItems';
11
- export function BulkActionDialog(props) {
12
- const [_, setDialog] = usePageDialog();
13
- const [translations] = useFrameworkTranslations();
14
- const [isSubmitting, setSubmitting] = useState(false);
15
- const [isSubmited, setSubmited] = useState(false);
16
- const [progress, setProgress] = useState(0);
17
- const [error, setError] = useState('');
18
- const [statuses, setStatuses] = useState();
19
- const onClose = useCallback(() => {
20
- props.onClose?.(props.items.filter((item) => statuses?.[props.keyFn(item)] === null));
21
- setDialog(undefined);
22
- }, [props, setDialog, statuses]);
23
- const onConfirm = () => {
24
- async function handleConfirm() {
25
- const limit = pLimit(5);
26
- setSubmitting(true);
27
- let progress = 0;
28
- await Promise.all(props.items.map((item) => limit(async () => {
29
- const key = props.keyFn(item);
30
- try {
31
- await props.action(item);
32
- setStatuses((statuses) => ({ ...(statuses ?? {}), [key]: null }));
33
- }
34
- catch (err) {
35
- if (err instanceof Error) {
36
- const message = err.message;
37
- setStatuses((statuses) => ({ ...(statuses ?? {}), [key]: message }));
38
- }
39
- else {
40
- setStatuses((statuses) => ({
41
- ...(statuses ?? {}),
42
- [key]: `Unknown error`,
43
- }));
44
- }
45
- setError(props.error);
46
- }
47
- finally {
48
- setProgress(++progress);
49
- }
50
- })));
51
- setSubmitting(false);
52
- setSubmited(true);
53
- }
54
- void handleConfirm();
55
- };
56
- const { paged, page, perPage, setPage, setPerPage } = usePaged(props.items);
57
- const [confirmed, setConfirmed] = useState(!props.confirmText);
58
- return (_jsx(Modal, { titleIconVariant: props.isDanger ? 'warning' : undefined, title: props.title, variant: ModalVariant.medium, isOpen: true, onClose: onClose, actions: !isSubmited
59
- ? [
60
- _jsx(Button, { variant: props.isDanger ? 'danger' : 'primary', onClick: onConfirm, isDisabled: !confirmed || isSubmitting || isSubmited, isLoading: isSubmitting, children: isSubmitting
61
- ? props.submitting ?? translations.submittingText
62
- : props.submitText ?? translations.submitText }, "submit"),
63
- _jsx(Button, { variant: "link", onClick: onClose, children: props.cancelText ?? translations.cancelText }, "cancel"),
64
- ]
65
- : [
66
- _jsx(Button, { variant: "secondary", onClick: onClose, children: props.closeText ?? translations.closeText }, "close"),
67
- ], description: _jsx(Collapse, { open: !isSubmitting && !isSubmited, children: props.prompt }), hasNoBodyWrapper: true, children: _jsxs(ModalBoxBody, { style: { paddingLeft: 0, paddingRight: 0 }, children: [_jsx(Collapse, { open: isSubmitting || isSubmited, children: _jsx(ModalBoxBody, { style: { paddingTop: 0 }, children: _jsx(Progress, { value: (progress / props.items.length) * 100, title: error
68
- ? props.error
69
- : progress === props.items.length
70
- ? props.successText ?? translations.successText
71
- : props.submittingTitle, size: ProgressSize.lg, variant: error
72
- ? ProgressVariant.danger
73
- : progress === props.items.length
74
- ? ProgressVariant.success
75
- : undefined, measureLocation: error && progress === props.items.length ? ProgressMeasureLocation.none : undefined }) }) }), _jsx("div", { style: {
76
- display: 'flex',
77
- flexDirection: 'column',
78
- maxHeight: 500,
79
- overflow: 'hidden',
80
- borderTop: 'thin solid var(--pf-global--BorderColor--100)',
81
- }, children: !isSubmitting && !isSubmited ? (_jsx(PageTable, { pageItems: paged, itemCount: props.items.length, tableColumns: props.columns, keyFn: props.keyFn, page: page, perPage: perPage, setPage: setPage, setPerPage: setPerPage, compact: true, errorStateTitle: "Error", emptyStateTitle: "No items", disableBodyPadding: true }, "items")) : (_jsx(PageTable, { pageItems: [...paged], itemCount: props.items.length, tableColumns: [
82
- ...props.errorColumns,
83
- {
84
- header: 'Status',
85
- cell: (item) => {
86
- const key = props.keyFn(item);
87
- const status = statuses?.[key];
88
- if (status === undefined) {
89
- return (_jsxs("span", { style: {
90
- color: 'var(--pf-global--info-color--100)',
91
- }, children: [_jsx(PendingIcon, {}), "\u00A0 ", props.pendingText ?? translations.pendingText, ' ', JSON.stringify(status)] }));
92
- }
93
- if (status === null) {
94
- return (_jsxs("span", { style: {
95
- color: 'var(--pf-global--success-color--100)',
96
- }, children: [_jsx(CheckCircleIcon, {}), "\u00A0", ' ', props.successText ?? translations.successText] }));
97
- }
98
- return (_jsxs("span", { style: {
99
- color: 'var(--pf-global--danger-color--100)',
100
- }, children: [_jsx(ExclamationCircleIcon, {}), "\u00A0 ", statuses?.[key]] }));
101
- },
102
- },
103
- ], keyFn: props.keyFn, page: page, perPage: perPage, setPage: setPage, setPerPage: setPerPage, compact: true, errorStateTitle: "", emptyStateTitle: "No items", disableBodyPadding: true }, "status")) }), props.confirmText && (_jsx(Collapse, { open: !isSubmitting && !isSubmited, children: _jsx("div", { style: { marginLeft: 32, marginTop: 0, marginBottom: 8 }, children: _jsx(Checkbox, { id: "confirm", label: props.confirmText, isChecked: confirmed, onChange: setConfirmed }) }) }))] }) }));
104
- }
@@ -1,131 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Button, Modal, ModalBoxBody, ModalVariant, Progress, ProgressSize, ProgressVariant, } from '@patternfly/react-core';
3
- import { CheckCircleIcon, ExclamationCircleIcon, PendingIcon } from '@patternfly/react-icons';
4
- import pLimit from 'p-limit';
5
- import { useCallback, useEffect, useState } from 'react';
6
- import { usePageDialog } from './PageDialog';
7
- import { PageTable } from './PageTable';
8
- import { useFrameworkTranslations } from './useFrameworkTranslations';
9
- import { usePaged } from './useTableItems';
10
- export function BulkProgressDialog(props) {
11
- const { title, keyFn, items, columns, actionFn, onClose, processingText, errorText, itemPendingText, itemSuccessText, successText, cancelText, closeText, isDanger, } = props;
12
- const [translations] = useFrameworkTranslations();
13
- const [isProcessing, setProcessing] = useState(true);
14
- const [progress, setProgress] = useState(0);
15
- const [error, setError] = useState('');
16
- const [statuses, setStatuses] = useState();
17
- const [abortController] = useState(() => new AbortController());
18
- const onCancelClicked = useCallback(() => {
19
- abortController.abort();
20
- setProcessing(false);
21
- }, [abortController]);
22
- const onCloseClicked = useCallback(() => {
23
- onClose?.(items.filter((item) => statuses?.[keyFn(item)] === null));
24
- }, [items, keyFn, onClose, statuses]);
25
- useEffect(() => {
26
- async function process() {
27
- const limit = pLimit(5);
28
- let progress = 0;
29
- await Promise.all(items.map((item) => limit(async () => {
30
- if (abortController.signal.aborted)
31
- return;
32
- const key = keyFn(item);
33
- try {
34
- await actionFn(item, abortController.signal);
35
- if (!abortController.signal.aborted) {
36
- setStatuses((statuses) => ({ ...(statuses ?? {}), [key]: null }));
37
- }
38
- }
39
- catch (err) {
40
- if (!abortController.signal.aborted) {
41
- if (err instanceof Error) {
42
- const message = err.message;
43
- setStatuses((statuses) => ({
44
- ...(statuses ?? {}),
45
- [key]: message,
46
- }));
47
- }
48
- else {
49
- setStatuses((statuses) => ({
50
- ...(statuses ?? {}),
51
- [key]: `Unknown error`,
52
- }));
53
- }
54
- setError(errorText ?? translations.errorText);
55
- }
56
- }
57
- finally {
58
- if (!abortController.signal.aborted) {
59
- setProgress(++progress);
60
- }
61
- }
62
- })));
63
- if (!abortController.signal.aborted) {
64
- setProcessing(false);
65
- }
66
- }
67
- void process();
68
- }, [abortController, actionFn, errorText, items, keyFn, translations.errorText]);
69
- const { paged, page, perPage, setPage, setPerPage } = usePaged(items);
70
- return (_jsxs(Modal, { titleIconVariant: isDanger ? 'warning' : undefined, title: title, variant: ModalVariant.medium, isOpen: true, onClose: () => {
71
- onCancelClicked();
72
- onCloseClicked();
73
- }, actions: isProcessing
74
- ? [
75
- _jsx(Button, { variant: "link", onClick: onCancelClicked, children: cancelText ?? translations.cancelText }, "cancel"),
76
- ]
77
- : [
78
- _jsx(Button, { variant: "secondary", onClick: onCloseClicked, children: closeText ?? translations.closeText }, "close"),
79
- ], hasNoBodyWrapper: true, children: [_jsx(ModalBoxBody, { children: _jsx(Progress, { value: (progress / items.length) * 100, title: abortController.signal.aborted
80
- ? 'Cancelled'
81
- : error
82
- ? errorText ?? translations.errorText
83
- : progress === items.length
84
- ? successText ?? translations.successText
85
- : processingText ?? translations.processingText, size: ProgressSize.lg, variant: error
86
- ? ProgressVariant.danger
87
- : progress === items.length
88
- ? ProgressVariant.success
89
- : undefined }) }), _jsx("div", { style: {
90
- display: 'flex',
91
- flexDirection: 'column',
92
- maxHeight: 560,
93
- overflow: 'hidden',
94
- paddingTop: 16,
95
- }, children: _jsx(PageTable, { pageItems: [...paged], itemCount: items.length, tableColumns: [
96
- ...columns,
97
- {
98
- header: 'Status',
99
- cell: (item) => {
100
- const key = keyFn(item);
101
- const status = statuses?.[key];
102
- if (status === undefined) {
103
- return (_jsxs("span", { style: { color: 'var(--pf-global--info-color--100)' }, children: [_jsx(PendingIcon, {}), "\u00A0 ", itemPendingText ?? translations.pendingText, ' ', JSON.stringify(status)] }));
104
- }
105
- if (status === null) {
106
- return (_jsxs("span", { style: {
107
- color: 'var(--pf-global--success-color--100)',
108
- }, children: [_jsx(CheckCircleIcon, {}), "\u00A0 ", itemSuccessText ?? translations.successText] }));
109
- }
110
- return (_jsxs("span", { style: { color: 'var(--pf-global--danger-color--100)' }, children: [_jsx(ExclamationCircleIcon, {}), "\u00A0 ", statuses?.[key]] }));
111
- },
112
- },
113
- ], keyFn: keyFn, page: page, perPage: perPage, setPage: setPage, setPerPage: setPerPage, compact: true, errorStateTitle: "", emptyStateTitle: "No items" }, "status") })] }));
114
- }
115
- export function useBulkProgressDialog() {
116
- const [_, setDialog] = usePageDialog();
117
- const [props, setProps] = useState();
118
- useEffect(() => {
119
- if (props) {
120
- const onCloseHandler = (items) => {
121
- setProps(undefined);
122
- props.onClose?.(items);
123
- };
124
- setDialog(_jsx(BulkProgressDialog, { ...props, onClose: onCloseHandler }));
125
- }
126
- else {
127
- setDialog(undefined);
128
- }
129
- }, [props, setDialog]);
130
- return setProps;
131
- }
@@ -1,24 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- /* eslint-disable @typescript-eslint/no-non-null-assertion */
3
- /* eslint-disable @typescript-eslint/no-empty-function */
4
- import { Checkbox, DrawerPanelBody, DrawerPanelContent, DrawerSection, Stack, Title, } from '@patternfly/react-core';
5
- import { Fragment, useCallback } from 'react';
6
- export function FilterDrawer(props) {
7
- let { t } = props;
8
- t = t ? t : (t) => t;
9
- const { filters, filterState, setFilterValues } = props;
10
- const toggleFilterValue = useCallback((filter, filterValues, option) => {
11
- if (filterValues?.includes(option)) {
12
- setFilterValues(filter, filterValues.filter((o) => o !== option));
13
- }
14
- else {
15
- setFilterValues(filter, [...(filterValues ?? []), option]);
16
- }
17
- }, [setFilterValues]);
18
- if (!filters)
19
- return _jsx(Fragment, {});
20
- return (_jsx(DrawerPanelContent, { minSize: "250px", defaultSize: "250px", maxSize: "250px", children: _jsxs(DrawerPanelBody, { children: [_jsx(Title, { headingLevel: "h2", style: { paddingBottom: 24 }, children: t('Filters') }), filters?.map((filter) => {
21
- const filterValues = filterState[filter.label];
22
- return (_jsx(DrawerSection, { style: { paddingBottom: 32 }, children: _jsxs(Stack, { hasGutter: true, children: [_jsx(Title, { headingLevel: "h4", children: filter.label }), filter.options.map((option) => (_jsx(Checkbox, { id: option.label, isChecked: filterValues?.includes(option.value), onChange: () => toggleFilterValue(filter, filterValues, option.value), label: option.label }, option.label)))] }) }, filter.label));
23
- })] }) }));
24
- }
@@ -1,48 +0,0 @@
1
- import { createElement as _createElement } from "react";
2
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { Alert, AlertActionCloseButton, AlertGroup } from '@patternfly/react-core';
4
- import { createContext, useContext, useState } from 'react';
5
- export const PageAlertToasterContext = createContext({
6
- addAlert: () => null,
7
- removeAlert: () => null,
8
- replaceAlert: () => null,
9
- removeAlerts: () => null,
10
- });
11
- export function usePageAlertToaster() {
12
- return useContext(PageAlertToasterContext);
13
- }
14
- export function PageAlertToasterProvider(props) {
15
- const [toasterAlerts, setToasterAlerts] = useState([]);
16
- const [pageAlertToaster] = useState(() => {
17
- function removeAlerts(filter) {
18
- setToasterAlerts((alerts) => (filter ? alerts.filter(filter) : []));
19
- }
20
- function removeAlert(alert) {
21
- setToasterAlerts((alerts) => alerts.filter((a) => a !== alert));
22
- }
23
- function addAlert(alert) {
24
- if (Number.isInteger(alert.timeout)) {
25
- setTimeout(() => removeAlert(alert), alert.timeout);
26
- delete alert.timeout;
27
- }
28
- setToasterAlerts((alerts) => [...alerts, alert]);
29
- }
30
- function replaceAlert(oldAlert, alert) {
31
- setToasterAlerts((alerts) => {
32
- const oldAlertIndex = alerts.findIndex((a) => a === oldAlert);
33
- if (oldAlertIndex !== -1) {
34
- if (Number.isInteger(alert.timeout)) {
35
- setTimeout(() => removeAlert(alert), alert.timeout);
36
- delete alert.timeout;
37
- }
38
- const newAlerts = [...alerts];
39
- newAlerts[oldAlertIndex] = alert;
40
- return newAlerts;
41
- }
42
- return alerts;
43
- });
44
- }
45
- return { addAlert, removeAlert, removeAlerts, replaceAlert };
46
- });
47
- return (_jsxs(PageAlertToasterContext.Provider, { value: pageAlertToaster, children: [_jsx(AlertGroup, { isToast: true, isLiveRegion: true, children: toasterAlerts.map((alertProps, index) => (_createElement(Alert, { ...alertProps, key: alertProps.key ?? alertProps.id ?? index, actionClose: _jsx(AlertActionCloseButton, { onClose: () => pageAlertToaster.removeAlert(alertProps) }) }))) }), props.children] }));
48
- }
package/mjs/PageBody.js DELETED
@@ -1,29 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useTranslation } from 'react-i18next';
3
- import { useBreakpoint } from '.';
4
- import ErrorBoundary from './components/ErrorBoundary';
5
- import { useSettings } from './Settings';
6
- export function PageBody(props) {
7
- const usePadding = useBreakpoint('xxl') && props.disablePadding !== true;
8
- const settings = useSettings();
9
- const { t } = useTranslation();
10
- return (_jsx(ErrorBoundary, { message: t('Error'), children: _jsx("div", { style: {
11
- display: 'flex',
12
- flexDirection: 'column',
13
- height: '100%',
14
- maxHeight: '100%',
15
- overflow: 'hidden',
16
- backgroundColor: 'var(--pf-c-page__main-section--BackgroundColor)',
17
- }, children: _jsx("div", { style: {
18
- display: 'flex',
19
- flexDirection: 'column',
20
- height: '100%',
21
- maxHeight: '100%',
22
- margin: usePadding ? 24 : 0,
23
- overflow: 'hidden',
24
- border: settings.borders && usePadding
25
- ? 'thin solid var(--pf-global--BorderColor--100)'
26
- : undefined,
27
- backgroundColor: 'var(--pf-global--BackgroundColor--100)',
28
- }, children: props.children }) }) }));
29
- }
package/mjs/PageCells.js DELETED
@@ -1,102 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { Button, ClipboardCopy, Flex, FlexItem, Label, LabelGroup, Split, SplitItem, Tooltip, Truncate, } from '@patternfly/react-core';
3
- import { DateTime } from 'luxon';
4
- import { useEffect, useState } from 'react';
5
- import { useTranslation } from 'react-i18next';
6
- import { Link } from 'react-router-dom';
7
- import { IconWrapper } from './components/IconWrapper';
8
- import { getPatternflyColor } from './components/patternfly-colors';
9
- import { useSettings } from './Settings';
10
- export function LabelsCell(props) {
11
- return (_jsx(LabelGroup, { numLabels: 999, style: { flexWrap: 'nowrap' }, children: props.labels.map((label) => (_jsx(Label, { children: label }, label))) }));
12
- }
13
- export function DateCell(props) {
14
- const date = new Date(props.value);
15
- return (_jsxs(Split, { hasGutter: true, children: [_jsx(SplitItem, { children: date.toLocaleDateString() }), _jsx(SplitItem, { children: date.toLocaleTimeString() })] }));
16
- }
17
- export function TextCell(props) {
18
- return (_jsxs(Split, { children: [props.icon && (_jsx(SplitItem, { children: _jsx(IconWrapper, { size: props.iconSize ?? 'md', children: props.icon }) })), props.to ? (_jsx(SplitItem, { children: _jsx(Tooltip, { content: props.text ?? '', children: _jsx("div", { style: {
19
- maxWidth: 300,
20
- whiteSpace: 'nowrap',
21
- textOverflow: 'ellipsis',
22
- overflow: 'hidden',
23
- }, children: _jsx(Link, { to: props.to, children: props.text ?? '' }) }) }) })) : props.onClick !== undefined ? (_jsx(SplitItem, { onClick: props.onClick, children: _jsx(Button, { variant: "link", isInline: true, style: {
24
- whiteSpace: 'nowrap',
25
- }, children: props.text }) })) : (_jsx(SplitItem, { style: {
26
- color: props.textColor ? getPatternflyColor(props.textColor) : undefined,
27
- }, children: _jsx(Tooltip, { content: props.text ?? '', children: _jsx("div", { style: {
28
- maxWidth: 300,
29
- whiteSpace: 'nowrap',
30
- textOverflow: 'ellipsis',
31
- overflow: 'hidden',
32
- }, children: props.text ?? '' }) }) }))] }));
33
- }
34
- export function CopyCell(props) {
35
- if (!props.text)
36
- return _jsx(_Fragment, {});
37
- return (_jsx(ClipboardCopy, { hoverTip: "Copy", clickTip: "Copied", variant: "inline-compact", style: { display: 'flex', flexWrap: 'nowrap', borderRadius: 4 }, onCopy: () => {
38
- void navigator.clipboard.writeText(props.text ?? '');
39
- }, children: _jsx(Truncate, { content: props.text, style: { minWidth: props.minWidth } }) }));
40
- }
41
- export function SinceCell(props) {
42
- let { t } = props;
43
- t = t ? t : (t) => t;
44
- const { author, onClick } = props;
45
- const [dateTime, setDateTime] = useState(null);
46
- useEffect(() => {
47
- if (props.value) {
48
- setDateTime(DateTime.fromISO(props.value).toRelative());
49
- }
50
- const timeout = setInterval(() => {
51
- if (props.value) {
52
- setDateTime(DateTime.fromISO(props.value).toRelative());
53
- }
54
- }, 1000);
55
- return () => clearTimeout(timeout);
56
- }, [props.value]);
57
- if (props.value === undefined)
58
- return _jsx(_Fragment, {});
59
- return (_jsxs("span", { style: { whiteSpace: 'nowrap' }, children: [dateTime, author && _jsxs("span", { children: ["\u00A0", t('by'), "\u00A0"] }), onClick ? (_jsx(Button, { variant: "link", isInline: true, onClick: onClick, children: author })) : (_jsx("span", { children: author }))] }));
60
- }
61
- export function CapacityCell(props) {
62
- const { t } = useTranslation();
63
- const settings = useSettings();
64
- const ratio = props.used / props.capacity;
65
- if (props.capacity === 0)
66
- return _jsx(_Fragment, {});
67
- const base = ratio >= 0.8
68
- ? 'var(--pf-global--palette--red'
69
- : ratio >= 0.5
70
- ? 'var(--pf-global--palette--gold'
71
- : 'var(--pf-global--palette--green';
72
- const color1 = settings.theme === 'light' ? `${base}-100)` : `${base}-600)`;
73
- const color2 = settings.theme === 'light' ? `${base}-400)` : `${base}-200)`;
74
- const borderColor = settings.theme === 'light' ? `#0002` : `#fff2`;
75
- return (_jsxs(Flex, { alignItems: { default: 'alignItemsBaseline' }, spaceItems: { default: 'spaceItemsSm' }, children: [props.capacity > 0 && (_jsx(FlexItem, { children: _jsx("div", { style: {
76
- width: 18,
77
- height: 25,
78
- background: color1,
79
- marginBottom: -9,
80
- paddingTop: Math.max(0, Math.min(25, (25 * (props.capacity - props.used)) / props.capacity)),
81
- borderRadius: 2,
82
- border: `thin solid ${borderColor}`,
83
- }, children: _jsx("div", { style: {
84
- width: '100%',
85
- height: '100%',
86
- background: color2,
87
- borderRadius: 2,
88
- } }) }) })), props.format ? (_jsx(FlexItem, { children: props.format
89
- .replace('{used}', props.used.toString())
90
- .replace('{capacity}', props.capacity.toString()) })) : (_jsxs(FlexItem, { children: [props.used, t(' of '), props.capacity] }))] }));
91
- }
92
- export function BytesCell(props) {
93
- const { bytes } = props;
94
- if (!+bytes)
95
- return _jsx(_Fragment, {});
96
- const k = 1024;
97
- const decimals = props.decimals ? props.decimals : 0;
98
- const dm = decimals < 0 ? 0 : decimals;
99
- const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
100
- const i = Math.floor(Math.log(bytes) / Math.log(k));
101
- return _jsx(_Fragment, { children: `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}` });
102
- }