@centreon/ui 24.4.4 → 24.4.6

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.
Files changed (66) hide show
  1. package/package.json +12 -16
  2. package/src/Button/Save/StartIcon.tsx +3 -3
  3. package/src/Dashboard/Item.tsx +1 -1
  4. package/src/Dashboard/Layout.tsx +2 -2
  5. package/src/FileDropZone/index.tsx +1 -3
  6. package/src/Form/Inputs/CheckboxGroup.tsx +4 -1
  7. package/src/Form/Inputs/index.tsx +1 -1
  8. package/src/Graph/HeatMap/HeatMap.styles.tsx +0 -1
  9. package/src/Graph/HeatMap/ResponsiveHeatMap.tsx +8 -12
  10. package/src/Graph/HeatMap/model.ts +0 -1
  11. package/src/Graph/LineChart/BasicComponents/Lines/Threshold/Circle.tsx +2 -2
  12. package/src/Graph/LineChart/BasicComponents/Lines/Threshold/index.tsx +4 -5
  13. package/src/Graph/LineChart/BasicComponents/Thresholds.tsx +2 -2
  14. package/src/Graph/LineChart/BasicComponents/useFilterLines.ts +1 -1
  15. package/src/Graph/LineChart/InteractiveComponents/AnchorPoint/GuidingLines.tsx +2 -2
  16. package/src/Graph/LineChart/InteractiveComponents/Annotations/Annotation/index.tsx +3 -2
  17. package/src/Graph/LineChart/InteractiveComponents/Annotations/EventAnnotations.tsx +1 -1
  18. package/src/Graph/LineChart/Legend/useLegend.ts +3 -3
  19. package/src/Graph/LineChart/helpers/doc.ts +13 -16
  20. package/src/Graph/LineChart/helpers/index.ts +1 -1
  21. package/src/Graph/LineChart/index.stories.tsx +2 -4
  22. package/src/Graph/SingleBar/Thresholds.tsx +2 -2
  23. package/src/Graph/Text/Text.stories.tsx +4 -60
  24. package/src/Graph/common/timeSeries/index.ts +3 -3
  25. package/src/InputField/Select/Autocomplete/Connected/Multi/index.test.tsx +0 -1
  26. package/src/InputField/Select/Autocomplete/Connected/index.test.tsx +0 -1
  27. package/src/InputField/Select/Autocomplete/Connected/index.tsx +7 -13
  28. package/src/InputField/Select/Autocomplete/Draggable/SortableList.tsx +1 -1
  29. package/src/InputField/Select/Autocomplete/Draggable/SortableListContent.tsx +1 -1
  30. package/src/InputField/Select/Autocomplete/Draggable/index.tsx +1 -1
  31. package/src/InputField/Select/IconPopover/index.tsx +2 -2
  32. package/src/InputField/Select/index.tsx +1 -1
  33. package/src/InputField/Text/index.tsx +1 -6
  34. package/src/Listing/Header/ListingHeader.tsx +1 -1
  35. package/src/Listing/index.stories.tsx +1 -12
  36. package/src/Listing/index.tsx +1 -1
  37. package/src/RichTextEditor/RichTextEditor.tsx +1 -12
  38. package/src/SortableItems/index.tsx +7 -2
  39. package/src/ThemeProvider/palettes.ts +4 -4
  40. package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/PickersStartEndDate.tsx +3 -8
  41. package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/models.ts +2 -0
  42. package/src/TimePeriods/DateTimePickerInput.tsx +17 -45
  43. package/src/TimePeriods/TimePeriods.cypress.spec.tsx +33 -9
  44. package/src/TimePeriods/helpers/index.ts +1 -1
  45. package/src/TimePeriods/index.stories.tsx +4 -12
  46. package/src/TimePeriods/index.tsx +2 -2
  47. package/src/api/QueryProvider.tsx +1 -1
  48. package/src/api/TestQueryProvider.tsx +1 -1
  49. package/src/api/buildListingEndpoint/models.ts +1 -2
  50. package/src/api/customFetch.ts +3 -12
  51. package/src/api/useFetchQuery/index.ts +28 -43
  52. package/src/api/useMutationQuery/index.ts +18 -43
  53. package/src/components/DataTable/Item/DataTableItem.tsx +2 -2
  54. package/src/components/Form/AccessRights/__fixtures__/contactAccessRight.mock.ts +0 -2
  55. package/src/components/Form/AccessRights/useAccessRightsForm.utils.ts +1 -1
  56. package/src/components/Form/Dashboard/DashboardForm.tsx +12 -15
  57. package/src/index.ts +0 -1
  58. package/src/queryParameters/url/index.ts +1 -5
  59. package/src/screens/dashboard/DashboardsDetail.stories.tsx +108 -0
  60. package/src/screens/dashboard/DashboardsOverview.stories.tsx +281 -0
  61. package/src/utils/index.ts +1 -0
  62. package/src/utils/useDateTimePickerAdapter.ts +309 -0
  63. package/src/utils/useInfiniteScrollListing.ts +7 -22
  64. package/src/utils/{useLicenseExpirationWarning.test.tsx → useLicenseExpirationWarning.cypress.spec.tsx} +37 -48
  65. package/src/utils/useLicenseExpirationWarning.ts +18 -18
  66. package/src/utils/useLocaleDateTimeFormat/index.ts +0 -3
@@ -1,13 +1,6 @@
1
1
  import dayjs from 'dayjs';
2
- import { renderHook } from '@testing-library/react';
3
2
 
4
- import {
5
- getFetchCall,
6
- mockResponse,
7
- resetMocks,
8
- waitFor
9
- } from '../../test/testRenderer';
10
- import TestQueryProvider from '../api/TestQueryProvider';
3
+ import { TestQueryProvider, Method, SnackbarProvider } from '@centreon/ui';
11
4
 
12
5
  import { labelLicenseWarning } from './translatedLabel';
13
6
 
@@ -86,63 +79,59 @@ const getMockedResponse = (expirationDate): object => ({
86
79
  });
87
80
 
88
81
  const mockRequest = ({ expirationDate }: { expirationDate }): void => {
89
- resetMocks();
90
- mockResponse({
91
- data: getMockedResponse(expirationDate)
82
+ cy.interceptAPIRequest({
83
+ alias: 'getLicenseInformations',
84
+ method: Method.GET,
85
+ path: '**internal.php?object=centreon_module&action=list',
86
+ response: getMockedResponse(expirationDate)
92
87
  });
93
88
  };
94
89
 
95
- const showMessage = jest.fn();
90
+ const TestComponent = (): JSX.Element => {
91
+ useLicenseExpirationWarning({
92
+ module: 'centreon-autodiscovery-server'
93
+ });
96
94
 
97
- jest.mock('../Snackbar/useSnackbar', () => ({
98
- __esModule: true,
99
- default: jest
100
- .fn()
101
- .mockImplementation(() => ({ showWarningMessage: showMessage }))
102
- }));
95
+ return <div />;
96
+ };
103
97
 
104
- const initialize = (): void => {
105
- renderHook(
106
- () =>
107
- useLicenseExpirationWarning({
108
- module: 'centreon-autodiscovery-server'
109
- }),
110
- {
111
- wrapper: TestQueryProvider
112
- }
98
+ const TestWithQueryProvider = (): JSX.Element => {
99
+ return (
100
+ <TestQueryProvider>
101
+ <SnackbarProvider>
102
+ <TestComponent />
103
+ </SnackbarProvider>
104
+ </TestQueryProvider>
113
105
  );
114
106
  };
115
107
 
108
+ const initialize = (): void => {
109
+ cy.viewport('macbook-13');
110
+
111
+ cy.mount({
112
+ Component: <TestWithQueryProvider />
113
+ });
114
+ };
115
+
116
116
  const currentDate = dayjs();
117
117
 
118
118
  describe('License', () => {
119
+ beforeEach(initialize);
120
+
119
121
  it('does not display any warning message when the license expires in more than 15 days from the current date', () => {
120
122
  mockRequest({ expirationDate: currentDate.add(20, 'day') });
121
- initialize();
122
123
 
123
- waitFor(() => {
124
- expect(getFetchCall(0)).toEqual(
125
- 'internal.php?object=centreon_module&action=list'
126
- );
127
- });
124
+ cy.waitForRequest('@getLicenseInformations');
128
125
 
129
- expect(showMessage).not.toHaveBeenCalled();
126
+ cy.findByText(
127
+ labelLicenseWarning('centreon-autodiscovery-server', 20)
128
+ ).should('not.exist');
130
129
  });
131
-
132
130
  it('displays a warning message when the license expires within 15 days', () => {
133
131
  mockRequest({ expirationDate: currentDate.add(10.5, 'day') });
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
- });
132
+
133
+ cy.findByText(labelLicenseWarning('centreon-autodiscovery-server', 10));
134
+
135
+ cy.makeSnapshot();
147
136
  });
148
137
  });
@@ -19,7 +19,7 @@ export const useLicenseExpirationWarning = ({ module }: Props): void => {
19
19
  const { t } = useTranslation();
20
20
  const { showWarningMessage } = useSnackbar();
21
21
 
22
- const { data } = useFetchQuery({
22
+ const { fetchQuery } = 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(module, 'id')),
31
+ find(propEq('id', module)),
32
32
  path(['license', 'expiration_date'])
33
33
  ) as (data) => string;
34
34
 
35
35
  useEffect(() => {
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]);
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
52
  };
@@ -1,7 +1,6 @@
1
1
  import dayjs from 'dayjs';
2
2
  import humanizeDuration from 'humanize-duration';
3
3
  import { useAtomValue } from 'jotai';
4
- import localizedFormat from 'dayjs/plugin/localizedFormat';
5
4
 
6
5
  import { userAtom } from '@centreon/ui-context';
7
6
 
@@ -21,8 +20,6 @@ export interface LocaleDateTimeFormat {
21
20
  toTime: (date: Date | string) => string;
22
21
  }
23
22
 
24
- dayjs.extend(localizedFormat);
25
-
26
23
  const dateFormat = 'L';
27
24
  const timeFormat = 'LT';
28
25
  const dateTimeFormat = `${dateFormat} ${timeFormat}`;