@centreon/ui 24.4.7 → 24.4.9
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 +17 -12
- package/src/Button/Save/StartIcon.tsx +3 -3
- package/src/Dashboard/Item.tsx +1 -1
- package/src/Dashboard/Layout.tsx +2 -2
- package/src/FileDropZone/index.tsx +3 -1
- package/src/Form/Inputs/CheckboxGroup.tsx +1 -4
- package/src/Form/Inputs/index.tsx +1 -1
- package/src/Graph/LineChart/BasicComponents/Lines/Threshold/Circle.tsx +2 -2
- package/src/Graph/LineChart/BasicComponents/Lines/Threshold/index.tsx +5 -4
- 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/Annotation/index.tsx +2 -3
- package/src/Graph/LineChart/InteractiveComponents/Annotations/EventAnnotations.tsx +1 -1
- 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/SingleBar/Thresholds.tsx +2 -2
- package/src/Graph/Text/Text.stories.tsx +60 -4
- package/src/Graph/common/timeSeries/index.ts +3 -3
- 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/IconPopover/index.tsx +2 -2
- package/src/InputField/Select/index.tsx +1 -1
- package/src/Listing/Header/ListingHeader.tsx +1 -1
- package/src/Listing/Listing.styles.ts +2 -3
- package/src/Listing/index.stories.tsx +12 -1
- package/src/Listing/index.tsx +1 -2
- package/src/RichTextEditor/RichTextEditor.tsx +12 -1
- package/src/SortableItems/index.tsx +2 -7
- package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/PickersStartEndDate.tsx +8 -3
- package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/models.ts +0 -2
- package/src/TimePeriods/DateTimePickerInput.tsx +45 -17
- 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/api/QueryProvider.tsx +1 -1
- package/src/api/TestQueryProvider.tsx +1 -1
- package/src/api/useFetchQuery/index.ts +27 -23
- package/src/api/useMutationQuery/index.ts +39 -17
- package/src/components/DataTable/DataListing.tsx +6 -0
- package/src/components/DataTable/DataTable.cypress.spec.tsx +193 -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 +2 -2
- package/src/components/DataTable/index.ts +3 -1
- package/src/components/Form/AccessRights/__fixtures__/contactAccessRight.mock.ts +2 -0
- package/src/components/Form/AccessRights/useAccessRightsForm.utils.ts +1 -1
- package/src/components/Form/Dashboard/DashboardForm.tsx +15 -12
- package/src/components/Modal/Modal.styles.ts +4 -2
- package/src/index.ts +1 -0
- package/src/queryParameters/url/index.ts +5 -1
- package/src/utils/index.ts +0 -1
- package/src/utils/{useLicenseExpirationWarning.cypress.spec.tsx → useLicenseExpirationWarning.test.tsx} +48 -37
- package/src/utils/useLicenseExpirationWarning.ts +18 -18
- 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,193 @@
|
|
|
1
|
+
import { Box } from '@mui/material';
|
|
2
|
+
|
|
3
|
+
import { ColumnType } from '../../Listing/models';
|
|
4
|
+
|
|
5
|
+
import { DataTable } from '.';
|
|
6
|
+
|
|
7
|
+
const data = Array(5)
|
|
8
|
+
.fill(0)
|
|
9
|
+
.map((_, idx) => ({
|
|
10
|
+
description: `Description ${idx}`,
|
|
11
|
+
id: idx,
|
|
12
|
+
title: `Entity ${idx}`
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
const initializeDataTableGrid = ({
|
|
16
|
+
hasActions,
|
|
17
|
+
hasCardAction,
|
|
18
|
+
canDelete
|
|
19
|
+
}): void => {
|
|
20
|
+
cy.viewport(1200, 590);
|
|
21
|
+
cy.mount({
|
|
22
|
+
Component: (
|
|
23
|
+
<DataTable variant="grid">
|
|
24
|
+
{data.map(({ title, description }) => (
|
|
25
|
+
<DataTable.Item
|
|
26
|
+
description={description}
|
|
27
|
+
hasActions={hasActions}
|
|
28
|
+
hasCardAction={hasCardAction}
|
|
29
|
+
key={title}
|
|
30
|
+
labelsDelete={{
|
|
31
|
+
cancel: 'Cancel',
|
|
32
|
+
confirm: {
|
|
33
|
+
label: 'Delete'
|
|
34
|
+
}
|
|
35
|
+
}}
|
|
36
|
+
title={title}
|
|
37
|
+
onDelete={canDelete ? cy.stub() : undefined}
|
|
38
|
+
/>
|
|
39
|
+
))}
|
|
40
|
+
</DataTable>
|
|
41
|
+
)
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const initializeDataTableEmpty = (canCreate = false): void => {
|
|
46
|
+
cy.viewport(1200, 590);
|
|
47
|
+
cy.mount({
|
|
48
|
+
Component: (
|
|
49
|
+
<DataTable isEmpty variant="grid">
|
|
50
|
+
<DataTable.EmptyState
|
|
51
|
+
canCreate={canCreate}
|
|
52
|
+
labels={{
|
|
53
|
+
actions: {
|
|
54
|
+
create: 'Create'
|
|
55
|
+
},
|
|
56
|
+
title: 'Welcome'
|
|
57
|
+
}}
|
|
58
|
+
onCreate={cy.stub()}
|
|
59
|
+
/>
|
|
60
|
+
</DataTable>
|
|
61
|
+
)
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const initializeDataTableListing = (): void => {
|
|
66
|
+
cy.viewport(1200, 590);
|
|
67
|
+
cy.mount({
|
|
68
|
+
Component: (
|
|
69
|
+
<Box sx={{ height: '100vh' }}>
|
|
70
|
+
<DataTable variant="listing">
|
|
71
|
+
<DataTable.Listing
|
|
72
|
+
columns={[
|
|
73
|
+
{
|
|
74
|
+
getFormattedString: (row) => row.title,
|
|
75
|
+
id: 'title',
|
|
76
|
+
label: 'Title',
|
|
77
|
+
type: ColumnType.string
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
getFormattedString: (row) => row.description,
|
|
81
|
+
id: 'description',
|
|
82
|
+
label: 'Description',
|
|
83
|
+
type: ColumnType.string
|
|
84
|
+
}
|
|
85
|
+
]}
|
|
86
|
+
rows={data}
|
|
87
|
+
/>
|
|
88
|
+
</DataTable>
|
|
89
|
+
</Box>
|
|
90
|
+
)
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
describe('DataTable: Grid', () => {
|
|
95
|
+
it('displays items with title and description only', () => {
|
|
96
|
+
initializeDataTableGrid({
|
|
97
|
+
canDelete: false,
|
|
98
|
+
hasActions: false,
|
|
99
|
+
hasCardAction: false
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
data.forEach(({ title, description }) => {
|
|
103
|
+
cy.contains(title).should('be.visible');
|
|
104
|
+
cy.contains(description).should('be.visible');
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
cy.makeSnapshot();
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('displays items with actions', () => {
|
|
111
|
+
initializeDataTableGrid({
|
|
112
|
+
canDelete: false,
|
|
113
|
+
hasActions: true,
|
|
114
|
+
hasCardAction: false
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
cy.findAllByLabelText('edit access rights').should('have.length', 5);
|
|
118
|
+
cy.findAllByLabelText('edit').should('have.length', 5);
|
|
119
|
+
|
|
120
|
+
cy.makeSnapshot();
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('displays items with delete action', () => {
|
|
124
|
+
initializeDataTableGrid({
|
|
125
|
+
canDelete: true,
|
|
126
|
+
hasActions: true,
|
|
127
|
+
hasCardAction: false
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
cy.findAllByLabelText('delete').should('have.length', 5);
|
|
131
|
+
|
|
132
|
+
cy.makeSnapshot();
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('displays items with card action only', () => {
|
|
136
|
+
initializeDataTableGrid({
|
|
137
|
+
canDelete: false,
|
|
138
|
+
hasActions: false,
|
|
139
|
+
hasCardAction: true
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
cy.findAllByLabelText('view').should('have.length', 5);
|
|
143
|
+
|
|
144
|
+
cy.makeSnapshot();
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('displays items with card action and bottom actions', () => {
|
|
148
|
+
initializeDataTableGrid({
|
|
149
|
+
canDelete: true,
|
|
150
|
+
hasActions: true,
|
|
151
|
+
hasCardAction: true
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
cy.findAllByLabelText('view').should('have.length', 5);
|
|
155
|
+
cy.findAllByLabelText('delete').should('have.length', 5);
|
|
156
|
+
cy.findAllByLabelText('edit access rights').should('have.length', 5);
|
|
157
|
+
cy.findAllByLabelText('edit').should('have.length', 5);
|
|
158
|
+
|
|
159
|
+
cy.makeSnapshot();
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
describe('DataTable: Empty', () => {
|
|
164
|
+
it('displays the title', () => {
|
|
165
|
+
initializeDataTableEmpty();
|
|
166
|
+
|
|
167
|
+
cy.contains('Welcome').should('be.visible');
|
|
168
|
+
|
|
169
|
+
cy.makeSnapshot();
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('displays the title and the action button', () => {
|
|
173
|
+
initializeDataTableEmpty(true);
|
|
174
|
+
|
|
175
|
+
cy.contains('Welcome').should('be.visible');
|
|
176
|
+
cy.contains('Create').should('be.visible');
|
|
177
|
+
|
|
178
|
+
cy.makeSnapshot();
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
describe('DataTable: Listing', () => {
|
|
183
|
+
it('displays the listing', () => {
|
|
184
|
+
initializeDataTableListing();
|
|
185
|
+
|
|
186
|
+
data.forEach(({ title, description }) => {
|
|
187
|
+
cy.contains(title).should('be.visible');
|
|
188
|
+
cy.contains(description).should('be.visible');
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
cy.makeSnapshot();
|
|
192
|
+
});
|
|
193
|
+
});
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { Meta, StoryObj } from '@storybook/react';
|
|
2
2
|
|
|
3
|
+
import { Box } from '@mui/material';
|
|
4
|
+
|
|
5
|
+
import { ColumnType } from '../../Listing/models';
|
|
6
|
+
|
|
3
7
|
import { DataTable } from './index';
|
|
4
8
|
|
|
5
9
|
const meta: Meta<typeof DataTable> = {
|
|
@@ -49,3 +53,39 @@ export const withFixedHeightContainer: Story = {
|
|
|
49
53
|
</div>
|
|
50
54
|
)
|
|
51
55
|
};
|
|
56
|
+
|
|
57
|
+
const ListingTemplate = (args): JSX.Element => (
|
|
58
|
+
<Box sx={{ height: '80vh' }}>
|
|
59
|
+
<DataTable {...args} />
|
|
60
|
+
</Box>
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
export const listing: Story = {
|
|
64
|
+
args: {
|
|
65
|
+
children: (
|
|
66
|
+
<DataTable.Listing
|
|
67
|
+
columns={[
|
|
68
|
+
{
|
|
69
|
+
getFormattedString: (row) => row.title,
|
|
70
|
+
id: 'title',
|
|
71
|
+
label: 'Title',
|
|
72
|
+
type: ColumnType.string
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
getFormattedString: (row) => row.description,
|
|
76
|
+
id: 'description',
|
|
77
|
+
label: 'Description',
|
|
78
|
+
type: ColumnType.string
|
|
79
|
+
}
|
|
80
|
+
]}
|
|
81
|
+
rows={[...Array(5)].map((_, i) => ({
|
|
82
|
+
description: `Item description ${i}`,
|
|
83
|
+
id: i,
|
|
84
|
+
title: `Item ${i}`
|
|
85
|
+
}))}
|
|
86
|
+
/>
|
|
87
|
+
),
|
|
88
|
+
variant: 'listing'
|
|
89
|
+
},
|
|
90
|
+
render: ListingTemplate
|
|
91
|
+
};
|
|
@@ -10,6 +10,9 @@ const useStyles = makeStyles()((theme) => ({
|
|
|
10
10
|
gridGap: theme.spacing(2.5),
|
|
11
11
|
gridTemplateColumns: `repeat(auto-fill, ${theme.spacing(45)})`
|
|
12
12
|
},
|
|
13
|
+
'&[data-variant="listing"]': {
|
|
14
|
+
height: '100%'
|
|
15
|
+
},
|
|
13
16
|
'&[data-variant][data-is-empty="true"]': {
|
|
14
17
|
display: 'flex',
|
|
15
18
|
justifyContent: 'center',
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ReactElement, ReactNode } from 'react';
|
|
2
2
|
|
|
3
3
|
import { useStyles } from './DataTable.styles';
|
|
4
4
|
|
|
5
5
|
type DataTableProps = {
|
|
6
|
-
children
|
|
6
|
+
children?: ReactNode | Array<ReactNode>;
|
|
7
7
|
isEmpty?: boolean;
|
|
8
|
-
variant
|
|
8
|
+
variant: 'grid' | 'listing';
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
/** *
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { makeStyles } from 'tss-react/mui';
|
|
2
2
|
|
|
3
3
|
const useStyles = makeStyles()((theme) => ({
|
|
4
|
+
actions: {
|
|
5
|
+
display: 'flex',
|
|
6
|
+
flexDirection: 'row',
|
|
7
|
+
justifyContent: 'space-between'
|
|
8
|
+
},
|
|
4
9
|
dataTableItem: {
|
|
5
10
|
'& .MuiCardActionArea-root': {
|
|
6
11
|
alignItems: 'flex-start',
|
|
7
12
|
display: 'flex',
|
|
8
13
|
flexDirection: 'column',
|
|
9
14
|
height: '100%',
|
|
10
|
-
justifyContent: '
|
|
15
|
+
justifyContent: 'flex-start'
|
|
11
16
|
},
|
|
12
17
|
'& .MuiCardActions-root': {
|
|
13
18
|
'& > span': {
|
|
@@ -15,13 +20,13 @@ const useStyles = makeStyles()((theme) => ({
|
|
|
15
20
|
gap: theme.spacing(1)
|
|
16
21
|
},
|
|
17
22
|
display: 'flex',
|
|
18
|
-
|
|
19
23
|
justifyContent: 'space-between'
|
|
20
24
|
},
|
|
21
25
|
borderRadius: theme.shape.borderRadius,
|
|
22
26
|
display: 'flex',
|
|
23
27
|
flexDirection: 'column',
|
|
24
28
|
height: '186px',
|
|
29
|
+
justifyContent: 'space-between',
|
|
25
30
|
p: {
|
|
26
31
|
color: theme.palette.text.secondary,
|
|
27
32
|
letterSpacing: '0',
|
|
@@ -22,7 +22,7 @@ export interface DataTableItemProps {
|
|
|
22
22
|
description?: string;
|
|
23
23
|
hasActions?: boolean;
|
|
24
24
|
hasCardAction?: boolean;
|
|
25
|
-
labelsDelete
|
|
25
|
+
labelsDelete?: {
|
|
26
26
|
cancel: string;
|
|
27
27
|
confirm: {
|
|
28
28
|
label: string;
|
|
@@ -76,7 +76,7 @@ const DataTableItem = forwardRef(
|
|
|
76
76
|
{hasActions && (
|
|
77
77
|
<MuiCardActions>
|
|
78
78
|
<span>
|
|
79
|
-
{onDelete && (
|
|
79
|
+
{onDelete && labelsDelete && (
|
|
80
80
|
<ConfirmationTooltip
|
|
81
81
|
confirmVariant="error"
|
|
82
82
|
labels={labelsDelete}
|
|
@@ -2,9 +2,11 @@ import { DataTable as DataTableRoot } from './DataTable';
|
|
|
2
2
|
import { DataTableItem } from './Item/DataTableItem';
|
|
3
3
|
import { DataTableItemSkeleton } from './Item/DataTableItemSkeleton';
|
|
4
4
|
import { DataTableEmptyState } from './EmptyState/DataTableEmptyState';
|
|
5
|
+
import { DataListing } from './DataListing';
|
|
5
6
|
|
|
6
7
|
export const DataTable = Object.assign(DataTableRoot, {
|
|
7
8
|
EmptyState: DataTableEmptyState,
|
|
8
9
|
Item: DataTableItem,
|
|
9
|
-
ItemSkeleton: DataTableItemSkeleton
|
|
10
|
+
ItemSkeleton: DataTableItemSkeleton,
|
|
11
|
+
Listing: DataListing
|
|
10
12
|
});
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ReactElement, useCallback, useMemo } from 'react';
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import { string, number, object } from 'yup';
|
|
4
4
|
import { useTranslation } from 'react-i18next';
|
|
5
|
+
import { equals } from 'ramda';
|
|
5
6
|
|
|
6
7
|
import { InputType } from '../../../Form/Inputs/models';
|
|
7
8
|
import { Form, FormProps } from '../../../Form';
|
|
@@ -84,8 +85,8 @@ const DashboardForm = ({
|
|
|
84
85
|
}
|
|
85
86
|
],
|
|
86
87
|
submit: (values, bag) => onSubmit?.(values, bag),
|
|
87
|
-
validationSchema:
|
|
88
|
-
description:
|
|
88
|
+
validationSchema: object({
|
|
89
|
+
description: string()
|
|
89
90
|
.label(labels?.entity?.description || '')
|
|
90
91
|
.max(
|
|
91
92
|
180,
|
|
@@ -93,17 +94,19 @@ const DashboardForm = ({
|
|
|
93
94
|
`${p.label} ${t(labelMustBeMost)} ${p.max} ${t(labelCharacters)}`
|
|
94
95
|
)
|
|
95
96
|
.nullable(),
|
|
96
|
-
globalRefreshInterval:
|
|
97
|
-
interval:
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
97
|
+
globalRefreshInterval: object({
|
|
98
|
+
interval: number().when('type', ([type], schema) => {
|
|
99
|
+
if (equals(type, 'manual')) {
|
|
100
|
+
schema
|
|
101
|
+
.min(1, ({ min }) => t(labelMustBeAtLeast, { min }))
|
|
102
|
+
.required(t(labelRequired) as string);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return schema.nullable();
|
|
103
106
|
}),
|
|
104
|
-
type:
|
|
107
|
+
type: string()
|
|
105
108
|
}),
|
|
106
|
-
name:
|
|
109
|
+
name: string()
|
|
107
110
|
.label(labels?.entity?.name)
|
|
108
111
|
.min(3, ({ min, label }) => t(labelMustBeAtLeast, { label, min }))
|
|
109
112
|
.max(50, ({ max, label }) => t(labelMustBeMost, { label, max }))
|
|
@@ -24,9 +24,9 @@ const useStyles = makeStyles<{
|
|
|
24
24
|
},
|
|
25
25
|
'&[data-size="fullscreen"] .MuiDialog-paper': {
|
|
26
26
|
bottom: props?.bottom ?? 0,
|
|
27
|
+
height: 'calc(100vh - 90px)',
|
|
27
28
|
left: props?.left ?? 0,
|
|
28
29
|
margin: 0,
|
|
29
|
-
maxHeight: 'unset',
|
|
30
30
|
maxWidth: 'unset',
|
|
31
31
|
position: 'absolute',
|
|
32
32
|
right: props?.right ?? 0,
|
|
@@ -50,11 +50,13 @@ const useStyles = makeStyles<{
|
|
|
50
50
|
},
|
|
51
51
|
modalActions: {
|
|
52
52
|
bottom: 0,
|
|
53
|
+
bottom: theme.spacing(2),
|
|
53
54
|
display: 'flex',
|
|
54
55
|
flexDirection: 'row',
|
|
55
56
|
gap: theme.spacing(2),
|
|
56
57
|
justifyContent: 'flex-end',
|
|
57
|
-
position: '
|
|
58
|
+
position: 'fixed',
|
|
59
|
+
right: theme.spacing(2)
|
|
58
60
|
},
|
|
59
61
|
modalBody: {
|
|
60
62
|
'& > p': {
|
package/src/index.ts
CHANGED
|
@@ -162,4 +162,5 @@ export * from './Graph/common/timeSeries';
|
|
|
162
162
|
|
|
163
163
|
export { default as TimePeriods } from './TimePeriods';
|
|
164
164
|
export { default as SimpleCustomTimePeriod } from './TimePeriods/CustomTimePeriod/SimpleCustomTimePeriod';
|
|
165
|
+
export { default as DateTimePickerInput } from './TimePeriods/DateTimePickerInput';
|
|
165
166
|
export * from './ParentSize';
|
|
@@ -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';
|
|
@@ -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
|
};
|