@centreon/ui 25.10.14 → 25.10.16
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
package/src/Dashboard/Item.tsx
CHANGED
|
@@ -1,28 +1,29 @@
|
|
|
1
|
+
import { Card, useTheme } from '@mui/material';
|
|
2
|
+
|
|
3
|
+
import { useAtomValue } from 'jotai';
|
|
4
|
+
import { equals, isNil, omit, type } from 'ramda';
|
|
1
5
|
import {
|
|
2
|
-
CSSProperties,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
forwardRef,
|
|
6
|
+
type CSSProperties,
|
|
7
|
+
type MouseEvent,
|
|
8
|
+
type ReactElement,
|
|
9
|
+
RefObject,
|
|
7
10
|
useEffect,
|
|
8
11
|
useMemo
|
|
9
12
|
} from 'react';
|
|
10
13
|
|
|
11
|
-
import { useAtomValue } from 'jotai';
|
|
12
|
-
import { equals, isNil, omit, type } from 'ramda';
|
|
13
|
-
|
|
14
|
-
import { Card, useTheme } from '@mui/material';
|
|
15
|
-
import LoadingSkeleton from '../LoadingSkeleton';
|
|
16
14
|
import ExpandableContainer from '../components/ExpandableContainer';
|
|
17
|
-
import { Parameters } from '../components/ExpandableContainer/models';
|
|
15
|
+
import type { Parameters } from '../components/ExpandableContainer/models';
|
|
18
16
|
import { useMemoComponent, useViewportIntersection } from '../utils';
|
|
19
|
-
import { useDashboardItemStyles } from './Dashboard.styles';
|
|
20
17
|
import { isResizingItemAtom } from './atoms';
|
|
18
|
+
import { useDashboardItemStyles } from './Dashboard.styles';
|
|
21
19
|
|
|
22
20
|
interface DashboardItemProps {
|
|
23
21
|
additionalMemoProps?: Array<unknown>;
|
|
24
22
|
canMove?: boolean;
|
|
25
|
-
children:
|
|
23
|
+
children: Array<
|
|
24
|
+
| ReactElement
|
|
25
|
+
| (({ isInViewport }: { isInViewport: boolean }) => ReactElement)
|
|
26
|
+
>;
|
|
26
27
|
className?: string;
|
|
27
28
|
disablePadding?: boolean;
|
|
28
29
|
header?: ReactElement | ((params: Parameters) => ReactElement);
|
|
@@ -31,148 +32,140 @@ interface DashboardItemProps {
|
|
|
31
32
|
onMouseUp?: (e: MouseEvent<HTMLDivElement>) => void;
|
|
32
33
|
onTouchEnd?: (e) => void;
|
|
33
34
|
style?: CSSProperties;
|
|
35
|
+
ref?: RefObject<HTMLDivElement>;
|
|
34
36
|
}
|
|
35
37
|
|
|
36
|
-
const Item =
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
)
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
data-padding={!disablePadding}
|
|
123
|
-
>
|
|
124
|
-
{childrenHeader && (
|
|
125
|
-
<div
|
|
126
|
-
className={classes.widgetHeader}
|
|
127
|
-
data-can-move={canControl}
|
|
128
|
-
>
|
|
129
|
-
{canControl && (
|
|
130
|
-
<div
|
|
131
|
-
{...listeners}
|
|
132
|
-
className={classes.widgetHeaderDraggable}
|
|
133
|
-
data-testid={`${id}_move_panel`}
|
|
134
|
-
/>
|
|
135
|
-
)}
|
|
136
|
-
{childrenHeader}
|
|
137
|
-
</div>
|
|
138
|
-
)}
|
|
38
|
+
const Item = ({
|
|
39
|
+
children,
|
|
40
|
+
style,
|
|
41
|
+
className,
|
|
42
|
+
header,
|
|
43
|
+
onMouseDown,
|
|
44
|
+
onMouseUp,
|
|
45
|
+
onTouchEnd,
|
|
46
|
+
id,
|
|
47
|
+
disablePadding = false,
|
|
48
|
+
canMove = false,
|
|
49
|
+
additionalMemoProps = [],
|
|
50
|
+
ref
|
|
51
|
+
}: DashboardItemProps): ReactElement => {
|
|
52
|
+
const { isInViewport, setElement } = useViewportIntersection({
|
|
53
|
+
rootMargin: '140px 0px 140px 0px'
|
|
54
|
+
});
|
|
55
|
+
const hasHeader = !isNil(header);
|
|
56
|
+
|
|
57
|
+
const { classes, cx } = useDashboardItemStyles({ hasHeader });
|
|
58
|
+
const theme = useTheme();
|
|
59
|
+
|
|
60
|
+
const isResizingItem = useAtomValue(isResizingItemAtom);
|
|
61
|
+
|
|
62
|
+
const isResizing = useMemo(
|
|
63
|
+
() => equals(id, isResizingItem),
|
|
64
|
+
[isResizingItem, id]
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
const sanitizedReactGridLayoutClassName = useMemo(
|
|
68
|
+
() => (isResizing ? className : className?.replace(' resizing ', '')),
|
|
69
|
+
[className, isResizing]
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
const listeners = {
|
|
73
|
+
onMouseDown,
|
|
74
|
+
onMouseUp,
|
|
75
|
+
onTouchEnd
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const cardContainerListeners = !hasHeader ? listeners : {};
|
|
79
|
+
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
if (isNil(ref?.current)) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
setElement(ref.current);
|
|
86
|
+
}, [ref, setElement]);
|
|
87
|
+
|
|
88
|
+
const newTransform =
|
|
89
|
+
style?.transform &&
|
|
90
|
+
`translate3d(${style.transform.match(/translate\(([a-z0-9 ,-]+)\)/)?.[1]}, 0px)`;
|
|
91
|
+
|
|
92
|
+
return useMemoComponent({
|
|
93
|
+
Component: (
|
|
94
|
+
<div
|
|
95
|
+
{...cardContainerListeners}
|
|
96
|
+
className={sanitizedReactGridLayoutClassName}
|
|
97
|
+
ref={ref}
|
|
98
|
+
style={{
|
|
99
|
+
...omit(['transform'], style || {}),
|
|
100
|
+
transform: newTransform
|
|
101
|
+
}}
|
|
102
|
+
>
|
|
103
|
+
<ExpandableContainer>
|
|
104
|
+
{({ isExpanded, label, key, ...rest }) => {
|
|
105
|
+
const canControl = isExpanded ? false : canMove;
|
|
106
|
+
|
|
107
|
+
const childrenHeader = equals(type(header), 'Function')
|
|
108
|
+
? (header as (params: Parameters) => ReactElement)({
|
|
109
|
+
isExpanded,
|
|
110
|
+
key,
|
|
111
|
+
label,
|
|
112
|
+
ref: ref as RefObject<HTMLDivElement>,
|
|
113
|
+
...rest
|
|
114
|
+
})
|
|
115
|
+
: (header as ReactElement);
|
|
116
|
+
|
|
117
|
+
return (
|
|
118
|
+
<div className={classes.widgetSubContainer} key={key}>
|
|
119
|
+
<Card
|
|
120
|
+
className={classes.widgetContainer}
|
|
121
|
+
data-padding={!disablePadding}
|
|
122
|
+
>
|
|
123
|
+
{childrenHeader && (
|
|
139
124
|
<div
|
|
140
|
-
className={
|
|
141
|
-
|
|
142
|
-
!disablePadding && classes.widgetPadding
|
|
143
|
-
)}
|
|
125
|
+
className={classes.widgetHeader}
|
|
126
|
+
data-can-move={canControl}
|
|
144
127
|
>
|
|
145
|
-
{
|
|
146
|
-
<
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
width="100%"
|
|
128
|
+
{canControl && (
|
|
129
|
+
<div
|
|
130
|
+
{...listeners}
|
|
131
|
+
className={classes.widgetHeaderDraggable}
|
|
132
|
+
data-testid={`${id}_move_panel`}
|
|
151
133
|
/>
|
|
152
|
-
) : (
|
|
153
|
-
children
|
|
154
134
|
)}
|
|
135
|
+
{childrenHeader}
|
|
155
136
|
</div>
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
137
|
+
)}
|
|
138
|
+
<div
|
|
139
|
+
className={cx(
|
|
140
|
+
classes.widgetContent,
|
|
141
|
+
!disablePadding && classes.widgetPadding
|
|
142
|
+
)}
|
|
143
|
+
>
|
|
144
|
+
{children.map((child) =>
|
|
145
|
+
typeof child === 'function'
|
|
146
|
+
? child({ isInViewport })
|
|
147
|
+
: child
|
|
148
|
+
)}
|
|
149
|
+
</div>
|
|
150
|
+
</Card>
|
|
151
|
+
</div>
|
|
152
|
+
);
|
|
153
|
+
}}
|
|
154
|
+
</ExpandableContainer>
|
|
155
|
+
</div>
|
|
156
|
+
),
|
|
157
|
+
memoProps: isInViewport
|
|
158
|
+
? [
|
|
159
|
+
style,
|
|
160
|
+
className,
|
|
161
|
+
header,
|
|
162
|
+
theme.palette.mode,
|
|
163
|
+
canMove,
|
|
164
|
+
isInViewport,
|
|
165
|
+
...additionalMemoProps
|
|
166
|
+
]
|
|
167
|
+
: [isInViewport, theme.palette.mode, style]
|
|
168
|
+
});
|
|
169
|
+
};
|
|
177
170
|
|
|
178
171
|
export default Item;
|
|
@@ -98,6 +98,7 @@
|
|
|
98
98
|
--color-primary-main: #2e68aa;
|
|
99
99
|
--color-primary-light: #cde7fc;
|
|
100
100
|
--color-primary-dark: #255891;
|
|
101
|
+
--color-primary-contrastText: #fff;
|
|
101
102
|
--color-secondary-main: #c772d6;
|
|
102
103
|
--color-secondary-light: #e5a5f0;
|
|
103
104
|
--color-secondary-dark: #ac28c1;
|
|
@@ -185,6 +186,7 @@
|
|
|
185
186
|
--color-primary-main: #6eaff8;
|
|
186
187
|
--color-primary-light: #8bbff9;
|
|
187
188
|
--color-primary-dark: #4974a5;
|
|
189
|
+
--color-primary-contrastText: #000;
|
|
188
190
|
--color-secondary-main: #7c1fa2;
|
|
189
191
|
--color-status-background-error: #d60101;
|
|
190
192
|
--color-status-background-none: --alpha(#2e68aa / 10%);
|
|
@@ -37,6 +37,7 @@ interface UseMetricsQueryProps {
|
|
|
37
37
|
timePeriodType: number;
|
|
38
38
|
};
|
|
39
39
|
isEnabled?: boolean;
|
|
40
|
+
enforceIsEnabled?: boolean;
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
interface UseMetricsQueryState {
|
|
@@ -103,7 +104,8 @@ const useGraphQuery = ({
|
|
|
103
104
|
refreshCount,
|
|
104
105
|
bypassQueryParams = false,
|
|
105
106
|
prefix,
|
|
106
|
-
isEnabled = true
|
|
107
|
+
isEnabled = true,
|
|
108
|
+
enforceIsEnabled
|
|
107
109
|
}: UseMetricsQueryProps): UseMetricsQueryState => {
|
|
108
110
|
const timePeriodToUse = equals(timePeriod?.timePeriodType, -1)
|
|
109
111
|
? {
|
|
@@ -161,9 +163,10 @@ const useGraphQuery = ({
|
|
|
161
163
|
],
|
|
162
164
|
queryOptions: {
|
|
163
165
|
enabled:
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
166
|
+
enforceIsEnabled ??
|
|
167
|
+
(areResourcesFullfilled(resources) &&
|
|
168
|
+
!isEmpty(definedMetrics) &&
|
|
169
|
+
isEnabled),
|
|
167
170
|
refetchInterval: refreshInterval,
|
|
168
171
|
suspense: false
|
|
169
172
|
},
|
|
@@ -18,10 +18,9 @@ export const useViewportIntersection = (
|
|
|
18
18
|
observer.current.disconnect();
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
observer.current = new window.IntersectionObserver(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
);
|
|
21
|
+
observer.current = new window.IntersectionObserver(([newEntry]) => {
|
|
22
|
+
setEntry(newEntry);
|
|
23
|
+
}, options);
|
|
25
24
|
|
|
26
25
|
if (element) {
|
|
27
26
|
observer.current.observe(element);
|