@centreon/ui 24.4.1-sync-release-34022.0 → 24.4.1-test-code-coverage.0

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 (220) hide show
  1. package/package.json +48 -40
  2. package/src/ActionsList/ActionsList.styles.ts +40 -71
  3. package/src/Button/Icon/index.stories.tsx +1 -1
  4. package/src/Button/Icon/index.tsx +1 -1
  5. package/src/Dashboard/Dashboard.styles.ts +6 -5
  6. package/src/Dialog/Confirm/index.tsx +10 -2
  7. package/src/Dialog/UnsavedChanges/index.tsx +21 -20
  8. package/src/Dialog/UnsavedChanges/translatedLabels.ts +4 -6
  9. package/src/Dialog/index.tsx +8 -1
  10. package/src/Form/Inputs/CheckboxGroup.tsx +4 -1
  11. package/src/Form/Inputs/Text.tsx +3 -1
  12. package/src/Form/Inputs/models.ts +1 -0
  13. package/src/Graph/BarStack/BarStack.cypress.spec.tsx +139 -0
  14. package/src/Graph/BarStack/BarStack.stories.tsx +123 -0
  15. package/src/Graph/BarStack/BarStack.styles.ts +37 -0
  16. package/src/Graph/BarStack/BarStack.tsx +14 -0
  17. package/src/Graph/BarStack/ResponsiveBarStack.tsx +209 -0
  18. package/src/Graph/BarStack/index.ts +1 -0
  19. package/src/Graph/BarStack/models.ts +19 -0
  20. package/src/Graph/BarStack/useResponsiveBarStack.ts +131 -0
  21. package/src/Graph/Gauge/Gauge.cypress.spec.tsx +102 -0
  22. package/src/Graph/Gauge/Gauge.tsx +1 -1
  23. package/src/Graph/HeatMap/HeatMap.cypress.spec.tsx +145 -0
  24. package/src/Graph/HeatMap/HeatMap.stories.tsx +0 -25
  25. package/src/Graph/HeatMap/ResponsiveHeatMap.tsx +8 -2
  26. package/src/Graph/Legend/Legend.tsx +21 -0
  27. package/src/Graph/Legend/index.ts +1 -0
  28. package/src/Graph/Legend/models.ts +11 -0
  29. package/src/Graph/LineChart/BasicComponents/Lines/Threshold/index.tsx +4 -5
  30. package/src/Graph/LineChart/BasicComponents/ThresholdLine.tsx +3 -1
  31. package/src/Graph/LineChart/Header/index.tsx +3 -31
  32. package/src/Graph/LineChart/InteractiveComponents/AnchorPoint/useTickGraph.ts +9 -11
  33. package/src/Graph/LineChart/InteractiveComponents/Annotations/Annotation/index.tsx +3 -2
  34. package/src/Graph/LineChart/InteractiveComponents/GraphValueTooltip/GraphValueTooltip.tsx +68 -0
  35. package/src/Graph/LineChart/InteractiveComponents/GraphValueTooltip/useGraphValueTooltip.ts +27 -0
  36. package/src/Graph/LineChart/InteractiveComponents/GraphValueTooltip/useGraphValueTooltipStyles.ts +31 -0
  37. package/src/Graph/LineChart/InteractiveComponents/index.tsx +132 -17
  38. package/src/Graph/LineChart/InteractiveComponents/interactionWithGraphAtoms.ts +7 -27
  39. package/src/Graph/LineChart/Legend/Legend.styles.ts +5 -9
  40. package/src/Graph/LineChart/Legend/LegendHeader.tsx +10 -22
  41. package/src/Graph/LineChart/Legend/index.tsx +17 -55
  42. package/src/Graph/LineChart/LineChart.cypress.spec.tsx +91 -0
  43. package/src/Graph/LineChart/LineChart.styles.ts +8 -0
  44. package/src/Graph/LineChart/LineChart.tsx +106 -116
  45. package/src/Graph/LineChart/LoadingSkeleton.tsx +2 -2
  46. package/src/Graph/LineChart/index.tsx +6 -7
  47. package/src/Graph/LineChart/mockedData/lastDayWithIncompleteValues.json +1320 -0
  48. package/src/Graph/LineChart/mockedData/lastDayWithNullValues.json +1314 -0
  49. package/src/Graph/LineChart/models.ts +12 -1
  50. package/src/Graph/PieChart/PieChart.cypress.spec.tsx +154 -0
  51. package/src/Graph/PieChart/PieChart.stories.tsx +194 -0
  52. package/src/Graph/PieChart/PieChart.styles.ts +39 -0
  53. package/src/Graph/PieChart/PieChart.tsx +14 -0
  54. package/src/Graph/PieChart/ResponsivePie.tsx +243 -0
  55. package/src/Graph/PieChart/index.ts +1 -0
  56. package/src/Graph/PieChart/models.ts +19 -0
  57. package/src/Graph/PieChart/useResponsivePie.ts +81 -0
  58. package/src/Graph/SingleBar/SingleBar.cypress.spec.tsx +121 -0
  59. package/src/Graph/Text/Text.cypress.spec.tsx +101 -0
  60. package/src/Graph/Text/Text.styles.ts +12 -1
  61. package/src/Graph/Text/Text.tsx +17 -12
  62. package/src/Graph/Tree/DescendantNodes.tsx +89 -0
  63. package/src/Graph/Tree/Links.tsx +77 -0
  64. package/src/Graph/Tree/StandaloneTree.tsx +32 -0
  65. package/src/Graph/Tree/Tree.cypress.spec.tsx +195 -0
  66. package/src/Graph/Tree/Tree.stories.tsx +160 -0
  67. package/src/Graph/Tree/Tree.tsx +116 -0
  68. package/src/Graph/Tree/constants.ts +2 -0
  69. package/src/Graph/Tree/index.ts +4 -0
  70. package/src/Graph/Tree/models.ts +55 -0
  71. package/src/Graph/Tree/stories/contents.tsx +164 -0
  72. package/src/Graph/Tree/stories/datas.ts +305 -0
  73. package/src/Graph/Tree/utils.ts +49 -0
  74. package/src/Graph/common/testUtils.ts +71 -0
  75. package/src/Graph/common/timeSeries/index.ts +50 -12
  76. package/src/Graph/common/utils.ts +19 -0
  77. package/src/Graph/index.ts +4 -0
  78. package/src/InputField/Number/Number.cypress.spec.tsx +85 -0
  79. package/src/InputField/Number/Number.stories.tsx +66 -0
  80. package/src/InputField/Number/Number.tsx +74 -0
  81. package/src/InputField/Search/index.tsx +2 -2
  82. package/src/InputField/Select/Autocomplete/Multi/index.tsx +4 -2
  83. package/src/InputField/Select/Autocomplete/index.tsx +10 -3
  84. package/src/InputField/Select/IconPopover/index.tsx +1 -1
  85. package/src/InputField/Select/index.tsx +14 -1
  86. package/src/InputField/Text/index.tsx +38 -38
  87. package/src/Listing/ActionBar/index.tsx +10 -10
  88. package/src/Listing/Cell/DataCell.styles.ts +3 -0
  89. package/src/Listing/Cell/DataCell.tsx +8 -4
  90. package/src/Listing/Listing.cypress.spec.tsx +217 -33
  91. package/src/Listing/Listing.styles.ts +3 -5
  92. package/src/Listing/Row/Row.tsx +7 -3
  93. package/src/Listing/index.stories.tsx +25 -2
  94. package/src/Listing/index.test.tsx +1 -1
  95. package/src/Listing/index.tsx +202 -143
  96. package/src/Listing/models.ts +1 -0
  97. package/src/Listing/useStyleTable.ts +1 -0
  98. package/src/Panel/index.tsx +1 -1
  99. package/src/PopoverMenu/index.tsx +6 -5
  100. package/src/ThemeProvider/index.tsx +3 -0
  101. package/src/TimePeriods/CustomTimePeriod/CompactCustomTimePeriod.styles.ts +6 -7
  102. package/src/TimePeriods/ResolutionTimePeriod.cypress.spec.tsx +12 -9
  103. package/src/Typography/FluidTypography/FluidTypography.cypress.spec.tsx +27 -0
  104. package/src/Typography/FluidTypography/index.stories.tsx +2 -2
  105. package/src/Typography/FluidTypography/index.tsx +21 -28
  106. package/src/api/index.ts +3 -3
  107. package/src/api/useGraphQuery/index.ts +26 -5
  108. package/src/api/useGraphQuery/models.ts +5 -0
  109. package/src/api/useMutationQuery/index.test.ts +4 -4
  110. package/src/api/useMutationQuery/index.ts +24 -13
  111. package/src/components/CollapsibleItem/CollapsibleItem.cypress.spec.tsx +76 -0
  112. package/src/components/CollapsibleItem/CollapsibleItem.stories.tsx +26 -0
  113. package/src/components/CollapsibleItem/CollapsibleItem.tsx +43 -14
  114. package/src/components/CollapsibleItem/useCollapsibleItemStyles.ts +24 -1
  115. package/src/components/DataTable/DataTable.cypress.spec.tsx +14 -33
  116. package/src/components/DataTable/Item/DataTableItem.tsx +4 -60
  117. package/src/components/Form/{AccessRightsV2 → AccessRights}/AccessRights.cypress.spec.tsx +36 -13
  118. package/src/components/Form/{AccessRightsV2 → AccessRights}/ShareInput/ContactSwitch.tsx +11 -3
  119. package/src/components/Form/{AccessRightsV2 → AccessRights}/ShareInput/ShareInput.styles.ts +8 -0
  120. package/src/components/Form/{AccessRightsV2 → AccessRights}/ShareInput/ShareInput.tsx +1 -0
  121. package/src/components/Form/{AccessRightsV2 → AccessRights}/ShareInput/useShareInput.tsx +4 -0
  122. package/src/components/Form/{AccessRightsV2 → AccessRights}/models.ts +1 -0
  123. package/src/components/Form/{AccessRightsV2 → AccessRights}/storiesData.ts +23 -22
  124. package/src/components/Form/Dashboard/DashboardDuplicationForm.tsx +85 -0
  125. package/src/components/Form/Dashboard/index.ts +1 -0
  126. package/src/components/Form/FormActions.tsx +7 -2
  127. package/src/components/Form/index.ts +2 -2
  128. package/src/components/ItemComposition/Item.tsx +1 -1
  129. package/src/components/ItemComposition/ItemComposition.cypress.spec.tsx +113 -0
  130. package/src/components/ItemComposition/ItemComposition.stories.tsx +14 -0
  131. package/src/components/ItemComposition/ItemComposition.styles.ts +36 -3
  132. package/src/components/ItemComposition/ItemComposition.tsx +41 -17
  133. package/src/components/List/Item/ListItem.tsx +3 -3
  134. package/src/components/Modal/ConfirmationModal/ConfirmationModal.cypress.spec.tsx +168 -0
  135. package/src/components/Modal/ConfirmationModal/ConfirmationModal.stories.tsx +62 -0
  136. package/src/components/Modal/ConfirmationModal/ConfirmationModal.tsx +87 -0
  137. package/src/components/Modal/Modal.styles.ts +8 -3
  138. package/src/components/Modal/index.ts +2 -0
  139. package/src/components/Tooltip/ConfirmationTooltip/ConfirmationTooltip.stories.tsx +3 -3
  140. package/src/components/Tooltip/ConfirmationTooltip/ConfirmationTooltip.tsx +1 -1
  141. package/src/components/Tooltip/ConfirmationTooltip/models.ts +1 -1
  142. package/src/components/Zoom/Minimap.tsx +129 -0
  143. package/src/components/Zoom/Zoom.cypress.spec.tsx +246 -0
  144. package/src/components/Zoom/Zoom.stories.tsx +115 -0
  145. package/src/components/Zoom/Zoom.styles.tsx +68 -0
  146. package/src/components/Zoom/Zoom.tsx +64 -0
  147. package/src/components/Zoom/ZoomContent.tsx +170 -0
  148. package/src/components/Zoom/constants.ts +2 -0
  149. package/src/components/Zoom/localPoint.ts +51 -0
  150. package/src/components/Zoom/models.ts +25 -0
  151. package/src/components/Zoom/useMinimap.ts +156 -0
  152. package/src/components/Zoom/useZoom.ts +70 -0
  153. package/src/components/Zoom/utils.ts +55 -0
  154. package/src/components/index.ts +1 -0
  155. package/src/index.ts +1 -0
  156. package/src/utils/index.ts +3 -0
  157. package/src/utils/resourcesStatusURL.ts +166 -0
  158. package/src/utils/useFullscreen/Fullscreen.cypress.spec.tsx +130 -0
  159. package/src/utils/useFullscreen/atoms.ts +3 -0
  160. package/src/utils/useFullscreen/index.ts +2 -0
  161. package/src/utils/useFullscreen/translatedLabels.ts +1 -0
  162. package/src/utils/useFullscreen/useFullscreen.ts +73 -0
  163. package/src/utils/useFullscreen/useFullscreenListener.ts +62 -0
  164. package/src/utils/useInfiniteScrollListing.ts +4 -1
  165. package/src/Graph/LineChart/BasicComponents/LoadingProgress.tsx +0 -46
  166. package/src/Graph/LineChart/InteractiveComponents/AnchorPoint/TooltipAnchorPoint.tsx +0 -96
  167. package/src/Graph/LineChart/InteractiveComponents/AnchorPoint/useTooltipAnchorPoint.ts +0 -107
  168. package/src/Graph/LineChart/Legend/InteractiveValue.tsx +0 -22
  169. package/src/Graph/LineChart/Legend/useInteractiveValues.ts +0 -99
  170. package/src/Typography/FluidTypography/useFluidResizeObserver.ts +0 -56
  171. package/src/components/Form/AccessRights/AccessRights.resource.ts +0 -45
  172. package/src/components/Form/AccessRights/AccessRightsForm.stories.tsx +0 -59
  173. package/src/components/Form/AccessRights/AccessRightsForm.styles.ts +0 -21
  174. package/src/components/Form/AccessRights/AccessRightsForm.tsx +0 -67
  175. package/src/components/Form/AccessRights/AccessRightsFormActions.tsx +0 -80
  176. package/src/components/Form/AccessRights/Input/AddAction.tsx +0 -31
  177. package/src/components/Form/AccessRights/Input/ContactAccessRightInput.stories.tsx +0 -54
  178. package/src/components/Form/AccessRights/Input/ContactAccessRightInput.tsx +0 -72
  179. package/src/components/Form/AccessRights/Input/ContactAccessRightsInput.styles.ts +0 -22
  180. package/src/components/Form/AccessRights/Input/ContactInputField.tsx +0 -105
  181. package/src/components/Form/AccessRights/Input/RoleInputField.tsx +0 -29
  182. package/src/components/Form/AccessRights/List/ContactAccessRightsList.stories.tsx +0 -97
  183. package/src/components/Form/AccessRights/List/ContactAccessRightsList.styles.ts +0 -71
  184. package/src/components/Form/AccessRights/List/ContactAccessRightsList.tsx +0 -51
  185. package/src/components/Form/AccessRights/List/ContactAccessRightsListItem.stories.tsx +0 -116
  186. package/src/components/Form/AccessRights/List/ContactAccessRightsListItem.tsx +0 -118
  187. package/src/components/Form/AccessRights/List/ContactAccessRightsListItemSkeleton.tsx +0 -26
  188. package/src/components/Form/AccessRights/List/ContactAccessRightsListSkeleton.tsx +0 -28
  189. package/src/components/Form/AccessRights/Stats/AccessRightsStats.styles.ts +0 -18
  190. package/src/components/Form/AccessRights/Stats/AccessRightsStats.tsx +0 -41
  191. package/src/components/Form/AccessRights/__fixtures__/contactAccessRight.mock.ts +0 -54
  192. package/src/components/Form/AccessRights/common/GroupLabel.styles.ts +0 -18
  193. package/src/components/Form/AccessRights/common/GroupLabel.tsx +0 -15
  194. package/src/components/Form/AccessRights/common/Input.styles.ts +0 -48
  195. package/src/components/Form/AccessRights/common/RoleInputSelect.styles.ts +0 -11
  196. package/src/components/Form/AccessRights/common/RoleInputSelect.tsx +0 -57
  197. package/src/components/Form/AccessRights/index.ts +0 -3
  198. package/src/components/Form/AccessRights/useAccessRightsForm.test.tsx +0 -531
  199. package/src/components/Form/AccessRights/useAccessRightsForm.tsx +0 -282
  200. package/src/components/Form/AccessRights/useAccessRightsForm.utils.ts +0 -41
  201. /package/src/components/Form/{AccessRightsV2 → AccessRights}/AccessRights.stories.tsx +0 -0
  202. /package/src/components/Form/{AccessRightsV2 → AccessRights}/AccessRights.styles.ts +0 -0
  203. /package/src/components/Form/{AccessRightsV2 → AccessRights}/AccessRights.tsx +0 -0
  204. /package/src/components/Form/{AccessRightsV2 → AccessRights}/Actions/Actions.styles.ts +0 -0
  205. /package/src/components/Form/{AccessRightsV2 → AccessRights}/Actions/Actions.tsx +0 -0
  206. /package/src/components/Form/{AccessRightsV2 → AccessRights}/Actions/useActions.ts +0 -0
  207. /package/src/components/Form/{AccessRightsV2 → AccessRights}/List/Item.tsx +0 -0
  208. /package/src/components/Form/{AccessRightsV2 → AccessRights}/List/List.styles.tsx +0 -0
  209. /package/src/components/Form/{AccessRightsV2 → AccessRights}/List/List.tsx +0 -0
  210. /package/src/components/Form/{AccessRightsV2 → AccessRights}/List/ListItemSkeleton.tsx +0 -0
  211. /package/src/components/Form/{AccessRightsV2 → AccessRights}/List/ListSkeleton.tsx +0 -0
  212. /package/src/components/Form/{AccessRightsV2 → AccessRights}/List/RemoveAccessRight.tsx +0 -0
  213. /package/src/components/Form/{AccessRightsV2 → AccessRights}/List/StateChip.tsx +0 -0
  214. /package/src/components/Form/{AccessRightsV2 → AccessRights}/List/useItem.ts +0 -0
  215. /package/src/components/Form/{AccessRightsV2 → AccessRights}/Provider.tsx +0 -0
  216. /package/src/components/Form/{AccessRightsV2 → AccessRights}/Stats/Stats.tsx +0 -0
  217. /package/src/components/Form/{AccessRightsV2 → AccessRights}/atoms.ts +0 -0
  218. /package/src/components/Form/{AccessRightsV2 → AccessRights}/common/RoleSelectField.styles.tsx +0 -0
  219. /package/src/components/Form/{AccessRightsV2 → AccessRights}/common/RoleSelectField.tsx +0 -0
  220. /package/src/components/Form/{AccessRightsV2 → AccessRights}/useAccessRightsInitValues.ts +0 -0
@@ -0,0 +1,27 @@
1
+ import FluidTypography from '.';
2
+
3
+ const initialize = ({ width, min, max, pref }): void => {
4
+ cy.viewport(width, 590);
5
+
6
+ cy.mount({
7
+ Component: (
8
+ <FluidTypography max={max} min={min} pref={pref} text="Unreachable" />
9
+ )
10
+ });
11
+ };
12
+
13
+ describe('FluidTypography', () => {
14
+ [500, 300, 150].forEach((width) => {
15
+ Object.entries({ max: '80px', min: '30px', pref: 10 }).forEach(
16
+ ([key, value]) => {
17
+ it(`displays the text when the viewport is ${width}px and the ${key} is ${value}`, () => {
18
+ initialize({ [key]: value, width });
19
+
20
+ cy.contains('Unreachable').should('be.visible');
21
+
22
+ cy.matchImageSnapshot();
23
+ });
24
+ }
25
+ );
26
+ });
27
+ });
@@ -40,9 +40,9 @@ basic.args = {
40
40
 
41
41
  export const with200pxWidth = FluidTypographyTemplate.bind({});
42
42
  with200pxWidth.args = {
43
- height: '200px',
43
+ height: '50%',
44
44
  text: 'Hello world',
45
- width: '200px'
45
+ width: '50%'
46
46
  };
47
47
 
48
48
  export const with20pxHeight = FluidTypographyTemplate.bind({});
@@ -1,49 +1,42 @@
1
- import { useRef } from 'react';
2
-
3
1
  import { Typography, TypographyProps } from '@mui/material';
4
2
 
5
- import useFluidResizeObserver from './useFluidResizeObserver';
6
-
7
3
  type CustomTypographyProps = Pick<TypographyProps, 'variant'>;
8
4
  export interface FluidTypographyProps extends CustomTypographyProps {
9
5
  className?: string;
6
+ containerClassName?: string;
7
+ max?: string;
8
+ min?: string;
9
+ pref?: number;
10
10
  text: string;
11
11
  }
12
12
 
13
13
  const FluidTypography = ({
14
14
  text,
15
15
  variant = 'body1',
16
- className
16
+ className,
17
+ containerClassName,
18
+ min = '10px',
19
+ max = '1000px',
20
+ pref = 19
17
21
  }: FluidTypographyProps): JSX.Element => {
18
- const containerRef = useRef<HTMLElement>();
19
- const parentRef = useRef<HTMLElement>();
20
-
21
- const size = useFluidResizeObserver({ ref: containerRef });
22
- const parentSize = useFluidResizeObserver({ isParent: true, ref: parentRef });
23
-
24
22
  return (
25
23
  <div
26
- ref={parentRef}
24
+ className={containerClassName}
27
25
  style={{
28
- height: `${parentSize.height}px`,
26
+ containerType: 'inline-size',
27
+ height: `100%`,
29
28
  width: `100%`
30
29
  }}
31
30
  >
32
- <div ref={containerRef} style={{ height: '100%', width: '100%' }}>
33
- <Typography
34
- className={className}
35
- sx={{
36
- fontSize: `clamp(10px, min(${Math.floor(
37
- size.width / 6
38
- )}px, ${Math.floor(size.height / 6)}px), min(${size.width}px, ${
39
- size.height
40
- }px))`
41
- }}
42
- variant={variant}
43
- >
44
- {text}
45
- </Typography>
46
- </div>
31
+ <Typography
32
+ className={className}
33
+ sx={{
34
+ fontSize: `clamp(${min}, ${pref}cqi, ${max})`
35
+ }}
36
+ variant={variant}
37
+ >
38
+ {text}
39
+ </Typography>
47
40
  </div>
48
41
  );
49
42
  };
package/src/api/index.ts CHANGED
@@ -30,7 +30,7 @@ const patchData =
30
30
  <TData, TResult>(cancelToken: CancelToken) =>
31
31
  ({ endpoint, data }: RequestWithData<TData>): Promise<TResult> =>
32
32
  axios
33
- .patch(endpoint, data, {
33
+ .patch(endpoint, JSON.stringify(data), {
34
34
  cancelToken,
35
35
  headers: contentTypeHeaders
36
36
  })
@@ -40,7 +40,7 @@ const postData =
40
40
  <TData, TResult>(cancelToken: CancelToken) =>
41
41
  ({ endpoint, data }: RequestWithData<TData>): Promise<TResult> =>
42
42
  axios
43
- .post(endpoint, data, {
43
+ .post(endpoint, JSON.stringify(data), {
44
44
  cancelToken,
45
45
  headers: contentTypeHeaders
46
46
  })
@@ -50,7 +50,7 @@ const putData =
50
50
  <TData, TResult>(cancelToken: CancelToken) =>
51
51
  ({ endpoint, data }: RequestWithData<TData>): Promise<TResult> =>
52
52
  axios
53
- .put(endpoint, data, {
53
+ .put(endpoint, JSON.stringify(data), {
54
54
  cancelToken,
55
55
  headers: contentTypeHeaders
56
56
  })
@@ -1,11 +1,20 @@
1
1
  import { useRef } from 'react';
2
2
 
3
- import { equals, has, isEmpty, pluck } from 'ramda';
3
+ import {
4
+ equals,
5
+ flatten,
6
+ has,
7
+ includes,
8
+ isEmpty,
9
+ not,
10
+ pipe,
11
+ pluck
12
+ } from 'ramda';
4
13
  import dayjs from 'dayjs';
5
14
 
6
15
  import { LineChartData, buildListingEndpoint, useFetchQuery } from '../..';
7
16
 
8
- import { Resource, WidgetResourceType } from './models';
17
+ import { Metric, Resource, WidgetResourceType } from './models';
9
18
 
10
19
  interface CustomTimePeriod {
11
20
  end: string;
@@ -14,7 +23,9 @@ interface CustomTimePeriod {
14
23
 
15
24
  interface UseMetricsQueryProps {
16
25
  baseEndpoint: string;
17
- metrics: Array<string>;
26
+ bypassMetricsExclusion?: boolean;
27
+ includeAllResources?: boolean;
28
+ metrics: Array<Metric>;
18
29
  refreshCount?: number;
19
30
  refreshInterval?: number | false;
20
31
  resources?: Array<Resource>;
@@ -71,6 +82,7 @@ const areResourcesFullfilled = (value: Array<Resource>): boolean =>
71
82
  );
72
83
 
73
84
  const useGraphQuery = ({
85
+ bypassMetricsExclusion,
74
86
  metrics,
75
87
  resources = [],
76
88
  baseEndpoint,
@@ -93,7 +105,7 @@ const useGraphQuery = ({
93
105
 
94
106
  const definedMetrics = metrics.filter((metric) => metric);
95
107
  const formattedDefinedMetrics = definedMetrics.map((metric) =>
96
- encodeURIComponent(metric)
108
+ encodeURIComponent(metric.name)
97
109
  );
98
110
 
99
111
  const {
@@ -145,7 +157,16 @@ const useGraphQuery = ({
145
157
  base: data.current.base,
146
158
  title: ''
147
159
  },
148
- metrics: data.current.metrics,
160
+ metrics: bypassMetricsExclusion
161
+ ? data.current.metrics
162
+ : data.current.metrics.filter(({ metric_id }) => {
163
+ return pipe(
164
+ pluck('excludedMetrics'),
165
+ flatten,
166
+ includes(metric_id),
167
+ not
168
+ )(metrics);
169
+ }),
149
170
  times: data.current.times
150
171
  }
151
172
  : undefined;
@@ -13,3 +13,8 @@ export enum WidgetResourceType {
13
13
  serviceCategory = 'service-category',
14
14
  serviceGroup = 'service-group'
15
15
  }
16
+
17
+ export interface Metric {
18
+ excludedMetrics: Array<number>;
19
+ name: string;
20
+ }
@@ -48,7 +48,7 @@ describe('useFetchQuery', () => {
48
48
  method: Method.POST
49
49
  });
50
50
 
51
- result.current.mutate(user);
51
+ result.current.mutate({ payload: user });
52
52
 
53
53
  await waitFor(() => {
54
54
  expect(result.current?.isError).toEqual(false);
@@ -64,7 +64,7 @@ describe('useFetchQuery', () => {
64
64
  method: Method.POST
65
65
  });
66
66
 
67
- result.current.mutate(user);
67
+ result.current.mutate({ payload: user });
68
68
 
69
69
  await waitFor(() => {
70
70
  expect(result.current?.isError).toEqual(true);
@@ -85,7 +85,7 @@ describe('useFetchQuery', () => {
85
85
  method: Method.POST
86
86
  });
87
87
 
88
- result.current.mutate(user);
88
+ result.current.mutate({ payload: user });
89
89
 
90
90
  await waitFor(() => {
91
91
  expect(result.current?.isError).toEqual(true);
@@ -109,7 +109,7 @@ describe('useFetchQuery', () => {
109
109
  method: Method.POST
110
110
  });
111
111
 
112
- result.current.mutate(user);
112
+ result.current.mutate({ payload: user });
113
113
 
114
114
  await waitFor(() => {
115
115
  expect(mockedShowErrorMessage).not.toHaveBeenCalled();
@@ -22,6 +22,11 @@ export enum Method {
22
22
  PUT = 'PUT'
23
23
  }
24
24
 
25
+ interface Variables<TMeta, T> {
26
+ _meta?: TMeta;
27
+ payload?: T;
28
+ }
29
+
25
30
  export type UseMutationQueryProps<T, TMeta> = {
26
31
  baseEndpoint?: string;
27
32
  catchError?: (props: CatchErrorProps) => void;
@@ -33,30 +38,36 @@ export type UseMutationQueryProps<T, TMeta> = {
33
38
  method: Method;
34
39
  onError?: (
35
40
  error: ResponseError,
36
- variables: T & { _meta: TMeta },
41
+ variables: Variables<TMeta, T>,
37
42
  context: unknown
38
43
  ) => unknown;
39
- onMutate?: (variables: T & { _meta: TMeta }) => Promise<unknown> | unknown;
44
+ onMutate?: (variables: Variables<TMeta, T>) => Promise<unknown> | unknown;
40
45
  onSuccess?: (
41
46
  data: ResponseError | T,
42
- variables: T & {
43
- _meta: TMeta;
44
- },
47
+ variables: Variables<TMeta, T>,
45
48
  context: unknown
46
49
  ) => unknown;
47
50
  } & Omit<
48
- UseMutationOptions<T & { _meta?: TMeta }>,
49
- 'mutationFn' | 'onError' | 'onMutate' | 'onSuccess'
51
+ UseMutationOptions<{ _meta?: TMeta; payload: T }>,
52
+ 'mutationFn' | 'onError' | 'onMutate' | 'onSuccess' | 'mutateAsync' | 'mutate'
50
53
  >;
51
54
 
52
55
  const log = anylogger('API Request');
53
56
 
54
- export type UseMutationQueryState<T> = Omit<
57
+ export type UseMutationQueryState<T, TMeta> = Omit<
55
58
  UseMutationResult<T | ResponseError>,
56
- 'isError'
59
+ 'isError' | 'mutate' | 'mutateAsync'
57
60
  > & {
58
61
  isError: boolean;
59
62
  isMutating: boolean;
63
+ mutate: (variables: Variables<TMeta, T>) => ResponseError | T;
64
+ mutateAsync: (
65
+ variables: Variables<TMeta, T>,
66
+ rest?: Pick<
67
+ UseMutationQueryProps<T, TMeta>,
68
+ 'onError' | 'onMutate' | 'onSettled' | 'onSuccess'
69
+ >
70
+ ) => Promise<ResponseError | T>;
60
71
  };
61
72
 
62
73
  const useMutationQuery = <T extends object, TMeta>({
@@ -72,18 +83,18 @@ const useMutationQuery = <T extends object, TMeta>({
72
83
  onSuccess,
73
84
  onSettled,
74
85
  baseEndpoint
75
- }: UseMutationQueryProps<T, TMeta>): UseMutationQueryState<T> => {
86
+ }: UseMutationQueryProps<T, TMeta>): UseMutationQueryState<T, TMeta> => {
76
87
  const { showErrorMessage } = useSnackbar();
77
88
 
78
89
  const queryData = useMutation<
79
90
  T | ResponseError,
80
91
  ResponseError,
81
- T & { _meta: TMeta }
92
+ Variables<TMeta, T>
82
93
  >({
83
94
  mutationFn: (
84
- _payload: T & { _meta: TMeta }
95
+ variables: Variables<TMeta, T>
85
96
  ): Promise<T | ResponseError> => {
86
- const { _meta, ...payload } = _payload || {};
97
+ const { _meta, payload } = variables || {};
87
98
 
88
99
  return customFetch<T>({
89
100
  baseEndpoint,
@@ -0,0 +1,76 @@
1
+ import { CollapsibleItem, Props } from './CollapsibleItem';
2
+
3
+ const title = 'Title';
4
+
5
+ const customizedTitle = <div>Customized title</div>;
6
+
7
+ const initialize = (props: Omit<Props, 'children'>): void => {
8
+ cy.mount({
9
+ Component: <CollapsibleItem {...props}>Content</CollapsibleItem>
10
+ });
11
+ };
12
+
13
+ describe('CollapsibleItem', () => {
14
+ it('displays the component collapsed by default', () => {
15
+ initialize({ title });
16
+
17
+ cy.contains(title).should('be.visible');
18
+ cy.contains('Content').should('not.be.visible');
19
+ cy.get('div[aria-expanded="false"]').should('exist');
20
+
21
+ cy.makeSnapshot();
22
+ });
23
+
24
+ it('displays the component expanded when the corresponding prop is set to true', () => {
25
+ initialize({ defaultExpanded: true, title });
26
+
27
+ cy.contains(title).should('be.visible');
28
+ cy.contains('Content').should('be.visible');
29
+ cy.get('div[aria-expanded="true"]').should('exist');
30
+
31
+ cy.makeSnapshot();
32
+ });
33
+
34
+ it('displays a customized title', () => {
35
+ initialize({ title: customizedTitle });
36
+
37
+ cy.contains('Customized title').should('be.visible');
38
+ cy.get('div[aria-expanded="false"]').should('exist');
39
+
40
+ cy.makeSnapshot();
41
+ });
42
+
43
+ it('displays the component as compact', () => {
44
+ initialize({ compact: true, title });
45
+
46
+ cy.contains(title).should('be.visible');
47
+ cy.get('div[aria-expanded="false"]').should('exist');
48
+ cy.get('div[data-compact="true"]').should('exist');
49
+
50
+ cy.makeSnapshot();
51
+ });
52
+
53
+ it('displays the component as compact and expanded when the icon is clicked', () => {
54
+ initialize({ compact: true, title });
55
+
56
+ cy.contains(title).should('be.visible');
57
+ cy.get('div[aria-expanded="false"]').should('exist');
58
+
59
+ cy.get('div[aria-expanded="false"]').click();
60
+
61
+ cy.get('div[aria-expanded="true"]').should('exist');
62
+ cy.contains('Content').should('be.visible');
63
+
64
+ cy.makeSnapshot();
65
+ });
66
+
67
+ it('displays the component as compact and a customized title', () => {
68
+ initialize({ compact: true, title: customizedTitle });
69
+
70
+ cy.contains('Customized title').should('be.visible');
71
+ cy.get('div[aria-expanded="false"]').should('exist');
72
+ cy.get('div[data-compact="true"]').should('exist');
73
+
74
+ cy.makeSnapshot();
75
+ });
76
+ });
@@ -1,5 +1,7 @@
1
1
  import { Meta, StoryObj } from '@storybook/react';
2
2
 
3
+ import { Checkbox, Typography } from '@mui/material';
4
+
3
5
  import { CollapsibleItem } from './CollapsibleItem';
4
6
 
5
7
  const meta: Meta<typeof CollapsibleItem> = {
@@ -23,3 +25,27 @@ export const ExpandedByDefault: Story = {
23
25
  title: 'Title'
24
26
  }
25
27
  };
28
+
29
+ export const customizedTitle: Story = {
30
+ args: {
31
+ children: 'Label',
32
+ defaultExpanded: false,
33
+ title: <Typography>Title</Typography>
34
+ }
35
+ };
36
+
37
+ export const customizedTitleAndCompact: Story = {
38
+ args: {
39
+ children: 'Label',
40
+ compact: true,
41
+ defaultExpanded: false,
42
+ title: (
43
+ <div
44
+ style={{ alignItems: 'center', display: 'flex', flexDirection: 'row' }}
45
+ >
46
+ <Checkbox size="small" />
47
+ <Typography>Title compact</Typography>
48
+ </div>
49
+ )
50
+ }
51
+ };
@@ -1,5 +1,7 @@
1
1
  import { ReactNode } from 'react';
2
2
 
3
+ import { equals, type } from 'ramda';
4
+
3
5
  import {
4
6
  AccordionDetails,
5
7
  AccordionSummary,
@@ -10,36 +12,63 @@ import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
10
12
 
11
13
  import { useCollapsibleItemStyles } from './useCollapsibleItemStyles';
12
14
 
13
- interface Props {
15
+ export interface Props {
14
16
  children: ReactNode;
17
+ compact?: boolean;
18
+ dataTestId?: string;
15
19
  defaultExpanded?: boolean;
16
- title: string;
20
+ title: string | JSX.Element;
17
21
  }
18
22
 
19
23
  export const CollapsibleItem = ({
20
24
  title,
21
25
  children,
22
- defaultExpanded
26
+ defaultExpanded,
27
+ compact = false,
28
+ dataTestId = ''
23
29
  }: Props): JSX.Element => {
24
- const { classes } = useCollapsibleItemStyles();
30
+ const { classes, cx } = useCollapsibleItemStyles();
31
+
32
+ const isStringTitle = equals(type(title), 'String');
25
33
 
26
34
  return (
27
35
  <Accordion
28
36
  disableGutters
29
37
  className={classes.accordion}
38
+ data-compact={compact}
39
+ data-testid={`${dataTestId}-accordion`}
30
40
  defaultExpanded={defaultExpanded}
31
41
  >
32
- <AccordionSummary
33
- classes={{
34
- content: classes.accordionSummary
35
- }}
36
- expandIcon={<ExpandMoreIcon color="primary" />}
42
+ <div className={classes.summaryContainer}>
43
+ <div className={classes.customTitle}>{!isStringTitle && title}</div>
44
+ <AccordionSummary
45
+ classes={{
46
+ content: cx(
47
+ compact
48
+ ? classes.accordionSummaryCompactContent
49
+ : classes.accordionSummary
50
+ ),
51
+ root: cx(
52
+ compact
53
+ ? classes.accordionSummaryCompactRoot
54
+ : classes.accordionSummaryRoot
55
+ )
56
+ }}
57
+ data-testid={`${dataTestId}-summary`}
58
+ expandIcon={<ExpandMoreIcon color="primary" />}
59
+ >
60
+ {isStringTitle && (
61
+ <Typography color="primary" variant="h6">
62
+ {title}
63
+ </Typography>
64
+ )}
65
+ </AccordionSummary>
66
+ </div>
67
+ <AccordionDetails
68
+ className={cx(
69
+ compact ? classes.accordionDetailsCompact : classes.accordionDetails
70
+ )}
37
71
  >
38
- <Typography color="primary" variant="h6">
39
- {title}
40
- </Typography>
41
- </AccordionSummary>
42
- <AccordionDetails className={classes.accordionDetails}>
43
72
  {children}
44
73
  </AccordionDetails>
45
74
  </Accordion>
@@ -4,12 +4,35 @@ export const useCollapsibleItemStyles = makeStyles()((theme) => ({
4
4
  accordion: {
5
5
  backgroundColor: 'transparent',
6
6
  border: 'none',
7
- borderBottom: `1px solid ${theme.palette.divider}`
7
+ borderBottom: `1px solid ${theme.palette.divider}`,
8
+ width: '100%'
8
9
  },
9
10
  accordionDetails: {
10
11
  padding: theme.spacing(0, 2, 2)
11
12
  },
13
+ accordionDetailsCompact: {
14
+ padding: theme.spacing(0)
15
+ },
12
16
  accordionSummary: {
13
17
  margin: theme.spacing(1.5, 0)
18
+ },
19
+ accordionSummaryCompactContent: {
20
+ margin: theme.spacing(0, 0, 0.5)
21
+ },
22
+ accordionSummaryCompactRoot: {
23
+ minHeight: theme.spacing(1),
24
+ width: '100%'
25
+ },
26
+ accordionSummaryRoot: {
27
+ width: '100%'
28
+ },
29
+ customTitle: {
30
+ whiteSpace: 'nowrap'
31
+ },
32
+ summaryContainer: {
33
+ alignItems: 'center',
34
+ display: 'flex',
35
+ flexDirection: 'row',
36
+ width: '100%'
14
37
  }
15
38
  }));
@@ -1,5 +1,7 @@
1
1
  import { Box } from '@mui/material';
2
+ import Delete from '@mui/icons-material/Delete';
2
3
 
4
+ import { IconButton } from '../..';
3
5
  import { ColumnType } from '../../Listing/models';
4
6
 
5
7
  import { DataTable } from '.';
@@ -12,29 +14,27 @@ const data = Array(5)
12
14
  title: `Entity ${idx}`
13
15
  }));
14
16
 
15
- const initializeDataTableGrid = ({
16
- hasActions,
17
- hasCardAction,
18
- canDelete
19
- }): void => {
17
+ const CardActions = (): JSX.Element => {
18
+ return (
19
+ <IconButton ariaLabel="Delete" title="Delete" onClick={cy.stub()}>
20
+ <Delete fontSize="small" />
21
+ </IconButton>
22
+ );
23
+ };
24
+
25
+ const initializeDataTableGrid = ({ hasActions, hasCardAction }): void => {
20
26
  cy.viewport(1200, 590);
21
27
  cy.mount({
22
28
  Component: (
23
29
  <DataTable variant="grid">
24
30
  {data.map(({ title, description }) => (
25
31
  <DataTable.Item
32
+ Actions={<CardActions />}
26
33
  description={description}
27
34
  hasActions={hasActions}
28
35
  hasCardAction={hasCardAction}
29
36
  key={title}
30
- labelsDelete={{
31
- cancel: 'Cancel',
32
- confirm: {
33
- label: 'Delete'
34
- }
35
- }}
36
37
  title={title}
37
- onDelete={canDelete ? cy.stub() : undefined}
38
38
  />
39
39
  ))}
40
40
  </DataTable>
@@ -94,7 +94,6 @@ const initializeDataTableListing = (): void => {
94
94
  describe('DataTable: Grid', () => {
95
95
  it('displays items with title and description only', () => {
96
96
  initializeDataTableGrid({
97
- canDelete: false,
98
97
  hasActions: false,
99
98
  hasCardAction: false
100
99
  });
@@ -109,32 +108,17 @@ describe('DataTable: Grid', () => {
109
108
 
110
109
  it('displays items with actions', () => {
111
110
  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
111
  hasActions: true,
127
112
  hasCardAction: false
128
113
  });
129
114
 
130
- cy.findAllByLabelText('delete').should('have.length', 5);
115
+ cy.findAllByLabelText('Delete').should('have.length', 5);
131
116
 
132
117
  cy.makeSnapshot();
133
118
  });
134
119
 
135
120
  it('displays items with card action only', () => {
136
121
  initializeDataTableGrid({
137
- canDelete: false,
138
122
  hasActions: false,
139
123
  hasCardAction: true
140
124
  });
@@ -146,15 +130,12 @@ describe('DataTable: Grid', () => {
146
130
 
147
131
  it('displays items with card action and bottom actions', () => {
148
132
  initializeDataTableGrid({
149
- canDelete: true,
150
133
  hasActions: true,
151
134
  hasCardAction: true
152
135
  });
153
136
 
154
137
  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);
138
+ cy.findAllByLabelText('Delete').should('have.length', 5);
158
139
 
159
140
  cy.makeSnapshot();
160
141
  });