@centreon/ui 26.11.15 → 26.12.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
|
@@ -8,6 +8,8 @@ import {
|
|
|
8
8
|
resetMocks,
|
|
9
9
|
waitFor
|
|
10
10
|
} from '../../../../../test/testRenderer';
|
|
11
|
+
import fetchMock from 'jest-fetch-mock';
|
|
12
|
+
|
|
11
13
|
import buildListingEndpoint from '../../../../api/buildListingEndpoint';
|
|
12
14
|
import type {
|
|
13
15
|
BuildListingEndpointParameters,
|
|
@@ -127,4 +129,39 @@ describe(SingleConnectedAutocompleteField, () => {
|
|
|
127
129
|
);
|
|
128
130
|
});
|
|
129
131
|
});
|
|
132
|
+
|
|
133
|
+
it('leaves no request rejected unhandled when it is closed while its options load', async () => {
|
|
134
|
+
const unhandledRejections: Array<unknown> = [];
|
|
135
|
+
const onUnhandledRejection = (reason: unknown): void => {
|
|
136
|
+
unhandledRejections.push(reason);
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
process.on('unhandledRejection', onUnhandledRejection);
|
|
140
|
+
|
|
141
|
+
try {
|
|
142
|
+
// Options that never arrive: the request is still running at unmount,
|
|
143
|
+
// which cancels it.
|
|
144
|
+
fetchMock.mockResponse(() => new Promise(() => undefined));
|
|
145
|
+
|
|
146
|
+
const { getByLabelText, unmount } =
|
|
147
|
+
renderSingleConnectedAutocompleteField();
|
|
148
|
+
|
|
149
|
+
fireEvent.click(getByLabelText('Open'));
|
|
150
|
+
|
|
151
|
+
await waitFor(() => {
|
|
152
|
+
expect(getFetchCall(0)).toEqual(`${baseEndpoint}?page=1`);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
unmount();
|
|
156
|
+
|
|
157
|
+
// Unhandled rejections are reported once the microtask queue drains.
|
|
158
|
+
await new Promise((resolve) => {
|
|
159
|
+
setTimeout(resolve, 50);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
expect(unhandledRejections).toEqual([]);
|
|
163
|
+
} finally {
|
|
164
|
+
process.off('unhandledRejection', onUnhandledRejection);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
130
167
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CircularProgress, useTheme } from '@mui/material';
|
|
2
2
|
import type { AutocompleteRenderOptionState } from '@mui/material/Autocomplete';
|
|
3
3
|
|
|
4
|
+
import { isCancelledError } from '@tanstack/react-query';
|
|
4
5
|
import {
|
|
5
6
|
equals,
|
|
6
7
|
has,
|
|
@@ -307,52 +308,62 @@ const ConnectedAutocompleteField = (
|
|
|
307
308
|
);
|
|
308
309
|
|
|
309
310
|
const fetchOptionsAndPrefetchNextOptions = useCallback((): void => {
|
|
310
|
-
fetchQuery()
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
311
|
+
fetchQuery()
|
|
312
|
+
.then((newOptions) => {
|
|
313
|
+
const isError = has('isError', newOptions);
|
|
314
|
+
|
|
315
|
+
if (isError) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
const moreOptions = page > 1 ? options : [];
|
|
320
|
+
|
|
321
|
+
const { result, limit, total } = getOptionResult(newOptions);
|
|
322
|
+
|
|
323
|
+
const formattedList = changeIdValue
|
|
324
|
+
? result.map((item) => ({
|
|
325
|
+
...item,
|
|
326
|
+
id: changeIdValue(item)
|
|
327
|
+
}))
|
|
328
|
+
: result;
|
|
329
|
+
|
|
330
|
+
if (!isEmpty(labelKey) && !isNil(labelKey)) {
|
|
331
|
+
const list = formattedList.map((item) =>
|
|
332
|
+
renameKey({ key: labelKey, newKey: 'name', object: item })
|
|
333
|
+
);
|
|
334
|
+
setOptions(moreOptions.concat(list as Array<TData>));
|
|
335
|
+
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
setOptions(moreOptions.concat(formattedList));
|
|
339
|
+
|
|
340
|
+
setOptions(moreOptions.concat(formattedList as Array<TData>));
|
|
341
|
+
|
|
342
|
+
const newMaxPage = Math.ceil(total / limit);
|
|
343
|
+
|
|
344
|
+
setMaxPage(newMaxPage);
|
|
345
|
+
if (equals(newMaxPage, page)) {
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
prefetchNextPage({
|
|
350
|
+
getPrefetchQueryKey: (newPage: number) => [
|
|
351
|
+
`autocomplete-${props.label}`,
|
|
352
|
+
newPage,
|
|
353
|
+
searchParameter
|
|
354
|
+
],
|
|
355
|
+
page
|
|
356
|
+
});
|
|
357
|
+
})
|
|
358
|
+
// The request is cancelled when the field unmounts while it loads: there
|
|
359
|
+
// is nothing left to update, and nothing went wrong.
|
|
360
|
+
.catch((error) => {
|
|
361
|
+
if (isCancelledError(error)) {
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
throw error;
|
|
354
366
|
});
|
|
355
|
-
});
|
|
356
367
|
}, [
|
|
357
368
|
changeIdValue,
|
|
358
369
|
fetchQuery,
|