@centreon/ui 25.4.4 → 25.5.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@centreon/ui",
3
- "version": "25.4.4",
3
+ "version": "25.5.0",
4
4
  "description": "Centreon UI Components",
5
5
  "scripts": {
6
6
  "update:deps": "pnpx npm-check-updates -i --format group",
@@ -29,6 +29,8 @@ export interface Metric {
29
29
  unit: string;
30
30
  warning_high_threshold: number | null;
31
31
  warning_low_threshold: number | null;
32
+ service_name: string | null;
33
+ host_name: string | null;
32
34
  }
33
35
 
34
36
  type TimeSeries = { timeTick: string };
@@ -46,6 +46,12 @@ interface UseMetricsQueryState {
46
46
  start: string;
47
47
  }
48
48
 
49
+ interface FormatLegend {
50
+ host?: string | null;
51
+ service?: string | null;
52
+ metric: string;
53
+ }
54
+
49
55
  const getStartEndFromTimePeriod = (
50
56
  timePeriod: number
51
57
  ): { end: string; start: string } => {
@@ -164,22 +170,108 @@ const useGraphQuery = ({
164
170
  data.current = graphData;
165
171
  }
166
172
 
173
+ const getCurrentMetrics = () => {
174
+ if (!data.current) {
175
+ return undefined;
176
+ }
177
+
178
+ return bypassMetricsExclusion
179
+ ? data.current.metrics
180
+ : data.current.metrics.filter(({ metric_id }) => {
181
+ return pipe(
182
+ pluck('excludedMetrics'),
183
+ flatten,
184
+ includes(metric_id),
185
+ not
186
+ )(metrics);
187
+ });
188
+ };
189
+
190
+
191
+ const formatLegend = ({
192
+ host = null,
193
+ service = null,
194
+ metric
195
+ }: FormatLegend) => {
196
+ if (!host && !service) {
197
+ return metric;
198
+ }
199
+
200
+ if (!host) {
201
+ return `${service}: ${metric}`;
202
+ }
203
+
204
+ if (!service) {
205
+ return `${host}: ${metric}`;
206
+ }
207
+
208
+ return `${host} ${service}: ${metric}`;
209
+ };
210
+
211
+ const getFormattedMetrics = () => {
212
+ const metrics = getCurrentMetrics();
213
+
214
+ if (equals(metrics?.length, 1)) {
215
+ return metrics?.map((line) => {
216
+ const formattedLegend = formatLegend({
217
+ host: line?.host_name,
218
+ service: line?.service_name,
219
+ metric: line?.metric
220
+ });
221
+
222
+ return { ...line, legend: formattedLegend };
223
+ });
224
+ }
225
+
226
+ return metrics?.map((line) => {
227
+ const areHostNameRedundant = metrics.every(({ host_name }) =>
228
+ equals(host_name, line.host_name)
229
+ );
230
+ const areServiceNameRedundant = metrics.every(({ service_name }) =>
231
+ equals(service_name, line.service_name)
232
+ );
233
+
234
+ if (areHostNameRedundant && areServiceNameRedundant) {
235
+ const formattedLegend = formatLegend({ metric: line.metric });
236
+
237
+ return { ...line, legend: formattedLegend };
238
+ }
239
+
240
+ if (areHostNameRedundant) {
241
+ const formattedLegend = formatLegend({
242
+ service: line.service_name,
243
+ metric: line.metric
244
+ });
245
+
246
+ return { ...line, legend: formattedLegend };
247
+ }
248
+
249
+ if (areServiceNameRedundant) {
250
+ const formattedLegend = formatLegend({
251
+ host: line.host_name,
252
+ metric: line.metric
253
+ });
254
+
255
+ return { ...line, legend: formattedLegend };
256
+ }
257
+
258
+ const formattedLegend = formatLegend({
259
+ host: line.host_name,
260
+ service: line.service_name,
261
+ metric: line.metric
262
+ });
263
+
264
+ return { ...line, legend: formattedLegend };
265
+ });
266
+ };
267
+
167
268
  const formattedGraphData = data.current
168
269
  ? {
169
270
  global: {
170
271
  base: data.current.base,
171
272
  title: ''
172
273
  },
173
- metrics: bypassMetricsExclusion
174
- ? data.current.metrics
175
- : data.current.metrics.filter(({ metric_id }) => {
176
- return pipe(
177
- pluck('excludedMetrics'),
178
- flatten,
179
- includes(metric_id),
180
- not
181
- )(metrics);
182
- }),
274
+ metrics: getFormattedMetrics(),
183
275
  times: data.current.times
184
276
  }
185
277
  : undefined;
@@ -12,6 +12,7 @@ export type FormActionsProps = {
12
12
  labels: FormActionsLabels;
13
13
  onCancel: () => void;
14
14
  variant: FormVariant;
15
+ isCancelButtonVisible?: boolean;
15
16
  };
16
17
 
17
18
  export type FormActionsLabels = {
@@ -23,7 +24,8 @@ const FormActions = <TResource extends object>({
23
24
  labels,
24
25
  onCancel,
25
26
  variant,
26
- enableSubmitWhenNotDirty
27
+ enableSubmitWhenNotDirty,
28
+ isCancelButtonVisible = true
27
29
  }: FormActionsProps): ReactElement => {
28
30
  const { classes } = useStyles();
29
31
  const { isSubmitting, dirty, isValid, submitForm } =
@@ -34,16 +36,18 @@ const FormActions = <TResource extends object>({
34
36
 
35
37
  return (
36
38
  <div className={classes.actions}>
37
- <Button
38
- aria-label={labels.cancel}
39
- data-testid="cancel"
40
- disabled={isSubmitting}
41
- size="medium"
42
- variant="secondary"
43
- onClick={() => onCancel?.()}
44
- >
45
- {labels.cancel}
46
- </Button>
39
+ {isCancelButtonVisible && (
40
+ <Button
41
+ aria-label={labels.cancel}
42
+ data-testid="cancel"
43
+ disabled={isSubmitting}
44
+ size="medium"
45
+ variant="secondary"
46
+ onClick={() => onCancel?.()}
47
+ >
48
+ {labels.cancel}
49
+ </Button>
50
+ )}
47
51
  <Button
48
52
  aria-label={labels.submit[variant]}
49
53
  data-testid="submit"