@centreon/ui 26.11.13 → 26.11.14
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,9 +1,11 @@
|
|
|
1
1
|
import AddIcon from '@mui/icons-material/Add';
|
|
2
2
|
import ArrowBackIcon from '@mui/icons-material/ArrowBack';
|
|
3
|
+
import { CircularProgress } from '@mui/material';
|
|
3
4
|
|
|
4
5
|
import { useTranslation } from 'react-i18next';
|
|
5
6
|
|
|
6
7
|
import { Button, Menu } from '../..';
|
|
8
|
+
import { labelLoading } from './translatedLabels';
|
|
7
9
|
|
|
8
10
|
interface NamedEntity {
|
|
9
11
|
id: number | string;
|
|
@@ -16,10 +18,13 @@ type Props = {
|
|
|
16
18
|
goBack: () => void;
|
|
17
19
|
isActive: (id: number | string) => boolean;
|
|
18
20
|
isDisabled?: (id: number | string) => boolean;
|
|
21
|
+
isLoading?: boolean;
|
|
19
22
|
labels: {
|
|
20
23
|
create: string;
|
|
21
24
|
goBack: string;
|
|
22
25
|
};
|
|
26
|
+
// Observed at the bottom of the list to load the next page when it is reached
|
|
27
|
+
loadMoreRef?: (node: Element | null) => void;
|
|
23
28
|
navigateToElement: (id: number | string) => () => void;
|
|
24
29
|
};
|
|
25
30
|
|
|
@@ -27,6 +32,8 @@ export const PageQuickAccess = ({
|
|
|
27
32
|
elements,
|
|
28
33
|
isActive,
|
|
29
34
|
isDisabled,
|
|
35
|
+
isLoading,
|
|
36
|
+
loadMoreRef,
|
|
30
37
|
navigateToElement,
|
|
31
38
|
goBack,
|
|
32
39
|
create,
|
|
@@ -38,16 +45,27 @@ export const PageQuickAccess = ({
|
|
|
38
45
|
<Menu>
|
|
39
46
|
<Menu.Button data-testid="quickaccess" />
|
|
40
47
|
<Menu.Items>
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
<div
|
|
49
|
+
className="max-h-[50vh] overflow-y-auto"
|
|
50
|
+
data-testid="quickaccess-elements"
|
|
51
|
+
>
|
|
52
|
+
{elements?.map((element) => (
|
|
53
|
+
<Menu.Item
|
|
54
|
+
isActive={isActive(element.id)}
|
|
55
|
+
isDisabled={isDisabled?.(element.id)}
|
|
56
|
+
key={`${element.id}`}
|
|
57
|
+
onClick={navigateToElement(element.id)}
|
|
58
|
+
>
|
|
59
|
+
{element.name}
|
|
60
|
+
</Menu.Item>
|
|
61
|
+
))}
|
|
62
|
+
{loadMoreRef && <div className="h-px" ref={loadMoreRef} />}
|
|
63
|
+
{isLoading && (
|
|
64
|
+
<div className="flex justify-center py-2">
|
|
65
|
+
<CircularProgress aria-label={t(labelLoading)} size={20} />
|
|
66
|
+
</div>
|
|
67
|
+
)}
|
|
68
|
+
</div>
|
|
51
69
|
<Menu.Divider key="divider" />
|
|
52
70
|
<div className="px-2 pb-2 flex gap-4">
|
|
53
71
|
<Button
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const labelLoading = 'Loading...';
|
|
@@ -49,6 +49,15 @@ export const useInfiniteScrollListing = <T>({
|
|
|
49
49
|
|
|
50
50
|
const [page, setPage] = useAtom(pageAtom);
|
|
51
51
|
|
|
52
|
+
// Shared by the active query and the next page prefetch, so that the
|
|
53
|
+
// prefetched page is reused instead of being requested again
|
|
54
|
+
const getQueryKey = (queryPage: number): Array<string | number> => [
|
|
55
|
+
queryKeyName,
|
|
56
|
+
queryPage,
|
|
57
|
+
JSON.stringify(parameters),
|
|
58
|
+
JSON.stringify(customQueryParameters)
|
|
59
|
+
];
|
|
60
|
+
|
|
52
61
|
const { data, isLoading, prefetchNextPage, fetchStatus } = useFetchQuery<
|
|
53
62
|
Listing<T>
|
|
54
63
|
>({
|
|
@@ -59,12 +68,7 @@ export const useInfiniteScrollListing = <T>({
|
|
|
59
68
|
customQueryParameters,
|
|
60
69
|
parameters: { limit, page: params?.page || page, ...parameters }
|
|
61
70
|
}),
|
|
62
|
-
getQueryKey: () =>
|
|
63
|
-
queryKeyName,
|
|
64
|
-
page,
|
|
65
|
-
JSON.stringify(parameters),
|
|
66
|
-
JSON.stringify(customQueryParameters)
|
|
67
|
-
],
|
|
71
|
+
getQueryKey: () => getQueryKey(page),
|
|
68
72
|
isPaginated: true,
|
|
69
73
|
queryOptions: {
|
|
70
74
|
enabled,
|
|
@@ -110,7 +114,7 @@ export const useInfiniteScrollListing = <T>({
|
|
|
110
114
|
}
|
|
111
115
|
|
|
112
116
|
prefetchNextPage({
|
|
113
|
-
getPrefetchQueryKey:
|
|
117
|
+
getPrefetchQueryKey: getQueryKey,
|
|
114
118
|
page
|
|
115
119
|
});
|
|
116
120
|
}, [data, limit, page, prefetchNextPage]);
|