@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.
- package/package.json +36 -29
- package/public/mockServiceWorker.js +1 -1
- package/src/Button/Icon/index.tsx +1 -1
- package/src/Button/Save/StartIcon.tsx +3 -3
- package/src/Button/Save/index.tsx +9 -5
- package/src/Checkbox/Checkbox.tsx +2 -2
- package/src/Checkbox/CheckboxGroup/index.tsx +2 -2
- package/src/Dashboard/Item.tsx +1 -1
- package/src/Dashboard/Layout.tsx +2 -2
- package/src/Dialog/Confirm/index.tsx +10 -2
- package/src/Dialog/index.tsx +9 -2
- package/src/FallbackPage/FallbackPage.tsx +3 -3
- package/src/FileDropZone/index.tsx +3 -1
- package/src/Form/Form.cypress.spec.tsx +133 -0
- package/src/Form/Inputs/List/Content.tsx +62 -0
- package/src/Form/Inputs/List/List.styles.ts +29 -0
- package/src/Form/Inputs/List/List.tsx +58 -0
- package/src/Form/Inputs/List/useList.ts +81 -0
- package/src/Form/Inputs/index.tsx +3 -1
- package/src/Form/Inputs/models.ts +9 -1
- package/src/Graph/BarStack/BarStack.cypress.spec.tsx +154 -0
- package/src/Graph/BarStack/BarStack.stories.tsx +123 -0
- package/src/Graph/BarStack/BarStack.styles.ts +36 -0
- package/src/Graph/BarStack/BarStack.tsx +14 -0
- package/src/Graph/BarStack/ResponsiveBarStack.tsx +208 -0
- package/src/Graph/BarStack/index.ts +1 -0
- package/src/Graph/BarStack/models.ts +19 -0
- package/src/Graph/BarStack/useResponsiveBarStack.ts +139 -0
- package/src/Graph/Gauge/Gauge.cypress.spec.tsx +102 -0
- package/src/Graph/Gauge/Gauge.tsx +1 -1
- package/src/Graph/HeatMap/HeatMap.cypress.spec.tsx +145 -0
- package/src/Graph/HeatMap/HeatMap.stories.tsx +0 -25
- package/src/Graph/HeatMap/ResponsiveHeatMap.tsx +8 -2
- package/src/Graph/Legend/Legend.tsx +21 -0
- package/src/Graph/Legend/index.ts +1 -0
- package/src/Graph/Legend/models.ts +11 -0
- package/src/Graph/LineChart/BasicComponents/Lines/Threshold/Circle.tsx +2 -2
- package/src/Graph/LineChart/BasicComponents/Thresholds.tsx +2 -2
- package/src/Graph/LineChart/BasicComponents/useFilterLines.ts +1 -1
- package/src/Graph/LineChart/InteractiveComponents/AnchorPoint/GuidingLines.tsx +2 -2
- package/src/Graph/LineChart/InteractiveComponents/Annotations/EventAnnotations.tsx +1 -1
- package/src/Graph/LineChart/Legend/Legend.styles.ts +1 -1
- package/src/Graph/LineChart/Legend/LegendHeader.tsx +1 -1
- package/src/Graph/LineChart/Legend/useInteractiveValues.ts +2 -2
- package/src/Graph/LineChart/Legend/useLegend.ts +3 -3
- package/src/Graph/LineChart/helpers/doc.ts +16 -13
- package/src/Graph/LineChart/helpers/index.ts +1 -1
- package/src/Graph/LineChart/index.stories.tsx +4 -2
- package/src/Graph/LineChart/index.tsx +1 -1
- package/src/Graph/PieChart/PieChart.cypress.spec.tsx +169 -0
- package/src/Graph/PieChart/PieChart.stories.tsx +194 -0
- package/src/Graph/PieChart/PieChart.styles.ts +39 -0
- package/src/Graph/PieChart/PieChart.tsx +14 -0
- package/src/Graph/PieChart/ResponsivePie.tsx +251 -0
- package/src/Graph/PieChart/index.ts +1 -0
- package/src/Graph/PieChart/models.ts +19 -0
- package/src/Graph/PieChart/useResponsivePie.ts +86 -0
- package/src/Graph/SingleBar/SingleBar.cypress.spec.tsx +121 -0
- package/src/Graph/SingleBar/Thresholds.tsx +2 -2
- package/src/Graph/Text/Text.cypress.spec.tsx +101 -0
- package/src/Graph/Text/Text.stories.tsx +60 -4
- package/src/Graph/Text/Text.tsx +1 -1
- package/src/Graph/common/testUtils.ts +71 -0
- package/src/Graph/common/timeSeries/index.ts +22 -14
- package/src/Graph/common/utils.ts +19 -0
- package/src/Graph/index.ts +3 -0
- package/src/Graph/translatedLabels.ts +1 -0
- package/src/InputField/Select/Autocomplete/Connected/index.tsx +10 -7
- package/src/InputField/Select/Autocomplete/Draggable/SortableList.tsx +1 -1
- package/src/InputField/Select/Autocomplete/Draggable/SortableListContent.tsx +1 -1
- package/src/InputField/Select/Autocomplete/Draggable/index.tsx +1 -1
- package/src/InputField/Select/Autocomplete/index.tsx +121 -115
- package/src/InputField/Select/IconPopover/index.tsx +2 -2
- package/src/InputField/Select/index.tsx +1 -1
- package/src/InputField/Text/index.tsx +2 -2
- package/src/Listing/ActionBar/index.tsx +9 -8
- package/src/Listing/Cell/DataCell.styles.ts +3 -0
- package/src/Listing/Cell/DataCell.tsx +23 -5
- package/src/Listing/Header/ListingHeader.tsx +1 -1
- package/src/Listing/Listing.cypress.spec.tsx +80 -4
- package/src/Listing/Listing.styles.ts +4 -7
- package/src/Listing/index.stories.tsx +37 -3
- package/src/Listing/index.test.tsx +1 -1
- package/src/Listing/index.tsx +4 -3
- package/src/Listing/models.ts +1 -0
- package/src/Module/Module.cypress.spec.tsx +129 -0
- package/src/Module/index.tsx +2 -4
- package/src/RichTextEditor/RichTextEditor.tsx +12 -1
- package/src/SortableItems/index.tsx +2 -7
- package/src/ThemeProvider/index.tsx +24 -0
- package/src/TimePeriods/CustomTimePeriod/CompactCustomTimePeriod.styles.ts +6 -7
- package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/PickersStartEndDate.tsx +8 -3
- package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/models.ts +0 -2
- package/src/TimePeriods/DateTimePickerInput.tsx +56 -19
- package/src/TimePeriods/ResolutionTimePeriod.cypress.spec.tsx +12 -9
- package/src/TimePeriods/TimePeriods.cypress.spec.tsx +9 -33
- package/src/TimePeriods/helpers/index.ts +1 -1
- package/src/TimePeriods/index.stories.tsx +12 -4
- package/src/TimePeriods/index.tsx +2 -2
- package/src/api/QueryProvider.tsx +1 -1
- package/src/api/TestQueryProvider.tsx +1 -1
- package/src/api/useFetchQuery/index.ts +27 -23
- package/src/api/useMutationQuery/index.test.ts +4 -4
- package/src/api/useMutationQuery/index.ts +60 -25
- package/src/components/Button/Icon/IconButton.tsx +6 -2
- package/src/components/DataTable/DataListing.tsx +6 -0
- package/src/components/DataTable/DataTable.cypress.spec.tsx +193 -0
- package/src/components/DataTable/DataTable.stories.tsx +40 -0
- package/src/components/DataTable/DataTable.styles.ts +3 -0
- package/src/components/DataTable/DataTable.tsx +3 -3
- package/src/components/DataTable/Item/DataTableItem.styles.ts +7 -2
- package/src/components/DataTable/Item/DataTableItem.tsx +4 -4
- package/src/components/DataTable/index.ts +3 -1
- package/src/components/Form/AccessRights/ShareInput/ContactSwitch.tsx +3 -3
- package/src/components/Form/AccessRights/ShareInput/ShareInput.tsx +1 -0
- package/src/components/Form/Dashboard/DashboardForm.tsx +15 -12
- package/src/components/Layout/PageLayout/PageLayout.tsx +1 -1
- package/src/components/Layout/PageLayout/PageLayoutActions.tsx +1 -0
- package/src/components/Layout/PageLayout/PageLayoutBody.tsx +1 -0
- package/src/components/Layout/PageLayout/PageLayoutHeader.tsx +5 -1
- package/src/components/Layout/PageLayout/PageQuickAccess.tsx +76 -0
- package/src/components/Layout/PageLayout/index.ts +3 -1
- package/src/components/Layout/PageLayout.cypress.spec.tsx +66 -0
- package/src/components/Modal/Modal.styles.ts +1 -1
- package/src/components/Tooltip/ConfirmationTooltip/ConfirmationTooltip.stories.tsx +3 -3
- package/src/components/Tooltip/ConfirmationTooltip/ConfirmationTooltip.tsx +1 -1
- package/src/components/Tooltip/ConfirmationTooltip/models.ts +1 -1
- package/src/index.ts +2 -2
- package/src/queryParameters/url/index.ts +5 -1
- package/src/utils/index.ts +1 -1
- package/src/utils/useFullscreen/useFullscreenListener.ts +10 -7
- package/src/utils/{useLicenseExpirationWarning.cypress.spec.tsx → useLicenseExpirationWarning.test.tsx} +48 -37
- package/src/utils/useLicenseExpirationWarning.ts +18 -18
- package/src/utils/usePluralizedTranslation.ts +21 -0
- package/src/screens/dashboard/DashboardsDetail.stories.tsx +0 -108
- package/src/screens/dashboard/DashboardsOverview.stories.tsx +0 -281
- package/src/utils/useDateTimePickerAdapter.ts +0 -309
|
@@ -0,0 +1,208 @@
|
|
|
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
|
+
|
|
9
|
+
import { Typography } from '@mui/material';
|
|
10
|
+
|
|
11
|
+
import { Tooltip } from '../../components';
|
|
12
|
+
import { LegendProps } from '../Legend/models';
|
|
13
|
+
import { Legend as LegendComponent } from '../Legend';
|
|
14
|
+
import { getValueByUnit } from '../common/utils';
|
|
15
|
+
import { labelNoDataFound } from '../translatedLabels';
|
|
16
|
+
|
|
17
|
+
import { BarStackProps } from './models';
|
|
18
|
+
import { useBarStackStyles } from './BarStack.styles';
|
|
19
|
+
import useResponsiveBarStack from './useResponsiveBarStack';
|
|
20
|
+
|
|
21
|
+
const DefaultLengd = ({ scale, direction }: LegendProps): JSX.Element => (
|
|
22
|
+
<LegendComponent direction={direction} scale={scale} />
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
const BarStack = ({
|
|
26
|
+
title,
|
|
27
|
+
data,
|
|
28
|
+
width,
|
|
29
|
+
height,
|
|
30
|
+
size = 72,
|
|
31
|
+
onSingleBarClick,
|
|
32
|
+
displayLegend = true,
|
|
33
|
+
TooltipContent,
|
|
34
|
+
Legend = DefaultLengd,
|
|
35
|
+
unit = 'number',
|
|
36
|
+
displayValues,
|
|
37
|
+
variant = 'vertical',
|
|
38
|
+
legendDirection = 'column'
|
|
39
|
+
}: BarStackProps & { height: number; width: number }): JSX.Element => {
|
|
40
|
+
const { t } = useTranslation();
|
|
41
|
+
const { classes } = useBarStackStyles();
|
|
42
|
+
|
|
43
|
+
const titleRef = useRef(null);
|
|
44
|
+
const legendRef = useRef(null);
|
|
45
|
+
|
|
46
|
+
const {
|
|
47
|
+
barSize,
|
|
48
|
+
colorScale,
|
|
49
|
+
input,
|
|
50
|
+
keys,
|
|
51
|
+
legendScale,
|
|
52
|
+
total,
|
|
53
|
+
xScale,
|
|
54
|
+
yScale,
|
|
55
|
+
svgWrapperWidth,
|
|
56
|
+
svgContainerSize,
|
|
57
|
+
isVerticalBar,
|
|
58
|
+
areAllValuesNull
|
|
59
|
+
} = useResponsiveBarStack({
|
|
60
|
+
data,
|
|
61
|
+
height,
|
|
62
|
+
legendRef,
|
|
63
|
+
size,
|
|
64
|
+
titleRef,
|
|
65
|
+
unit,
|
|
66
|
+
variant,
|
|
67
|
+
width
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const BarStackComponent = isVerticalBar
|
|
71
|
+
? BarStackVertical
|
|
72
|
+
: BarStackHorizontal;
|
|
73
|
+
|
|
74
|
+
if (areAllValuesNull) {
|
|
75
|
+
return (
|
|
76
|
+
<div className={classes.container} style={{ height, width }}>
|
|
77
|
+
<Typography variant="h3">{t(labelNoDataFound)}</Typography>
|
|
78
|
+
</div>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<div className={classes.container} style={{ height, width }}>
|
|
84
|
+
<div
|
|
85
|
+
className={classes.svgWrapper}
|
|
86
|
+
style={{
|
|
87
|
+
height,
|
|
88
|
+
width: svgWrapperWidth
|
|
89
|
+
}}
|
|
90
|
+
>
|
|
91
|
+
{title && (
|
|
92
|
+
<div className={classes.title} data-testid="Title" ref={titleRef}>
|
|
93
|
+
{`${numeral(total).format('0a').toUpperCase()} `} {title}
|
|
94
|
+
</div>
|
|
95
|
+
)}
|
|
96
|
+
<div
|
|
97
|
+
className={classes.svgContainer}
|
|
98
|
+
data-testid="barStack"
|
|
99
|
+
style={svgContainerSize}
|
|
100
|
+
>
|
|
101
|
+
<svg
|
|
102
|
+
data-variant={variant}
|
|
103
|
+
height={barSize.height}
|
|
104
|
+
width={barSize.width}
|
|
105
|
+
>
|
|
106
|
+
<Group>
|
|
107
|
+
<BarStackComponent
|
|
108
|
+
color={colorScale}
|
|
109
|
+
data={[input]}
|
|
110
|
+
keys={keys}
|
|
111
|
+
{...(isVerticalBar
|
|
112
|
+
? { x: () => undefined }
|
|
113
|
+
: { y: () => undefined })}
|
|
114
|
+
xScale={xScale}
|
|
115
|
+
yScale={yScale}
|
|
116
|
+
>
|
|
117
|
+
{(barStacks) =>
|
|
118
|
+
barStacks.map((barStack) =>
|
|
119
|
+
barStack.bars.map((bar) => {
|
|
120
|
+
const onClick = (): void => {
|
|
121
|
+
onSingleBarClick?.(bar);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
return (
|
|
125
|
+
<Tooltip
|
|
126
|
+
hasCaret
|
|
127
|
+
classes={{
|
|
128
|
+
tooltip: classes.barStackTooltip
|
|
129
|
+
}}
|
|
130
|
+
followCursor={false}
|
|
131
|
+
key={`bar-stack-${barStack.index}-${bar.index}`}
|
|
132
|
+
label={
|
|
133
|
+
TooltipContent && (
|
|
134
|
+
<TooltipContent
|
|
135
|
+
color={bar.color}
|
|
136
|
+
label={bar.key}
|
|
137
|
+
title={title}
|
|
138
|
+
total={total}
|
|
139
|
+
value={barStack.bars[0].bar.data[barStack.key]}
|
|
140
|
+
/>
|
|
141
|
+
)
|
|
142
|
+
}
|
|
143
|
+
position={
|
|
144
|
+
isVerticalBar ? 'right-start' : 'bottom-start'
|
|
145
|
+
}
|
|
146
|
+
>
|
|
147
|
+
<g data-testid={bar.key}>
|
|
148
|
+
<rect
|
|
149
|
+
fill={bar.color}
|
|
150
|
+
height={
|
|
151
|
+
isVerticalBar ? bar.height - 1 : bar.height
|
|
152
|
+
}
|
|
153
|
+
key={`bar-stack-${barStack.index}-${bar.index}`}
|
|
154
|
+
ry={5}
|
|
155
|
+
width={isVerticalBar ? bar.width : bar.width - 1}
|
|
156
|
+
x={bar.x}
|
|
157
|
+
y={bar.y}
|
|
158
|
+
onClick={onClick}
|
|
159
|
+
/>
|
|
160
|
+
{displayValues &&
|
|
161
|
+
bar.height > 10 &&
|
|
162
|
+
bar.width > 10 && (
|
|
163
|
+
<Text
|
|
164
|
+
cursor="pointer"
|
|
165
|
+
data-testid="value"
|
|
166
|
+
fill="#000"
|
|
167
|
+
fontSize={12}
|
|
168
|
+
textAnchor="middle"
|
|
169
|
+
verticalAnchor="middle"
|
|
170
|
+
x={bar.x + bar.width / 2}
|
|
171
|
+
y={bar.y + bar.height / 2}
|
|
172
|
+
>
|
|
173
|
+
{getValueByUnit({
|
|
174
|
+
total,
|
|
175
|
+
unit,
|
|
176
|
+
value:
|
|
177
|
+
barStack.bars[0].bar.data[barStack.key]
|
|
178
|
+
})}
|
|
179
|
+
</Text>
|
|
180
|
+
)}
|
|
181
|
+
</g>
|
|
182
|
+
</Tooltip>
|
|
183
|
+
);
|
|
184
|
+
})
|
|
185
|
+
)
|
|
186
|
+
}
|
|
187
|
+
</BarStackComponent>
|
|
188
|
+
</Group>
|
|
189
|
+
</svg>
|
|
190
|
+
</div>
|
|
191
|
+
</div>
|
|
192
|
+
{displayLegend && (
|
|
193
|
+
<div data-testid="Legend" ref={legendRef}>
|
|
194
|
+
<Legend
|
|
195
|
+
data={data}
|
|
196
|
+
direction={legendDirection}
|
|
197
|
+
scale={legendScale}
|
|
198
|
+
title={title}
|
|
199
|
+
total={total}
|
|
200
|
+
unit={unit}
|
|
201
|
+
/>
|
|
202
|
+
</div>
|
|
203
|
+
)}
|
|
204
|
+
</div>
|
|
205
|
+
);
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
export default BarStack;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as BarStack } from './BarStack';
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
legendDirection?: 'row' | 'column';
|
|
14
|
+
onSingleBarClick?: (barData) => void;
|
|
15
|
+
size?: number;
|
|
16
|
+
title?: string;
|
|
17
|
+
unit?: 'percentage' | 'number';
|
|
18
|
+
variant?: 'vertical' | 'horizontal';
|
|
19
|
+
};
|
|
@@ -0,0 +1,139 @@
|
|
|
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 + 24
|
|
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
|
+
nice: true
|
|
77
|
+
})
|
|
78
|
+
: scaleBand({
|
|
79
|
+
domain: [0, 0],
|
|
80
|
+
padding: 0
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const xScale = isVerticalBar
|
|
84
|
+
? scaleBand({
|
|
85
|
+
domain: [0, 0],
|
|
86
|
+
padding: 0
|
|
87
|
+
})
|
|
88
|
+
: scaleLinear({
|
|
89
|
+
domain: [0, total],
|
|
90
|
+
nice: true
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const keys = pluck('label', data);
|
|
94
|
+
|
|
95
|
+
const colorsRange = pluck('color', data);
|
|
96
|
+
|
|
97
|
+
const colorScale = scaleOrdinal({
|
|
98
|
+
domain: keys,
|
|
99
|
+
range: colorsRange
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const legendScale = {
|
|
103
|
+
domain: data.map(({ value }) => getValueByUnit({ total, unit, value })),
|
|
104
|
+
range: colorsRange
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const xMax = barSize.width;
|
|
108
|
+
const yMax = barSize.height;
|
|
109
|
+
|
|
110
|
+
xScale.rangeRound([0, xMax]);
|
|
111
|
+
yScale.range([yMax, 0]);
|
|
112
|
+
|
|
113
|
+
const input = data.reduce((acc, { label, value }) => {
|
|
114
|
+
acc[label] = value;
|
|
115
|
+
|
|
116
|
+
return acc;
|
|
117
|
+
}, {});
|
|
118
|
+
|
|
119
|
+
const values = pluck('value', data);
|
|
120
|
+
|
|
121
|
+
const areAllValuesNull = isEmpty(reject((value) => equals(value, 0), values));
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
areAllValuesNull,
|
|
125
|
+
barSize,
|
|
126
|
+
colorScale,
|
|
127
|
+
input,
|
|
128
|
+
isVerticalBar,
|
|
129
|
+
keys,
|
|
130
|
+
legendScale,
|
|
131
|
+
svgContainerSize,
|
|
132
|
+
svgWrapperWidth,
|
|
133
|
+
total,
|
|
134
|
+
xScale,
|
|
135
|
+
yScale
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
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
|
+
});
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { pluck } from 'ramda';
|
|
2
|
+
|
|
3
|
+
import { Box, Typography } from '@mui/material';
|
|
4
|
+
|
|
5
|
+
import EllipsisTypography from '../../Typography/EllipsisTypography';
|
|
6
|
+
|
|
7
|
+
import HeatMap from './HeatMap';
|
|
8
|
+
import heatMapData from './HeatMapData.json';
|
|
9
|
+
import { HeatMapProps } from './model';
|
|
10
|
+
|
|
11
|
+
const dataIds = pluck('id', heatMapData);
|
|
12
|
+
|
|
13
|
+
interface Data {
|
|
14
|
+
counter: number;
|
|
15
|
+
host: string;
|
|
16
|
+
service: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const TileContent = ({
|
|
20
|
+
isSmallestSize,
|
|
21
|
+
data
|
|
22
|
+
}: {
|
|
23
|
+
data: Data;
|
|
24
|
+
isSmallestSize: boolean;
|
|
25
|
+
}): JSX.Element | false =>
|
|
26
|
+
!isSmallestSize && (
|
|
27
|
+
<Box
|
|
28
|
+
sx={{
|
|
29
|
+
alignItems: 'center',
|
|
30
|
+
color: 'common.black',
|
|
31
|
+
display: 'flex',
|
|
32
|
+
flexDirection: 'column',
|
|
33
|
+
width: '100%'
|
|
34
|
+
}}
|
|
35
|
+
>
|
|
36
|
+
<EllipsisTypography textAlign="center">{data.host}</EllipsisTypography>
|
|
37
|
+
<EllipsisTypography textAlign="center">{data.service}</EllipsisTypography>
|
|
38
|
+
<EllipsisTypography textAlign="center">{data.counter}</EllipsisTypography>
|
|
39
|
+
</Box>
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const initialize = ({
|
|
43
|
+
width = '100vw',
|
|
44
|
+
height = '100vh',
|
|
45
|
+
...args
|
|
46
|
+
}: Omit<HeatMapProps<Data>, 'tiles' | 'children'> & {
|
|
47
|
+
height?: string;
|
|
48
|
+
width?: string;
|
|
49
|
+
}): void => {
|
|
50
|
+
cy.mount({
|
|
51
|
+
Component: (
|
|
52
|
+
<div style={{ height, width }}>
|
|
53
|
+
<HeatMap tiles={heatMapData} {...args}>
|
|
54
|
+
{TileContent}
|
|
55
|
+
</HeatMap>
|
|
56
|
+
</div>
|
|
57
|
+
)
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
describe('HeatMap', () => {
|
|
62
|
+
it('displays tiles', () => {
|
|
63
|
+
initialize({});
|
|
64
|
+
dataIds.forEach((id) => {
|
|
65
|
+
cy.findByTestId(id).should('be.visible');
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('does not display the tooltip when the prop is not set and the tile is hovered', () => {
|
|
70
|
+
initialize({});
|
|
71
|
+
|
|
72
|
+
cy.findByTestId(dataIds[0]).trigger('mouseover');
|
|
73
|
+
|
|
74
|
+
cy.findByTestId(`tooltip-${dataIds[0]}`).should('not.exist');
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('displays the tooltip when the prop is set and the tile is hovered', () => {
|
|
78
|
+
initialize({
|
|
79
|
+
tooltipContent: ({ data }) => (
|
|
80
|
+
<Typography>
|
|
81
|
+
This is the tooltip for {data.host}-{data.service}-{data.counter}
|
|
82
|
+
</Typography>
|
|
83
|
+
)
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
cy.findByTestId(dataIds[0]).trigger('mouseover');
|
|
87
|
+
|
|
88
|
+
cy.contains(`This is the tooltip for Server-Service Counter-53`).should(
|
|
89
|
+
'be.visible'
|
|
90
|
+
);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('displays the tooltip conditionally when the prop is set and the tile is hovered', () => {
|
|
94
|
+
initialize({
|
|
95
|
+
displayTooltipCondition: ({ counter }) => counter > 100,
|
|
96
|
+
tooltipContent: ({ data }) => (
|
|
97
|
+
<Typography>
|
|
98
|
+
This is the tooltip for {data.host}-{data.service}-{data.counter}
|
|
99
|
+
</Typography>
|
|
100
|
+
)
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
cy.findByTestId(dataIds[0]).trigger('mouseover');
|
|
104
|
+
|
|
105
|
+
cy.contains(`This is the tooltip for Server-Service Counter-53`).should(
|
|
106
|
+
'not.exist'
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
cy.findByTestId(dataIds[1]).trigger('mouseover');
|
|
110
|
+
|
|
111
|
+
cy.contains(`This is the tooltip for Server-Service Counter-779`).should(
|
|
112
|
+
'be.visible'
|
|
113
|
+
);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('displays tiles with fixed size', () => {
|
|
117
|
+
initialize({ height: '200px', tileSizeFixed: true, width: '590px' });
|
|
118
|
+
dataIds.forEach((id) => {
|
|
119
|
+
cy.findByTestId(id).should('be.visible');
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('displays tiles as small when the container width is under the breakpoint', () => {
|
|
124
|
+
initialize({ height: '200px', width: '590px' });
|
|
125
|
+
dataIds.forEach((id) => {
|
|
126
|
+
cy.findByTestId(id).should('be.visible');
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
cy.makeSnapshot();
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('does not display tiles as small when the contains width is 0', () => {
|
|
133
|
+
initialize({ height: '200px', width: '0px' });
|
|
134
|
+
dataIds.forEach((id) => {
|
|
135
|
+
cy.findByTestId(id).should('not.exist');
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
cy.makeSnapshot();
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('displays a single tile', () => {
|
|
142
|
+
initialize({ tiles: [heatMapData[0]] });
|
|
143
|
+
cy.findByTestId(dataIds[0]).should('be.visible');
|
|
144
|
+
});
|
|
145
|
+
});
|
|
@@ -3,8 +3,6 @@ import { makeStyles } from 'tss-react/mui';
|
|
|
3
3
|
|
|
4
4
|
import { Box, Typography } from '@mui/material';
|
|
5
5
|
|
|
6
|
-
import EllipsisTypography from '../../Typography/EllipsisTypography';
|
|
7
|
-
|
|
8
6
|
import heatMapData from './HeatMapData.json';
|
|
9
7
|
|
|
10
8
|
import { HeatMap } from '.';
|
|
@@ -22,29 +20,6 @@ const meta: Meta<typeof HeatMap<Data>> = {
|
|
|
22
20
|
export default meta;
|
|
23
21
|
type Story = StoryObj<typeof HeatMap<Data>>;
|
|
24
22
|
|
|
25
|
-
const TileContent = ({
|
|
26
|
-
isSmallestSize,
|
|
27
|
-
data
|
|
28
|
-
}: {
|
|
29
|
-
data: Data;
|
|
30
|
-
isSmallestSize: boolean;
|
|
31
|
-
}): JSX.Element | false =>
|
|
32
|
-
!isSmallestSize && (
|
|
33
|
-
<Box
|
|
34
|
-
sx={{
|
|
35
|
-
alignItems: 'center',
|
|
36
|
-
color: 'common.black',
|
|
37
|
-
display: 'flex',
|
|
38
|
-
flexDirection: 'column',
|
|
39
|
-
width: '100%'
|
|
40
|
-
}}
|
|
41
|
-
>
|
|
42
|
-
<EllipsisTypography textAlign="center">{data.host}</EllipsisTypography>
|
|
43
|
-
<EllipsisTypography textAlign="center">{data.service}</EllipsisTypography>
|
|
44
|
-
<EllipsisTypography textAlign="center">{data.counter}</EllipsisTypography>
|
|
45
|
-
</Box>
|
|
46
|
-
);
|
|
47
|
-
|
|
48
23
|
const TooltipContent = ({ data }: { data: Data }): JSX.Element => {
|
|
49
24
|
return (
|
|
50
25
|
<Box sx={{ backgroundColor: 'common.white', color: 'common.black' }}>
|
|
@@ -40,7 +40,7 @@ const ResponsiveHeatMap = <TData,>({
|
|
|
40
40
|
const theoricalTotalTilesWidth =
|
|
41
41
|
tilesLength * tileWidth + (tilesLength - 1) * gap;
|
|
42
42
|
|
|
43
|
-
if (lt(width, 680) && gt(maxTotalTilesWidth, width)) {
|
|
43
|
+
if (lt(width, 680) && gt(maxTotalTilesWidth, width) && !tileSizeFixed) {
|
|
44
44
|
return smallestTileSize;
|
|
45
45
|
}
|
|
46
46
|
|
|
@@ -66,13 +66,19 @@ const ResponsiveHeatMap = <TData,>({
|
|
|
66
66
|
}}
|
|
67
67
|
>
|
|
68
68
|
{tiles.map(({ backgroundColor, id, data }) => (
|
|
69
|
-
<Box
|
|
69
|
+
<Box
|
|
70
|
+
className={classes.heatMapTile}
|
|
71
|
+
data-testid={id}
|
|
72
|
+
key={id}
|
|
73
|
+
sx={{ backgroundColor }}
|
|
74
|
+
>
|
|
70
75
|
<Tooltip
|
|
71
76
|
hasCaret
|
|
72
77
|
classes={{
|
|
73
78
|
arrow: cx(classes.heatMapTooltipArrow, arrowClassName),
|
|
74
79
|
tooltip: classes.heatMapTooltip
|
|
75
80
|
}}
|
|
81
|
+
data-testid={`tooltip-${data?.id}`}
|
|
76
82
|
followCursor={false}
|
|
77
83
|
label={
|
|
78
84
|
displayTooltipCondition?.(data) &&
|