@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,98 @@
1
+ import { Meta, StoryObj } from '@storybook/react';
2
+ import dayjs from 'dayjs';
3
+
4
+ import Switch from '@mui/material/Switch';
5
+
6
+ import { dateFormat } from './models';
7
+
8
+ import TimePeriod from '.';
9
+
10
+ const meta: Meta<typeof TimePeriod> = {
11
+ component: TimePeriod,
12
+ tags: ['autodocs']
13
+ };
14
+
15
+ export default meta;
16
+
17
+ type Story = StoryObj<typeof TimePeriod>;
18
+
19
+ const Template: Story = {
20
+ render: (args) => <TimePeriod {...args} />
21
+ };
22
+
23
+ const TemplateWithExternalComponent: Story = {
24
+ render: (args) => (
25
+ <TimePeriod {...args} renderExternalComponent={<Switch />} />
26
+ )
27
+ };
28
+
29
+ const argTypes = {
30
+ disabled: {
31
+ control: 'boolean',
32
+ description: 'If true, the component is disabled.',
33
+ table: {
34
+ defaultValue: { summary: false },
35
+ type: { summary: 'boolean' }
36
+ }
37
+ },
38
+ extraTimePeriods: {
39
+ control: 'object',
40
+ description: 'soon',
41
+ table: {
42
+ defaultValue: { summary: '[]' },
43
+ type: { detail: 'extra selected time periods', summary: 'array' }
44
+ }
45
+ },
46
+ getIsError: {
47
+ description:
48
+ 'Callback fired when The end date is smaller or equal to the start date',
49
+ table: {
50
+ category: 'Events',
51
+ type: { detail: '(value:boolean)=>void', summary: 'function' }
52
+ }
53
+ },
54
+ getStartEndParameters: {
55
+ description: 'Callback fired when the the user select or pick a date',
56
+ table: {
57
+ category: 'Events',
58
+ type: {
59
+ detail: '({start:isoString,end:isoString})=>void',
60
+ summary: 'function'
61
+ }
62
+ }
63
+ }
64
+ };
65
+ const args = {
66
+ extraTimePeriods: [
67
+ {
68
+ dateTimeFormat: dateFormat,
69
+ getStart: (): Date => dayjs(Date.now()).subtract(29, 'day').toDate(),
70
+ id: 'last_29_days',
71
+ largeName: 'last 29 days',
72
+ name: '29 days'
73
+ },
74
+ {
75
+ dateTimeFormat: dateFormat,
76
+ getStart: (): Date => dayjs(Date.now()).subtract(5, 'day').toDate(),
77
+ id: 'last_5_days',
78
+ largeName: 'last 5 days',
79
+ name: '5 days'
80
+ }
81
+ ]
82
+ };
83
+
84
+ export const BasicTimePeriod: Story = {
85
+ ...Template,
86
+ argTypes
87
+ };
88
+
89
+ export const WithExtraTimePeriods: Story = {
90
+ ...Template,
91
+ argTypes,
92
+ args
93
+ };
94
+
95
+ export const WithExternalComponent: Story = {
96
+ ...TemplateWithExternalComponent,
97
+ argTypes
98
+ };
@@ -0,0 +1,78 @@
1
+ import { ReactNode } from 'react';
2
+
3
+ import { Responsive } from '@visx/visx';
4
+ import dayjs from 'dayjs';
5
+ import 'dayjs/locale/en';
6
+ import 'dayjs/locale/es';
7
+ import 'dayjs/locale/fr';
8
+ import 'dayjs/locale/pt';
9
+ import duration from 'dayjs/plugin/duration';
10
+ import isSameOrAfter from 'dayjs/plugin/isSameOrAfter';
11
+ import timezonePlugin from 'dayjs/plugin/timezone';
12
+ import utcPlugin from 'dayjs/plugin/utc';
13
+
14
+ import { Paper } from '@mui/material';
15
+
16
+ import CustomTimePeriod from './CustomTimePeriod';
17
+ import SelectedTimePeriod from './SelectedTimePeriod';
18
+ import { useStyles } from './TimePeriods.styles';
19
+ import {
20
+ CustomTimePeriod as CustomTimePeriodModel,
21
+ EndStartInterval,
22
+ TimePeriod
23
+ } from './models';
24
+ import useTimePeriod from './useTimePeriod';
25
+
26
+ dayjs.extend(isSameOrAfter);
27
+ dayjs.extend(utcPlugin);
28
+ dayjs.extend(timezonePlugin);
29
+ dayjs.extend(duration);
30
+ interface Parameters extends EndStartInterval {
31
+ timelineEventsLimit: number;
32
+ }
33
+ export interface Props {
34
+ adjustTimePeriodData?: Omit<CustomTimePeriodModel, 'timelineEventsLimit'>;
35
+ disabled?: boolean;
36
+ extraTimePeriods?: Array<Omit<TimePeriod, 'timelineEventsLimit'>>;
37
+ getIsError?: (value: boolean) => void;
38
+ getParameters?: ({ start, end, timelineEventsLimit }: Parameters) => void;
39
+ renderExternalComponent?: ReactNode;
40
+ }
41
+
42
+ const TimePeriod = ({
43
+ extraTimePeriods,
44
+ disabled = false,
45
+ getParameters,
46
+ getIsError,
47
+ adjustTimePeriodData,
48
+ renderExternalComponent
49
+ }: Props): JSX.Element => {
50
+ const { classes } = useStyles({ disabled });
51
+
52
+ useTimePeriod({
53
+ adjustTimePeriodData,
54
+ getIsError,
55
+ getParameters
56
+ });
57
+
58
+ return (
59
+ <div>
60
+ <Responsive.ParentSize>
61
+ {({ width }): JSX.Element => {
62
+ return (
63
+ <Paper className={classes.header} style={{ width }}>
64
+ <SelectedTimePeriod
65
+ disabled={disabled}
66
+ extraTimePeriods={extraTimePeriods}
67
+ width={width}
68
+ />
69
+ <CustomTimePeriod disabled={disabled} />
70
+ <div>{renderExternalComponent}</div>
71
+ </Paper>
72
+ );
73
+ }}
74
+ </Responsive.ParentSize>
75
+ </div>
76
+ );
77
+ };
78
+ export default TimePeriod;
@@ -0,0 +1,12 @@
1
+ import { ListingVariant } from '@centreon/ui-context';
2
+
3
+ export const retrievedUser = {
4
+ alias: 'Admin alias',
5
+ default_page: '/monitoring/resources',
6
+ is_export_button_enabled: true,
7
+ isExportButtonEnabled: true,
8
+ locale: 'fr_FR.UTF8',
9
+ name: 'Admin',
10
+ use_deprecated_pages: false,
11
+ user_interface_density: ListingVariant.compact
12
+ };
@@ -0,0 +1,97 @@
1
+ import dayjs from 'dayjs';
2
+
3
+ import {
4
+ labelLastDay,
5
+ label1Day,
6
+ label7Days,
7
+ label31Days,
8
+ labelLast7Days,
9
+ labelLast31Days
10
+ } from './translatedLabels';
11
+
12
+ export const dateFormat = 'L';
13
+ export const timeFormat = 'LT';
14
+ export const dateTimeFormat = `${dateFormat} ${timeFormat}`;
15
+
16
+ export enum CustomTimePeriodProperty {
17
+ end = 'end',
18
+ start = 'start'
19
+ }
20
+
21
+ export interface TimePeriod {
22
+ dateTimeFormat: string;
23
+ getStart: () => Date;
24
+ id: string;
25
+ largeName: string;
26
+ name: string;
27
+ timelineEventsLimit: number;
28
+ }
29
+
30
+ export const lastDayPeriod: TimePeriod = {
31
+ dateTimeFormat: timeFormat,
32
+ getStart: (): Date => dayjs(Date.now()).subtract(24, 'hour').toDate(),
33
+ id: 'last_24_h',
34
+ largeName: labelLastDay,
35
+ name: label1Day,
36
+ timelineEventsLimit: 20
37
+ };
38
+
39
+ export const last7Days: TimePeriod = {
40
+ dateTimeFormat: dateFormat,
41
+ getStart: (): Date => dayjs(Date.now()).subtract(7, 'day').toDate(),
42
+ id: 'last_7_days',
43
+ largeName: labelLast7Days,
44
+ name: label7Days,
45
+ timelineEventsLimit: 100
46
+ };
47
+
48
+ export const last31Days: TimePeriod = {
49
+ dateTimeFormat: dateFormat,
50
+ getStart: (): Date => dayjs(Date.now()).subtract(31, 'day').toDate(),
51
+ id: 'last_31_days',
52
+ largeName: labelLast31Days,
53
+ name: label31Days,
54
+ timelineEventsLimit: 500
55
+ };
56
+
57
+ export const timePeriods: Array<TimePeriod> = [
58
+ lastDayPeriod,
59
+ last7Days,
60
+ last31Days
61
+ ];
62
+
63
+ export interface TimePeriodById {
64
+ id: string;
65
+ timePeriods: Array<TimePeriod>;
66
+ }
67
+
68
+ export interface CustomTimePeriod {
69
+ end: Date;
70
+ start: Date;
71
+ timelineEventsLimit: number;
72
+ }
73
+
74
+ export interface DateTimePickerInputModel {
75
+ changeDate: (props) => void;
76
+ date: Date | null;
77
+ disabled?: boolean;
78
+ maxDate?: Date;
79
+ minDate?: Date;
80
+ property: CustomTimePeriodProperty;
81
+ }
82
+
83
+ export interface TimeLineAxisTickFormat extends CustomTimePeriod {
84
+ timeLineLimit: number;
85
+ xAxisTickFormat: string;
86
+ }
87
+
88
+ export interface GraphQueryParametersProps {
89
+ endDate?: Date;
90
+ startDate?: Date;
91
+ timePeriod?: TimePeriod | null;
92
+ }
93
+
94
+ export interface EndStartInterval {
95
+ end: string;
96
+ start: string;
97
+ }
@@ -0,0 +1,102 @@
1
+ import dayjs from 'dayjs';
2
+ import { atom } from 'jotai';
3
+ import { always, cond, gte, isNil, T } from 'ramda';
4
+
5
+ import {
6
+ defaultTimePeriod,
7
+ getTimePeriodById,
8
+ getTimePeriodFromNow
9
+ } from './helpers';
10
+ import { CustomTimePeriod, TimePeriod, TimePeriodById } from './models';
11
+
12
+ export const selectedTimePeriodAtom = atom<TimePeriod | null>(
13
+ defaultTimePeriod
14
+ );
15
+
16
+ const defaultCustomTimePeriod = getTimePeriodFromNow(defaultTimePeriod);
17
+
18
+ export const customTimePeriodAtom = atom(defaultCustomTimePeriod);
19
+
20
+ export const errorTimePeriodAtom = atom(false);
21
+
22
+ export const getNewCustomTimePeriod = ({
23
+ start,
24
+ end
25
+ }: Omit<CustomTimePeriod, 'timelineEventsLimit'>): CustomTimePeriod => {
26
+ const customTimePeriodInDay = dayjs
27
+ .duration(dayjs(end).diff(dayjs(start)))
28
+ .asDays();
29
+
30
+ const timelineEventsLimit = cond<number, number>([
31
+ [gte(1), always(20)],
32
+ [gte(7), always(100)],
33
+ [T, always(500)]
34
+ ])(customTimePeriodInDay) as number;
35
+
36
+ return {
37
+ end,
38
+ start,
39
+ timelineEventsLimit
40
+ };
41
+ };
42
+
43
+ export const changeSelectedTimePeriodDerivedAtom = atom(
44
+ null,
45
+ (_, set, { id, timePeriods }: TimePeriodById) => {
46
+ const timePeriod = getTimePeriodById({ id, timePeriods });
47
+
48
+ set(selectedTimePeriodAtom, timePeriod);
49
+
50
+ const newCustomTimePeriod = getTimePeriodFromNow(timePeriod);
51
+
52
+ set(customTimePeriodAtom, newCustomTimePeriod);
53
+ }
54
+ );
55
+
56
+ export const changeCustomTimePeriodDerivedAtom = atom(
57
+ null,
58
+ (get, set, { date, property }) => {
59
+ const customTimePeriod = get(customTimePeriodAtom);
60
+
61
+ const newCustomTimePeriod = getNewCustomTimePeriod({
62
+ ...customTimePeriod,
63
+ [property]: date
64
+ });
65
+
66
+ set(customTimePeriodAtom, newCustomTimePeriod);
67
+ set(selectedTimePeriodAtom, null);
68
+ }
69
+ );
70
+
71
+ export const getDatesDerivedAtom = atom(
72
+ (get) =>
73
+ (timePeriod?: TimePeriod | null): [string, string, number] => {
74
+ const customTimePeriod = get(customTimePeriodAtom);
75
+
76
+ if (isNil(timePeriod)) {
77
+ return [
78
+ customTimePeriod.start.toISOString(),
79
+ customTimePeriod.end.toISOString(),
80
+ customTimePeriod.timelineEventsLimit
81
+ ];
82
+ }
83
+
84
+ return [
85
+ timePeriod.getStart().toISOString(),
86
+ new Date(Date.now()).toISOString(),
87
+ timePeriod.timelineEventsLimit
88
+ ];
89
+ }
90
+ );
91
+
92
+ export const adjustTimePeriodDerivedAtom = atom(
93
+ null,
94
+ (
95
+ _,
96
+ set,
97
+ adjustTimePeriodProps: Omit<CustomTimePeriod, 'timelineEventsLimit'>
98
+ ) => {
99
+ set(customTimePeriodAtom, getNewCustomTimePeriod(adjustTimePeriodProps));
100
+ set(selectedTimePeriodAtom, null);
101
+ }
102
+ );
@@ -0,0 +1,9 @@
1
+ export const label1Day = '1 day';
2
+ export const label7Days = '7 days';
3
+ export const label31Days = '31 days';
4
+ export const labelLastDay = 'Last day';
5
+ export const labelLast7Days = 'Last 7 days';
6
+ export const labelLast31Days = 'Last 31 days';
7
+ export const labelFrom = 'From';
8
+ export const labelTo = 'To';
9
+ export const labelCompactTimePeriod = 'Compact time period';
@@ -0,0 +1,31 @@
1
+ import dayjs from 'dayjs';
2
+ import { T, always, cond, gte } from 'ramda';
3
+
4
+ import { getTimePeriodFromNow } from './helpers';
5
+ import { TimePeriod } from './models';
6
+
7
+ const useSortTimePeriods = (
8
+ timePeriods: Array<TimePeriod>
9
+ ): Array<TimePeriod> => {
10
+ const adjustedTimePeriods = timePeriods.map((item) => {
11
+ const { end, start } = getTimePeriodFromNow(item);
12
+
13
+ const numberOfDays = dayjs.duration(dayjs(end).diff(dayjs(start))).asDays();
14
+
15
+ const timelineEventsLimit = cond<number, number>([
16
+ [gte(1), always(20)],
17
+ [gte(7), always(100)],
18
+ [T, always(500)]
19
+ ])(numberOfDays) as number;
20
+
21
+ return { item: { ...item, timelineEventsLimit }, numberOfDays };
22
+ });
23
+
24
+ const sortedTimePeriods = adjustedTimePeriods.sort(
25
+ (a, b) => a.numberOfDays - b.numberOfDays
26
+ );
27
+
28
+ return sortedTimePeriods.map((element) => element.item);
29
+ };
30
+
31
+ export default useSortTimePeriods;
@@ -0,0 +1,49 @@
1
+ import { useEffect } from 'react';
2
+
3
+ import { useAtomValue, useSetAtom } from 'jotai';
4
+
5
+ import {
6
+ customTimePeriodAtom,
7
+ getDatesDerivedAtom,
8
+ selectedTimePeriodAtom,
9
+ errorTimePeriodAtom,
10
+ adjustTimePeriodDerivedAtom
11
+ } from './timePeriodsAtoms';
12
+
13
+ import { Props } from '.';
14
+
15
+ const useTimePeriod = ({
16
+ getParameters,
17
+ getIsError,
18
+ adjustTimePeriodData
19
+ }: Omit<Props, 'extraTimePeriods' | 'disabled'>): void => {
20
+ const selectedTimePeriod = useAtomValue(selectedTimePeriodAtom);
21
+ const customTimePeriod = useAtomValue(customTimePeriodAtom);
22
+ const getCurrentEndStartInterval = useAtomValue(getDatesDerivedAtom);
23
+ const errorTimePeriod = useAtomValue(errorTimePeriodAtom);
24
+ const adjustTimeTimePeriod = useSetAtom(adjustTimePeriodDerivedAtom);
25
+
26
+ useEffect(() => {
27
+ if (!adjustTimePeriodData) {
28
+ return;
29
+ }
30
+
31
+ adjustTimeTimePeriod(adjustTimePeriodData);
32
+ }, [adjustTimePeriodData?.start, adjustTimePeriodData?.end]);
33
+
34
+ useEffect(() => {
35
+ const [start, end, timelineEventsLimit] =
36
+ getCurrentEndStartInterval(selectedTimePeriod);
37
+
38
+ getParameters?.({ end, start, timelineEventsLimit });
39
+ }, [customTimePeriod.start, customTimePeriod.end, selectedTimePeriod]);
40
+
41
+ useEffect(() => {
42
+ if (!errorTimePeriod) {
43
+ return;
44
+ }
45
+ getIsError?.(errorTimePeriod);
46
+ }, [errorTimePeriod]);
47
+ };
48
+
49
+ export default useTimePeriod;
@@ -5,8 +5,7 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
5
5
  const client = new QueryClient({
6
6
  defaultOptions: {
7
7
  queries: {
8
- cacheTime: 0,
9
- retry: false
8
+ cacheTime: 0
10
9
  }
11
10
  }
12
11
  });
@@ -1,4 +1,4 @@
1
- import { useEffect, useMemo } from 'react';
1
+ import { useEffect } from 'react';
2
2
 
3
3
  import 'ulog';
4
4
  import {
@@ -30,13 +30,14 @@ export interface UseFetchQueryProps<T> {
30
30
  >;
31
31
  }
32
32
 
33
- export type UseFetchQueryState<T> = {
33
+ export interface UseFetchQueryState<T>
34
+ extends Omit<QueryObserverBaseResult, 'data'> {
34
35
  data?: T;
35
36
  fetchQuery: () => Promise<T | ResponseError>;
36
37
  prefetchNextPage: ({ page, getPrefetchQueryKey }) => void;
37
38
  prefetchPreviousPage: ({ page, getPrefetchQueryKey }) => void;
38
39
  prefetchQuery: ({ endpointParams, queryKey }) => void;
39
- } & Omit<QueryObserverBaseResult, 'data'>;
40
+ }
40
41
 
41
42
  export interface PrefetchEndpointParams {
42
43
  page: number;
@@ -154,11 +155,9 @@ const useFetchQuery = <T extends object>({
154
155
  );
155
156
  };
156
157
 
157
- const data = useMemo(
158
- () =>
159
- not(has('isError', queryData.data)) ? (queryData.data as T) : undefined,
160
- [queryData.data]
161
- );
158
+ const data = not(has('isError', queryData.data))
159
+ ? (queryData.data as T)
160
+ : undefined;
162
161
 
163
162
  const errorData = queryData.data as ResponseError | undefined;
164
163
 
@@ -1,11 +1,7 @@
1
1
  import 'ulog';
2
2
  import { useEffect } from 'react';
3
3
 
4
- import {
5
- useMutation,
6
- UseMutationOptions,
7
- UseMutationResult
8
- } from '@tanstack/react-query';
4
+ import { useMutation } from '@tanstack/react-query';
9
5
  import { JsonDecoder } from 'ts.data.json';
10
6
  import anylogger from 'anylogger';
11
7
  import { includes } from 'ramda';
@@ -21,7 +17,7 @@ export enum Method {
21
17
  PUT = 'PUT'
22
18
  }
23
19
 
24
- export type UseMutationQueryProps<T> = {
20
+ export interface UseMutationQueryProps<T> {
25
21
  catchError?: (props: CatchErrorProps) => void;
26
22
  decoder?: JsonDecoder.Decoder<T>;
27
23
  defaultFailureMessage?: string;
@@ -29,14 +25,16 @@ export type UseMutationQueryProps<T> = {
29
25
  getEndpoint: (payload) => string;
30
26
  httpCodesBypassErrorSnackbar?: Array<number>;
31
27
  method: Method;
32
- } & Omit<UseMutationOptions<T>, 'mutationFn'>;
28
+ }
33
29
 
34
30
  const log = anylogger('API Request');
35
31
 
36
- export type UseMutationQueryState<T> = {
32
+ export interface UseMutationQueryState<T> {
37
33
  isError: boolean;
38
34
  isMutating: boolean;
39
- } & UseMutationResult<T | ResponseError>;
35
+ mutate: (payload) => void;
36
+ mutateAsync: (payload) => Promise<T | ResponseError>;
37
+ }
40
38
 
41
39
  const useMutationQuery = <T extends object>({
42
40
  getEndpoint,
@@ -86,9 +84,10 @@ const useMutationQuery = <T extends object>({
86
84
  }, [queryData.data]);
87
85
 
88
86
  return {
89
- ...queryData,
90
87
  isError: (queryData.data as ResponseError | undefined)?.isError || false,
91
- isMutating: queryData.isLoading
88
+ isMutating: queryData.isLoading,
89
+ mutate: queryData.mutate,
90
+ mutateAsync: queryData.mutateAsync
92
91
  };
93
92
  };
94
93
 
@@ -2,20 +2,9 @@ import { makeStyles } from 'tss-react/mui';
2
2
 
3
3
  const useStyles = makeStyles()((theme) => ({
4
4
  button: {
5
- '&[data-size="medium"]': {
6
- fontSize: '16px',
7
- height: 'unset',
8
- lineHeight: '24px'
9
- },
10
-
11
5
  '&[data-size="small"]': {
12
- '&[data-variant="primary"], &[data-variant="secondary"]': {
13
- paddingLeft: theme.spacing(2),
14
- paddingRight: theme.spacing(2)
15
- },
16
- fontSize: '14px',
17
- height: 'unset',
18
- lineHeight: '22px'
6
+ paddingLeft: theme.spacing(2),
7
+ paddingRight: theme.spacing(2)
19
8
  },
20
9
 
21
10
  '&[data-variant="primary"]:not(:disabled)': {
@@ -34,10 +23,7 @@ const useStyles = makeStyles()((theme) => ({
34
23
 
35
24
  borderColor: theme.palette.primary.main,
36
25
  color: theme.palette.primary.main
37
- },
38
-
39
- textWrap: 'noWrap',
40
- transition: 'unset'
26
+ }
41
27
  }
42
28
  }));
43
29
 
@@ -16,15 +16,13 @@ const muiVariantMap: Record<
16
16
  secondary: 'outlined'
17
17
  };
18
18
 
19
- export type ButtonProps = {
19
+ type ButtonProps = {
20
20
  children: ReactNode;
21
- className?: string;
22
21
  disabled?: boolean;
23
22
  icon?: string | ReactNode;
24
23
  iconVariant?: 'none' | 'start' | 'end';
25
24
  isDanger?: boolean;
26
25
  onClick?: (e) => void;
27
- ref?: React.Ref<HTMLButtonElement>;
28
26
  size?: 'small' | 'medium' | 'large';
29
27
  type?: 'button' | 'submit' | 'reset';
30
28
  variant?: 'primary' | 'secondary' | 'ghost';
@@ -41,10 +39,9 @@ const Button = ({
41
39
  disabled = false,
42
40
  onClick,
43
41
  isDanger = false,
44
- className = '',
45
42
  ...attr
46
43
  }: ButtonProps): ReactElement => {
47
- const { classes, cx } = useStyles();
44
+ const { classes } = useStyles();
48
45
 
49
46
  const MuiOverrideProps = useMemo(
50
47
  () => ({
@@ -57,7 +54,7 @@ const Button = ({
57
54
 
58
55
  return (
59
56
  <MuiButton
60
- className={cx(classes.button, className)}
57
+ className={classes.button}
61
58
  data-icon-variant={iconVariant}
62
59
  data-is-danger={isDanger}
63
60
  data-size={size}
@@ -1,14 +1,7 @@
1
1
  import { makeStyles } from 'tss-react/mui';
2
2
 
3
- const useStyles = makeStyles()((theme) => ({
4
- iconButton: {
5
- '&[data-size="small"]': {
6
- '& > svg, & > .MuiSvgIcon-root': {
7
- fontSize: '1.125rem'
8
- },
9
- padding: theme.spacing(0.75)
10
- }
11
- }
3
+ const useStyles = makeStyles()(() => ({
4
+ iconButton: {}
12
5
  }));
13
6
 
14
7
  export { useStyles };
@@ -40,12 +40,3 @@ export const AsEmptyState: Story = {
40
40
  isEmpty: true
41
41
  }
42
42
  };
43
-
44
- export const withFixedHeightContainer: Story = {
45
- args: { ...Default.args },
46
- render: (args) => (
47
- <div style={{ height: '400px' }}>
48
- <DataTable {...args} />
49
- </div>
50
- )
51
- };