@centreon/ui 25.6.13 → 25.7.1
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
|
@@ -4,9 +4,11 @@ import {
|
|
|
4
4
|
always,
|
|
5
5
|
cond,
|
|
6
6
|
equals,
|
|
7
|
+
flatten,
|
|
7
8
|
gt,
|
|
8
9
|
gte,
|
|
9
10
|
head,
|
|
11
|
+
isEmpty,
|
|
10
12
|
isNil,
|
|
11
13
|
last,
|
|
12
14
|
length,
|
|
@@ -220,20 +222,26 @@ export const getFormattedAxisValues = ({
|
|
|
220
222
|
lines,
|
|
221
223
|
threshold
|
|
222
224
|
}: GetFormattedAxisValuesProps): Array<string> => {
|
|
223
|
-
const
|
|
224
|
-
?.metric_id;
|
|
225
|
+
const filteredMetrics = lines.filter(({ unit }) => equals(unit, axisUnit));
|
|
225
226
|
|
|
226
|
-
if (
|
|
227
|
+
if (isEmpty(filteredMetrics)) {
|
|
227
228
|
return [];
|
|
228
229
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
230
|
+
|
|
231
|
+
const metricIds = pluck('metric_id', filteredMetrics);
|
|
232
|
+
|
|
233
|
+
const formattedData = metricIds.map((metricId) =>
|
|
234
|
+
timeSeries.map((data) =>
|
|
235
|
+
formatMetricValue({
|
|
236
|
+
value: data[metricId],
|
|
237
|
+
unit: axisUnit,
|
|
238
|
+
base
|
|
239
|
+
})
|
|
240
|
+
)
|
|
235
241
|
);
|
|
236
242
|
|
|
243
|
+
const flattenedFormattedData = flatten(formattedData);
|
|
244
|
+
|
|
237
245
|
const formattedThresholdValues = equals(thresholdUnit, axisUnit)
|
|
238
246
|
? threshold.map(({ value }) =>
|
|
239
247
|
formatMetricValue({
|
|
@@ -244,7 +252,7 @@ export const getFormattedAxisValues = ({
|
|
|
244
252
|
) || []
|
|
245
253
|
: [];
|
|
246
254
|
|
|
247
|
-
return
|
|
255
|
+
return flattenedFormattedData
|
|
248
256
|
.concat(formattedThresholdValues)
|
|
249
257
|
.filter((v) => v) as Array<string>;
|
|
250
258
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
1
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
equals,
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
import { CircularProgress, useTheme } from '@mui/material';
|
|
18
18
|
|
|
19
19
|
import { Props as AutocompleteFieldProps } from '..';
|
|
20
|
-
import { ListingModel, SelectEntry } from '../../../..';
|
|
20
|
+
import { ListingModel, ListingMapModel, SelectEntry } from '../../../..';
|
|
21
21
|
import {
|
|
22
22
|
ConditionsSearchParameter,
|
|
23
23
|
SearchParameter
|
|
@@ -30,6 +30,12 @@ import {
|
|
|
30
30
|
} from '../../../../utils';
|
|
31
31
|
import Option from '../../Option';
|
|
32
32
|
|
|
33
|
+
interface OptionResult<T> {
|
|
34
|
+
result: Array<T>;
|
|
35
|
+
limit: number;
|
|
36
|
+
total: number;
|
|
37
|
+
}
|
|
38
|
+
|
|
33
39
|
export interface ConnectedAutoCompleteFieldProps<TData> {
|
|
34
40
|
allowUniqOption?: boolean;
|
|
35
41
|
baseEndpoint?: string;
|
|
@@ -91,7 +97,7 @@ const ConnectedAutocompleteField = (
|
|
|
91
97
|
const theme = useTheme();
|
|
92
98
|
|
|
93
99
|
const { fetchQuery, isFetching, prefetchNextPage, data } = useFetchQuery<
|
|
94
|
-
ListingModel<TData>
|
|
100
|
+
ListingModel<TData> | ListingMapModel<TData>
|
|
95
101
|
>({
|
|
96
102
|
decoder,
|
|
97
103
|
baseEndpoint,
|
|
@@ -116,6 +122,27 @@ const ConnectedAutocompleteField = (
|
|
|
116
122
|
}
|
|
117
123
|
});
|
|
118
124
|
|
|
125
|
+
const getOptionResult = useCallback((
|
|
126
|
+
newOptions: ListingModel<TData> | ListingMapModel<TData>
|
|
127
|
+
): OptionResult<TData> => {
|
|
128
|
+
if ('result' in newOptions) return {
|
|
129
|
+
result: newOptions.result || [],
|
|
130
|
+
total: newOptions.meta.total || 1,
|
|
131
|
+
limit: newOptions.meta.limit || 1,
|
|
132
|
+
};
|
|
133
|
+
if ('content' in newOptions) return {
|
|
134
|
+
result: newOptions.content || [],
|
|
135
|
+
total: newOptions.totalElements || 1,
|
|
136
|
+
limit: newOptions.size || 1,
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
return {
|
|
140
|
+
result: [],
|
|
141
|
+
total: 1,
|
|
142
|
+
limit: 1,
|
|
143
|
+
}
|
|
144
|
+
}, []);
|
|
145
|
+
|
|
119
146
|
const lastOptionRef = useIntersectionObserver({
|
|
120
147
|
action: () => setPage(page + 1),
|
|
121
148
|
loading: isFetching,
|
|
@@ -245,12 +272,14 @@ const ConnectedAutocompleteField = (
|
|
|
245
272
|
|
|
246
273
|
const moreOptions = page > 1 ? options : [];
|
|
247
274
|
|
|
275
|
+
const { result, limit, total } = getOptionResult(newOptions);
|
|
276
|
+
|
|
248
277
|
const formattedList = changeIdValue
|
|
249
|
-
?
|
|
278
|
+
? result.map((item) => ({
|
|
250
279
|
...item,
|
|
251
280
|
id: changeIdValue(item)
|
|
252
281
|
}))
|
|
253
|
-
:
|
|
282
|
+
: result;
|
|
254
283
|
|
|
255
284
|
if (!isEmpty(labelKey) && !isNil(labelKey)) {
|
|
256
285
|
const list = formattedList.map((item) =>
|
|
@@ -264,9 +293,6 @@ const ConnectedAutocompleteField = (
|
|
|
264
293
|
|
|
265
294
|
setOptions(moreOptions.concat(formattedList as Array<TData>));
|
|
266
295
|
|
|
267
|
-
const total = prop('total', newOptions.meta) || 1;
|
|
268
|
-
const limit = prop('limit', newOptions.meta) || 1;
|
|
269
|
-
|
|
270
296
|
const newMaxPage = Math.ceil(total / limit);
|
|
271
297
|
|
|
272
298
|
setMaxPage(newMaxPage);
|
|
@@ -325,7 +351,7 @@ const ConnectedAutocompleteField = (
|
|
|
325
351
|
|
|
326
352
|
return (
|
|
327
353
|
<AutocompleteField
|
|
328
|
-
total={data?.meta
|
|
354
|
+
total={data?.meta?.total || data?.totalElements || 1}
|
|
329
355
|
filterOptions={(opt): SelectEntry => opt}
|
|
330
356
|
loading={isFetching}
|
|
331
357
|
options={
|
package/src/api/models.ts
CHANGED
|
@@ -8,3 +8,12 @@ export interface Listing<TEntity> {
|
|
|
8
8
|
meta: ListingMeta;
|
|
9
9
|
result: Array<TEntity>;
|
|
10
10
|
}
|
|
11
|
+
|
|
12
|
+
export interface ListingMap<TEntity> {
|
|
13
|
+
content: Array<TEntity>;
|
|
14
|
+
totalPages: number;
|
|
15
|
+
totalElements: number;
|
|
16
|
+
size: number;
|
|
17
|
+
number: number;
|
|
18
|
+
numberOfElements: number;
|
|
19
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -72,6 +72,7 @@ export { default as StatusChip } from './StatusChip';
|
|
|
72
72
|
export type { Props as StatusChipProps } from './StatusChip';
|
|
73
73
|
|
|
74
74
|
export type { Listing as ListingModel } from './api/models';
|
|
75
|
+
export type { ListingMap as ListingMapModel } from './api/models';
|
|
75
76
|
|
|
76
77
|
export { default as useCancelTokenSource } from './api/useCancelTokenSource';
|
|
77
78
|
export { getData, patchData, postData, putData, deleteData } from './api';
|