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