@centreon/ui 25.4.3 → 25.4.5

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.3",
3
+ "version": "25.4.5",
4
4
  "description": "Centreon UI Components",
5
5
  "scripts": {
6
6
  "update:deps": "pnpx npm-check-updates -i --format group",
@@ -26,7 +26,7 @@ const Links = <TData extends BaseProp>({
26
26
  }: Props<TData>): Array<JSX.Element> => {
27
27
  const theme = useTheme();
28
28
 
29
- return links.map((link) => {
29
+ return links.map((link, idx) => {
30
30
  const ancestorIds = link.target
31
31
  .ancestors()
32
32
  .map((ancestor) => ancestor.data.data.id);
@@ -37,7 +37,7 @@ const Links = <TData extends BaseProp>({
37
37
 
38
38
  const LinkComponent = getLinkComponent(treeLink?.type);
39
39
 
40
- const key = `${link.source.data.data.id}-${link.source.data.data.name}-${ancestorIds}_${link.target.data.data.id}-${link.target.data.data.name}-${descendantIds}`;
40
+ const key = `${link.source.data.data.id}-${link.source.data.data.name}-${ancestorIds}_${link.target.data.data.id}-${link.target.data.data.name}-${descendantIds}-${idx}`;
41
41
 
42
42
  return (
43
43
  <LinkComponent
@@ -84,10 +84,10 @@ export const Tree = <TData extends BaseProp>({
84
84
  );
85
85
 
86
86
  return (
87
- <Group left={node.width}>
87
+ <Group left={node.width / 2}>
88
88
  <VisxTree
89
89
  left={0}
90
- nodeSize={[node.width + nodeMargins.y, node.height + nodeMargins.x]}
90
+ nodeSize={[node.height + nodeMargins.x, node.height + node.width]}
91
91
  root={hierarchy(formattedTree, getExpanded)}
92
92
  separation={() => 1}
93
93
  size={[containerWidth, containerHeight]}
@@ -1,2 +1,2 @@
1
1
  export const margins = { bottom: 30, left: 30, right: 30, top: 30 };
2
- export const nodeMargins = { x: 90, y: 16 };
2
+ export const nodeMargins = { x: 2 };
@@ -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;