@centreon/ui 24.4.59 → 24.4.61
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/package.json +50 -42
- package/public/mockServiceWorker.js +1 -1
- package/src/ActionsList/ActionsList.styles.ts +40 -71
- package/src/Button/Icon/index.tsx +1 -1
- package/src/Button/Save/StartIcon.tsx +3 -3
- package/src/Button/Save/index.tsx +9 -5
- package/src/Checkbox/Checkbox.tsx +2 -2
- package/src/Checkbox/CheckboxGroup/index.tsx +2 -2
- package/src/Dashboard/Item.tsx +1 -1
- package/src/Dashboard/Layout.tsx +2 -2
- package/src/Dialog/Confirm/index.tsx +10 -2
- package/src/Dialog/UnsavedChanges/index.tsx +21 -20
- package/src/Dialog/UnsavedChanges/translatedLabels.ts +4 -6
- package/src/Dialog/index.tsx +9 -2
- package/src/FallbackPage/FallbackPage.tsx +3 -3
- package/src/FileDropZone/index.tsx +3 -1
- package/src/Form/Form.cypress.spec.tsx +133 -0
- package/src/Form/Inputs/List/Content.tsx +62 -0
- package/src/Form/Inputs/List/List.styles.ts +29 -0
- package/src/Form/Inputs/List/List.tsx +58 -0
- package/src/Form/Inputs/List/useList.ts +81 -0
- package/src/Form/Inputs/Text.tsx +3 -1
- package/src/Form/Inputs/index.tsx +3 -1
- package/src/Form/Inputs/models.ts +10 -1
- package/src/Graph/BarStack/BarStack.cypress.spec.tsx +154 -0
- package/src/Graph/BarStack/BarStack.stories.tsx +123 -0
- package/src/Graph/BarStack/BarStack.styles.ts +37 -0
- package/src/Graph/BarStack/BarStack.tsx +14 -0
- package/src/Graph/BarStack/ResponsiveBarStack.tsx +222 -0
- package/src/Graph/BarStack/index.ts +1 -0
- package/src/Graph/BarStack/models.ts +20 -0
- package/src/Graph/BarStack/useResponsiveBarStack.ts +137 -0
- package/src/Graph/Gauge/Gauge.cypress.spec.tsx +102 -0
- package/src/Graph/Gauge/Gauge.tsx +1 -1
- package/src/Graph/HeatMap/HeatMap.cypress.spec.tsx +145 -0
- package/src/Graph/HeatMap/HeatMap.stories.tsx +0 -25
- package/src/Graph/HeatMap/ResponsiveHeatMap.tsx +8 -2
- package/src/Graph/Legend/Legend.tsx +21 -0
- package/src/Graph/Legend/index.ts +1 -0
- package/src/Graph/Legend/models.ts +11 -0
- package/src/Graph/LineChart/BasicComponents/Lines/Threshold/Circle.tsx +2 -2
- package/src/Graph/LineChart/BasicComponents/Thresholds.tsx +2 -2
- package/src/Graph/LineChart/BasicComponents/useFilterLines.ts +1 -1
- package/src/Graph/LineChart/InteractiveComponents/AnchorPoint/GuidingLines.tsx +2 -2
- package/src/Graph/LineChart/InteractiveComponents/Annotations/EventAnnotations.tsx +1 -1
- package/src/Graph/LineChart/Legend/Legend.styles.ts +1 -1
- package/src/Graph/LineChart/Legend/LegendHeader.tsx +1 -1
- package/src/Graph/LineChart/Legend/useInteractiveValues.ts +2 -2
- package/src/Graph/LineChart/Legend/useLegend.ts +3 -3
- package/src/Graph/LineChart/helpers/doc.ts +16 -13
- package/src/Graph/LineChart/helpers/index.ts +1 -1
- package/src/Graph/LineChart/index.stories.tsx +4 -2
- package/src/Graph/LineChart/index.tsx +1 -1
- package/src/Graph/PieChart/PieChart.cypress.spec.tsx +169 -0
- package/src/Graph/PieChart/PieChart.stories.tsx +194 -0
- package/src/Graph/PieChart/PieChart.styles.ts +39 -0
- package/src/Graph/PieChart/PieChart.tsx +14 -0
- package/src/Graph/PieChart/ResponsivePie.tsx +254 -0
- package/src/Graph/PieChart/index.ts +1 -0
- package/src/Graph/PieChart/models.ts +20 -0
- package/src/Graph/PieChart/useResponsivePie.ts +85 -0
- package/src/Graph/SingleBar/SingleBar.cypress.spec.tsx +121 -0
- package/src/Graph/SingleBar/Thresholds.tsx +2 -2
- package/src/Graph/Text/Text.cypress.spec.tsx +101 -0
- package/src/Graph/Text/Text.stories.tsx +60 -4
- package/src/Graph/Text/Text.tsx +1 -1
- package/src/Graph/common/testUtils.ts +71 -0
- package/src/Graph/common/timeSeries/index.ts +22 -14
- package/src/Graph/common/utils.ts +19 -0
- package/src/Graph/index.ts +3 -0
- package/src/Graph/translatedLabels.ts +1 -0
- package/src/InputField/Select/Autocomplete/Connected/index.tsx +10 -7
- package/src/InputField/Select/Autocomplete/Draggable/SortableList.tsx +1 -1
- package/src/InputField/Select/Autocomplete/Draggable/SortableListContent.tsx +1 -1
- package/src/InputField/Select/Autocomplete/Draggable/index.tsx +1 -1
- package/src/InputField/Select/Autocomplete/Multi/index.tsx +4 -2
- package/src/InputField/Select/Autocomplete/index.tsx +129 -116
- package/src/InputField/Select/IconPopover/index.tsx +2 -2
- package/src/InputField/Select/index.tsx +15 -2
- package/src/InputField/Text/index.tsx +2 -2
- package/src/Listing/ActionBar/index.tsx +9 -8
- package/src/Listing/Cell/DataCell.styles.ts +3 -0
- package/src/Listing/Cell/DataCell.tsx +23 -5
- package/src/Listing/Header/ListingHeader.tsx +1 -1
- package/src/Listing/Listing.cypress.spec.tsx +218 -33
- package/src/Listing/Listing.styles.ts +4 -7
- package/src/Listing/Row/Row.tsx +7 -3
- package/src/Listing/index.stories.tsx +37 -3
- package/src/Listing/index.test.tsx +1 -1
- package/src/Listing/index.tsx +80 -36
- package/src/Listing/models.ts +1 -0
- package/src/Listing/useStyleTable.ts +1 -0
- package/src/Module/Module.cypress.spec.tsx +129 -0
- package/src/Module/index.tsx +2 -4
- package/src/PopoverMenu/index.tsx +6 -5
- package/src/RichTextEditor/RichTextEditor.tsx +12 -1
- package/src/SortableItems/index.tsx +2 -7
- package/src/ThemeProvider/index.tsx +24 -0
- package/src/TimePeriods/CustomTimePeriod/CompactCustomTimePeriod.styles.ts +6 -7
- package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/PickersStartEndDate.tsx +8 -3
- package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/models.ts +0 -2
- package/src/TimePeriods/DateTimePickerInput.tsx +56 -19
- package/src/TimePeriods/ResolutionTimePeriod.cypress.spec.tsx +12 -9
- package/src/TimePeriods/TimePeriods.cypress.spec.tsx +9 -33
- package/src/TimePeriods/helpers/index.ts +1 -1
- package/src/TimePeriods/index.stories.tsx +12 -4
- package/src/TimePeriods/index.tsx +2 -2
- package/src/Typography/FluidTypography/FluidTypography.cypress.spec.tsx +27 -0
- package/src/Typography/FluidTypography/index.stories.tsx +2 -2
- package/src/Typography/FluidTypography/index.tsx +21 -28
- package/src/api/QueryProvider.tsx +1 -1
- package/src/api/TestQueryProvider.tsx +1 -1
- package/src/api/index.ts +3 -3
- package/src/api/useFetchQuery/index.ts +27 -23
- package/src/api/useMutationQuery/index.test.ts +4 -4
- package/src/api/useMutationQuery/index.ts +60 -25
- package/src/components/Button/Icon/IconButton.tsx +6 -2
- package/src/components/DataTable/DataListing.tsx +6 -0
- package/src/components/DataTable/DataTable.cypress.spec.tsx +174 -0
- package/src/components/DataTable/DataTable.stories.tsx +40 -0
- package/src/components/DataTable/DataTable.styles.ts +3 -0
- package/src/components/DataTable/DataTable.tsx +3 -3
- package/src/components/DataTable/Item/DataTableItem.styles.ts +7 -2
- package/src/components/DataTable/Item/DataTableItem.tsx +4 -60
- package/src/components/DataTable/index.ts +3 -1
- package/src/components/Form/AccessRights/AccessRights.cypress.spec.tsx +13 -13
- package/src/components/Form/AccessRights/ShareInput/ContactSwitch.tsx +3 -3
- package/src/components/Form/AccessRights/ShareInput/ShareInput.tsx +1 -0
- package/src/components/Form/AccessRights/storiesData.ts +22 -22
- package/src/components/Form/Dashboard/DashboardDuplicationForm.tsx +85 -0
- package/src/components/Form/Dashboard/DashboardForm.tsx +15 -12
- package/src/components/Form/Dashboard/index.ts +1 -0
- package/src/components/Form/FormActions.tsx +7 -2
- package/src/components/ItemComposition/ItemComposition.styles.ts +2 -2
- package/src/components/Layout/PageLayout/PageLayout.tsx +1 -1
- package/src/components/Layout/PageLayout/PageLayoutActions.tsx +1 -0
- package/src/components/Layout/PageLayout/PageLayoutBody.tsx +1 -0
- package/src/components/Layout/PageLayout/PageLayoutHeader.tsx +5 -1
- package/src/components/Layout/PageLayout/PageQuickAccess.tsx +76 -0
- package/src/components/Layout/PageLayout/index.ts +3 -1
- package/src/components/Layout/PageLayout.cypress.spec.tsx +66 -0
- package/src/components/List/Item/ListItem.tsx +3 -3
- package/src/components/Modal/ConfirmationModal/ConfirmationModal.cypress.spec.tsx +168 -0
- package/src/components/Modal/ConfirmationModal/ConfirmationModal.stories.tsx +62 -0
- package/src/components/Modal/ConfirmationModal/ConfirmationModal.tsx +87 -0
- package/src/components/Modal/Modal.styles.ts +8 -3
- package/src/components/Modal/index.ts +2 -0
- package/src/components/Tooltip/ConfirmationTooltip/ConfirmationTooltip.stories.tsx +3 -3
- package/src/components/Tooltip/ConfirmationTooltip/ConfirmationTooltip.tsx +1 -1
- package/src/components/Tooltip/ConfirmationTooltip/models.ts +1 -1
- package/src/index.ts +2 -2
- package/src/queryParameters/url/index.ts +5 -1
- package/src/utils/index.ts +1 -1
- package/src/utils/useFullscreen/Fullscreen.cypress.spec.tsx +1 -3
- package/src/utils/useFullscreen/useFullscreenListener.ts +10 -7
- package/src/utils/useInfiniteScrollListing.ts +4 -1
- package/src/utils/{useLicenseExpirationWarning.cypress.spec.tsx → useLicenseExpirationWarning.test.tsx} +48 -37
- package/src/utils/useLicenseExpirationWarning.ts +18 -18
- package/src/utils/usePluralizedTranslation.ts +21 -0
- package/src/Typography/FluidTypography/useFluidResizeObserver.ts +0 -56
- package/src/screens/dashboard/DashboardsDetail.stories.tsx +0 -108
- package/src/screens/dashboard/DashboardsOverview.stories.tsx +0 -281
- package/src/utils/useDateTimePickerAdapter.ts +0 -309
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { atom, useSetAtom, createStore, Provider } from 'jotai';
|
|
3
|
+
|
|
4
|
+
import { Button } from '../../Button';
|
|
5
|
+
|
|
6
|
+
import { ConfirmationModal } from './ConfirmationModal';
|
|
7
|
+
|
|
8
|
+
const meta: Meta<typeof ConfirmationModal> = {
|
|
9
|
+
component: ConfirmationModal
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export default meta;
|
|
13
|
+
type Story = StoryObj<typeof ConfirmationModal>;
|
|
14
|
+
|
|
15
|
+
const testAtom = atom<string | null>(null);
|
|
16
|
+
|
|
17
|
+
const store = createStore();
|
|
18
|
+
|
|
19
|
+
const Component = (args): JSX.Element => {
|
|
20
|
+
const setAtom = useSetAtom(testAtom);
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<>
|
|
24
|
+
<Button onClick={() => setAtom('John')}>Click to open modal</Button>
|
|
25
|
+
<ConfirmationModal<string> {...args} />
|
|
26
|
+
</>
|
|
27
|
+
);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const Default: Story = {
|
|
31
|
+
args: {
|
|
32
|
+
hasCloseButton: true,
|
|
33
|
+
labels: {
|
|
34
|
+
cancel: 'Cancel',
|
|
35
|
+
confirm: 'Confirm',
|
|
36
|
+
description: 'Description',
|
|
37
|
+
title: 'Title'
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
render: (args) => (
|
|
41
|
+
<Provider store={store}>
|
|
42
|
+
<Component {...args} atom={testAtom} />
|
|
43
|
+
</Provider>
|
|
44
|
+
)
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const WithDynamicLabels: Story = {
|
|
48
|
+
args: {
|
|
49
|
+
hasCloseButton: true,
|
|
50
|
+
labels: {
|
|
51
|
+
cancel: 'Cancel',
|
|
52
|
+
confirm: 'Confirm',
|
|
53
|
+
description: (data) => `Hello ${data} from description`,
|
|
54
|
+
title: (data) => `Hello ${data}`
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
render: (args) => (
|
|
58
|
+
<Provider store={store}>
|
|
59
|
+
<Component {...args} atom={testAtom} />
|
|
60
|
+
</Provider>
|
|
61
|
+
)
|
|
62
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
|
|
3
|
+
import { useAtom, PrimitiveAtom } from 'jotai';
|
|
4
|
+
import { equals, pick, type } from 'ramda';
|
|
5
|
+
|
|
6
|
+
import { Modal } from '..';
|
|
7
|
+
|
|
8
|
+
export interface ConfirmationModalProps<TAtom> {
|
|
9
|
+
atom: PrimitiveAtom<string | null>;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
hasCloseButton?: boolean;
|
|
12
|
+
isDanger?: boolean;
|
|
13
|
+
labels: {
|
|
14
|
+
cancel: string | ((atom: Awaited<TAtom> | null) => string);
|
|
15
|
+
confirm: string | ((atom: Awaited<TAtom> | null) => string);
|
|
16
|
+
description: string | ((atom: Awaited<TAtom> | null) => string);
|
|
17
|
+
title: string | ((atom: Awaited<TAtom> | null) => string);
|
|
18
|
+
};
|
|
19
|
+
onCancel?: (atomData: Awaited<TAtom> | null) => void;
|
|
20
|
+
onClose?: (atomData: Awaited<TAtom> | null) => void;
|
|
21
|
+
onConfirm?: (atomData: Awaited<TAtom> | null) => void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface GetLabelProps<TAtom> {
|
|
25
|
+
atomData: Awaited<TAtom> | null;
|
|
26
|
+
label: string | ((atom: Awaited<TAtom> | null) => string);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const getLabel = <TAtom,>({ label, atomData }: GetLabelProps<TAtom>): string =>
|
|
30
|
+
equals(type(label), 'String')
|
|
31
|
+
? (label as string)
|
|
32
|
+
: (label as (atom: Awaited<TAtom> | null) => string)(atomData);
|
|
33
|
+
|
|
34
|
+
export const ConfirmationModal = <TAtom,>({
|
|
35
|
+
atom,
|
|
36
|
+
labels,
|
|
37
|
+
onConfirm,
|
|
38
|
+
onCancel,
|
|
39
|
+
onClose,
|
|
40
|
+
hasCloseButton = true,
|
|
41
|
+
isDanger,
|
|
42
|
+
disabled
|
|
43
|
+
}: ConfirmationModalProps<TAtom>): JSX.Element => {
|
|
44
|
+
const [atomData, setAtomData] = useAtom<TAtom | null>(atom);
|
|
45
|
+
|
|
46
|
+
const closeModal = (): void => {
|
|
47
|
+
onClose?.(atomData);
|
|
48
|
+
setAtomData(null);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const formattedLabels = useMemo(() => {
|
|
52
|
+
return {
|
|
53
|
+
cancel: getLabel({ atomData, label: labels.cancel }),
|
|
54
|
+
confirm: getLabel({ atomData, label: labels.confirm }),
|
|
55
|
+
description: getLabel({ atomData, label: labels.description }),
|
|
56
|
+
title: getLabel({ atomData, label: labels.title })
|
|
57
|
+
};
|
|
58
|
+
}, [labels, atomData]);
|
|
59
|
+
|
|
60
|
+
const confirm = (): void => {
|
|
61
|
+
onConfirm?.(atomData);
|
|
62
|
+
setAtomData(null);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const cancel = (): void => {
|
|
66
|
+
onCancel?.(atomData);
|
|
67
|
+
setAtomData(null);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<Modal
|
|
72
|
+
hasCloseButton={hasCloseButton}
|
|
73
|
+
open={Boolean(atomData)}
|
|
74
|
+
onClose={closeModal}
|
|
75
|
+
>
|
|
76
|
+
<Modal.Header>{formattedLabels.title}</Modal.Header>
|
|
77
|
+
<Modal.Body>{formattedLabels.description}</Modal.Body>
|
|
78
|
+
<Modal.Actions
|
|
79
|
+
disabled={disabled}
|
|
80
|
+
isDanger={isDanger}
|
|
81
|
+
labels={pick(['confirm', 'cancel'], formattedLabels)}
|
|
82
|
+
onCancel={cancel}
|
|
83
|
+
onConfirm={confirm}
|
|
84
|
+
/>
|
|
85
|
+
</Modal>
|
|
86
|
+
);
|
|
87
|
+
};
|
|
@@ -28,6 +28,7 @@ const useStyles = makeStyles<{
|
|
|
28
28
|
left: props?.left ?? 0,
|
|
29
29
|
margin: 0,
|
|
30
30
|
maxWidth: 'unset',
|
|
31
|
+
paddingBottom: theme.spacing(8),
|
|
31
32
|
position: 'absolute',
|
|
32
33
|
right: props?.right ?? 0,
|
|
33
34
|
top: props?.top ?? 0,
|
|
@@ -50,14 +51,18 @@ const useStyles = makeStyles<{
|
|
|
50
51
|
},
|
|
51
52
|
modalActions: {
|
|
52
53
|
'&[data-fixed="true"]': {
|
|
53
|
-
|
|
54
|
+
background: theme.palette.background.paper,
|
|
55
|
+
position: 'fixed',
|
|
56
|
+
width: '100%'
|
|
54
57
|
},
|
|
55
|
-
bottom:
|
|
58
|
+
bottom: 0,
|
|
56
59
|
display: 'flex',
|
|
57
60
|
flexDirection: 'row',
|
|
58
61
|
gap: theme.spacing(2),
|
|
59
62
|
justifyContent: 'flex-end',
|
|
60
|
-
|
|
63
|
+
padding: theme.spacing(1, 2.5, 2.5, 0),
|
|
64
|
+
right: 0,
|
|
65
|
+
zIndex: theme.zIndex.modal
|
|
61
66
|
},
|
|
62
67
|
modalBody: {
|
|
63
68
|
'& > p': {
|
|
@@ -3,6 +3,8 @@ import { ModalHeader } from './ModalHeader';
|
|
|
3
3
|
import { ModalBody } from './ModalBody';
|
|
4
4
|
import { ModalActions } from './ModalActions';
|
|
5
5
|
|
|
6
|
+
export { ConfirmationModal } from './ConfirmationModal/ConfirmationModal';
|
|
7
|
+
|
|
6
8
|
export const Modal = Object.assign(ModalRoot, {
|
|
7
9
|
Actions: ModalActions,
|
|
8
10
|
Body: ModalBody,
|
|
@@ -15,7 +15,7 @@ type Story = StoryObj<typeof ConfirmationTooltip>;
|
|
|
15
15
|
|
|
16
16
|
export const Default: Story = {
|
|
17
17
|
args: {
|
|
18
|
-
children: (toggleTooltip) => (
|
|
18
|
+
children: ({ toggleTooltip }) => (
|
|
19
19
|
<IconButton icon={<SaveIcon />} onClick={toggleTooltip} />
|
|
20
20
|
),
|
|
21
21
|
labels: {
|
|
@@ -30,7 +30,7 @@ export const Default: Story = {
|
|
|
30
30
|
|
|
31
31
|
export const WithConfirmVariant: Story = {
|
|
32
32
|
args: {
|
|
33
|
-
children: (toggleTooltip) => (
|
|
33
|
+
children: ({ toggleTooltip }) => (
|
|
34
34
|
<IconButton icon={<DeleteIcon color="error" />} onClick={toggleTooltip} />
|
|
35
35
|
),
|
|
36
36
|
confirmVariant: 'error',
|
|
@@ -46,7 +46,7 @@ export const WithConfirmVariant: Story = {
|
|
|
46
46
|
|
|
47
47
|
export const WithSecondaryLabel: Story = {
|
|
48
48
|
args: {
|
|
49
|
-
children: (toggleTooltip) => (
|
|
49
|
+
children: ({ toggleTooltip }) => (
|
|
50
50
|
<IconButton icon={<DeleteIcon color="error" />} onClick={toggleTooltip} />
|
|
51
51
|
),
|
|
52
52
|
confirmVariant: 'error',
|
|
@@ -49,7 +49,7 @@ export const ConfirmationTooltip = ({
|
|
|
49
49
|
return (
|
|
50
50
|
<ClickAwayListener onClickAway={close}>
|
|
51
51
|
<div>
|
|
52
|
-
{children(isOpen ? close : open)}
|
|
52
|
+
{children({ isOpen, toggleTooltip: isOpen ? close : open })}
|
|
53
53
|
<Popper
|
|
54
54
|
anchorEl={anchorElement}
|
|
55
55
|
className={classes.popper}
|
package/src/index.ts
CHANGED
|
@@ -163,8 +163,8 @@ export * from './Graph/common/timeSeries';
|
|
|
163
163
|
|
|
164
164
|
export { default as TimePeriods } from './TimePeriods';
|
|
165
165
|
export { default as SimpleCustomTimePeriod } from './TimePeriods/CustomTimePeriod/SimpleCustomTimePeriod';
|
|
166
|
+
export { default as DateTimePickerInput } from './TimePeriods/DateTimePickerInput';
|
|
166
167
|
export * from './ParentSize';
|
|
167
|
-
|
|
168
|
+
export { default as Subtitle } from './Typography/Subtitle';
|
|
168
169
|
export { default as TablePagination } from './Listing/ActionBar/Pagination';
|
|
169
170
|
export { default as PaginationActions } from './Listing/ActionBar/PaginationActions';
|
|
170
|
-
export { default as Subtitle } from './Typography/Subtitle';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { fromPairs } from 'ramda';
|
|
1
|
+
import { fromPairs, startsWith } from 'ramda';
|
|
2
2
|
|
|
3
3
|
import { QueryParameter } from '../models';
|
|
4
4
|
|
|
@@ -25,6 +25,10 @@ const getUrlQueryParameters = <
|
|
|
25
25
|
|
|
26
26
|
const entries = [...urlParams.entries()].map<[string, string]>(
|
|
27
27
|
([key, value]) => {
|
|
28
|
+
if (startsWith('/', value)) {
|
|
29
|
+
return [key, value];
|
|
30
|
+
}
|
|
31
|
+
|
|
28
32
|
return [key, JSON.parse(value)];
|
|
29
33
|
}
|
|
30
34
|
);
|
package/src/utils/index.ts
CHANGED
|
@@ -3,7 +3,6 @@ export * from './getNormalizedId';
|
|
|
3
3
|
export * from './statuses';
|
|
4
4
|
export * from './typedMemo';
|
|
5
5
|
export * from './useCopyToClipboard';
|
|
6
|
-
export * from './useDateTimePickerAdapter';
|
|
7
6
|
export * from './useDebounce';
|
|
8
7
|
export * from './useDeepCallback';
|
|
9
8
|
export * from './useDeepMemo';
|
|
@@ -20,5 +19,6 @@ export * from './useInfiniteScrollListing';
|
|
|
20
19
|
export * from './useLicenseExpirationWarning';
|
|
21
20
|
export * from './useRefreshInterval';
|
|
22
21
|
export * from './centreonBaseURL';
|
|
22
|
+
export * from './usePluralizedTranslation';
|
|
23
23
|
export * from './useResizeObserver';
|
|
24
24
|
export * from './useFullscreen';
|
|
@@ -110,9 +110,7 @@ describe('Fullscreen', () => {
|
|
|
110
110
|
});
|
|
111
111
|
|
|
112
112
|
['input', 'textarea'].forEach((tag) => {
|
|
113
|
-
it(`cannot toggle fullscreen feature using the shortcut when ${
|
|
114
|
-
tag === 'input' ? 'an' : 'a'
|
|
115
|
-
} ${tag} is focused`, () => {
|
|
113
|
+
it(`cannot toggle fullscreen feature using the shortcut when ${tag === 'input' ? 'an' : 'a'} ${tag} is focused`, () => {
|
|
116
114
|
initialize();
|
|
117
115
|
|
|
118
116
|
cy.get('#test')
|
|
@@ -39,13 +39,16 @@ export const useFullscreenListener = (): boolean => {
|
|
|
39
39
|
resetVariables();
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
-
useEffect(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
42
|
+
useEffect(
|
|
43
|
+
() => {
|
|
44
|
+
document.addEventListener('fullscreenchange', changeFullscreen);
|
|
45
|
+
|
|
46
|
+
return () => {
|
|
47
|
+
document.removeEventListener('fullscreenchange', changeFullscreen);
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
useDeepCompare([document.fullscreenElement])
|
|
51
|
+
);
|
|
49
52
|
|
|
50
53
|
useEffect(() => {
|
|
51
54
|
window.addEventListener('keypress', toggle);
|
|
@@ -24,6 +24,7 @@ interface UseInfiniteScrollListing<T> {
|
|
|
24
24
|
interface UseInfiniteScrollListingProps<T> {
|
|
25
25
|
customQueryParameters?: Array<QueryParameter>;
|
|
26
26
|
decoder?: JsonDecoder.Decoder<Listing<T>>;
|
|
27
|
+
enabled?: boolean;
|
|
27
28
|
endpoint: string;
|
|
28
29
|
limit?: number;
|
|
29
30
|
pageAtom: PrimitiveAtom<number>;
|
|
@@ -40,7 +41,8 @@ export const useInfiniteScrollListing = <T>({
|
|
|
40
41
|
suspense = true,
|
|
41
42
|
parameters,
|
|
42
43
|
customQueryParameters,
|
|
43
|
-
limit = 100
|
|
44
|
+
limit = 100,
|
|
45
|
+
enabled = true
|
|
44
46
|
}: UseInfiniteScrollListingProps<T>): UseInfiniteScrollListing<T> => {
|
|
45
47
|
const [maxPage, setMaxPage] = useState(1);
|
|
46
48
|
|
|
@@ -61,6 +63,7 @@ export const useInfiniteScrollListing = <T>({
|
|
|
61
63
|
getQueryKey: () => [queryKeyName, page],
|
|
62
64
|
isPaginated: true,
|
|
63
65
|
queryOptions: {
|
|
66
|
+
enabled,
|
|
64
67
|
refetchOnMount: false,
|
|
65
68
|
refetchOnWindowFocus: false,
|
|
66
69
|
suspense: suspense && equals(page, 1)
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import dayjs from 'dayjs';
|
|
2
|
+
import { renderHook } from '@testing-library/react';
|
|
2
3
|
|
|
3
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
getFetchCall,
|
|
6
|
+
mockResponse,
|
|
7
|
+
resetMocks,
|
|
8
|
+
waitFor
|
|
9
|
+
} from '../../test/testRenderer';
|
|
10
|
+
import TestQueryProvider from '../api/TestQueryProvider';
|
|
4
11
|
|
|
5
12
|
import { labelLicenseWarning } from './translatedLabel';
|
|
6
13
|
|
|
@@ -79,59 +86,63 @@ const getMockedResponse = (expirationDate): object => ({
|
|
|
79
86
|
});
|
|
80
87
|
|
|
81
88
|
const mockRequest = ({ expirationDate }: { expirationDate }): void => {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
path: '**internal.php?object=centreon_module&action=list',
|
|
86
|
-
response: getMockedResponse(expirationDate)
|
|
89
|
+
resetMocks();
|
|
90
|
+
mockResponse({
|
|
91
|
+
data: getMockedResponse(expirationDate)
|
|
87
92
|
});
|
|
88
93
|
};
|
|
89
94
|
|
|
90
|
-
const
|
|
91
|
-
useLicenseExpirationWarning({
|
|
92
|
-
module: 'centreon-autodiscovery-server'
|
|
93
|
-
});
|
|
95
|
+
const showMessage = jest.fn();
|
|
94
96
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
<SnackbarProvider>
|
|
102
|
-
<TestComponent />
|
|
103
|
-
</SnackbarProvider>
|
|
104
|
-
</TestQueryProvider>
|
|
105
|
-
);
|
|
106
|
-
};
|
|
97
|
+
jest.mock('../Snackbar/useSnackbar', () => ({
|
|
98
|
+
__esModule: true,
|
|
99
|
+
default: jest
|
|
100
|
+
.fn()
|
|
101
|
+
.mockImplementation(() => ({ showWarningMessage: showMessage }))
|
|
102
|
+
}));
|
|
107
103
|
|
|
108
104
|
const initialize = (): void => {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
105
|
+
renderHook(
|
|
106
|
+
() =>
|
|
107
|
+
useLicenseExpirationWarning({
|
|
108
|
+
module: 'centreon-autodiscovery-server'
|
|
109
|
+
}),
|
|
110
|
+
{
|
|
111
|
+
wrapper: TestQueryProvider
|
|
112
|
+
}
|
|
113
|
+
);
|
|
114
114
|
};
|
|
115
115
|
|
|
116
116
|
const currentDate = dayjs();
|
|
117
117
|
|
|
118
118
|
describe('License', () => {
|
|
119
|
-
beforeEach(initialize);
|
|
120
|
-
|
|
121
119
|
it('does not display any warning message when the license expires in more than 15 days from the current date', () => {
|
|
122
120
|
mockRequest({ expirationDate: currentDate.add(20, 'day') });
|
|
121
|
+
initialize();
|
|
123
122
|
|
|
124
|
-
|
|
123
|
+
waitFor(() => {
|
|
124
|
+
expect(getFetchCall(0)).toEqual(
|
|
125
|
+
'internal.php?object=centreon_module&action=list'
|
|
126
|
+
);
|
|
127
|
+
});
|
|
125
128
|
|
|
126
|
-
|
|
127
|
-
labelLicenseWarning('centreon-autodiscovery-server', 20)
|
|
128
|
-
).should('not.exist');
|
|
129
|
+
expect(showMessage).not.toHaveBeenCalled();
|
|
129
130
|
});
|
|
131
|
+
|
|
130
132
|
it('displays a warning message when the license expires within 15 days', () => {
|
|
131
133
|
mockRequest({ expirationDate: currentDate.add(10.5, 'day') });
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
134
|
+
initialize();
|
|
135
|
+
|
|
136
|
+
waitFor(() => {
|
|
137
|
+
expect(getFetchCall(0)).toEqual(
|
|
138
|
+
'internal.php?object=centreon_module&action=list'
|
|
139
|
+
);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
waitFor(() => {
|
|
143
|
+
expect(showMessage).toHaveBeenCalledWith(
|
|
144
|
+
labelLicenseWarning('centreon-autodiscovery-server', 10)
|
|
145
|
+
);
|
|
146
|
+
});
|
|
136
147
|
});
|
|
137
148
|
});
|
|
@@ -19,7 +19,7 @@ export const useLicenseExpirationWarning = ({ module }: Props): void => {
|
|
|
19
19
|
const { t } = useTranslation();
|
|
20
20
|
const { showWarningMessage } = useSnackbar();
|
|
21
21
|
|
|
22
|
-
const {
|
|
22
|
+
const { data } = useFetchQuery({
|
|
23
23
|
getEndpoint: () => extensionsEndpoint,
|
|
24
24
|
getQueryKey: () => [module]
|
|
25
25
|
});
|
|
@@ -28,25 +28,25 @@ export const useLicenseExpirationWarning = ({ module }: Props): void => {
|
|
|
28
28
|
|
|
29
29
|
const getExpirationDate = pipe(
|
|
30
30
|
path(['result', 'module', 'entities']),
|
|
31
|
-
find(propEq('id'
|
|
31
|
+
find(propEq(module, 'id')),
|
|
32
32
|
path(['license', 'expiration_date'])
|
|
33
33
|
) as (data) => string;
|
|
34
34
|
|
|
35
35
|
useEffect(() => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
}, []);
|
|
36
|
+
if (isNil(data)) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const expirationDate = getExpirationDate(data);
|
|
41
|
+
|
|
42
|
+
if (isNil(expirationDate)) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const daysUntilExpiration = dayjs(expirationDate).diff(currentDate, 'day');
|
|
47
|
+
|
|
48
|
+
if (lt(daysUntilExpiration, 15)) {
|
|
49
|
+
showWarningMessage(t(labelLicenseWarning(module, daysUntilExpiration)));
|
|
50
|
+
}
|
|
51
|
+
}, [data]);
|
|
52
52
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useTranslation } from 'react-i18next';
|
|
2
|
+
import pluralize from 'pluralize';
|
|
3
|
+
|
|
4
|
+
interface TProps {
|
|
5
|
+
count: number;
|
|
6
|
+
label: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const usePluralizedTranslation = (): {
|
|
10
|
+
pluralizedT: (props: TProps) => string;
|
|
11
|
+
} => {
|
|
12
|
+
const translation = useTranslation();
|
|
13
|
+
|
|
14
|
+
const pluralizedT = ({ label, count }: TProps): string => {
|
|
15
|
+
return pluralize(translation.t(label), count);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
pluralizedT
|
|
20
|
+
};
|
|
21
|
+
};
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
MutableRefObject,
|
|
3
|
-
useCallback,
|
|
4
|
-
useEffect,
|
|
5
|
-
useRef,
|
|
6
|
-
useState
|
|
7
|
-
} from 'react';
|
|
8
|
-
|
|
9
|
-
interface Size {
|
|
10
|
-
height: number;
|
|
11
|
-
width: number;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
interface UseFluidResizeObserver {
|
|
15
|
-
isParent?: boolean;
|
|
16
|
-
ref: MutableRefObject<HTMLElement | undefined>;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const useFluidResizeObserver = ({
|
|
20
|
-
ref,
|
|
21
|
-
isParent
|
|
22
|
-
}: UseFluidResizeObserver): Size => {
|
|
23
|
-
const [size, setSize] = useState<Size>({ height: 0, width: 0 });
|
|
24
|
-
|
|
25
|
-
const observer = useRef<ResizeObserver | null>(null);
|
|
26
|
-
|
|
27
|
-
const resizeObserver = useCallback(
|
|
28
|
-
(element) => {
|
|
29
|
-
if (observer.current) {
|
|
30
|
-
observer.current.disconnect();
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
observer.current = new ResizeObserver(
|
|
34
|
-
([entry]: Array<ResizeObserverEntry>) => {
|
|
35
|
-
setSize({
|
|
36
|
-
height: entry.target?.getBoundingClientRect().height || 0,
|
|
37
|
-
width: entry.target?.getBoundingClientRect().width || 0
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
if (element && observer.current) {
|
|
43
|
-
observer.current.observe(element);
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
[ref.current]
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
useEffect(() => {
|
|
50
|
-
resizeObserver(isParent ? ref.current?.parentElement : ref.current);
|
|
51
|
-
}, [ref.current]);
|
|
52
|
-
|
|
53
|
-
return size;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export default useFluidResizeObserver;
|