@centreon/ui 25.6.13 → 25.7.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,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';
|