@centreon/ui 23.10.30-MON-19324-dashboard-section-navigation.3 → 23.10.30

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 (205) hide show
  1. package/package.json +9 -12
  2. package/src/@assets/icons/downtime.icon.svg +1 -0
  3. package/src/Dashboard/DashboardLayout.stories.tsx +5 -3
  4. package/src/Dashboard/Layout.tsx +4 -4
  5. package/src/Dashboard/utils.ts +28 -28
  6. package/src/Graph/BasicComponents/Axes/UnitLabel.tsx +20 -0
  7. package/src/Graph/BasicComponents/Axes/index.tsx +88 -0
  8. package/src/Graph/BasicComponents/Axes/models.ts +26 -0
  9. package/src/Graph/BasicComponents/Axes/useAxisY.ts +100 -0
  10. package/src/Graph/BasicComponents/Grids/index.tsx +20 -0
  11. package/src/Graph/BasicComponents/Lines/RegularLines/index.tsx +91 -0
  12. package/src/Graph/BasicComponents/Lines/RegularLines/useRegularLines.ts +15 -0
  13. package/src/Graph/BasicComponents/Lines/StackedLines/index.tsx +76 -0
  14. package/src/Graph/BasicComponents/Lines/StackedLines/useStackedLines.ts +39 -0
  15. package/src/Graph/BasicComponents/Lines/Threshold/BasicThreshold.tsx +51 -0
  16. package/src/Graph/BasicComponents/Lines/Threshold/Circle.tsx +43 -0
  17. package/src/Graph/BasicComponents/Lines/Threshold/ThresholdWithPatternLines.tsx +73 -0
  18. package/src/Graph/BasicComponents/Lines/Threshold/ThresholdWithVariation.tsx +59 -0
  19. package/src/Graph/BasicComponents/Lines/Threshold/helpers/index.ts +69 -0
  20. package/src/Graph/BasicComponents/Lines/Threshold/index.tsx +138 -0
  21. package/src/Graph/BasicComponents/Lines/Threshold/models.ts +105 -0
  22. package/src/Graph/BasicComponents/Lines/Threshold/useCoordinateCircle.ts +46 -0
  23. package/src/Graph/BasicComponents/Lines/Threshold/useScaleThreshold.ts +171 -0
  24. package/src/Graph/BasicComponents/Lines/index.tsx +180 -0
  25. package/src/Graph/BasicComponents/Lines/models.ts +42 -0
  26. package/src/Graph/BasicComponents/LoadingProgress.tsx +46 -0
  27. package/src/Graph/BasicComponents/useFilterLines.ts +60 -0
  28. package/src/Graph/Graph.styles.ts +45 -0
  29. package/src/Graph/Graph.tsx +217 -0
  30. package/src/Graph/Header/index.tsx +65 -0
  31. package/src/Graph/Icons/Downtime.tsx +9 -0
  32. package/src/Graph/InteractiveComponents/AnchorPoint/AnchorPoint.styles.ts +58 -0
  33. package/src/Graph/InteractiveComponents/AnchorPoint/GuidingLines.tsx +45 -0
  34. package/src/Graph/InteractiveComponents/AnchorPoint/RegularAnchorPoint.tsx +66 -0
  35. package/src/Graph/InteractiveComponents/AnchorPoint/StackedAnchorPoint.tsx +76 -0
  36. package/src/Graph/InteractiveComponents/AnchorPoint/TooltipAnchorPoint.tsx +70 -0
  37. package/src/Graph/InteractiveComponents/AnchorPoint/index.tsx +20 -0
  38. package/src/Graph/InteractiveComponents/AnchorPoint/models.ts +62 -0
  39. package/src/Graph/InteractiveComponents/AnchorPoint/useTickGraph.ts +94 -0
  40. package/src/Graph/InteractiveComponents/AnchorPoint/useTooltipAnchorPoint.ts +107 -0
  41. package/src/Graph/InteractiveComponents/Annotations/Annotation/Area.tsx +114 -0
  42. package/src/Graph/InteractiveComponents/Annotations/Annotation/Line.tsx +103 -0
  43. package/src/Graph/InteractiveComponents/Annotations/Annotation/index.tsx +81 -0
  44. package/src/Graph/InteractiveComponents/Annotations/Area/Downtime.tsx +27 -0
  45. package/src/Graph/InteractiveComponents/Annotations/EventAnnotations.tsx +61 -0
  46. package/src/Graph/InteractiveComponents/Annotations/Line/Acknowledgement.tsx +27 -0
  47. package/src/Graph/InteractiveComponents/Annotations/Line/Comments.tsx +25 -0
  48. package/src/Graph/InteractiveComponents/Annotations/annotationsAtoms.ts +183 -0
  49. package/src/Graph/InteractiveComponents/Annotations/index.tsx +49 -0
  50. package/src/Graph/InteractiveComponents/Annotations/models.ts +25 -0
  51. package/src/Graph/InteractiveComponents/Annotations/useAnnotation.ts +56 -0
  52. package/src/Graph/InteractiveComponents/Bar.tsx +21 -0
  53. package/src/Graph/InteractiveComponents/TimeShiftZones/TimeShiftIcon.tsx +62 -0
  54. package/src/Graph/InteractiveComponents/TimeShiftZones/TimeShiftZone.tsx +74 -0
  55. package/src/Graph/InteractiveComponents/TimeShiftZones/index.tsx +85 -0
  56. package/src/Graph/InteractiveComponents/TimeShiftZones/models.ts +12 -0
  57. package/src/Graph/InteractiveComponents/TimeShiftZones/useTimeShiftZones.ts +72 -0
  58. package/src/Graph/InteractiveComponents/Tooltip/index.tsx +59 -0
  59. package/src/Graph/InteractiveComponents/Tooltip/models.ts +9 -0
  60. package/src/Graph/InteractiveComponents/Tooltip/useGraphTooltip.ts +67 -0
  61. package/src/Graph/InteractiveComponents/ZoomPreview/index.tsx +38 -0
  62. package/src/Graph/InteractiveComponents/ZoomPreview/models.ts +9 -0
  63. package/src/Graph/InteractiveComponents/ZoomPreview/useZoomPreview.ts +107 -0
  64. package/src/Graph/InteractiveComponents/ZoomPreview/zoomPreviewAtoms.ts +3 -0
  65. package/src/Graph/InteractiveComponents/index.tsx +168 -0
  66. package/src/Graph/InteractiveComponents/interactionWithGraphAtoms.ts +51 -0
  67. package/src/Graph/Legend/InteractiveValue.tsx +22 -0
  68. package/src/Graph/Legend/Legend.styles.ts +71 -0
  69. package/src/Graph/Legend/LegendContent.tsx +27 -0
  70. package/src/Graph/Legend/LegendHeader.tsx +45 -0
  71. package/src/Graph/Legend/Marker.tsx +43 -0
  72. package/src/Graph/Legend/index.tsx +166 -0
  73. package/src/Graph/Legend/models.ts +11 -0
  74. package/src/Graph/Legend/useInteractiveValues.ts +86 -0
  75. package/src/Graph/Legend/useLegend.ts +114 -0
  76. package/src/Graph/LoadingSkeleton.tsx +44 -0
  77. package/src/Graph/common/index.ts +35 -0
  78. package/src/Graph/graphAtoms.ts +6 -0
  79. package/src/Graph/helpers/doc.ts +560 -0
  80. package/src/Graph/helpers/index.ts +58 -0
  81. package/src/Graph/index.stories.tsx +372 -0
  82. package/src/Graph/index.tsx +90 -0
  83. package/src/Graph/mockedData/annotationData.json +326 -0
  84. package/src/Graph/mockedData/exclusionPeriodFirstPeriod.json +588 -0
  85. package/src/Graph/mockedData/exclusionPeriodSecondPeriod.json +588 -0
  86. package/src/Graph/mockedData/exclusionPeriodThirdPeriod.json +581 -0
  87. package/src/Graph/mockedData/lastDay.json +1326 -0
  88. package/src/Graph/mockedData/lastDayAreaStack.json +3106 -0
  89. package/src/Graph/mockedData/lastDayForward.json +1338 -0
  90. package/src/Graph/mockedData/lastDayThreshold.json +2352 -0
  91. package/src/Graph/mockedData/lastMonth.json +1674 -0
  92. package/src/Graph/mockedData/lastWeek.json +2202 -0
  93. package/src/Graph/mockedData/zoomPreview.json +742 -0
  94. package/src/Graph/models.ts +150 -0
  95. package/src/Graph/timeSeries/index.test.ts +506 -0
  96. package/src/Graph/timeSeries/index.ts +512 -0
  97. package/src/Graph/timeSeries/models.ts +120 -0
  98. package/src/Graph/translatedLabels.ts +9 -0
  99. package/src/Graph/useGraphData.ts +47 -0
  100. package/src/Graph/useGraphIntersection.ts +36 -0
  101. package/src/ThemeProvider/index.tsx +5 -6
  102. package/src/ThemeProvider/palettes.ts +215 -385
  103. package/src/TimePeriods/CustomTimePeriod/CompactCustomTimePeriod.styles.ts +51 -0
  104. package/src/TimePeriods/CustomTimePeriod/CompactCustomTimePeriod.tsx +95 -0
  105. package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/ErrorText.tsx +14 -0
  106. package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/PickersStartEndDate.tsx +163 -0
  107. package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/index.tsx +76 -0
  108. package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/models.ts +61 -0
  109. package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/usePickersStartEndDate.ts +82 -0
  110. package/src/TimePeriods/CustomTimePeriod/index.tsx +66 -0
  111. package/src/TimePeriods/DateTimePickerInput.tsx +49 -0
  112. package/src/TimePeriods/ResolutionTimePeriod.cypress.spec.tsx +65 -0
  113. package/src/TimePeriods/SelectedTimePeriod.tsx +102 -0
  114. package/src/TimePeriods/TimePeriods.cypress.spec.tsx +510 -0
  115. package/src/TimePeriods/TimePeriods.styles.ts +22 -0
  116. package/src/TimePeriods/helpers/index.ts +26 -0
  117. package/src/TimePeriods/index.stories.tsx +98 -0
  118. package/src/TimePeriods/index.tsx +78 -0
  119. package/src/TimePeriods/mockedData.ts +12 -0
  120. package/src/TimePeriods/models.ts +97 -0
  121. package/src/TimePeriods/timePeriodsAtoms.ts +102 -0
  122. package/src/TimePeriods/translatedLabels.ts +9 -0
  123. package/src/TimePeriods/useSortTimePeriods.ts +31 -0
  124. package/src/TimePeriods/useTimePeriod.ts +49 -0
  125. package/src/api/TestQueryProvider.tsx +1 -2
  126. package/src/api/useFetchQuery/index.ts +7 -8
  127. package/src/api/useMutationQuery/index.ts +10 -11
  128. package/src/components/Button/Button.styles.ts +3 -17
  129. package/src/components/Button/Button.tsx +3 -6
  130. package/src/components/Button/Icon/IconButton.styles.ts +2 -9
  131. package/src/components/DataTable/DataTable.stories.tsx +0 -9
  132. package/src/components/DataTable/DataTable.styles.ts +0 -5
  133. package/src/components/DataTable/DataTable.tsx +6 -8
  134. package/src/components/DataTable/EmptyState/DataTableEmptyState.tsx +1 -4
  135. package/src/components/DataTable/Item/DataTableItem.styles.ts +2 -5
  136. package/src/components/DataTable/Item/DataTableItem.tsx +18 -36
  137. package/src/components/Header/Header.stories.tsx +27 -0
  138. package/src/components/Header/Header.styles.ts +27 -0
  139. package/src/components/Header/Header.tsx +23 -0
  140. package/src/components/Header/index.ts +1 -1
  141. package/src/components/Modal/index.ts +0 -2
  142. package/src/components/index.ts +0 -3
  143. package/src/index.ts +2 -0
  144. package/src/layout/TiledListingPage/TiledListingActions.tsx +15 -0
  145. package/src/layout/TiledListingPage/TiledListingContent.tsx +21 -0
  146. package/src/layout/TiledListingPage/TiledListingList.tsx +11 -0
  147. package/src/layout/TiledListingPage/TiledListingPage.styles.ts +16 -0
  148. package/src/layout/TiledListingPage/TiledListingPage.tsx +15 -0
  149. package/src/layout/TiledListingPage/index.ts +4 -0
  150. package/src/screens/dashboard/DashboardsOverview.stories.tsx +102 -110
  151. package/src/utils/index.ts +1 -1
  152. package/src/utils/sanitizedHTML.ts +1 -1
  153. package/test/setupTests.js +0 -3
  154. package/src/base/tokens/README.md +0 -3
  155. package/src/base/tokens/source/$metadata.json +0 -5
  156. package/src/base/tokens/source/base.json +0 -142
  157. package/src/base/tokens/themes/base.tokens.d.ts +0 -38
  158. package/src/base/tokens/themes/base.tokens.json +0 -695
  159. package/src/base/tokens/themes/base.tokens.ts +0 -38
  160. package/src/base/tokens/themes/ui-dark.tokens.d.ts +0 -38
  161. package/src/base/tokens/themes/ui-dark.tokens.json +0 -695
  162. package/src/base/tokens/themes/ui-dark.tokens.ts +0 -38
  163. package/src/base/tokens/themes/ui-light.tokens.d.ts +0 -38
  164. package/src/base/tokens/themes/ui-light.tokens.json +0 -695
  165. package/src/base/tokens/themes/ui-light.tokens.ts +0 -38
  166. package/src/components/Header/PageHeader/PageHeader.stories.tsx +0 -88
  167. package/src/components/Header/PageHeader/PageHeader.styles.ts +0 -99
  168. package/src/components/Header/PageHeader/PageHeader.tsx +0 -15
  169. package/src/components/Header/PageHeader/PageHeaderActions.tsx +0 -17
  170. package/src/components/Header/PageHeader/PageHeaderMain.tsx +0 -15
  171. package/src/components/Header/PageHeader/PageHeaderMenu.tsx +0 -15
  172. package/src/components/Header/PageHeader/PageHeaderTitle.tsx +0 -47
  173. package/src/components/Header/PageHeader/index.ts +0 -12
  174. package/src/components/Layout/AreaIndicator.styles.ts +0 -33
  175. package/src/components/Layout/AreaIndicator.tsx +0 -35
  176. package/src/components/Layout/PageLayout/PageLayout.stories.tsx +0 -81
  177. package/src/components/Layout/PageLayout/PageLayout.styles.ts +0 -40
  178. package/src/components/Layout/PageLayout/PageLayout.tsx +0 -21
  179. package/src/components/Layout/PageLayout/PageLayoutActions.tsx +0 -15
  180. package/src/components/Layout/PageLayout/PageLayoutBody.tsx +0 -24
  181. package/src/components/Layout/PageLayout/PageLayoutHeader.tsx +0 -15
  182. package/src/components/Layout/PageLayout/index.ts +0 -10
  183. package/src/components/Layout/index.ts +0 -1
  184. package/src/components/Menu/Button/MenuButton.stories.tsx +0 -16
  185. package/src/components/Menu/Button/MenuButton.styles.ts +0 -27
  186. package/src/components/Menu/Button/MenuButton.tsx +0 -59
  187. package/src/components/Menu/Button/index.ts +0 -1
  188. package/src/components/Menu/Menu.stories.tsx +0 -71
  189. package/src/components/Menu/Menu.styles.ts +0 -70
  190. package/src/components/Menu/Menu.tsx +0 -25
  191. package/src/components/Menu/MenuDivider.tsx +0 -13
  192. package/src/components/Menu/MenuItem.tsx +0 -36
  193. package/src/components/Menu/MenuItems.tsx +0 -35
  194. package/src/components/Menu/index.ts +0 -12
  195. package/src/components/Menu/useMenu.tsx +0 -79
  196. package/src/components/Tooltip/TextOverflowTooltip/TextOverflowTooltip.stories.tsx +0 -71
  197. package/src/components/Tooltip/TextOverflowTooltip/TextOverflowTooltip.styles.ts +0 -5
  198. package/src/components/Tooltip/TextOverflowTooltip/TextOverflowTooltip.tsx +0 -115
  199. package/src/components/Tooltip/TextOverflowTooltip/index.tsx +0 -1
  200. package/src/components/Tooltip/Tooltip.stories.tsx +0 -41
  201. package/src/components/Tooltip/Tooltip.styles.ts +0 -5
  202. package/src/components/Tooltip/Tooltip.tsx +0 -46
  203. package/src/components/Tooltip/index.ts +0 -1
  204. package/src/screens/dashboard/DashboardsDetail.stories.tsx +0 -108
  205. package/src/utils/useResizeObserver.ts +0 -6
@@ -0,0 +1,102 @@
1
+ import { useAtomValue, useSetAtom } from 'jotai';
2
+ import { T, always, cond, equals, lte, map, pick } from 'ramda';
3
+ import { makeStyles } from 'tss-react/mui';
4
+ import { useTranslation } from 'react-i18next';
5
+
6
+ import { Button, ButtonGroup, Tooltip, useTheme } from '@mui/material';
7
+
8
+ import { TimePeriod, timePeriods } from './models';
9
+ import {
10
+ changeSelectedTimePeriodDerivedAtom,
11
+ selectedTimePeriodAtom
12
+ } from './timePeriodsAtoms';
13
+ import useSortTimePeriods from './useSortTimePeriods';
14
+
15
+ const useStyles = makeStyles()((theme) => ({
16
+ button: {
17
+ fontSize: theme.typography.body2.fontSize,
18
+ pointerEvents: 'all'
19
+ },
20
+ buttonGroup: {
21
+ alignSelf: 'center',
22
+ height: '100%'
23
+ }
24
+ }));
25
+
26
+ interface Props {
27
+ disabled?: boolean;
28
+ extraTimePeriods?: Array<Omit<TimePeriod, 'timelineEventsLimit'>>;
29
+ width: number;
30
+ }
31
+
32
+ const SelectedTimePeriod = ({
33
+ width,
34
+ disabled = false,
35
+ extraTimePeriods = []
36
+ }: Props): JSX.Element => {
37
+ const { classes } = useStyles();
38
+ const theme = useTheme();
39
+ const { t } = useTranslation();
40
+ const selectedTimePeriodData = useAtomValue(selectedTimePeriodAtom);
41
+
42
+ const changeSelectedTimePeriod = useSetAtom(
43
+ changeSelectedTimePeriodDerivedAtom
44
+ );
45
+
46
+ const currentTimePeriods = useSortTimePeriods([
47
+ ...timePeriods,
48
+ ...extraTimePeriods
49
+ ] as Array<TimePeriod>);
50
+
51
+ const timePeriodOptions = map(
52
+ pick(['id', 'name', 'largeName']),
53
+ currentTimePeriods
54
+ );
55
+
56
+ const translatedTimePeriodOptions = timePeriodOptions.map((timePeriod) => ({
57
+ ...timePeriod,
58
+ largeName: t(timePeriod.largeName),
59
+ name: t(timePeriod.name)
60
+ }));
61
+
62
+ return (
63
+ <ButtonGroup
64
+ className={classes.buttonGroup}
65
+ color="primary"
66
+ disabled={disabled}
67
+ size="small"
68
+ >
69
+ {map(
70
+ ({ id, name, largeName }) => (
71
+ <Tooltip key={name} placement="top" title={largeName}>
72
+ <Button
73
+ className={classes.button}
74
+ data-testid={id}
75
+ variant={
76
+ equals(selectedTimePeriodData?.id, id)
77
+ ? 'contained'
78
+ : 'outlined'
79
+ }
80
+ onClick={(): void =>
81
+ changeSelectedTimePeriod({
82
+ id,
83
+ timePeriods: currentTimePeriods
84
+ })
85
+ }
86
+ >
87
+ {
88
+ cond<number, string>([
89
+ [lte(theme.breakpoints.values.md), always(largeName)],
90
+ [T, always(name)]
91
+ ])(width) as string
92
+ }
93
+ </Button>
94
+ </Tooltip>
95
+ ),
96
+ translatedTimePeriodOptions
97
+ )}
98
+ </ButtonGroup>
99
+ );
100
+ };
101
+
102
+ export default SelectedTimePeriod;
@@ -0,0 +1,510 @@
1
+ import dayjs from 'dayjs';
2
+ import localizedFormatPlugin from 'dayjs/plugin/localizedFormat';
3
+ import timezonePlugin from 'dayjs/plugin/timezone';
4
+ import utcPlugin from 'dayjs/plugin/utc';
5
+ import { Provider, createStore } from 'jotai';
6
+ import { equals, inc } from 'ramda';
7
+ import { renderHook } from '@testing-library/react';
8
+
9
+ import { LocalizationProvider } from '@mui/x-date-pickers';
10
+
11
+ import {
12
+ useLocaleDateTimeFormat,
13
+ useDateTimePickerAdapter
14
+ } from '@centreon/ui';
15
+ import { ListingVariant, userAtom } from '@centreon/ui-context';
16
+
17
+ import { CustomTimePeriodProperty } from './models';
18
+ import DateTimePickerInput from './DateTimePickerInput';
19
+
20
+ dayjs.extend(timezonePlugin);
21
+ dayjs.extend(utcPlugin);
22
+ dayjs.extend(localizedFormatPlugin);
23
+
24
+ const retrievedUser = {
25
+ alias: 'Admin alias',
26
+ default_page: '/monitoring/resources',
27
+ is_export_button_enabled: true,
28
+ isExportButtonEnabled: true,
29
+ locale: 'fr_FR.UTF8',
30
+ name: 'Admin',
31
+ use_deprecated_pages: false,
32
+ user_interface_density: ListingVariant.compact
33
+ };
34
+
35
+ const numberDaysInWeek = 7;
36
+
37
+ const days = [
38
+ 'Sunday',
39
+ 'Monday',
40
+ 'Tuesday',
41
+ 'Wednesday',
42
+ 'Thursday',
43
+ 'Friday',
44
+ 'Saturday'
45
+ ];
46
+
47
+ const months2023 = [
48
+ {
49
+ January: {
50
+ date: '2023-01-01T12:59:41.041Z',
51
+ firstDay: { day: days[0], indexDayInRowWeek: 0, value: 1 },
52
+ lastDay: { day: days[2], indexDayInRowWeek: 2, value: 31 },
53
+ numberWeeks: 5
54
+ }
55
+ },
56
+ {
57
+ February: {
58
+ date: '2023-02-01T12:59:41.041Z',
59
+ firstDay: { day: days[3], indexDayInRowWeek: 3, value: 1 },
60
+ lastDay: { day: days[2], indexDayInRowWeek: 2, value: 28 },
61
+ numberWeeks: 5
62
+ }
63
+ },
64
+ {
65
+ March: {
66
+ date: '2023-03-01T12:59:41.041Z',
67
+ firstDay: { day: days[3], indexDayInRowWeek: 3, value: 1 },
68
+ lastDay: { day: days[5], indexDayInRowWeek: 5, value: 31 },
69
+ numberWeeks: 5
70
+ }
71
+ },
72
+ {
73
+ April: {
74
+ date: '2023-04-01T12:59:41.041Z',
75
+ firstDay: { day: days[6], indexDayInRowWeek: 6, value: 1 },
76
+ lastDay: { day: days[0], indexDayInRowWeek: 0, value: 30 },
77
+ numberWeeks: 6
78
+ }
79
+ },
80
+ {
81
+ May: {
82
+ date: '2023-05-01T12:59:41.041Z',
83
+ firstDay: { day: days[1], indexDayInRowWeek: 1, value: 1 },
84
+ lastDay: { day: days[3], indexDayInRowWeek: 3, value: 31 },
85
+ numberWeeks: 5
86
+ }
87
+ },
88
+ {
89
+ June: {
90
+ date: '2023-06-01T12:59:41.041Z',
91
+ firstDay: { day: days[4], indexDayInRowWeek: 4, value: 1 },
92
+ lastDay: { day: days[5], indexDayInRowWeek: 5, value: 30 },
93
+ numberWeeks: 5
94
+ }
95
+ },
96
+ {
97
+ July: {
98
+ date: '2023-07-01T12:59:41.041Z',
99
+ firstDay: { day: days[6], indexDayInRowWeek: 6, value: 1 },
100
+ lastDay: { day: days[1], indexDayInRowWeek: 1, value: 31 },
101
+ numberWeeks: 6
102
+ }
103
+ },
104
+ {
105
+ August: {
106
+ date: '2023-08-01T12:59:41.041Z',
107
+ firstDay: { day: days[2], indexDayInRowWeek: 2, value: 1 },
108
+ lastDay: { day: days[4], indexDayInRowWeek: 4, value: 31 },
109
+ numberWeeks: 5
110
+ }
111
+ },
112
+ {
113
+ September: {
114
+ date: '2023-09-01T12:59:41.041Z',
115
+ firstDay: { day: days[5], indexDayInRowWeek: 5, value: 1 },
116
+ lastDay: { day: days[6], indexDayInRowWeek: 6, value: 30 },
117
+ numberWeeks: 5
118
+ }
119
+ },
120
+ {
121
+ October: {
122
+ date: '2023-10-01T12:59:41.041Z',
123
+ firstDay: { day: days[0], indexDayInRowWeek: 0, value: 1 },
124
+ lastDay: { day: days[2], indexDayInRowWeek: 2, value: 31 },
125
+ numberWeeks: 5
126
+ }
127
+ },
128
+ {
129
+ November: {
130
+ date: '2023-11-01T12:59:41.041Z',
131
+ firstDay: { day: days[3], indexDayInRowWeek: 3, value: 1 },
132
+ lastDay: { day: days[4], indexDayInRowWeek: 4, value: 30 },
133
+ numberWeeks: 5
134
+ }
135
+ },
136
+ {
137
+ December: {
138
+ date: '2023-12-01T12:59:41.041Z',
139
+ firstDay: { day: days[5], indexDayInRowWeek: 5, value: 1 },
140
+ lastDay: { day: days[0], indexDayInRowWeek: 0, value: 31 },
141
+ numberWeeks: 6
142
+ }
143
+ }
144
+ ];
145
+
146
+ const month2023Reverse = [
147
+ {
148
+ December: {
149
+ date: '2023-12-01T12:59:41.041Z',
150
+ firstDay: { day: days[5], indexDayInRowWeek: 5, value: 1 },
151
+ lastDay: { day: days[0], indexDayInRowWeek: 0, value: 31 },
152
+ numberWeeks: 6
153
+ }
154
+ },
155
+ {
156
+ November: {
157
+ date: '2023-11-01T12:59:41.041Z',
158
+ firstDay: { day: days[3], indexDayInRowWeek: 3, value: 1 },
159
+ lastDay: { day: days[4], indexDayInRowWeek: 4, value: 30 },
160
+ numberWeeks: 5
161
+ }
162
+ },
163
+ {
164
+ October: {
165
+ date: '2023-10-01T12:59:41.041Z',
166
+ firstDay: { day: days[0], indexDayInRowWeek: 0, value: 1 },
167
+ lastDay: { day: days[2], indexDayInRowWeek: 2, value: 31 },
168
+ numberWeeks: 5
169
+ }
170
+ },
171
+ {
172
+ September: {
173
+ date: '2023-09-01T12:59:41.041Z',
174
+ firstDay: { day: days[5], indexDayInRowWeek: 5, value: 1 },
175
+ lastDay: { day: days[6], indexDayInRowWeek: 6, value: 30 },
176
+ numberWeeks: 5
177
+ }
178
+ },
179
+ {
180
+ August: {
181
+ date: '2023-08-01T12:59:41.041Z',
182
+ firstDay: { day: days[2], indexDayInRowWeek: 2, value: 1 },
183
+ lastDay: { day: days[4], indexDayInRowWeek: 4, value: 31 },
184
+ numberWeeks: 5
185
+ }
186
+ },
187
+ {
188
+ July: {
189
+ date: '2023-07-01T12:59:41.041Z',
190
+ firstDay: { day: days[6], indexDayInRowWeek: 6, value: 1 },
191
+ lastDay: { day: days[1], indexDayInRowWeek: 1, value: 31 },
192
+ numberWeeks: 6
193
+ }
194
+ },
195
+ {
196
+ June: {
197
+ date: '2023-06-01T12:59:41.041Z',
198
+ firstDay: { day: days[4], indexDayInRowWeek: 4, value: 1 },
199
+ lastDay: { day: days[5], indexDayInRowWeek: 5, value: 30 },
200
+ numberWeeks: 5
201
+ }
202
+ },
203
+ {
204
+ May: {
205
+ date: '2023-05-01T12:59:41.041Z',
206
+ firstDay: { day: days[1], indexDayInRowWeek: 1, value: 1 },
207
+ lastDay: { day: days[3], indexDayInRowWeek: 3, value: 31 },
208
+ numberWeeks: 5
209
+ }
210
+ },
211
+ {
212
+ April: {
213
+ date: '2023-04-01T12:59:41.041Z',
214
+ firstDay: { day: days[6], indexDayInRowWeek: 6, value: 1 },
215
+ lastDay: { day: days[0], indexDayInRowWeek: 0, value: 30 },
216
+ numberWeeks: 6
217
+ }
218
+ },
219
+ {
220
+ March: {
221
+ date: '2023-03-01T12:59:41.041Z',
222
+ firstDay: { day: days[3], indexDayInRowWeek: 3, value: 1 },
223
+ lastDay: { day: days[5], indexDayInRowWeek: 5, value: 31 },
224
+ numberWeeks: 5
225
+ }
226
+ },
227
+ {
228
+ February: {
229
+ date: '2023-02-01T12:59:41.041Z',
230
+ firstDay: { day: days[3], indexDayInRowWeek: 3, value: 1 },
231
+ lastDay: { day: days[2], indexDayInRowWeek: 2, value: 28 },
232
+ numberWeeks: 5
233
+ }
234
+ },
235
+ {
236
+ January: {
237
+ date: '2023-01-01T12:59:41.041Z',
238
+ firstDay: { day: days[0], indexDayInRowWeek: 0, value: 1 },
239
+ lastDay: { day: days[2], indexDayInRowWeek: 2, value: 31 },
240
+ numberWeeks: 5
241
+ }
242
+ }
243
+ ];
244
+
245
+ const testData = [
246
+ {
247
+ button: 'Next month',
248
+ data: months2023,
249
+ initialDate: '2023-01-01T12:59:41.041Z',
250
+ timezone: 'Europe/Paris'
251
+ },
252
+ {
253
+ button: 'Previous month',
254
+ data: month2023Reverse,
255
+ initialDate: '2023-12-01T12:59:41.041Z',
256
+ timezone: 'Europe/Paris'
257
+ }
258
+ ];
259
+
260
+ enum ButtonCalendar {
261
+ NMONTH = 'Next month',
262
+ PMONTH = 'Previous month'
263
+ }
264
+ interface GetPreviousNextMonth {
265
+ currentMonth: string;
266
+ labelButton: string;
267
+ }
268
+
269
+ const getNextMonth = ({
270
+ currentMonth,
271
+ labelButton
272
+ }: GetPreviousNextMonth): Cypress.Chainable | null => {
273
+ if (equals(currentMonth, 'December')) {
274
+ return null;
275
+ }
276
+
277
+ return cy.get(`[aria-label="${labelButton}"]`).click();
278
+ };
279
+
280
+ const getPreviousMonth = ({
281
+ currentMonth,
282
+ labelButton
283
+ }: GetPreviousNextMonth): Cypress.Chainable | null => {
284
+ if (equals(currentMonth, 'January')) {
285
+ return null;
286
+ }
287
+
288
+ return cy.get(`[aria-label="${labelButton}"]`).click();
289
+ };
290
+
291
+ const checkIfDuplicateExists = (arr: Array<unknown>): boolean => {
292
+ return new Set(arr).size !== arr.length;
293
+ };
294
+
295
+ testData.forEach((item) =>
296
+ describe(`DateTimePicker ${item.button}`, () => {
297
+ beforeEach(() => {
298
+ cy.viewport('macbook-13');
299
+
300
+ const { result } = renderHook(() => useDateTimePickerAdapter());
301
+
302
+ const { Adapter } = result.current;
303
+
304
+ const store = createStore();
305
+ store.set(userAtom, {
306
+ ...retrievedUser,
307
+ locale: 'en_US',
308
+ timezone: item.timezone
309
+ });
310
+
311
+ cy.mount({
312
+ Component: (
313
+ <Provider store={store}>
314
+ <LocalizationProvider adapterLocale="en" dateAdapter={Adapter}>
315
+ <DateTimePickerInput
316
+ changeDate={cy.stub()}
317
+ date={new Date(item.initialDate)}
318
+ desktopMediaQuery="@media (min-width: 1024px)"
319
+ property={CustomTimePeriodProperty.start}
320
+ />
321
+ </LocalizationProvider>
322
+ </Provider>
323
+ )
324
+ });
325
+ });
326
+
327
+ it('checks input calendar value contains correct date', () => {
328
+ const { result } = renderHook(() => useLocaleDateTimeFormat());
329
+ const { format } = result.current;
330
+
331
+ const dateInput = format({
332
+ date: dayjs(item.initialDate).tz(item.timezone),
333
+ formatString: 'L hh:mm A'
334
+ });
335
+
336
+ cy.get('input').should('have.value', dateInput);
337
+ });
338
+
339
+ it(`displays the correct number of days for the current month when the ${item.button} button is clicked`, () => {
340
+ cy.get('button').click();
341
+ item.data.forEach((element) => {
342
+ const { lastDay } = Object.values(element)[0];
343
+
344
+ cy.get('[role="rowgroup"]').children().as('listWeeks');
345
+ cy.get('@listWeeks').children('button').as('days');
346
+ cy.get('@days').should('have.length', lastDay.value);
347
+
348
+ const currentMonth = Object.keys(element)[0];
349
+
350
+ if (equals(item.button, ButtonCalendar.PMONTH)) {
351
+ getPreviousMonth({ currentMonth, labelButton: item.button });
352
+ } else {
353
+ getNextMonth({ currentMonth, labelButton: item.button });
354
+ }
355
+ });
356
+ });
357
+
358
+ it(`does not duplicate days in any of the month in the year when the ${item.button} button is clicked`, () => {
359
+ cy.get('button').click();
360
+ item.data.forEach((element) => {
361
+ const daysInCurrentMonth: Array<string> = [];
362
+ cy.get('[role="rowgroup"]').first().children().as('listWeeks');
363
+ cy.get('@listWeeks').children('button').as('days');
364
+
365
+ cy.get('@days')
366
+ .each(($day) => daysInCurrentMonth.push($day.text()))
367
+ .as('currentDays');
368
+
369
+ cy.get('@currentDays').then(() => {
370
+ const isDuplicateExist = checkIfDuplicateExists(daysInCurrentMonth);
371
+
372
+ return expect(isDuplicateExist).to.be.false;
373
+ });
374
+
375
+ const currentMonth = Object.keys(element)[0];
376
+ if (equals(item.button, ButtonCalendar.PMONTH)) {
377
+ getPreviousMonth({ currentMonth, labelButton: item.button });
378
+ } else {
379
+ getNextMonth({ currentMonth, labelButton: item.button });
380
+ }
381
+ });
382
+ });
383
+
384
+ it(`displays the first day as the start of the week when the ${item.button} button is clicked`, () => {
385
+ cy.get('button').click();
386
+
387
+ item.data.forEach((element) => {
388
+ const { firstDay, numberWeeks } = Object.values(element)[0];
389
+
390
+ cy.get('[role="rowgroup"]').children().as('listWeeks');
391
+
392
+ cy.get('@listWeeks').should('have.length', inc(numberWeeks));
393
+ cy.get('@listWeeks').eq(0).as('firstWeek');
394
+ cy.get('@firstWeek').children().as('listDaysInFirstWeek');
395
+
396
+ cy.get('@listDaysInFirstWeek').should('have.length', numberDaysInWeek);
397
+ cy.get('@listDaysInFirstWeek')
398
+ .eq(firstDay.indexDayInRowWeek)
399
+ .as('firstDayInWeek');
400
+ cy.get('@firstDayInWeek').contains(firstDay.value);
401
+
402
+ const currentMonth = Object.keys(element)[0];
403
+ if (equals(item.button, ButtonCalendar.PMONTH)) {
404
+ getPreviousMonth({ currentMonth, labelButton: item.button });
405
+ } else {
406
+ getNextMonth({ currentMonth, labelButton: item.button });
407
+ }
408
+ });
409
+ });
410
+
411
+ it(`displays the last day as the end of the week when the ${item.button} button is clicked`, () => {
412
+ cy.get('button').click();
413
+
414
+ item.data.forEach((element) => {
415
+ const { lastDay, numberWeeks } = Object.values(element)[0];
416
+
417
+ cy.get('[role="rowgroup"]').children().as('listWeeks');
418
+
419
+ cy.get('@listWeeks').should('have.length', inc(numberWeeks));
420
+
421
+ cy.get('@listWeeks')
422
+ .eq(numberWeeks - 1)
423
+ .as('lastWeek');
424
+
425
+ cy.get('@lastWeek').children().as('listDaysInLastWeek');
426
+ cy.get('@listDaysInLastWeek').should('have.length', numberDaysInWeek);
427
+
428
+ cy.get('@listDaysInLastWeek')
429
+ .eq(lastDay.indexDayInRowWeek)
430
+ .as('lastDayInWeek');
431
+ cy.get('@lastDayInWeek').contains(lastDay.value);
432
+ const currentMonth = Object.keys(element)[0];
433
+ if (equals(item.button, ButtonCalendar.PMONTH)) {
434
+ getPreviousMonth({ currentMonth, labelButton: item.button });
435
+ } else {
436
+ getNextMonth({ currentMonth, labelButton: item.button });
437
+ }
438
+ });
439
+ });
440
+
441
+ it(`displays the month and the year in the calendar's header when the ${item.button} button is clicked`, () => {
442
+ cy.get('button').click();
443
+ const { result } = renderHook(() => useLocaleDateTimeFormat());
444
+
445
+ item.data.forEach((element) => {
446
+ const { date } = Object.values(element)[0];
447
+
448
+ const { format } = result.current;
449
+ const monthAndYear = format({
450
+ date: dayjs(date).tz(item.timezone),
451
+ formatString: 'MMMM YYYY'
452
+ });
453
+ cy.contains(monthAndYear);
454
+ const currentMonth = Object.keys(element)[0];
455
+ if (equals(item.button, ButtonCalendar.PMONTH)) {
456
+ getPreviousMonth({ currentMonth, labelButton: item.button });
457
+ } else {
458
+ getNextMonth({ currentMonth, labelButton: item.button });
459
+ }
460
+ });
461
+ });
462
+
463
+ it(`displays the correct day name on calendar's header when the ${item.button} button is clicked`, () => {
464
+ cy.get('button').click();
465
+ const { result } = renderHook(() => useLocaleDateTimeFormat());
466
+
467
+ item.data.forEach((element) => {
468
+ const { date } = Object.values(element)[0];
469
+ const dateByTimeZone = dayjs(date).tz(item.timezone);
470
+ const firstDay = dateByTimeZone.isUTC()
471
+ ? dateByTimeZone.utc().startOf('month').startOf('week')
472
+ : dateByTimeZone.startOf('month').startOf('week');
473
+
474
+ const { format } = result.current;
475
+ const daysArray = [0, 1, 2, 3, 4, 5, 6].map((diff) =>
476
+ format({
477
+ date: firstDay.add(diff, 'day'),
478
+ formatString: 'dd'
479
+ })
480
+ );
481
+ daysArray.forEach((day) => cy.contains(day.toUpperCase()));
482
+ const currentMonth = Object.keys(element)[0];
483
+ if (equals(item.button, ButtonCalendar.PMONTH)) {
484
+ getPreviousMonth({ currentMonth, labelButton: item.button });
485
+ } else {
486
+ getNextMonth({ currentMonth, labelButton: item.button });
487
+ }
488
+ });
489
+ });
490
+
491
+ it(`displays the calendar for the timezone ${item.timezone} when the ${item.button} button is clicked`, () => {
492
+ cy.get('button').click();
493
+
494
+ item.data.forEach((element) => {
495
+ const currentMonth = Object.keys(element)[0];
496
+ if (equals(item.button, ButtonCalendar.PMONTH)) {
497
+ getPreviousMonth({ currentMonth, labelButton: item.button });
498
+ } else {
499
+ getNextMonth({ currentMonth, labelButton: item.button });
500
+ }
501
+
502
+ cy.matchImageSnapshot(
503
+ `calendar-${item.timezone}-${
504
+ Object.keys(element)[0]
505
+ }-when-clicking-on-${item.button}`
506
+ );
507
+ });
508
+ });
509
+ })
510
+ );
@@ -0,0 +1,22 @@
1
+ import { makeStyles } from 'tss-react/mui';
2
+
3
+ interface StylesProps {
4
+ disabled: boolean;
5
+ }
6
+
7
+ export const useStyles = makeStyles<StylesProps>()((theme, { disabled }) => ({
8
+ header: {
9
+ [theme.breakpoints.down('sm')]: {
10
+ flexWrap: 'wrap',
11
+ justifyContent: 'center',
12
+ rowGap: theme.spacing(1)
13
+ },
14
+ backgroundColor: disabled ? 'transparent' : 'undefined',
15
+ border: disabled ? 'unset' : 'undefined',
16
+ boxShadow: disabled ? 'unset' : 'undefined',
17
+ columnGap: theme.spacing(2),
18
+ display: 'flex',
19
+ gridTemplateRows: '1fr',
20
+ justifyContent: 'center'
21
+ }
22
+ }));
@@ -0,0 +1,26 @@
1
+ import { find, propEq } from 'ramda';
2
+
3
+ import {
4
+ CustomTimePeriod,
5
+ TimePeriod,
6
+ TimePeriodById,
7
+ lastDayPeriod
8
+ } from '../models';
9
+
10
+ export const defaultTimePeriod = lastDayPeriod;
11
+
12
+ export const getTimePeriodFromNow = (
13
+ timePeriod: TimePeriod | null
14
+ ): CustomTimePeriod => {
15
+ return {
16
+ end: new Date(Date.now()),
17
+ start: new Date(timePeriod?.getStart() || 0),
18
+ timelineEventsLimit: timePeriod?.timelineEventsLimit as number
19
+ };
20
+ };
21
+
22
+ export const getTimePeriodById = ({
23
+ id,
24
+ timePeriods
25
+ }: TimePeriodById): TimePeriod =>
26
+ find<TimePeriod>(propEq('id', id))(timePeriods) as TimePeriod;