@centreon/ui 25.10.28 → 25.10.30

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 (73) hide show
  1. package/package.json +3 -3
  2. package/public/mockServiceWorker.js +8 -31
  3. package/src/Dashboard/Item.tsx +142 -149
  4. package/src/Form/Inputs/ConnectedAutocomplete.tsx +2 -0
  5. package/src/Form/Inputs/Grid.tsx +2 -3
  6. package/src/Form/Inputs/models.ts +2 -0
  7. package/src/Form/Section/navigateToSection.ts +6 -6
  8. package/src/Graph/BarChart/BarChart.cypress.spec.tsx +55 -102
  9. package/src/Graph/BarChart/BarChart.stories.tsx +1 -51
  10. package/src/Graph/BarChart/BarChart.tsx +1 -1
  11. package/src/Graph/BarChart/BarGroup.tsx +32 -22
  12. package/src/Graph/BarChart/BarStack.tsx +26 -15
  13. package/src/Graph/BarChart/MemoizedGroup.tsx +18 -14
  14. package/src/Graph/BarChart/ResponsiveBarChart.tsx +6 -7
  15. package/src/Graph/BarChart/Tooltip/BarChartTooltip.tsx +2 -2
  16. package/src/Graph/Chart/BasicComponents/Lines/StackedLines/index.tsx +5 -4
  17. package/src/Graph/Chart/BasicComponents/Lines/StackedLines/useStackedLines.ts +45 -18
  18. package/src/Graph/Chart/BasicComponents/Lines/index.tsx +118 -124
  19. package/src/Graph/Chart/Chart.cypress.spec.tsx +6 -25
  20. package/src/Graph/Chart/Chart.stories.tsx +1 -43
  21. package/src/Graph/Chart/Chart.tsx +13 -9
  22. package/src/Graph/Chart/InteractiveComponents/GraphValueTooltip/useGraphValueTooltip.ts +4 -2
  23. package/src/Graph/Chart/Legend/index.tsx +2 -26
  24. package/src/Graph/Chart/index.tsx +45 -31
  25. package/src/Graph/Chart/models.ts +1 -6
  26. package/src/Graph/Chart/translatedLabels.ts +1 -0
  27. package/src/Graph/Chart/useChartData.ts +24 -3
  28. package/src/Graph/common/Axes/index.tsx +1 -1
  29. package/src/Graph/common/BaseChart/BaseChart.tsx +1 -6
  30. package/src/Graph/common/BaseChart/ChartSvgWrapper.tsx +23 -16
  31. package/src/Graph/common/Error/NoData.tsx +18 -0
  32. package/src/Graph/common/Grids/index.tsx +4 -4
  33. package/src/Graph/common/timeSeries/index.test.ts +4 -24
  34. package/src/Graph/common/timeSeries/index.ts +120 -184
  35. package/src/Graph/common/timeSeries/models.ts +1 -1
  36. package/src/Graph/common/utils.ts +4 -10
  37. package/src/Graph/index.ts +20 -20
  38. package/src/InputField/Select/Autocomplete/Connected/index.tsx +9 -9
  39. package/src/InputField/Select/Autocomplete/Multi/Listbox.tsx +11 -3
  40. package/src/InputField/Select/Autocomplete/Multi/Multi.tsx +3 -2
  41. package/src/InputField/Select/Autocomplete/index.tsx +28 -17
  42. package/src/InputField/Select/Option.tsx +3 -3
  43. package/src/InputField/Select/index.tsx +2 -1
  44. package/src/Listing/ActionBar/Pagination.tsx +2 -1
  45. package/src/Listing/ActionBar/index.tsx +113 -8
  46. package/src/Listing/index.tsx +19 -2
  47. package/src/Listing/translatedLabels.ts +4 -0
  48. package/src/Module/index.tsx +2 -8
  49. package/src/ThemeProvider/index.tsx +21 -30
  50. package/src/ThemeProvider/tailwindcss.css +12 -10
  51. package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/PickersStartEndDate.tsx +8 -5
  52. package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/models.ts +0 -1
  53. package/src/api/useGraphQuery/index.ts +7 -4
  54. package/src/components/Form/AccessRights/ShareInput/ShareInput.tsx +4 -3
  55. package/src/components/Form/AccessRights/ShareInput/useShareInput.tsx +15 -10
  56. package/src/components/Layout/PageLayout/PageLayout.tsx +3 -9
  57. package/src/components/Layout/PageLayout/PageLayoutActions.tsx +3 -5
  58. package/src/components/Layout/PageLayout/PageLayoutBody.tsx +3 -5
  59. package/src/components/Layout/PageLayout/PageLayoutHeader.tsx +3 -5
  60. package/src/components/Layout/PageLayout/PageQuickAccess.tsx +44 -25
  61. package/src/components/Layout/PageLayout/translatedLabels.ts +1 -0
  62. package/src/components/Menu/Button/MenuButton.styles.ts +27 -0
  63. package/src/components/Menu/Button/MenuButton.tsx +5 -8
  64. package/src/components/Menu/Menu.styles.ts +68 -0
  65. package/src/components/Menu/MenuDivider.tsx +5 -1
  66. package/src/components/Menu/MenuItem.tsx +5 -1
  67. package/src/components/Menu/MenuItems.tsx +4 -5
  68. package/src/components/Modal/Modal.styles.ts +2 -1
  69. package/src/components/Modal/ModalHeader.tsx +1 -5
  70. package/src/utils/useInfiniteScrollListing.ts +11 -7
  71. package/src/utils/useViewportIntersection.ts +3 -4
  72. package/src/Graph/mockedData/dataWithMissingPoint.json +0 -74
  73. package/src/Graph/mockedData/pingServiceWithStackedKeys.json +0 -205
@@ -26,14 +26,14 @@ import {
26
26
  map,
27
27
  negate,
28
28
  pipe,
29
- pluck,
30
29
  prop,
31
30
  propEq,
32
31
  reduce,
33
32
  reject,
34
33
  sortBy,
35
34
  split,
36
- uniq
35
+ uniq,
36
+ isNotNil
37
37
  } from 'ramda';
38
38
 
39
39
  import { margin } from '../../Chart/common';
@@ -54,6 +54,17 @@ interface TimeTickWithMetrics {
54
54
  timeTick: string;
55
55
  }
56
56
 
57
+ const defaultDsData = {
58
+ ds_color_line: '#000000',
59
+ ds_filled: false,
60
+ ds_invert: false,
61
+ ds_legend: '',
62
+ ds_order: '0',
63
+ ds_stack: '0',
64
+ ds_stack_key: null,
65
+ ds_transparency: 80
66
+ };
67
+
57
68
  const toTimeTickWithMetrics = ({
58
69
  metrics,
59
70
  times
@@ -73,7 +84,7 @@ const toTimeTickValue = (
73
84
  const getMetricsForIndex = (): Omit<TimeValue, 'timeTick'> => {
74
85
  const addMetricForTimeIndex = (acc, { metric_id, data }): TimeValue => ({
75
86
  ...acc,
76
- [metric_id]: data[timeIndex] === undefined ? null : data[timeIndex]
87
+ [metric_id]: data[timeIndex]
77
88
  });
78
89
 
79
90
  return reduce(addMetricForTimeIndex, {} as TimeValue, metrics);
@@ -120,30 +131,39 @@ const toLine = ({
120
131
  maximum_value,
121
132
  metric_id,
122
133
  displayAs
123
- }: Metric): Line => ({
124
- areaColor: ds_data.ds_color_area,
125
- average_value,
126
- color: ds_data.ds_color_line,
127
- display: true,
128
- displayAs,
129
- filled: ds_data.ds_filled,
130
- highlight: undefined,
131
- invert: ds_data.ds_invert,
132
- legend: ds_data.ds_legend,
133
- lineColor: ds_data.ds_color_line,
134
- maximum_value,
135
- metric,
136
- metric_id,
137
- minimum_value,
138
- name: legend,
139
- stackOrder:
140
- equals(ds_data.ds_stack, '1') || equals(ds_data.ds_stack, true)
141
- ? Number.parseInt(ds_data.ds_order || '0', 10)
142
- : null,
143
- stackKey: ds_data.ds_stack_key || null,
144
- transparency: ds_data.ds_transparency,
145
- unit
146
- });
134
+ }: Metric): Line => {
135
+ const safeDsData = {
136
+ ...defaultDsData,
137
+ ...(ds_data || {}),
138
+ ds_color_area:
139
+ ds_data?.ds_color_area ?? ds_data?.ds_color_line ?? defaultDsData.ds_color_line
140
+ };
141
+
142
+ return {
143
+ areaColor: safeDsData.ds_color_area,
144
+ average_value,
145
+ color: safeDsData.ds_color_line,
146
+ display: true,
147
+ displayAs,
148
+ filled: safeDsData.ds_filled,
149
+ highlight: undefined,
150
+ invert: safeDsData.ds_invert,
151
+ legend: safeDsData.ds_legend,
152
+ lineColor: safeDsData.ds_color_line,
153
+ maximum_value,
154
+ metric,
155
+ metric_id,
156
+ minimum_value,
157
+ name: legend,
158
+ stackKey: safeDsData.ds_stack_key || null,
159
+ stackOrder:
160
+ equals(safeDsData.ds_stack, '1') || equals(safeDsData.ds_stack, true)
161
+ ? Number.parseInt(safeDsData.ds_order || '0', 10)
162
+ : null,
163
+ transparency: safeDsData.ds_transparency,
164
+ unit
165
+ };
166
+ };
147
167
 
148
168
  const getLineData = (graphData: LineChartData): Array<Line> =>
149
169
  map(toLine, graphData.metrics);
@@ -160,8 +180,8 @@ const getMetrics = (timeValue: TimeValue): Array<string> =>
160
180
 
161
181
  const getValueForMetric =
162
182
  (timeValue: TimeValue) =>
163
- (metric_id: number): number =>
164
- prop(metric_id, timeValue) as number;
183
+ (metric_id: number): number =>
184
+ prop(metric_id, timeValue) as number;
165
185
 
166
186
  const getUnits = (lines: Array<Line>): Array<string> =>
167
187
  pipe(map(prop('unit')), uniq)(lines);
@@ -242,10 +262,7 @@ const getStackedMetricValues = ({
242
262
  timeSeries
243
263
  }: LinesTimeSeries): Array<number> => {
244
264
  const getTimeSeriesValuesForMetric = (metric_id): Array<number> =>
245
- map(
246
- (timeValue) => getValueForMetric(timeValue)(metric_id) || 0,
247
- timeSeries
248
- );
265
+ map((timeValue) => getValueForMetric(timeValue)(metric_id), timeSeries);
249
266
 
250
267
  const metricsValues = pipe(
251
268
  map(prop('metric_id')) as (metric) => Array<number>,
@@ -308,8 +325,8 @@ const getTimeSeriesForLines = ({
308
325
  ...acc,
309
326
  [metric_id]:
310
327
  invert &&
311
- metricsValue[metric_id] &&
312
- gt(metricsValue[metric_id], 0)
328
+ metricsValue[metric_id] &&
329
+ gt(metricsValue[metric_id], 0)
313
330
  ? negate(metricsValue[metric_id])
314
331
  : metricsValue[metric_id]
315
332
  };
@@ -342,10 +359,10 @@ const getYScale = ({
342
359
 
343
360
  return invert
344
361
  ? getScaleType(scale)({
345
- base: scaleLogarithmicBase,
346
- domain: yScale.domain().reverse(),
347
- range: yScale.range().reverse()
348
- })
362
+ base: scaleLogarithmicBase,
363
+ domain: yScale.domain().reverse(),
364
+ range: yScale.range().reverse()
365
+ })
349
366
  : yScale;
350
367
  };
351
368
 
@@ -382,6 +399,7 @@ const getScale = ({
382
399
  invert,
383
400
  hasDisplayAsBar,
384
401
  hasLineFilled,
402
+ hasStackedLines,
385
403
  min,
386
404
  max
387
405
  }): ScaleLinear<number, number> => {
@@ -389,30 +407,42 @@ const getScale = ({
389
407
  const sanitizedValuesForMinimum = min
390
408
  ? [min]
391
409
  : getSanitizedValues([
392
- invert && graphValues.every(lt(0))
393
- ? negate(getMax(graphValues))
394
- : getMin(graphValues),
395
- !isEmpty(stackedValues) &&
396
- !equals(stackedValues, [0]) &&
397
- getMin(stackedValues),
398
- Math.min(...thresholds)
399
- ]);
400
- const minValue = Math.min(...sanitizedValuesForMinimum);
401
- const minValueWithMargin =
402
- (hasDisplayAsBar || hasLineFilled) && minValue > 0 && !min
403
- ? 0
404
- : minValue - Math.abs(minValue) * 0.05;
410
+ invert && graphValues.every(lt(0))
411
+ ? negate(getMax(graphValues))
412
+ : getMin(graphValues),
413
+ !isEmpty(stackedValues) &&
414
+ !equals(stackedValues, [0]) &&
415
+ getMin(stackedValues),
416
+ Math.min(...thresholds)
417
+ ]);
418
+ const minValue = Math.min(...sanitizedValuesForMinimum.filter(isNotNil));
405
419
 
406
420
  const sanitizedValuesForMaximum = max
407
421
  ? [max]
408
422
  : getSanitizedValues([
409
- getMax(graphValues),
410
- getMax(stackedValues),
411
- hasOnlyZeroesHasValue(graphValues) ? 1 : 0,
412
- Math.max(...thresholds)
413
- ]);
414
- const maxValue = Math.max(...sanitizedValuesForMaximum);
415
- const maxValueWithMargin = maxValue + Math.abs(maxValue) * 0.05;
423
+ getMax(graphValues),
424
+ getMax(stackedValues),
425
+ hasOnlyZeroesHasValue(graphValues) ? 1 : null,
426
+ Math.max(...thresholds)
427
+ ]);
428
+ const maxValue = Math.max(...sanitizedValuesForMaximum.filter(isNotNil));
429
+
430
+ const minValueWithMargin =
431
+ (hasDisplayAsBar && minValue > 0) ||
432
+ (hasLineFilled &&
433
+ Math.max(maxValue, minValue) > minValue &&
434
+ minValue > 0) ||
435
+ (hasStackedLines && minValue > maxValue)
436
+ ? 0
437
+ : minValue - Math.abs(minValue) * 0.05;
438
+ const maxValueWithMargin =
439
+ (hasDisplayAsBar && maxValue < 0) ||
440
+ (hasLineFilled &&
441
+ Math.min(maxValue, minValue) < maxValue &&
442
+ maxValue < 0) ||
443
+ (hasStackedLines && minValue > maxValue)
444
+ ? 0
445
+ : maxValue + Math.abs(maxValue) * 0.05;
416
446
 
417
447
  const scaleType = getScaleType(scale);
418
448
 
@@ -479,7 +509,8 @@ const getYScaleUnit = ({
479
509
  min,
480
510
  max,
481
511
  isBarChart,
482
- boundariesUnit
512
+ boundariesUnit,
513
+ isFilled
483
514
  }: AxeScale & {
484
515
  invert?: boolean | string | null;
485
516
  unit: string;
@@ -487,6 +518,7 @@ const getYScaleUnit = ({
487
518
  min?: number;
488
519
  boundariesUnit?: string;
489
520
  isBarChart?: boolean;
521
+ isFilled?: boolean;
490
522
  }): ScaleLinear<number, number> => {
491
523
  const [firstUnit] = getUnits(dataLines);
492
524
  const shouldApplyThresholds =
@@ -505,12 +537,12 @@ const getYScaleUnit = ({
505
537
 
506
538
  const stackedValues = hasStackedLines
507
539
  ? getStackedMetricValues({
508
- lines: getSortedStackedLines(dataLines).filter(
509
- ({ unit: stackedUnit }) => equals(unit, stackedUnit)
510
- ),
511
- timeSeries: dataTimeSeries
512
- })
513
- : [0];
540
+ lines: getSortedStackedLines(dataLines).filter(
541
+ ({ unit: stackedUnit }) => equals(unit, stackedUnit)
542
+ ),
543
+ timeSeries: dataTimeSeries
544
+ })
545
+ : [];
514
546
 
515
547
  return getScale({
516
548
  graphValues,
@@ -520,8 +552,14 @@ const getYScaleUnit = ({
520
552
  ({ displayAs, unit: lineUnit }) =>
521
553
  equals(unit, lineUnit) && equals(displayAs, 'bar')
522
554
  ),
523
- hasLineFilled: dataLines.some(
524
- ({ unit: lineUnit, filled }) => equals(unit, lineUnit) && filled
555
+ hasLineFilled: isNil(isFilled)
556
+ ? dataLines.some(
557
+ ({ unit: lineUnit, filled }) => equals(unit, lineUnit) && filled
558
+ )
559
+ : isFilled,
560
+ hasStackedLines: dataLines.some(
561
+ ({ unit: lineUnit, stackKey, stackOrder }) =>
562
+ equals(unit, lineUnit) && (stackKey || stackOrder)
525
563
  ),
526
564
  height: valueGraphHeight,
527
565
  invert,
@@ -561,12 +599,14 @@ const getYScalePerUnit = ({
561
599
  isBarChart,
562
600
  min,
563
601
  max,
564
- boundariesUnit
602
+ boundariesUnit,
603
+ isFilled
565
604
  }: AxeScale & {
566
605
  min?: number;
567
606
  max?: number;
568
607
  isBarChart?: boolean;
569
608
  boundariesUnit?: string;
609
+ isFilled?: boolean;
570
610
  }): Record<string, ScaleLinear<number, number>> => {
571
611
  const units = getUnits(dataLines);
572
612
 
@@ -590,7 +630,8 @@ const getYScalePerUnit = ({
590
630
  min,
591
631
  max,
592
632
  isBarChart,
593
- boundariesUnit
633
+ boundariesUnit,
634
+ isFilled
594
635
  })
595
636
  };
596
637
  }, {});
@@ -598,15 +639,15 @@ const getYScalePerUnit = ({
598
639
  return scalePerUnit;
599
640
  };
600
641
 
601
- const formatTime = ({ value, unit }): string => {
602
- return `${numeral(value).format('0.[00]a')} ${unit}`;
642
+ const formatTime = (value: number): string => {
643
+ return `${numeral(value).format('0.[00]a')} ms`;
603
644
  };
604
645
 
605
646
  const registerMsUnitToNumeral = (): null => {
606
647
  try {
607
648
  numeral.register('format', 'milliseconds', {
608
649
  format: (value) => {
609
- return formatTime({ value, unit: 'ms' });
650
+ return formatTime(value);
610
651
  },
611
652
  regexps: {
612
653
  format: /(ms)/,
@@ -623,27 +664,6 @@ const registerMsUnitToNumeral = (): null => {
623
664
 
624
665
  registerMsUnitToNumeral();
625
666
 
626
- const registerSecondsUnitToNumeral = (): null => {
627
- try {
628
- numeral.register('format', 'seconds', {
629
- format: (value) => {
630
- return formatTime({ value, unit: 's' });
631
- },
632
- regexps: {
633
- format: /(s)/,
634
- unformat: /(s)/
635
- },
636
- unformat: () => ''
637
- });
638
-
639
- return null;
640
- } catch (_) {
641
- return null;
642
- }
643
- };
644
-
645
- registerSecondsUnitToNumeral();
646
-
647
667
  const getBase1024 = ({ unit, base }): boolean => {
648
668
  const base2Units = [
649
669
  'B',
@@ -673,13 +693,12 @@ const formatMetricValue = ({
673
693
 
674
694
  const formatSuffix = cond([
675
695
  [equals('ms'), always(' ms')],
676
- [equals('s'), always(' s')],
677
696
  [T, always(base1024 ? ' ib' : 'a')]
678
697
  ])(unit);
679
698
 
680
699
  const formattedMetricValue = numeral(Math.abs(value))
681
700
  .format(`0.[00]${formatSuffix}`)
682
- .replace(/(iB|B)/g, unit);
701
+ .replace(/B/, unit);
683
702
 
684
703
  if (lt(value, 0)) {
685
704
  return `-${formattedMetricValue}`;
@@ -698,6 +717,8 @@ const formatMetricValueWithUnit = ({
698
717
  return null;
699
718
  }
700
719
 
720
+ const base1024 = getBase1024({ base, unit });
721
+
701
722
  if (isRaw) {
702
723
  const unitText = equals('%', unit) ? unit : ` ${unit}`;
703
724
 
@@ -710,7 +731,9 @@ const formatMetricValueWithUnit = ({
710
731
 
711
732
  const formattedMetricValue = formatMetricValue({ base, unit, value });
712
733
 
713
- return formattedMetricValue;
734
+ return base1024 || !unit || equals(unit, 'ms')
735
+ ? formattedMetricValue
736
+ : `${formattedMetricValue} ${unit}`;
714
737
  };
715
738
 
716
739
  const bisectDate = bisector(identity).center;
@@ -760,93 +783,6 @@ export const formatMetricName = ({
760
783
  return metricName;
761
784
  };
762
785
 
763
- export const getStackedLinesTimeSeriesPerStackAndUnit = ({
764
- stackedLines,
765
- timeSeries,
766
- invert
767
- }: {
768
- stackedLines: Array<Line>;
769
- timeSeries: Array<TimeValue>;
770
- invert?: boolean;
771
- }): {
772
- stackedLinesTimeSeriesPerStackKeyAndUnit: Record<
773
- string,
774
- { lines: Array<Line>; timeSeries: Array<TimeValue> }
775
- >;
776
- stackedKeys: Record<string, null>;
777
- } => {
778
- const stackedKeys = stackedLines.reduce(
779
- (acc, { unit, stackKey }) => ({
780
- ...acc,
781
- [`stacked-${unit || ''}-${stackKey ? stackKey : ''}`]: null
782
- }),
783
- {}
784
- );
785
- const stackedKeysWithOnlyStackKey = Object.keys(stackedKeys).filter(
786
- (stackKey: string) => stackKey.split('-')[2]
787
- );
788
- const stackedKeysWithOnlyUnit = Object.keys(stackedKeys).filter(
789
- (stackKey: string) => !stackKey.split('-')[2]
790
- );
791
-
792
- const stackedLinesTimeSeriesPerStackKey = stackedKeysWithOnlyStackKey.reduce(
793
- (acc, stackedKey: string) => {
794
- const [, stackUnit, stackKey] = stackedKey.split('-');
795
- const relatedLines = stackedLines.filter(({ unit, stackKey: key }) => {
796
- return stackUnit === (unit || '') && stackKey === key;
797
- });
798
-
799
- return {
800
- ...acc,
801
- [stackedKey]: {
802
- lines: relatedLines,
803
- timeSeries: getTimeSeriesForLines({
804
- invert,
805
- lines: relatedLines,
806
- timeSeries
807
- })
808
- }
809
- };
810
- },
811
- {}
812
- );
813
- const affectedLinesPerStackKey = flatten(
814
- pluck('lines', Object.values(stackedLinesTimeSeriesPerStackKey))
815
- );
816
- const stackedLinesTimeSeriesPerUnit = stackedKeysWithOnlyUnit.reduce(
817
- (acc, stackedKey: string) => {
818
- const [, stackUnit] = stackedKey.split('-');
819
- const relatedLines = stackedLines.filter(
820
- (line) =>
821
- !affectedLinesPerStackKey.some(
822
- (affectedLine) => line.metric_id === affectedLine.metric_id
823
- ) && stackUnit === (line.unit || '')
824
- );
825
-
826
- return {
827
- ...acc,
828
- [stackedKey]: {
829
- lines: relatedLines,
830
- timeSeries: getTimeSeriesForLines({
831
- lines: relatedLines,
832
- timeSeries,
833
- invert
834
- })
835
- }
836
- };
837
- },
838
- {}
839
- );
840
-
841
- return {
842
- stackedLinesTimeSeriesPerStackKeyAndUnit: {
843
- ...stackedLinesTimeSeriesPerStackKey,
844
- ...stackedLinesTimeSeriesPerUnit
845
- },
846
- stackedKeys
847
- };
848
- };
849
-
850
786
  export {
851
787
  getTimeSeries,
852
788
  getLineData,
@@ -21,7 +21,7 @@ export interface Metric {
21
21
  critical_low_threshold: number | null;
22
22
  data: Array<number | null>;
23
23
  displayAs?: 'line' | 'bar';
24
- ds_data: DsData;
24
+ ds_data?: DsData;
25
25
  legend: string;
26
26
  maximum_value: number | null;
27
27
  metric: string;
@@ -25,7 +25,7 @@ import { BarStyle } from '../BarChart/models';
25
25
  import { margin } from '../Chart/common';
26
26
  import { LineStyle } from '../Chart/models';
27
27
  import { Threshold, Thresholds } from './models';
28
- import { formatMetricValueWithUnit } from './timeSeries';
28
+ import { formatMetricValue } from './timeSeries';
29
29
  import { Line, TimeValue } from './timeSeries/models';
30
30
 
31
31
  interface GetColorFromDataAndThresholdsProps {
@@ -234,7 +234,7 @@ export const getFormattedAxisValues = ({
234
234
 
235
235
  const formattedData = metricIds.map((metricId) =>
236
236
  timeSeries.map((data) =>
237
- formatMetricValueWithUnit({
237
+ formatMetricValue({
238
238
  value: data[metricId],
239
239
  unit: axisUnit,
240
240
  base
@@ -246,7 +246,7 @@ export const getFormattedAxisValues = ({
246
246
 
247
247
  const formattedThresholdValues = equals(thresholdUnit, axisUnit)
248
248
  ? threshold.map(({ value }) =>
249
- formatMetricValueWithUnit({
249
+ formatMetricValue({
250
250
  value,
251
251
  unit: axisUnit,
252
252
  base
@@ -273,11 +273,5 @@ export const computeGElementMarginLeft = ({
273
273
  export const computPixelsToShiftMouse = (xScale): number => {
274
274
  const domain = xScale.domain();
275
275
 
276
- const hoursDiffInGraph = dayjs(domain[1]).diff(domain[0], 'h');
277
-
278
- if (!hoursDiffInGraph) {
279
- return 0;
280
- }
281
-
282
- return Math.round(8 / hoursDiffInGraph);
276
+ return Math.round(8 / dayjs(domain[1]).diff(domain[0], 'h'));
283
277
  };
@@ -1,20 +1,20 @@
1
- export type { ParentSizeProps } from '@visx/responsive/lib/components/ParentSize';
2
- export { default as LineChart } from './Chart';
3
- export { default as ThresholdLines } from './Chart/BasicComponents/Lines/Threshold';
4
- export { default as useLineChartData } from './Chart/useChartData';
5
- export { default as BarChart } from './BarChart/BarChart';
6
- export { Gauge } from './Gauge';
7
- export { SingleBar } from './SingleBar';
8
- export { Text as GraphText } from './Text';
9
- export { default as Header } from './common/BaseChart/Header';
10
-
11
- export { HeatMap } from './HeatMap';
12
- export { BarStack } from './BarStack';
13
- export { PieChart } from './PieChart';
14
- export { Timeline } from './Timeline';
15
- export * from './Tree';
16
- export type { LineChartData, Threshold, Thresholds } from './common/models';
17
- export * from './common/timeSeries';
18
- export type { Metric } from './common/timeSeries/models';
19
- export * from './Chart/models';
20
- export * from './PieChart/models';
1
+ export type { ParentSizeProps } from "@visx/responsive/lib/components/ParentSize";
2
+ export { default as BarChart } from "./BarChart/BarChart";
3
+ export { BarStack } from "./BarStack";
4
+ export { default as LineChart } from "./Chart";
5
+ export { default as ThresholdLines } from "./Chart/BasicComponents/Lines/Threshold";
6
+ export * from "./Chart/models";
7
+ export { default as useLineChartData } from "./Chart/useChartData";
8
+ export { default as Header } from "./common/BaseChart/Header";
9
+ export { default as NoData } from "./common/Error/NoData";
10
+ export type { LineChartData, Threshold, Thresholds } from "./common/models";
11
+ export * from "./common/timeSeries";
12
+ export type { Metric } from "./common/timeSeries/models";
13
+ export { Gauge } from "./Gauge";
14
+ export { HeatMap } from "./HeatMap";
15
+ export { PieChart } from "./PieChart";
16
+ export * from "./PieChart/models";
17
+ export { SingleBar } from "./SingleBar";
18
+ export { Text as GraphText } from "./Text";
19
+ export { Timeline } from "./Timeline";
20
+ export * from "./Tree";
@@ -1,4 +1,4 @@
1
- import { useCallback, useEffect, useState } from 'react';
1
+ import { ReactElement, useCallback, useEffect, useState } from 'react';
2
2
 
3
3
  import {
4
4
  equals,
@@ -44,7 +44,7 @@ export interface ConnectedAutoCompleteFieldProps<TData> {
44
44
  field: string;
45
45
  getEndpoint: ({ search, page }) => string;
46
46
  decoder?;
47
- getRenderedOptionText: (option: TData) => string;
47
+ getRenderedOptionText?: (option: TData) => ReactElement | string;
48
48
  getRequestHeaders?: HeadersInit;
49
49
  initialPage: number;
50
50
  labelKey?: string;
@@ -53,9 +53,9 @@ export interface ConnectedAutoCompleteFieldProps<TData> {
53
53
  }
54
54
 
55
55
  const ConnectedAutocompleteField = (
56
- AutocompleteField: (props) => JSX.Element,
56
+ AutocompleteField: (props) => ReactElement,
57
57
  multiple: boolean
58
- ): ((props) => JSX.Element) => {
58
+ ): ((props) => ReactElement) => {
59
59
  const InnerConnectedAutocompleteField = <TData extends { name: string }>({
60
60
  initialPage = 1,
61
61
  getEndpoint,
@@ -65,7 +65,7 @@ const ConnectedAutocompleteField = (
65
65
  open,
66
66
  exclusionOptionProperty = 'id',
67
67
  searchConditions = [],
68
- getRenderedOptionText = (option): string => option.name?.toString(),
68
+ getRenderedOptionText = (option): string => option?.name?.toString(),
69
69
  getRequestHeaders,
70
70
  displayOptionThumbnail,
71
71
  queryKey,
@@ -74,7 +74,7 @@ const ConnectedAutocompleteField = (
74
74
  changeIdValue,
75
75
  ...props
76
76
  }: ConnectedAutoCompleteFieldProps<TData> &
77
- Omit<AutocompleteFieldProps, 'options'>): JSX.Element => {
77
+ Omit<AutocompleteFieldProps, 'options'>): ReactElement => {
78
78
  const [options, setOptions] = useState<Array<TData>>([]);
79
79
  const [page, setPage] = useState(1);
80
80
  const [maxPage, setMaxPage] = useState(initialPage);
@@ -221,7 +221,7 @@ const ConnectedAutocompleteField = (
221
221
  debounce(event.target.value);
222
222
  };
223
223
 
224
- const renderOptions = (renderProps, option, { selected }): JSX.Element => {
224
+ const renderOptions = (renderProps, option, { selected }): ReactElement => {
225
225
  const { value } = props;
226
226
 
227
227
  const lastValue = Array.isArray(value) ? last(value) : value;
@@ -340,11 +340,11 @@ const ConnectedAutocompleteField = (
340
340
  );
341
341
 
342
342
  useEffect(() => {
343
- if (!autocompleteChangedValue && !props?.value) {
343
+ if (!autocompleteChangedValue) {
344
344
  return;
345
345
  }
346
346
  setSearchParameter(undefined);
347
- }, [autocompleteChangedValue, props?.value]);
347
+ }, [autocompleteChangedValue]);
348
348
 
349
349
  useEffect(() => {
350
350
  if (!optionsOpen) {
@@ -38,7 +38,8 @@ const ListboxComponent = ({
38
38
  options,
39
39
  isOptionSelected,
40
40
  onChange,
41
- total
41
+ total,
42
+ value = []
42
43
  }) => {
43
44
  if (disableSelectAll) {
44
45
  return;
@@ -54,12 +55,19 @@ const ListboxComponent = ({
54
55
  const syntheticEvent = {} as React.SyntheticEvent;
55
56
 
56
57
  if (allSelected) {
57
- onChange?.(syntheticEvent, [], 'selectOption');
58
+ const remaining = value.filter(
59
+ (v) => !options.some((opt) => opt.id === v.id)
60
+ );
61
+ onChange?.(syntheticEvent, remaining, 'selectOption');
58
62
 
59
63
  return;
60
64
  }
61
65
 
62
- onChange?.(syntheticEvent, options, 'selectOption');
66
+ const merged = [
67
+ ...value,
68
+ ...options.filter((opt) => !isOptionSelected(opt))
69
+ ];
70
+ onChange?.(syntheticEvent, merged, 'selectOption');
63
71
  };
64
72
 
65
73
  return (
@@ -36,7 +36,7 @@ const MultiAutocompleteField = ({
36
36
  disableSortedOptions = false,
37
37
  disableSelectAll = true,
38
38
  optionProperty = 'name',
39
- getOptionLabel = (option): string => option.name,
39
+ getOptionLabel = (option): string => option?.name,
40
40
  getTagLabel = (option): string => option[optionProperty],
41
41
  getOptionTooltipLabel,
42
42
  chipProps,
@@ -113,7 +113,8 @@ const MultiAutocompleteField = ({
113
113
  onChange,
114
114
  isOptionSelected,
115
115
  disableSelectAll,
116
- options
116
+ options,
117
+ value: values
117
118
  })}
118
119
  onChange={onChange}
119
120
  {...props}