@centreon/ui 24.10.30 → 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,6 @@
1
1
  {
2
2
  "name": "@centreon/ui",
3
- "version": "24.10.30",
3
+ "version": "24.10.32",
4
4
  "description": "Centreon UI Components",
5
5
  "scripts": {
6
6
  "update:deps": "pnpx npm-check-updates -i --format group",
@@ -9,7 +9,7 @@ import { getColorFromDataAndTresholds } from '../common/utils';
9
9
  import AnimatedPie from './AnimatedPie';
10
10
  import { thresholdThickness } from './Thresholds';
11
11
  import { GaugeProps } from './models';
12
- import { angles } from './utils';
12
+ import { getAngles } from './utils';
13
13
 
14
14
  const dataThickness = 45;
15
15
 
@@ -43,7 +43,7 @@ const PieData = ({
43
43
 
44
44
  return (
45
45
  <Pie
46
- {...angles}
46
+ {...getAngles()}
47
47
  data={pieData}
48
48
  innerRadius={radius - dataThickness * dataThicknessFactor}
49
49
  outerRadius={
@@ -6,7 +6,7 @@ import { useTheme } from '@mui/material';
6
6
 
7
7
  import AnimatedPie from './AnimatedPie';
8
8
  import { GaugeProps } from './models';
9
- import { angles } from './utils';
9
+ import { getAngles } from './utils';
10
10
 
11
11
  export const thresholdThickness = 12;
12
12
 
@@ -90,7 +90,7 @@ const Thresholds = ({
90
90
  <>
91
91
  {arcs.map(({ thresholdArc, thresholdScaleOrdinal }) => (
92
92
  <Pie
93
- {...angles}
93
+ {...getAngles()}
94
94
  data={thresholdArc}
95
95
  innerRadius={radius - thresholdThickness * thresholdThicknessFactor}
96
96
  key={`arc-${thresholdArc[0].name}`}
@@ -1,4 +1,12 @@
1
- export const angles = {
2
- endAngle: -(2 * Math.PI) / 3,
3
- startAngle: (2 * Math.PI) / 3
4
- };
1
+ import { includes } from 'ramda';
2
+
3
+ export const getAngles = () =>
4
+ includes('Firefox', window.navigator.userAgent)
5
+ ? {
6
+ endAngle: (2 * Math.PI) / 3,
7
+ startAngle: -(2 * Math.PI) / 3
8
+ }
9
+ : {
10
+ endAngle: -(2 * Math.PI) / 3,
11
+ startAngle: (2 * Math.PI) / 3
12
+ };
@@ -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
- {elements?.map((element) => (
40
- <Menu.Item
41
- key={`${element.id}`}
42
- onClick={navigateToElement(element.id)}
43
- {...(isActive(element.id) && {
44
- isActive: true,
45
- isDisabled: true
46
- })}
47
- >
48
- {element.name}
49
- </Menu.Item>
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: (newPage) => ['dashboards', newPage],
118
+ getPrefetchQueryKey: getQueryKey,
115
119
  page
116
120
  });
117
121
  }, [data]);