@centreon/ui 23.10.53 → 23.10.54
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
CHANGED
package/src/utils/index.ts
CHANGED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
|
|
3
|
+
import { TestQueryProvider, Method, SnackbarProvider } from '@centreon/ui';
|
|
4
|
+
|
|
5
|
+
import { labelLicenseWarning } from './translatedLabel';
|
|
6
|
+
|
|
7
|
+
import { useLicenseExpirationWarning } from '.';
|
|
8
|
+
|
|
9
|
+
const getMockedResponse = (expirationDate): object => ({
|
|
10
|
+
result: {
|
|
11
|
+
module: {
|
|
12
|
+
entities: [
|
|
13
|
+
{
|
|
14
|
+
description: 'Centreon Auto Discovery',
|
|
15
|
+
id: 'centreon-autodiscovery-server',
|
|
16
|
+
label: 'Centreon',
|
|
17
|
+
license: {
|
|
18
|
+
expiration_date: expirationDate,
|
|
19
|
+
host_limit: -1,
|
|
20
|
+
host_usage: 1,
|
|
21
|
+
is_valid: true,
|
|
22
|
+
required: true
|
|
23
|
+
},
|
|
24
|
+
type: 'module',
|
|
25
|
+
version: {
|
|
26
|
+
available: '23.10.0',
|
|
27
|
+
current: '23.10.0',
|
|
28
|
+
installed: true,
|
|
29
|
+
outdated: false
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
description: 'Centreon License Manager',
|
|
34
|
+
id: 'centreon-license-manager',
|
|
35
|
+
label: 'Centreon',
|
|
36
|
+
license: {
|
|
37
|
+
required: false
|
|
38
|
+
},
|
|
39
|
+
type: 'module',
|
|
40
|
+
version: {
|
|
41
|
+
available: '23.10.0',
|
|
42
|
+
current: '23.10.0',
|
|
43
|
+
installed: true,
|
|
44
|
+
outdated: false
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
description: 'Centreon Monitoring Connectors Manager',
|
|
49
|
+
id: 'centreon-pp-manager',
|
|
50
|
+
label: 'Centreon',
|
|
51
|
+
license: {
|
|
52
|
+
required: false
|
|
53
|
+
},
|
|
54
|
+
type: 'module',
|
|
55
|
+
version: {
|
|
56
|
+
available: '23.10.0',
|
|
57
|
+
current: '23.10.0',
|
|
58
|
+
installed: true,
|
|
59
|
+
outdated: false
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
],
|
|
63
|
+
pagination: {
|
|
64
|
+
limit: 3,
|
|
65
|
+
offset: 0,
|
|
66
|
+
total: 3
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
widget: {
|
|
70
|
+
entities: [],
|
|
71
|
+
pagination: {
|
|
72
|
+
limit: 0,
|
|
73
|
+
offset: 0,
|
|
74
|
+
total: 0
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
status: true
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const mockRequest = ({ expirationDate }: { expirationDate }): void => {
|
|
82
|
+
cy.interceptAPIRequest({
|
|
83
|
+
alias: 'getLicenseInformations',
|
|
84
|
+
method: Method.GET,
|
|
85
|
+
path: '**internal.php?object=centreon_module&action=list',
|
|
86
|
+
response: getMockedResponse(expirationDate)
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const TestComponent = (): JSX.Element => {
|
|
91
|
+
useLicenseExpirationWarning({
|
|
92
|
+
module: 'centreon-autodiscovery-server'
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
return <div />;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const TestWithQueryProvider = (): JSX.Element => {
|
|
99
|
+
return (
|
|
100
|
+
<TestQueryProvider>
|
|
101
|
+
<SnackbarProvider>
|
|
102
|
+
<TestComponent />
|
|
103
|
+
</SnackbarProvider>
|
|
104
|
+
</TestQueryProvider>
|
|
105
|
+
);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const initialize = (): void => {
|
|
109
|
+
cy.viewport('macbook-13');
|
|
110
|
+
|
|
111
|
+
cy.mount({
|
|
112
|
+
Component: <TestWithQueryProvider />
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const currentDate = dayjs();
|
|
117
|
+
|
|
118
|
+
describe('License', () => {
|
|
119
|
+
beforeEach(initialize);
|
|
120
|
+
|
|
121
|
+
it('does not display any warning message when the license expires in more than 15 days from the current date', () => {
|
|
122
|
+
mockRequest({ expirationDate: currentDate.add(20, 'day') });
|
|
123
|
+
|
|
124
|
+
cy.waitForRequest('@getLicenseInformations');
|
|
125
|
+
|
|
126
|
+
cy.findByText(
|
|
127
|
+
labelLicenseWarning('centreon-autodiscovery-server', 20)
|
|
128
|
+
).should('not.exist');
|
|
129
|
+
});
|
|
130
|
+
it('displays a warning message when the license expires within 15 days', () => {
|
|
131
|
+
mockRequest({ expirationDate: currentDate.add(10.5, 'day') });
|
|
132
|
+
|
|
133
|
+
cy.findByText(labelLicenseWarning('centreon-autodiscovery-server', 10));
|
|
134
|
+
|
|
135
|
+
cy.matchImageSnapshot();
|
|
136
|
+
});
|
|
137
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
import dayjs from 'dayjs';
|
|
4
|
+
import { path, pipe, propEq, find, lt, isNil } from 'ramda';
|
|
5
|
+
import { useTranslation } from 'react-i18next';
|
|
6
|
+
|
|
7
|
+
import { useFetchQuery, useSnackbar } from '..';
|
|
8
|
+
|
|
9
|
+
import { labelLicenseWarning } from './translatedLabel';
|
|
10
|
+
|
|
11
|
+
const legacyBaseEndpoint = './api/internal.php';
|
|
12
|
+
const extensionsEndpoint = `${legacyBaseEndpoint}?object=centreon_module&action=list`;
|
|
13
|
+
|
|
14
|
+
interface Props {
|
|
15
|
+
module: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const useLicenseExpirationWarning = ({ module }: Props): void => {
|
|
19
|
+
const { t } = useTranslation();
|
|
20
|
+
const { showWarningMessage } = useSnackbar();
|
|
21
|
+
|
|
22
|
+
const { fetchQuery } = useFetchQuery({
|
|
23
|
+
getEndpoint: () => extensionsEndpoint,
|
|
24
|
+
getQueryKey: () => [module]
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const currentDate = dayjs();
|
|
28
|
+
|
|
29
|
+
const getExpirationDate = pipe(
|
|
30
|
+
path(['result', 'module', 'entities']),
|
|
31
|
+
find(propEq('id', module)),
|
|
32
|
+
path(['license', 'expiration_date'])
|
|
33
|
+
) as (data) => string;
|
|
34
|
+
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
fetchQuery().then((response) => {
|
|
37
|
+
const expirationDate = getExpirationDate(response);
|
|
38
|
+
if (isNil(expirationDate)) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const daysUntilExpiration = dayjs(expirationDate).diff(
|
|
43
|
+
currentDate,
|
|
44
|
+
'day'
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
if (lt(daysUntilExpiration, 15)) {
|
|
48
|
+
showWarningMessage(t(labelLicenseWarning(module, daysUntilExpiration)));
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}, []);
|
|
52
|
+
};
|