@centreon/ui 24.4.59 → 24.4.61

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 (163) hide show
  1. package/package.json +50 -42
  2. package/public/mockServiceWorker.js +1 -1
  3. package/src/ActionsList/ActionsList.styles.ts +40 -71
  4. package/src/Button/Icon/index.tsx +1 -1
  5. package/src/Button/Save/StartIcon.tsx +3 -3
  6. package/src/Button/Save/index.tsx +9 -5
  7. package/src/Checkbox/Checkbox.tsx +2 -2
  8. package/src/Checkbox/CheckboxGroup/index.tsx +2 -2
  9. package/src/Dashboard/Item.tsx +1 -1
  10. package/src/Dashboard/Layout.tsx +2 -2
  11. package/src/Dialog/Confirm/index.tsx +10 -2
  12. package/src/Dialog/UnsavedChanges/index.tsx +21 -20
  13. package/src/Dialog/UnsavedChanges/translatedLabels.ts +4 -6
  14. package/src/Dialog/index.tsx +9 -2
  15. package/src/FallbackPage/FallbackPage.tsx +3 -3
  16. package/src/FileDropZone/index.tsx +3 -1
  17. package/src/Form/Form.cypress.spec.tsx +133 -0
  18. package/src/Form/Inputs/List/Content.tsx +62 -0
  19. package/src/Form/Inputs/List/List.styles.ts +29 -0
  20. package/src/Form/Inputs/List/List.tsx +58 -0
  21. package/src/Form/Inputs/List/useList.ts +81 -0
  22. package/src/Form/Inputs/Text.tsx +3 -1
  23. package/src/Form/Inputs/index.tsx +3 -1
  24. package/src/Form/Inputs/models.ts +10 -1
  25. package/src/Graph/BarStack/BarStack.cypress.spec.tsx +154 -0
  26. package/src/Graph/BarStack/BarStack.stories.tsx +123 -0
  27. package/src/Graph/BarStack/BarStack.styles.ts +37 -0
  28. package/src/Graph/BarStack/BarStack.tsx +14 -0
  29. package/src/Graph/BarStack/ResponsiveBarStack.tsx +222 -0
  30. package/src/Graph/BarStack/index.ts +1 -0
  31. package/src/Graph/BarStack/models.ts +20 -0
  32. package/src/Graph/BarStack/useResponsiveBarStack.ts +137 -0
  33. package/src/Graph/Gauge/Gauge.cypress.spec.tsx +102 -0
  34. package/src/Graph/Gauge/Gauge.tsx +1 -1
  35. package/src/Graph/HeatMap/HeatMap.cypress.spec.tsx +145 -0
  36. package/src/Graph/HeatMap/HeatMap.stories.tsx +0 -25
  37. package/src/Graph/HeatMap/ResponsiveHeatMap.tsx +8 -2
  38. package/src/Graph/Legend/Legend.tsx +21 -0
  39. package/src/Graph/Legend/index.ts +1 -0
  40. package/src/Graph/Legend/models.ts +11 -0
  41. package/src/Graph/LineChart/BasicComponents/Lines/Threshold/Circle.tsx +2 -2
  42. package/src/Graph/LineChart/BasicComponents/Thresholds.tsx +2 -2
  43. package/src/Graph/LineChart/BasicComponents/useFilterLines.ts +1 -1
  44. package/src/Graph/LineChart/InteractiveComponents/AnchorPoint/GuidingLines.tsx +2 -2
  45. package/src/Graph/LineChart/InteractiveComponents/Annotations/EventAnnotations.tsx +1 -1
  46. package/src/Graph/LineChart/Legend/Legend.styles.ts +1 -1
  47. package/src/Graph/LineChart/Legend/LegendHeader.tsx +1 -1
  48. package/src/Graph/LineChart/Legend/useInteractiveValues.ts +2 -2
  49. package/src/Graph/LineChart/Legend/useLegend.ts +3 -3
  50. package/src/Graph/LineChart/helpers/doc.ts +16 -13
  51. package/src/Graph/LineChart/helpers/index.ts +1 -1
  52. package/src/Graph/LineChart/index.stories.tsx +4 -2
  53. package/src/Graph/LineChart/index.tsx +1 -1
  54. package/src/Graph/PieChart/PieChart.cypress.spec.tsx +169 -0
  55. package/src/Graph/PieChart/PieChart.stories.tsx +194 -0
  56. package/src/Graph/PieChart/PieChart.styles.ts +39 -0
  57. package/src/Graph/PieChart/PieChart.tsx +14 -0
  58. package/src/Graph/PieChart/ResponsivePie.tsx +254 -0
  59. package/src/Graph/PieChart/index.ts +1 -0
  60. package/src/Graph/PieChart/models.ts +20 -0
  61. package/src/Graph/PieChart/useResponsivePie.ts +85 -0
  62. package/src/Graph/SingleBar/SingleBar.cypress.spec.tsx +121 -0
  63. package/src/Graph/SingleBar/Thresholds.tsx +2 -2
  64. package/src/Graph/Text/Text.cypress.spec.tsx +101 -0
  65. package/src/Graph/Text/Text.stories.tsx +60 -4
  66. package/src/Graph/Text/Text.tsx +1 -1
  67. package/src/Graph/common/testUtils.ts +71 -0
  68. package/src/Graph/common/timeSeries/index.ts +22 -14
  69. package/src/Graph/common/utils.ts +19 -0
  70. package/src/Graph/index.ts +3 -0
  71. package/src/Graph/translatedLabels.ts +1 -0
  72. package/src/InputField/Select/Autocomplete/Connected/index.tsx +10 -7
  73. package/src/InputField/Select/Autocomplete/Draggable/SortableList.tsx +1 -1
  74. package/src/InputField/Select/Autocomplete/Draggable/SortableListContent.tsx +1 -1
  75. package/src/InputField/Select/Autocomplete/Draggable/index.tsx +1 -1
  76. package/src/InputField/Select/Autocomplete/Multi/index.tsx +4 -2
  77. package/src/InputField/Select/Autocomplete/index.tsx +129 -116
  78. package/src/InputField/Select/IconPopover/index.tsx +2 -2
  79. package/src/InputField/Select/index.tsx +15 -2
  80. package/src/InputField/Text/index.tsx +2 -2
  81. package/src/Listing/ActionBar/index.tsx +9 -8
  82. package/src/Listing/Cell/DataCell.styles.ts +3 -0
  83. package/src/Listing/Cell/DataCell.tsx +23 -5
  84. package/src/Listing/Header/ListingHeader.tsx +1 -1
  85. package/src/Listing/Listing.cypress.spec.tsx +218 -33
  86. package/src/Listing/Listing.styles.ts +4 -7
  87. package/src/Listing/Row/Row.tsx +7 -3
  88. package/src/Listing/index.stories.tsx +37 -3
  89. package/src/Listing/index.test.tsx +1 -1
  90. package/src/Listing/index.tsx +80 -36
  91. package/src/Listing/models.ts +1 -0
  92. package/src/Listing/useStyleTable.ts +1 -0
  93. package/src/Module/Module.cypress.spec.tsx +129 -0
  94. package/src/Module/index.tsx +2 -4
  95. package/src/PopoverMenu/index.tsx +6 -5
  96. package/src/RichTextEditor/RichTextEditor.tsx +12 -1
  97. package/src/SortableItems/index.tsx +2 -7
  98. package/src/ThemeProvider/index.tsx +24 -0
  99. package/src/TimePeriods/CustomTimePeriod/CompactCustomTimePeriod.styles.ts +6 -7
  100. package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/PickersStartEndDate.tsx +8 -3
  101. package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/models.ts +0 -2
  102. package/src/TimePeriods/DateTimePickerInput.tsx +56 -19
  103. package/src/TimePeriods/ResolutionTimePeriod.cypress.spec.tsx +12 -9
  104. package/src/TimePeriods/TimePeriods.cypress.spec.tsx +9 -33
  105. package/src/TimePeriods/helpers/index.ts +1 -1
  106. package/src/TimePeriods/index.stories.tsx +12 -4
  107. package/src/TimePeriods/index.tsx +2 -2
  108. package/src/Typography/FluidTypography/FluidTypography.cypress.spec.tsx +27 -0
  109. package/src/Typography/FluidTypography/index.stories.tsx +2 -2
  110. package/src/Typography/FluidTypography/index.tsx +21 -28
  111. package/src/api/QueryProvider.tsx +1 -1
  112. package/src/api/TestQueryProvider.tsx +1 -1
  113. package/src/api/index.ts +3 -3
  114. package/src/api/useFetchQuery/index.ts +27 -23
  115. package/src/api/useMutationQuery/index.test.ts +4 -4
  116. package/src/api/useMutationQuery/index.ts +60 -25
  117. package/src/components/Button/Icon/IconButton.tsx +6 -2
  118. package/src/components/DataTable/DataListing.tsx +6 -0
  119. package/src/components/DataTable/DataTable.cypress.spec.tsx +174 -0
  120. package/src/components/DataTable/DataTable.stories.tsx +40 -0
  121. package/src/components/DataTable/DataTable.styles.ts +3 -0
  122. package/src/components/DataTable/DataTable.tsx +3 -3
  123. package/src/components/DataTable/Item/DataTableItem.styles.ts +7 -2
  124. package/src/components/DataTable/Item/DataTableItem.tsx +4 -60
  125. package/src/components/DataTable/index.ts +3 -1
  126. package/src/components/Form/AccessRights/AccessRights.cypress.spec.tsx +13 -13
  127. package/src/components/Form/AccessRights/ShareInput/ContactSwitch.tsx +3 -3
  128. package/src/components/Form/AccessRights/ShareInput/ShareInput.tsx +1 -0
  129. package/src/components/Form/AccessRights/storiesData.ts +22 -22
  130. package/src/components/Form/Dashboard/DashboardDuplicationForm.tsx +85 -0
  131. package/src/components/Form/Dashboard/DashboardForm.tsx +15 -12
  132. package/src/components/Form/Dashboard/index.ts +1 -0
  133. package/src/components/Form/FormActions.tsx +7 -2
  134. package/src/components/ItemComposition/ItemComposition.styles.ts +2 -2
  135. package/src/components/Layout/PageLayout/PageLayout.tsx +1 -1
  136. package/src/components/Layout/PageLayout/PageLayoutActions.tsx +1 -0
  137. package/src/components/Layout/PageLayout/PageLayoutBody.tsx +1 -0
  138. package/src/components/Layout/PageLayout/PageLayoutHeader.tsx +5 -1
  139. package/src/components/Layout/PageLayout/PageQuickAccess.tsx +76 -0
  140. package/src/components/Layout/PageLayout/index.ts +3 -1
  141. package/src/components/Layout/PageLayout.cypress.spec.tsx +66 -0
  142. package/src/components/List/Item/ListItem.tsx +3 -3
  143. package/src/components/Modal/ConfirmationModal/ConfirmationModal.cypress.spec.tsx +168 -0
  144. package/src/components/Modal/ConfirmationModal/ConfirmationModal.stories.tsx +62 -0
  145. package/src/components/Modal/ConfirmationModal/ConfirmationModal.tsx +87 -0
  146. package/src/components/Modal/Modal.styles.ts +8 -3
  147. package/src/components/Modal/index.ts +2 -0
  148. package/src/components/Tooltip/ConfirmationTooltip/ConfirmationTooltip.stories.tsx +3 -3
  149. package/src/components/Tooltip/ConfirmationTooltip/ConfirmationTooltip.tsx +1 -1
  150. package/src/components/Tooltip/ConfirmationTooltip/models.ts +1 -1
  151. package/src/index.ts +2 -2
  152. package/src/queryParameters/url/index.ts +5 -1
  153. package/src/utils/index.ts +1 -1
  154. package/src/utils/useFullscreen/Fullscreen.cypress.spec.tsx +1 -3
  155. package/src/utils/useFullscreen/useFullscreenListener.ts +10 -7
  156. package/src/utils/useInfiniteScrollListing.ts +4 -1
  157. package/src/utils/{useLicenseExpirationWarning.cypress.spec.tsx → useLicenseExpirationWarning.test.tsx} +48 -37
  158. package/src/utils/useLicenseExpirationWarning.ts +18 -18
  159. package/src/utils/usePluralizedTranslation.ts +21 -0
  160. package/src/Typography/FluidTypography/useFluidResizeObserver.ts +0 -56
  161. package/src/screens/dashboard/DashboardsDetail.stories.tsx +0 -108
  162. package/src/screens/dashboard/DashboardsOverview.stories.tsx +0 -281
  163. package/src/utils/useDateTimePickerAdapter.ts +0 -309
@@ -0,0 +1,123 @@
1
+ import { Meta, StoryObj } from '@storybook/react';
2
+
3
+ import { BarType } from './models';
4
+
5
+ import { BarStack } from '.';
6
+
7
+ const data = [
8
+ { color: '#88B922', label: 'Ok', value: 148 },
9
+ { color: '#999999', label: 'Unknown', value: 63 },
10
+ { color: '#F7931A', label: 'Warning', value: 16 },
11
+ { color: '#FF6666', label: 'Down', value: 13 }
12
+ ];
13
+
14
+ const dataWithBigNumbers = [
15
+ { color: '#88B922', label: 'Ok', value: 260000 },
16
+ { color: '#999999', label: 'Unknown', value: 1010900 },
17
+ { color: '#F7931A', label: 'Warning', value: 63114 },
18
+ { color: '#FF6666', label: 'Down', value: 122222 }
19
+ ];
20
+
21
+ const dataWithSmallNumber = [
22
+ { color: '#88B922', label: 'Ok', value: 148 },
23
+ { color: '#999999', label: 'Unknown', value: 42 },
24
+ { color: '#F7931A', label: 'Warning', value: 7 },
25
+ { color: '#FF6666', label: 'Down', value: 5 }
26
+ ];
27
+
28
+ const meta: Meta<typeof BarStack> = {
29
+ component: BarStack
30
+ };
31
+
32
+ export default meta;
33
+ type Story = StoryObj<typeof BarStack>;
34
+
35
+ const TooltipContent = ({ label, color, value }: BarType): JSX.Element => {
36
+ return (
37
+ <div style={{ color }}>
38
+ {label} : {value}
39
+ </div>
40
+ );
41
+ };
42
+
43
+ const Template = (args): JSX.Element => {
44
+ return (
45
+ <div style={{ height: '300px', width: '500px' }}>
46
+ <BarStack {...args} />
47
+ </div>
48
+ );
49
+ };
50
+
51
+ export const Vertical: Story = {
52
+ args: { data, title: 'hosts' },
53
+ render: Template
54
+ };
55
+
56
+ export const WithoutTitle: Story = {
57
+ args: { data },
58
+ render: Template
59
+ };
60
+
61
+ export const WithoutLegend: Story = {
62
+ args: { data, displayLegend: false, title: 'hosts' },
63
+
64
+ render: Template
65
+ };
66
+
67
+ export const withDisplayedValues: Story = {
68
+ args: { data, displayValues: true, title: 'hosts' },
69
+ render: Template
70
+ };
71
+
72
+ export const WithPencentage: Story = {
73
+ args: { data, displayValues: true, title: 'hosts', unit: 'percentage' },
74
+ render: Template
75
+ };
76
+
77
+ export const WithTooltip: Story = {
78
+ args: { TooltipContent, data, title: 'hosts' },
79
+ render: Template
80
+ };
81
+
82
+ export const WithBigNumbers: Story = {
83
+ args: {
84
+ TooltipContent,
85
+ data: dataWithBigNumbers,
86
+ displayValues: true,
87
+ title: 'hosts'
88
+ },
89
+ render: Template
90
+ };
91
+
92
+ export const WithSmallNumbers: Story = {
93
+ args: {
94
+ TooltipContent,
95
+ data: dataWithSmallNumber,
96
+ displayValues: true,
97
+ title: 'hosts'
98
+ },
99
+ render: Template
100
+ };
101
+
102
+ export const Horizontal: Story = {
103
+ args: {
104
+ TooltipContent,
105
+ data,
106
+ displayValues: true,
107
+ title: 'hosts',
108
+ variant: 'horizontal'
109
+ },
110
+ render: Template
111
+ };
112
+
113
+ export const HorizontalWithoutLegend: Story = {
114
+ args: {
115
+ TooltipContent,
116
+ data,
117
+ displayLegend: false,
118
+ displayValues: true,
119
+ title: 'hosts',
120
+ variant: 'horizontal'
121
+ },
122
+ render: Template
123
+ };
@@ -0,0 +1,37 @@
1
+ import { makeStyles } from 'tss-react/mui';
2
+
3
+ export const useBarStackStyles = makeStyles()((theme) => ({
4
+ barStackTooltip: {
5
+ backgroundColor: theme.palette.background.paper,
6
+ color: theme.palette.text.primary,
7
+ padding: 0,
8
+ position: 'relative'
9
+ },
10
+ container: {
11
+ alignItems: 'center',
12
+ display: 'flex',
13
+ gap: theme.spacing(1.5),
14
+ justifyContent: 'center'
15
+ },
16
+ svgContainer: {
17
+ alignItems: 'center',
18
+ backgroundColor: theme.palette.background.panelGroups,
19
+ borderRadius: theme.spacing(1.25),
20
+ display: 'flex',
21
+ justifyContent: 'center'
22
+ },
23
+ svgWrapper: {
24
+ alignItems: 'center',
25
+ display: 'flex',
26
+ flexDirection: 'column',
27
+ gap: theme.spacing(1),
28
+ justifyContent: 'center'
29
+ },
30
+ title: {
31
+ fontSize: theme.typography.h6.fontSize,
32
+ fontWeight: theme.typography.fontWeightMedium,
33
+ margin: 0,
34
+ padding: 0,
35
+ textAlign: 'center'
36
+ }
37
+ }));
@@ -0,0 +1,14 @@
1
+ import { ParentSize } from '../..';
2
+
3
+ import ResponsiveBarStack from './ResponsiveBarStack';
4
+ import { BarStackProps } from './models';
5
+
6
+ const Bar = (props: BarStackProps): JSX.Element => (
7
+ <ParentSize>
8
+ {({ width, height }) => (
9
+ <ResponsiveBarStack {...props} height={height} width={width} />
10
+ )}
11
+ </ParentSize>
12
+ );
13
+
14
+ export default Bar;
@@ -0,0 +1,222 @@
1
+ import { useRef } from 'react';
2
+
3
+ import { BarStack as BarStackVertical, BarStackHorizontal } from '@visx/shape';
4
+ import { Group } from '@visx/group';
5
+ import numeral from 'numeral';
6
+ import { Text } from '@visx/text';
7
+ import { useTranslation } from 'react-i18next';
8
+ import { equals } from 'ramda';
9
+
10
+ import { Typography } from '@mui/material';
11
+
12
+ import { Tooltip } from '../../components';
13
+ import { LegendProps } from '../Legend/models';
14
+ import { Legend as LegendComponent } from '../Legend';
15
+ import { getValueByUnit } from '../common/utils';
16
+ import { labelNoDataFound as defaultlabelNoDataFound } from '../translatedLabels';
17
+
18
+ import { BarStackProps } from './models';
19
+ import { useBarStackStyles } from './BarStack.styles';
20
+ import useResponsiveBarStack from './useResponsiveBarStack';
21
+
22
+ const DefaultLengd = ({ scale, direction }: LegendProps): JSX.Element => (
23
+ <LegendComponent direction={direction} scale={scale} />
24
+ );
25
+
26
+ const BarStack = ({
27
+ title,
28
+ data,
29
+ width,
30
+ height,
31
+ size = 72,
32
+ onSingleBarClick,
33
+ displayLegend = true,
34
+ TooltipContent,
35
+ Legend = DefaultLengd,
36
+ unit = 'number',
37
+ displayValues,
38
+ variant = 'vertical',
39
+ legendDirection = 'column',
40
+ labelNoDataFound = defaultlabelNoDataFound
41
+ }: BarStackProps & { height: number; width: number }): JSX.Element => {
42
+ const { t } = useTranslation();
43
+ const { classes } = useBarStackStyles();
44
+
45
+ const titleRef = useRef(null);
46
+ const legendRef = useRef(null);
47
+
48
+ const {
49
+ barSize,
50
+ colorScale,
51
+ input,
52
+ keys,
53
+ legendScale,
54
+ total,
55
+ xScale,
56
+ yScale,
57
+ svgWrapperWidth,
58
+ svgContainerSize,
59
+ isVerticalBar,
60
+ areAllValuesNull
61
+ } = useResponsiveBarStack({
62
+ data,
63
+ height,
64
+ legendRef,
65
+ size,
66
+ titleRef,
67
+ unit,
68
+ variant,
69
+ width
70
+ });
71
+
72
+ const BarStackComponent = isVerticalBar
73
+ ? BarStackVertical
74
+ : BarStackHorizontal;
75
+
76
+ if (areAllValuesNull) {
77
+ return (
78
+ <div className={classes.container} style={{ height, width }}>
79
+ <Typography variant="h3">{t(labelNoDataFound)}</Typography>
80
+ </div>
81
+ );
82
+ }
83
+
84
+ return (
85
+ <div className={classes.container} style={{ height, width }}>
86
+ <div
87
+ className={classes.svgWrapper}
88
+ style={{
89
+ height,
90
+ width: svgWrapperWidth
91
+ }}
92
+ >
93
+ {title && (
94
+ <div className={classes.title} data-testid="Title" ref={titleRef}>
95
+ {`${numeral(total).format('0a').toUpperCase()} `} {t(title)}
96
+ </div>
97
+ )}
98
+ <div
99
+ className={classes.svgContainer}
100
+ data-testid="barStack"
101
+ style={svgContainerSize}
102
+ >
103
+ <svg
104
+ data-variant={variant}
105
+ height={barSize.height}
106
+ width={barSize.width}
107
+ >
108
+ <Group>
109
+ <BarStackComponent
110
+ color={colorScale}
111
+ data={[input]}
112
+ keys={keys}
113
+ {...(isVerticalBar
114
+ ? { x: () => undefined }
115
+ : { y: () => undefined })}
116
+ xScale={xScale}
117
+ yScale={yScale}
118
+ >
119
+ {(barStacks) =>
120
+ barStacks.map((barStack) =>
121
+ barStack.bars.map((bar) => {
122
+ const shouldDisplayValues = (): boolean => {
123
+ if (bar.height < 10) {
124
+ return false;
125
+ }
126
+
127
+ return (
128
+ (equals(unit, 'number') && bar.width > 10) ||
129
+ (equals(unit, 'percentage') && bar.width > 25)
130
+ );
131
+ };
132
+
133
+ const TextX = bar.x + bar.width / 2;
134
+ const TextY = bar.y + bar.height / 2;
135
+
136
+ const onClick = (): void => {
137
+ onSingleBarClick?.(bar);
138
+ };
139
+
140
+ return (
141
+ <Tooltip
142
+ hasCaret
143
+ classes={{
144
+ tooltip: classes.barStackTooltip
145
+ }}
146
+ followCursor={false}
147
+ key={`bar-stack-${barStack.index}-${bar.index}`}
148
+ label={
149
+ TooltipContent && (
150
+ <TooltipContent
151
+ color={bar.color}
152
+ label={bar.key}
153
+ title={title}
154
+ total={total}
155
+ value={barStack.bars[0].bar.data[barStack.key]}
156
+ />
157
+ )
158
+ }
159
+ position={
160
+ isVerticalBar ? 'right-start' : 'bottom-start'
161
+ }
162
+ >
163
+ <g data-testid={bar.key} onClick={onClick}>
164
+ <rect
165
+ cursor="pointer"
166
+ fill={bar.color}
167
+ height={
168
+ isVerticalBar ? bar.height - 1 : bar.height
169
+ }
170
+ key={`bar-stack-${barStack.index}-${bar.index}`}
171
+ ry={10}
172
+ width={isVerticalBar ? bar.width : bar.width - 1}
173
+ x={bar.x}
174
+ y={bar.y}
175
+ />
176
+ {displayValues && shouldDisplayValues() && (
177
+ <Text
178
+ cursor="pointer"
179
+ data-testid="value"
180
+ fill="#000"
181
+ fontSize={12}
182
+ fontWeight={600}
183
+ textAnchor="middle"
184
+ verticalAnchor="middle"
185
+ x={TextX}
186
+ y={TextY}
187
+ >
188
+ {getValueByUnit({
189
+ total,
190
+ unit,
191
+ value: barStack.bars[0].bar.data[barStack.key]
192
+ })}
193
+ </Text>
194
+ )}
195
+ </g>
196
+ </Tooltip>
197
+ );
198
+ })
199
+ )
200
+ }
201
+ </BarStackComponent>
202
+ </Group>
203
+ </svg>
204
+ </div>
205
+ </div>
206
+ {displayLegend && (
207
+ <div data-testid="Legend" ref={legendRef}>
208
+ <Legend
209
+ data={data}
210
+ direction={legendDirection}
211
+ scale={legendScale}
212
+ title={title}
213
+ total={total}
214
+ unit={unit}
215
+ />
216
+ </div>
217
+ )}
218
+ </div>
219
+ );
220
+ };
221
+
222
+ export default BarStack;
@@ -0,0 +1 @@
1
+ export { default as BarStack } from './BarStack';
@@ -0,0 +1,20 @@
1
+ export interface BarType {
2
+ color: string;
3
+ label: string;
4
+ value: number;
5
+ }
6
+
7
+ export type BarStackProps = {
8
+ Legend?: ({ scale, data, title, total, unit, direction }) => JSX.Element;
9
+ TooltipContent?: (barData) => JSX.Element | boolean | null;
10
+ data: Array<BarType>;
11
+ displayLegend?: boolean;
12
+ displayValues?: boolean;
13
+ labelNoDataFound?: string;
14
+ legendDirection?: 'row' | 'column';
15
+ onSingleBarClick?: (barData) => void;
16
+ size?: number;
17
+ title?: string;
18
+ unit?: 'percentage' | 'number';
19
+ variant?: 'vertical' | 'horizontal';
20
+ };
@@ -0,0 +1,137 @@
1
+ import { scaleBand, scaleLinear, scaleOrdinal } from '@visx/scale';
2
+ import { equals, isEmpty, pluck, reject } from 'ramda';
3
+
4
+ import { getValueByUnit } from '../common/utils';
5
+ import { LegendScale } from '../Legend/models';
6
+
7
+ import { BarType } from './models';
8
+
9
+ interface Size {
10
+ height: number;
11
+ width: number;
12
+ }
13
+
14
+ interface useBarStackProps {
15
+ data: Array<BarType>;
16
+ height: number;
17
+ legendRef;
18
+ size: number;
19
+ titleRef;
20
+ unit?: 'percentage' | 'number';
21
+ variant?: 'vertical' | 'horizontal';
22
+ width: number;
23
+ }
24
+ interface useBarStackState {
25
+ areAllValuesNull: boolean;
26
+ barSize: Size;
27
+ colorScale;
28
+ input;
29
+ isVerticalBar: boolean;
30
+ keys: Array<string>;
31
+ legendScale: LegendScale;
32
+ svgContainerSize: Size;
33
+ svgWrapperWidth: number;
34
+ total: number;
35
+ xScale;
36
+ yScale;
37
+ }
38
+
39
+ const useResponsiveBarStack = ({
40
+ data,
41
+ variant,
42
+ height,
43
+ width,
44
+ unit = 'number',
45
+ titleRef,
46
+ legendRef,
47
+ size
48
+ }: useBarStackProps): useBarStackState => {
49
+ const isVerticalBar = equals(variant, 'vertical');
50
+
51
+ const heightOfTitle = titleRef.current?.offsetHeight || 0;
52
+ const widthOfLegend = legendRef.current?.offsetWidth || 0;
53
+
54
+ const horizontalGap = widthOfLegend > 0 ? 12 : 0;
55
+ const verticalGap = heightOfTitle > 0 ? 8 : 0;
56
+
57
+ const svgWrapperWidth = isVerticalBar
58
+ ? size + 36
59
+ : width - widthOfLegend - horizontalGap;
60
+
61
+ const svgContainerSize = {
62
+ height: isVerticalBar ? height - heightOfTitle - verticalGap : size,
63
+ width: isVerticalBar ? size : width - widthOfLegend - horizontalGap
64
+ };
65
+
66
+ const barSize = {
67
+ height: svgContainerSize.height - 16,
68
+ width: svgContainerSize.width - 16
69
+ };
70
+
71
+ const total = Math.floor(data.reduce((acc, { value }) => acc + value, 0));
72
+
73
+ const yScale = isVerticalBar
74
+ ? scaleLinear({
75
+ domain: [0, total]
76
+ })
77
+ : scaleBand({
78
+ domain: [0, 0],
79
+ padding: 0
80
+ });
81
+
82
+ const xScale = isVerticalBar
83
+ ? scaleBand({
84
+ domain: [0, 0],
85
+ padding: 0
86
+ })
87
+ : scaleLinear({
88
+ domain: [0, total]
89
+ });
90
+
91
+ const keys = pluck('label', data);
92
+
93
+ const colorsRange = pluck('color', data);
94
+
95
+ const colorScale = scaleOrdinal({
96
+ domain: keys,
97
+ range: colorsRange
98
+ });
99
+
100
+ const legendScale = {
101
+ domain: data.map(({ value }) => getValueByUnit({ total, unit, value })),
102
+ range: colorsRange
103
+ };
104
+
105
+ const xMax = barSize.width;
106
+ const yMax = barSize.height;
107
+
108
+ xScale.rangeRound([0, xMax]);
109
+ yScale.range([yMax, 0]);
110
+
111
+ const input = data.reduce((acc, { label, value }) => {
112
+ acc[label] = value;
113
+
114
+ return acc;
115
+ }, {});
116
+
117
+ const values = pluck('value', data);
118
+
119
+ const areAllValuesNull = isEmpty(reject((value) => equals(value, 0), values));
120
+
121
+ return {
122
+ areAllValuesNull,
123
+ barSize,
124
+ colorScale,
125
+ input,
126
+ isVerticalBar,
127
+ keys,
128
+ legendScale,
129
+ svgContainerSize,
130
+ svgWrapperWidth,
131
+ total,
132
+ xScale,
133
+ yScale
134
+ };
135
+ };
136
+
137
+ export default useResponsiveBarStack;
@@ -0,0 +1,102 @@
1
+ import dataLastWeek from '../LineChart/mockedData/lastWeek.json';
2
+ import {
3
+ criticalThresholds,
4
+ rangedThresholds,
5
+ successThresholds,
6
+ warningThresholds
7
+ } from '../common/testUtils';
8
+
9
+ import { Props, Gauge } from './Gauge';
10
+
11
+ const initialize = (
12
+ args: Omit<Props, 'data' | 'labels' | 'baseColor'>
13
+ ): void => {
14
+ cy.mount({
15
+ Component: (
16
+ <div style={{ height: '100vh', width: '100vw' }}>
17
+ <Gauge
18
+ baseColor="#000"
19
+ data={dataLastWeek}
20
+ labels={{
21
+ critical: 'Critical',
22
+ warning: 'Warning'
23
+ }}
24
+ {...args}
25
+ />
26
+ </div>
27
+ )
28
+ });
29
+ };
30
+
31
+ describe('Gauge', () => {
32
+ it('does not display the gauge when there is no data', () => {
33
+ initialize({ data: undefined, thresholds: successThresholds });
34
+
35
+ cy.contains('0.41 s').should('not.exist');
36
+ });
37
+
38
+ it('displays the gauge as success when corresponding thresholds are set', () => {
39
+ initialize({ thresholds: successThresholds });
40
+
41
+ cy.contains('0.41 s').should('have.css', 'fill', 'rgb(136, 185, 34)');
42
+ cy.findByTestId('1.1500000000000001-arc').should('be.visible');
43
+ cy.findByTestId('0.15000000000000013-arc').should('be.visible');
44
+
45
+ cy.makeSnapshot();
46
+ });
47
+
48
+ it('displays the gauge as warning when corresponding thresholds are set', () => {
49
+ initialize({ thresholds: warningThresholds });
50
+
51
+ cy.contains('0.41 s').should('have.css', 'fill', 'rgb(253, 155, 39)');
52
+ cy.findByTestId('1.25-arc').should('be.visible');
53
+ cy.findByTestId('0.15000000000000013-arc').should('be.visible');
54
+
55
+ cy.makeSnapshot();
56
+ });
57
+
58
+ it('displays the gauge as critical when corresponding thresholds are set', () => {
59
+ initialize({ thresholds: criticalThresholds });
60
+
61
+ cy.contains('0.41 s').should('have.css', 'fill', 'rgb(255, 74, 74)');
62
+ cy.findByTestId('0.6399999999999999-arc').should('be.visible');
63
+ cy.findByTestId('0.54-arc').should('be.visible');
64
+
65
+ cy.makeSnapshot();
66
+ });
67
+
68
+ it('displays ranged thresholds', () => {
69
+ initialize({ thresholds: rangedThresholds });
70
+
71
+ cy.findByTestId('0.37-arc').should('be.visible');
72
+ cy.findByTestId('0.09999999999999998-arc').should('be.visible');
73
+
74
+ cy.makeSnapshot();
75
+ });
76
+
77
+ it('displays the threshold tooltip when a threshold is hovered', () => {
78
+ initialize({ thresholds: successThresholds });
79
+
80
+ cy.findByTestId('1.1500000000000001-arc').trigger('mouseover', {
81
+ force: true
82
+ });
83
+
84
+ cy.contains('Warning').should('be.visible');
85
+
86
+ cy.findByTestId('0.15000000000000013-arc').trigger('mouseover', {
87
+ force: true
88
+ });
89
+
90
+ cy.contains('Critical').should('be.visible');
91
+
92
+ cy.makeSnapshot();
93
+ });
94
+
95
+ it('displays the value as raw when the prop is set', () => {
96
+ initialize({ displayAsRaw: true, thresholds: successThresholds });
97
+
98
+ cy.contains('0.40663333333 s').should('be.visible');
99
+
100
+ cy.makeSnapshot();
101
+ });
102
+ });
@@ -5,7 +5,7 @@ import { Metric } from '../common/timeSeries/models';
5
5
 
6
6
  import ResponsiveGauge from './ResponsiveGauge';
7
7
 
8
- interface Props {
8
+ export interface Props {
9
9
  baseColor?: string;
10
10
  data?: LineChartData;
11
11
  displayAsRaw?: boolean;