@centreon/ui 24.4.48 → 24.4.49

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 (137) hide show
  1. package/package.json +36 -29
  2. package/public/mockServiceWorker.js +1 -1
  3. package/src/Button/Icon/index.tsx +1 -1
  4. package/src/Button/Save/StartIcon.tsx +3 -3
  5. package/src/Button/Save/index.tsx +9 -5
  6. package/src/Checkbox/Checkbox.tsx +2 -2
  7. package/src/Checkbox/CheckboxGroup/index.tsx +2 -2
  8. package/src/Dashboard/Item.tsx +1 -1
  9. package/src/Dashboard/Layout.tsx +2 -2
  10. package/src/Dialog/Confirm/index.tsx +10 -2
  11. package/src/Dialog/index.tsx +9 -2
  12. package/src/FallbackPage/FallbackPage.tsx +3 -3
  13. package/src/FileDropZone/index.tsx +3 -1
  14. package/src/Form/Form.cypress.spec.tsx +133 -0
  15. package/src/Form/Inputs/List/Content.tsx +62 -0
  16. package/src/Form/Inputs/List/List.styles.ts +29 -0
  17. package/src/Form/Inputs/List/List.tsx +58 -0
  18. package/src/Form/Inputs/List/useList.ts +81 -0
  19. package/src/Form/Inputs/index.tsx +3 -1
  20. package/src/Form/Inputs/models.ts +9 -1
  21. package/src/Graph/BarStack/BarStack.cypress.spec.tsx +154 -0
  22. package/src/Graph/BarStack/BarStack.stories.tsx +123 -0
  23. package/src/Graph/BarStack/BarStack.styles.ts +36 -0
  24. package/src/Graph/BarStack/BarStack.tsx +14 -0
  25. package/src/Graph/BarStack/ResponsiveBarStack.tsx +208 -0
  26. package/src/Graph/BarStack/index.ts +1 -0
  27. package/src/Graph/BarStack/models.ts +19 -0
  28. package/src/Graph/BarStack/useResponsiveBarStack.ts +139 -0
  29. package/src/Graph/Gauge/Gauge.cypress.spec.tsx +102 -0
  30. package/src/Graph/Gauge/Gauge.tsx +1 -1
  31. package/src/Graph/HeatMap/HeatMap.cypress.spec.tsx +145 -0
  32. package/src/Graph/HeatMap/HeatMap.stories.tsx +0 -25
  33. package/src/Graph/HeatMap/ResponsiveHeatMap.tsx +8 -2
  34. package/src/Graph/Legend/Legend.tsx +21 -0
  35. package/src/Graph/Legend/index.ts +1 -0
  36. package/src/Graph/Legend/models.ts +11 -0
  37. package/src/Graph/LineChart/BasicComponents/Lines/Threshold/Circle.tsx +2 -2
  38. package/src/Graph/LineChart/BasicComponents/Thresholds.tsx +2 -2
  39. package/src/Graph/LineChart/BasicComponents/useFilterLines.ts +1 -1
  40. package/src/Graph/LineChart/InteractiveComponents/AnchorPoint/GuidingLines.tsx +2 -2
  41. package/src/Graph/LineChart/InteractiveComponents/Annotations/EventAnnotations.tsx +1 -1
  42. package/src/Graph/LineChart/Legend/Legend.styles.ts +1 -1
  43. package/src/Graph/LineChart/Legend/LegendHeader.tsx +1 -1
  44. package/src/Graph/LineChart/Legend/useInteractiveValues.ts +2 -2
  45. package/src/Graph/LineChart/Legend/useLegend.ts +3 -3
  46. package/src/Graph/LineChart/helpers/doc.ts +16 -13
  47. package/src/Graph/LineChart/helpers/index.ts +1 -1
  48. package/src/Graph/LineChart/index.stories.tsx +4 -2
  49. package/src/Graph/LineChart/index.tsx +1 -1
  50. package/src/Graph/PieChart/PieChart.cypress.spec.tsx +169 -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 +251 -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 +86 -0
  58. package/src/Graph/SingleBar/SingleBar.cypress.spec.tsx +121 -0
  59. package/src/Graph/SingleBar/Thresholds.tsx +2 -2
  60. package/src/Graph/Text/Text.cypress.spec.tsx +101 -0
  61. package/src/Graph/Text/Text.stories.tsx +60 -4
  62. package/src/Graph/Text/Text.tsx +1 -1
  63. package/src/Graph/common/testUtils.ts +71 -0
  64. package/src/Graph/common/timeSeries/index.ts +22 -14
  65. package/src/Graph/common/utils.ts +19 -0
  66. package/src/Graph/index.ts +3 -0
  67. package/src/Graph/translatedLabels.ts +1 -0
  68. package/src/InputField/Select/Autocomplete/Connected/index.tsx +10 -7
  69. package/src/InputField/Select/Autocomplete/Draggable/SortableList.tsx +1 -1
  70. package/src/InputField/Select/Autocomplete/Draggable/SortableListContent.tsx +1 -1
  71. package/src/InputField/Select/Autocomplete/Draggable/index.tsx +1 -1
  72. package/src/InputField/Select/Autocomplete/index.tsx +121 -115
  73. package/src/InputField/Select/IconPopover/index.tsx +2 -2
  74. package/src/InputField/Select/index.tsx +1 -1
  75. package/src/InputField/Text/index.tsx +2 -2
  76. package/src/Listing/ActionBar/index.tsx +9 -8
  77. package/src/Listing/Cell/DataCell.styles.ts +3 -0
  78. package/src/Listing/Cell/DataCell.tsx +23 -5
  79. package/src/Listing/Header/ListingHeader.tsx +1 -1
  80. package/src/Listing/Listing.cypress.spec.tsx +80 -4
  81. package/src/Listing/Listing.styles.ts +4 -7
  82. package/src/Listing/index.stories.tsx +37 -3
  83. package/src/Listing/index.test.tsx +1 -1
  84. package/src/Listing/index.tsx +4 -3
  85. package/src/Listing/models.ts +1 -0
  86. package/src/Module/Module.cypress.spec.tsx +129 -0
  87. package/src/Module/index.tsx +2 -4
  88. package/src/RichTextEditor/RichTextEditor.tsx +12 -1
  89. package/src/SortableItems/index.tsx +2 -7
  90. package/src/ThemeProvider/index.tsx +24 -0
  91. package/src/TimePeriods/CustomTimePeriod/CompactCustomTimePeriod.styles.ts +6 -7
  92. package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/PickersStartEndDate.tsx +8 -3
  93. package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/models.ts +0 -2
  94. package/src/TimePeriods/DateTimePickerInput.tsx +56 -19
  95. package/src/TimePeriods/ResolutionTimePeriod.cypress.spec.tsx +12 -9
  96. package/src/TimePeriods/TimePeriods.cypress.spec.tsx +9 -33
  97. package/src/TimePeriods/helpers/index.ts +1 -1
  98. package/src/TimePeriods/index.stories.tsx +12 -4
  99. package/src/TimePeriods/index.tsx +2 -2
  100. package/src/api/QueryProvider.tsx +1 -1
  101. package/src/api/TestQueryProvider.tsx +1 -1
  102. package/src/api/useFetchQuery/index.ts +27 -23
  103. package/src/api/useMutationQuery/index.test.ts +4 -4
  104. package/src/api/useMutationQuery/index.ts +60 -25
  105. package/src/components/Button/Icon/IconButton.tsx +6 -2
  106. package/src/components/DataTable/DataListing.tsx +6 -0
  107. package/src/components/DataTable/DataTable.cypress.spec.tsx +193 -0
  108. package/src/components/DataTable/DataTable.stories.tsx +40 -0
  109. package/src/components/DataTable/DataTable.styles.ts +3 -0
  110. package/src/components/DataTable/DataTable.tsx +3 -3
  111. package/src/components/DataTable/Item/DataTableItem.styles.ts +7 -2
  112. package/src/components/DataTable/Item/DataTableItem.tsx +4 -4
  113. package/src/components/DataTable/index.ts +3 -1
  114. package/src/components/Form/AccessRights/ShareInput/ContactSwitch.tsx +3 -3
  115. package/src/components/Form/AccessRights/ShareInput/ShareInput.tsx +1 -0
  116. package/src/components/Form/Dashboard/DashboardForm.tsx +15 -12
  117. package/src/components/Layout/PageLayout/PageLayout.tsx +1 -1
  118. package/src/components/Layout/PageLayout/PageLayoutActions.tsx +1 -0
  119. package/src/components/Layout/PageLayout/PageLayoutBody.tsx +1 -0
  120. package/src/components/Layout/PageLayout/PageLayoutHeader.tsx +5 -1
  121. package/src/components/Layout/PageLayout/PageQuickAccess.tsx +76 -0
  122. package/src/components/Layout/PageLayout/index.ts +3 -1
  123. package/src/components/Layout/PageLayout.cypress.spec.tsx +66 -0
  124. package/src/components/Modal/Modal.styles.ts +1 -1
  125. package/src/components/Tooltip/ConfirmationTooltip/ConfirmationTooltip.stories.tsx +3 -3
  126. package/src/components/Tooltip/ConfirmationTooltip/ConfirmationTooltip.tsx +1 -1
  127. package/src/components/Tooltip/ConfirmationTooltip/models.ts +1 -1
  128. package/src/index.ts +2 -2
  129. package/src/queryParameters/url/index.ts +5 -1
  130. package/src/utils/index.ts +1 -1
  131. package/src/utils/useFullscreen/useFullscreenListener.ts +10 -7
  132. package/src/utils/{useLicenseExpirationWarning.cypress.spec.tsx → useLicenseExpirationWarning.test.tsx} +48 -37
  133. package/src/utils/useLicenseExpirationWarning.ts +18 -18
  134. package/src/utils/usePluralizedTranslation.ts +21 -0
  135. package/src/screens/dashboard/DashboardsDetail.stories.tsx +0 -108
  136. package/src/screens/dashboard/DashboardsOverview.stories.tsx +0 -281
  137. package/src/utils/useDateTimePickerAdapter.ts +0 -309
@@ -0,0 +1,251 @@
1
+ import { useRef } from 'react';
2
+
3
+ import { Pie } from '@visx/shape';
4
+ import { Group } from '@visx/group';
5
+ import { Text } from '@visx/text';
6
+ import numeral from 'numeral';
7
+ import { always, equals, gt, ifElse, lt } from 'ramda';
8
+ import { useTranslation } from 'react-i18next';
9
+
10
+ import { Typography, useTheme } from '@mui/material';
11
+
12
+ import { Tooltip } from '../../components';
13
+ import { Legend as LegendComponent } from '../Legend';
14
+ import { LegendProps } from '../Legend/models';
15
+ import { getValueByUnit } from '../common/utils';
16
+ import { labelNoDataFound } from '../translatedLabels';
17
+
18
+ import { PieProps } from './models';
19
+ import { usePieStyles } from './PieChart.styles';
20
+ import { useResponsivePie } from './useResponsivePie';
21
+
22
+ const DefaultLengd = ({ scale, direction }: LegendProps): JSX.Element => (
23
+ <LegendComponent direction={direction} scale={scale} />
24
+ );
25
+
26
+ type Placement = 'left' | 'right' | 'top' | 'bottom';
27
+
28
+ const getTooltipPlacement = ({ radianX, radianY }): Placement => {
29
+ if (gt(Math.abs(radianX), Math.abs(radianY))) {
30
+ return ifElse<[b: number], Placement, Placement>(
31
+ lt(0),
32
+ always<Placement>('right'),
33
+ always<Placement>('left')
34
+ )(radianX);
35
+ }
36
+
37
+ return ifElse<[b: number], Placement, Placement>(
38
+ lt(0),
39
+ always<Placement>('bottom'),
40
+ always<Placement>('top')
41
+ )(radianY);
42
+ };
43
+
44
+ const ResponsivePie = ({
45
+ title,
46
+ variant = 'pie',
47
+ width,
48
+ height,
49
+ data,
50
+ unit = 'number',
51
+ Legend = DefaultLengd,
52
+ displayLegend = true,
53
+ innerRadius: defaultInnerRadius = 40,
54
+ onArcClick,
55
+ displayValues,
56
+ TooltipContent,
57
+ legendDirection = 'column'
58
+ }: PieProps & { height: number; width: number }): JSX.Element => {
59
+ const { t } = useTranslation();
60
+ const theme = useTheme();
61
+
62
+ const legendRef = useRef(null);
63
+ const titleRef = useRef(null);
64
+
65
+ const {
66
+ half,
67
+ legendScale,
68
+ svgContainerSize,
69
+ svgSize,
70
+ svgWrapperWidth,
71
+ total,
72
+ innerRadius,
73
+ isContainsExactlyOneNonZeroValue,
74
+ areAllValuesNull
75
+ } = useResponsivePie({
76
+ data,
77
+ defaultInnerRadius,
78
+ height,
79
+ legendRef,
80
+ titleRef,
81
+ unit,
82
+ width
83
+ });
84
+
85
+ const { classes } = usePieStyles({ svgSize });
86
+
87
+ if (areAllValuesNull) {
88
+ return (
89
+ <div className={classes.container} style={{ height, width }}>
90
+ <Typography variant="h3">{t(labelNoDataFound)}</Typography>
91
+ </div>
92
+ );
93
+ }
94
+
95
+ return (
96
+ <div
97
+ className={classes.container}
98
+ style={{
99
+ height,
100
+ width
101
+ }}
102
+ >
103
+ <div
104
+ className={classes.svgWrapper}
105
+ style={{
106
+ height,
107
+ width: svgWrapperWidth
108
+ }}
109
+ >
110
+ {equals(variant, 'pie') && title && (
111
+ <div className={classes.title} data-testid="Title" ref={titleRef}>
112
+ {`${numeral(total).format('0a').toUpperCase()} `} {title}
113
+ </div>
114
+ )}
115
+ <div
116
+ className={classes.svgContainer}
117
+ data-testid="pieChart"
118
+ style={{
119
+ height: svgContainerSize,
120
+ width: svgContainerSize
121
+ }}
122
+ >
123
+ <svg data-variant={variant} height={svgSize} width={svgSize}>
124
+ <Group left={half} top={half}>
125
+ <Pie
126
+ cornerRadius={4}
127
+ data={data}
128
+ innerRadius={() => {
129
+ return equals(variant, 'pie') ? 0 : half - innerRadius;
130
+ }}
131
+ outerRadius={half}
132
+ pieValue={(items) => items.value}
133
+ >
134
+ {(pie) => {
135
+ return pie.arcs.map((arc) => {
136
+ const [centroidX, centroidY] = pie.path.centroid(arc);
137
+ const midAngle = Math.atan2(centroidY, centroidX);
138
+
139
+ const labelRadius = half * 0.8;
140
+
141
+ const labelX = Math.cos(midAngle) * labelRadius;
142
+ const labelY = Math.sin(midAngle) * labelRadius;
143
+
144
+ const angle = arc.endAngle - arc.startAngle;
145
+ const minAngle = 0.2;
146
+
147
+ const x = equals(variant, 'donut') ? centroidX : labelX;
148
+ const y = equals(variant, 'donut') ? centroidY : labelY;
149
+
150
+ const onClick = (): void => {
151
+ onArcClick?.(arc.data);
152
+ };
153
+
154
+ return (
155
+ <Tooltip
156
+ hasCaret
157
+ classes={{
158
+ tooltip: classes.pieChartTooltip
159
+ }}
160
+ followCursor={false}
161
+ key={arc.data.label}
162
+ label={
163
+ TooltipContent && (
164
+ <TooltipContent
165
+ color={arc.data.color}
166
+ label={arc.data.label}
167
+ title={title}
168
+ total={total}
169
+ value={arc.data.value}
170
+ />
171
+ )
172
+ }
173
+ leaveDelay={200}
174
+ placement={getTooltipPlacement({
175
+ radianX: Math.cos(midAngle),
176
+ radianY: Math.sin(midAngle)
177
+ })}
178
+ >
179
+ <g data-testid={arc.data.label} onClick={onClick}>
180
+ <path
181
+ d={pie.path(arc) as string}
182
+ fill={arc.data.color}
183
+ />
184
+ {displayValues &&
185
+ !isContainsExactlyOneNonZeroValue &&
186
+ angle > minAngle && (
187
+ <Text
188
+ data-testid="value"
189
+ dy=".33em"
190
+ fill="#000"
191
+ fontSize={12}
192
+ pointerEvents="none"
193
+ textAnchor="middle"
194
+ x={x}
195
+ y={y}
196
+ >
197
+ {getValueByUnit({
198
+ total,
199
+ unit,
200
+ value: arc.data.value
201
+ })}
202
+ </Text>
203
+ )}
204
+ </g>
205
+ </Tooltip>
206
+ );
207
+ });
208
+ }}
209
+ </Pie>
210
+ {equals(variant, 'donut') && title && (
211
+ <>
212
+ <Text
213
+ className={classes.title}
214
+ dy={lt(svgSize, 150) ? -10 : -15}
215
+ fill={theme.palette.text.primary}
216
+ textAnchor="middle"
217
+ >
218
+ {numeral(total).format('0a').toUpperCase()}
219
+ </Text>
220
+ <Text
221
+ className={classes.title}
222
+ data-testid="Title"
223
+ dy={lt(svgSize, 150) ? 10 : 15}
224
+ fill={theme.palette.text.primary}
225
+ textAnchor="middle"
226
+ >
227
+ {title}
228
+ </Text>
229
+ </>
230
+ )}
231
+ </Group>
232
+ </svg>
233
+ </div>
234
+ </div>
235
+ {displayLegend && (
236
+ <div data-testid="Legend" ref={legendRef}>
237
+ <Legend
238
+ data={data}
239
+ direction={legendDirection}
240
+ scale={legendScale}
241
+ title={title}
242
+ total={total}
243
+ unit={unit}
244
+ />
245
+ </div>
246
+ )}
247
+ </div>
248
+ );
249
+ };
250
+
251
+ export default ResponsivePie;
@@ -0,0 +1 @@
1
+ export { default as PieChart } from './PieChart';
@@ -0,0 +1,19 @@
1
+ export interface ArcType {
2
+ color: string;
3
+ label: string;
4
+ value: number;
5
+ }
6
+
7
+ export interface PieProps {
8
+ Legend?: ({ scale, direction, data, title, total, unit }) => JSX.Element;
9
+ TooltipContent?: (arcData) => JSX.Element | boolean | null;
10
+ data: Array<ArcType>;
11
+ displayLegend?: boolean;
12
+ displayValues?: boolean;
13
+ innerRadius?: number;
14
+ legendDirection?: 'row' | 'column';
15
+ onArcClick?: (ardata) => void;
16
+ title?: string;
17
+ unit?: 'percentage' | 'number';
18
+ variant?: 'pie' | 'donut';
19
+ }
@@ -0,0 +1,86 @@
1
+ import { equals, isEmpty, pluck, reject } from 'ramda';
2
+
3
+ import { LegendScale } from '../Legend/models';
4
+ import { getValueByUnit } from '../common/utils';
5
+
6
+ import { ArcType } from './models';
7
+
8
+ interface ResponsivePieProps {
9
+ data: Array<ArcType>;
10
+ defaultInnerRadius: number;
11
+ height: number;
12
+ legendRef;
13
+ titleRef;
14
+ unit: 'percentage' | 'number';
15
+ width: number;
16
+ }
17
+
18
+ interface ResponsivePieState {
19
+ areAllValuesNull: boolean;
20
+ half: number;
21
+ innerRadius: number;
22
+ isContainsExactlyOneNonZeroValue: boolean;
23
+ legendScale: LegendScale;
24
+ svgContainerSize: number;
25
+ svgSize: number;
26
+ svgWrapperWidth: number;
27
+ total: number;
28
+ }
29
+ export const useResponsivePie = ({
30
+ titleRef,
31
+ legendRef,
32
+ height,
33
+ width,
34
+ data,
35
+ unit,
36
+ defaultInnerRadius
37
+ }: ResponsivePieProps): ResponsivePieState => {
38
+ const heightOfTitle = titleRef.current?.offsetHeight || 0;
39
+ const widthOfLegend = legendRef.current?.offsetWidth || 0;
40
+
41
+ const horizontalGap = widthOfLegend > 0 ? 16 : 0;
42
+ const verticalGap = heightOfTitle > 0 ? 8 : 0;
43
+
44
+ const svgWrapperWidth = width - widthOfLegend - horizontalGap;
45
+
46
+ const svgContainerSize = Math.min(
47
+ height - heightOfTitle - verticalGap,
48
+ width - widthOfLegend - horizontalGap
49
+ );
50
+
51
+ const outerRadius = Math.min(32, svgContainerSize / 6);
52
+
53
+ const svgSize = svgContainerSize - outerRadius;
54
+
55
+ const half = svgSize / 2;
56
+
57
+ const total = Math.floor(data.reduce((acc, { value }) => acc + value, 0));
58
+
59
+ const innerRadius = Math.min(defaultInnerRadius, svgSize / 5);
60
+
61
+ const legendScale = {
62
+ domain: data.map(({ value }) => getValueByUnit({ total, unit, value })),
63
+ range: pluck('color', data)
64
+ };
65
+
66
+ const values = pluck('value', data);
67
+
68
+ const isContainsExactlyOneNonZeroValue = equals(
69
+ reject((value) => equals(value, 0), values).length,
70
+ 1
71
+ );
72
+
73
+ const areAllValuesNull = isEmpty(reject((value) => equals(value, 0), values));
74
+
75
+ return {
76
+ areAllValuesNull,
77
+ half,
78
+ innerRadius,
79
+ isContainsExactlyOneNonZeroValue,
80
+ legendScale,
81
+ svgContainerSize,
82
+ svgSize,
83
+ svgWrapperWidth,
84
+ total
85
+ };
86
+ };
@@ -0,0 +1,121 @@
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 SingleBar from './SingleBar';
10
+ import { SingleBarProps } from './models';
11
+
12
+ const initialize = (
13
+ args: Omit<SingleBarProps, 'data' | 'labels' | 'baseColor'>
14
+ ): void => {
15
+ cy.mount({
16
+ Component: (
17
+ <div style={{ height: '100vh', width: '100vw' }}>
18
+ <SingleBar
19
+ baseColor="#000"
20
+ data={dataLastWeek}
21
+ labels={{
22
+ critical: 'Critical',
23
+ warning: 'Warning'
24
+ }}
25
+ {...args}
26
+ />
27
+ </div>
28
+ )
29
+ });
30
+ };
31
+
32
+ describe('Single bar', () => {
33
+ it('displays the single bar as success when corresponding thresholds are set', () => {
34
+ initialize({ thresholds: successThresholds });
35
+
36
+ cy.contains('0.41 s').should('have.css', 'fill', 'rgb(136, 185, 34)');
37
+ cy.findByTestId('warning-line-0.5').should('be.visible');
38
+ cy.findByTestId('warning-line-0.5-tooltip').should('be.visible');
39
+ cy.findByTestId('critical-line-1.5').should('be.visible');
40
+ cy.findByTestId('critical-line-1.5-tooltip').should('be.visible');
41
+
42
+ cy.makeSnapshot();
43
+ });
44
+
45
+ it('displays the single bar as warning when corresponding thresholds are set', () => {
46
+ initialize({ thresholds: warningThresholds });
47
+
48
+ cy.contains('0.41 s').should('have.css', 'fill', 'rgb(253, 155, 39)');
49
+ cy.findByTestId('warning-line-0.4').should('be.visible');
50
+ cy.findByTestId('warning-line-0.4-tooltip').should('be.visible');
51
+ cy.findByTestId('critical-line-1.5').should('be.visible');
52
+ cy.findByTestId('critical-line-1.5-tooltip').should('be.visible');
53
+
54
+ cy.makeSnapshot();
55
+ });
56
+
57
+ it('displays the single bar as critical when corresponding thresholds are set', () => {
58
+ initialize({ thresholds: criticalThresholds });
59
+
60
+ cy.contains('0.41 s').should('have.css', 'fill', 'rgb(255, 74, 74)');
61
+ cy.findByTestId('warning-line-0.2').should('be.visible');
62
+ cy.findByTestId('warning-line-0.2-tooltip').should('be.visible');
63
+ cy.findByTestId('critical-line-0.3').should('be.visible');
64
+ cy.findByTestId('critical-line-0.3-tooltip').should('be.visible');
65
+
66
+ cy.makeSnapshot();
67
+ });
68
+
69
+ it('displays ranged thresholds', () => {
70
+ initialize({ thresholds: rangedThresholds });
71
+
72
+ cy.findByTestId('warning-line-0.13').should('be.visible');
73
+ cy.findByTestId('warning-line-0.13-tooltip').should('be.visible');
74
+ cy.findByTestId('warning-line-0.5').should('be.visible');
75
+ cy.findByTestId('warning-line-0.5-tooltip').should('be.visible');
76
+ cy.findByTestId('critical-line-0.55').should('be.visible');
77
+ cy.findByTestId('critical-line-0.55-tooltip').should('be.visible');
78
+ cy.findByTestId('critical-line-0.65').should('be.visible');
79
+ cy.findByTestId('critical-line-0.65-tooltip').should('be.visible');
80
+
81
+ cy.makeSnapshot();
82
+ });
83
+
84
+ it('displays the threshold tooltip when a threshold is hovered', () => {
85
+ initialize({ thresholds: successThresholds });
86
+
87
+ cy.findByTestId('warning-line-0.5-tooltip').trigger('mouseover');
88
+
89
+ cy.contains('Warning').should('be.visible');
90
+
91
+ cy.findByTestId('critical-line-1.5-tooltip').trigger('mouseover');
92
+
93
+ cy.contains('Critical').should('be.visible');
94
+
95
+ cy.makeSnapshot();
96
+ });
97
+
98
+ it('displays single bar as small when the props is set', () => {
99
+ initialize({ size: 'small', thresholds: successThresholds });
100
+
101
+ cy.findByTestId('warning-line-0.5-tooltip').should('be.visible');
102
+
103
+ cy.makeSnapshot();
104
+ });
105
+
106
+ it('displays the value as raw when the prop is set', () => {
107
+ initialize({ displayAsRaw: true, thresholds: successThresholds });
108
+
109
+ cy.contains('0.40663333333 s').should('be.visible');
110
+
111
+ cy.makeSnapshot();
112
+ });
113
+
114
+ it('does not display the value when the prop is set', () => {
115
+ initialize({ showLabels: false, thresholds: successThresholds });
116
+
117
+ cy.contains('0.41 s').should('not.exist');
118
+
119
+ cy.makeSnapshot();
120
+ });
121
+ });
@@ -1,4 +1,4 @@
1
- import { Thresholds } from '../common/models';
1
+ import { Thresholds as ThresholdsModel } from '../common/models';
2
2
 
3
3
  import { ThresholdLine } from './ThresholdLine';
4
4
 
@@ -8,7 +8,7 @@ interface Props {
8
8
  hideTooltip: () => void;
9
9
  showTooltip: (args) => void;
10
10
  size: 'small' | 'medium';
11
- thresholds: Thresholds;
11
+ thresholds: ThresholdsModel;
12
12
  xScale: (value: number) => number;
13
13
  }
14
14
 
@@ -0,0 +1,101 @@
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 { Text, Props } from './Text';
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
+ <Text
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('Text', () => {
32
+ it('displays the text as success when corresponding thresholds are set', () => {
33
+ initialize({ thresholds: successThresholds });
34
+
35
+ cy.contains('0.41 s').should('have.css', 'color', 'rgb(136, 185, 34)');
36
+ cy.contains('Warning: 0.5 s').should('be.visible');
37
+ cy.contains('Critical: 1.5 s').should('be.visible');
38
+
39
+ cy.makeSnapshot();
40
+ });
41
+
42
+ it('displays the text as warning when corresponding thresholds are set', () => {
43
+ initialize({ thresholds: warningThresholds });
44
+
45
+ cy.contains('0.41 s').should('have.css', 'color', 'rgb(253, 155, 39)');
46
+ cy.contains('Warning: 0.4 s').should('be.visible');
47
+ cy.contains('Critical: 1.5 s').should('be.visible');
48
+
49
+ cy.makeSnapshot();
50
+ });
51
+
52
+ it('displays the text as critical when corresponding thresholds are set', () => {
53
+ initialize({ thresholds: criticalThresholds });
54
+
55
+ cy.contains('0.41 s').should('have.css', 'color', 'rgb(255, 74, 74)');
56
+ cy.contains('Warning: 0.2 s').should('be.visible');
57
+ cy.contains('Critical: 0.3 s').should('be.visible');
58
+
59
+ cy.makeSnapshot();
60
+ });
61
+
62
+ it('displays ranged thresholds', () => {
63
+ initialize({ thresholds: rangedThresholds });
64
+
65
+ cy.contains('Warning: 0.13 s - 0.5 s').should('be.visible');
66
+ cy.contains('Critical: 0.55 s - 0.65 s').should('be.visible');
67
+
68
+ cy.makeSnapshot();
69
+ });
70
+
71
+ it('displays the value as raw when the prop is set', () => {
72
+ initialize({ displayAsRaw: true, thresholds: successThresholds });
73
+
74
+ cy.contains('0.40663333333 s').should('be.visible');
75
+
76
+ cy.makeSnapshot();
77
+ });
78
+
79
+ it('does not display the text', () => {
80
+ initialize({ data: undefined, thresholds: successThresholds });
81
+
82
+ cy.contains('0.41 s').should('not.exist');
83
+
84
+ cy.makeSnapshot();
85
+ });
86
+
87
+ it('displays text with default values when the data is empty', () => {
88
+ initialize({
89
+ data: {
90
+ global: {},
91
+ metrics: [],
92
+ times: []
93
+ },
94
+ thresholds: successThresholds
95
+ });
96
+
97
+ cy.contains('0').should('be.visible');
98
+
99
+ cy.makeSnapshot();
100
+ });
101
+ });
@@ -24,7 +24,21 @@ export const success: Story = {
24
24
  critical: 'Critical',
25
25
  warning: 'Warning'
26
26
  },
27
- thresholds: [0.5, 1.5]
27
+ thresholds: {
28
+ critical: [
29
+ {
30
+ label: 'Critical',
31
+ value: 1.5
32
+ }
33
+ ],
34
+ enabled: true,
35
+ warning: [
36
+ {
37
+ label: 'Warning',
38
+ value: 0.5
39
+ }
40
+ ]
41
+ }
28
42
  },
29
43
  render: Template
30
44
  };
@@ -36,7 +50,21 @@ export const warning: Story = {
36
50
  critical: 'Critical',
37
51
  warning: 'Warning'
38
52
  },
39
- thresholds: [0.2, 0.5]
53
+ thresholds: {
54
+ critical: [
55
+ {
56
+ label: 'Critical',
57
+ value: 1.5
58
+ }
59
+ ],
60
+ enabled: true,
61
+ warning: [
62
+ {
63
+ label: 'Warning',
64
+ value: 0.4
65
+ }
66
+ ]
67
+ }
40
68
  },
41
69
  render: Template
42
70
  };
@@ -48,7 +76,21 @@ export const critical: Story = {
48
76
  critical: 'Critical',
49
77
  warning: 'Warning'
50
78
  },
51
- thresholds: [0.13, 0.35]
79
+ thresholds: {
80
+ critical: [
81
+ {
82
+ label: 'Critical',
83
+ value: 0.3
84
+ }
85
+ ],
86
+ enabled: true,
87
+ warning: [
88
+ {
89
+ label: 'Warning',
90
+ value: 0.2
91
+ }
92
+ ]
93
+ }
52
94
  },
53
95
  render: Template
54
96
  };
@@ -61,7 +103,21 @@ export const rawValue: Story = {
61
103
  critical: 'Critical',
62
104
  warning: 'Warning'
63
105
  },
64
- thresholds: [0.5, 1.5]
106
+ thresholds: {
107
+ critical: [
108
+ {
109
+ label: 'Critical',
110
+ value: 1.5
111
+ }
112
+ ],
113
+ enabled: true,
114
+ warning: [
115
+ {
116
+ label: 'Warning',
117
+ value: 0.5
118
+ }
119
+ ]
120
+ }
65
121
  },
66
122
  render: Template
67
123
  };
@@ -11,7 +11,7 @@ import { getColorFromDataAndTresholds } from '../common/utils';
11
11
 
12
12
  import { useTextStyles } from './Text.styles';
13
13
 
14
- interface Props {
14
+ export interface Props {
15
15
  baseColor?: string;
16
16
  data?: LineChartData;
17
17
  displayAsRaw?: boolean;