@centreon/ui 25.1.1 → 25.1.3

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": "25.1.1",
3
+ "version": "25.1.3",
4
4
  "description": "Centreon UI Components",
5
5
  "scripts": {
6
6
  "update:deps": "pnpx npm-check-updates -i --format group",
@@ -80,6 +80,10 @@ export const useDashboardItemStyles = makeStyles<{ hasHeader: boolean }>()(
80
80
  height: '100%',
81
81
  width: '100%'
82
82
  },
83
+ widgetSubContainer: {
84
+ height: '100%',
85
+ width: '100%'
86
+ },
83
87
  widgetContent: {
84
88
  height: hasHeader
85
89
  ? `calc(100% - ${theme.spacing(3.5)} - ${theme.spacing(0.5)})`
@@ -9,13 +9,13 @@ import {
9
9
  } from 'react';
10
10
 
11
11
  import { useAtomValue } from 'jotai';
12
- import { equals, isNil, prop } from 'ramda';
12
+ import { equals, isNil, prop, type } from 'ramda';
13
13
 
14
14
  import { Card, useTheme } from '@mui/material';
15
-
16
15
  import LoadingSkeleton from '../LoadingSkeleton';
16
+ import ExpandableContainer from '../components/ExpandableContainer';
17
+ import { Parameters } from '../components/ExpandableContainer/models';
17
18
  import { useMemoComponent, useViewportIntersection } from '../utils';
18
-
19
19
  import { useDashboardItemStyles } from './Dashboard.styles';
20
20
  import { isResizingItemAtom } from './atoms';
21
21
 
@@ -25,7 +25,7 @@ interface DashboardItemProps {
25
25
  children: ReactElement;
26
26
  className?: string;
27
27
  disablePadding?: boolean;
28
- header?: ReactElement;
28
+ header?: ReactElement | ((params: Parameters) => ReactElement);
29
29
  id: string;
30
30
  onMouseDown?: (e: MouseEvent<HTMLDivElement>) => void;
31
31
  onMouseUp?: (e: MouseEvent<HTMLDivElement>) => void;
@@ -86,51 +86,76 @@ const Item = forwardRef<HTMLDivElement, DashboardItemProps>(
86
86
  setElement(ref.current);
87
87
  }, [ref]);
88
88
 
89
+ const originStyle = {
90
+ ...style,
91
+ width: `calc(${prop('width', style) || '0px'} - 12px)`
92
+ };
93
+
89
94
  return useMemoComponent({
90
95
  Component: (
91
96
  <div
97
+ ref={ref}
92
98
  {...cardContainerListeners}
93
99
  className={sanitizedReactGridLayoutClassName}
94
- ref={ref}
95
- style={{
96
- ...style,
97
- width: `calc(${prop('width', style) || '0px'} - 12px)`
98
- }}
100
+ style={originStyle}
99
101
  >
100
- <Card
101
- className={classes.widgetContainer}
102
- data-padding={!disablePadding}
103
- >
104
- {header && (
105
- <div className={classes.widgetHeader} data-canMove={canMove}>
106
- {canMove && (
107
- <div
108
- {...listeners}
109
- className={classes.widgetHeaderDraggable}
110
- data-testid={`${id}_move_panel`}
111
- />
112
- )}
113
- {header}
114
- </div>
115
- )}
116
- <div
117
- className={cx(
118
- classes.widgetContent,
119
- !disablePadding && classes.widgetPadding
120
- )}
121
- >
122
- {!isInViewport ? (
123
- <LoadingSkeleton
124
- animation={false}
125
- data-widget-skeleton={id}
126
- height="100%"
127
- width="100%"
128
- />
129
- ) : (
130
- children
131
- )}
132
- </div>
133
- </Card>
102
+ <ExpandableContainer>
103
+ {({ isExpanded, label, key, ...rest }) => {
104
+ const canControl = isExpanded ? false : canMove;
105
+
106
+ const childrenHeader = equals(type(header), 'Function')
107
+ ? (header as (params: Parameters) => ReactElement)({
108
+ isExpanded,
109
+ label,
110
+ ref,
111
+ key,
112
+ ...rest
113
+ })
114
+ : header;
115
+
116
+ return (
117
+ <div key={key} className={classes.widgetSubContainer}>
118
+ <Card
119
+ className={classes.widgetContainer}
120
+ data-padding={!disablePadding}
121
+ >
122
+ {childrenHeader && (
123
+ <div
124
+ className={classes.widgetHeader}
125
+ data-canMove={canControl}
126
+ >
127
+ {canControl && (
128
+ <div
129
+ {...listeners}
130
+ className={classes.widgetHeaderDraggable}
131
+ data-testid={`${id}_move_panel`}
132
+ />
133
+ )}
134
+ {childrenHeader}
135
+ </div>
136
+ )}
137
+ <div
138
+ className={cx(
139
+ classes.widgetContent,
140
+ !disablePadding && classes.widgetPadding
141
+ )}
142
+ >
143
+ {!isInViewport ? (
144
+ <LoadingSkeleton
145
+ animation={false}
146
+ data-widget-skeleton={id}
147
+ height="100%"
148
+ width="100%"
149
+ />
150
+ ) : (
151
+ children
152
+ )}
153
+ </div>
154
+ </Card>
155
+ </div>
156
+ );
157
+ }}
158
+ </ExpandableContainer>
134
159
  </div>
135
160
  ),
136
161
  memoProps: isInViewport
@@ -0,0 +1,63 @@
1
+ import { OpenInFull } from '@mui/icons-material';
2
+ import { useState } from 'react';
3
+ import { Modal } from '../Modal';
4
+ import { useStyles } from './expandableContainer.styles';
5
+ import { Parameters } from './models';
6
+ import { labelExpand, labelReduce } from './translatedLabels';
7
+
8
+ interface Props {
9
+ children: (params: Omit<Parameters, 'ref'>) => JSX.Element;
10
+ }
11
+
12
+ const ExpandableContainer = ({ children }: Props) => {
13
+ const { classes } = useStyles();
14
+
15
+ const [isExpanded, setIsExpanded] = useState(false);
16
+
17
+ const toggleExpand = (): void => {
18
+ setIsExpanded(!isExpanded);
19
+ };
20
+ const currentMode = isExpanded ? labelExpand : labelReduce;
21
+
22
+ const reducedChildrenData = {
23
+ toggleExpand,
24
+ isExpanded: false,
25
+ label: labelExpand,
26
+ Icon: OpenInFull,
27
+ key: currentMode
28
+ };
29
+
30
+ const expandedChildrenData = {
31
+ toggleExpand,
32
+ isExpanded,
33
+ label: labelReduce,
34
+ Icon: OpenInFull,
35
+ key: currentMode
36
+ };
37
+
38
+ return (
39
+ <>
40
+ {children(reducedChildrenData)}
41
+ {isExpanded && (
42
+ <Modal
43
+ open={isExpanded}
44
+ size="xlarge"
45
+ classes={{
46
+ paper: classes.papper
47
+ }}
48
+ PaperProps={{
49
+ style: {
50
+ width: '90vw',
51
+ maxWidth: '90vw'
52
+ }
53
+ }}
54
+ hasCloseButton={false}
55
+ >
56
+ {children(expandedChildrenData)}
57
+ </Modal>
58
+ )}
59
+ </>
60
+ );
61
+ };
62
+
63
+ export default ExpandableContainer;
@@ -0,0 +1,9 @@
1
+ import { makeStyles } from 'tss-react/mui';
2
+
3
+ export const useStyles = makeStyles()({
4
+ papper: {
5
+ backgroundColor: 'transparent',
6
+ border: 'initial',
7
+ height: '90vh'
8
+ }
9
+ });
@@ -0,0 +1,3 @@
1
+ import ExpandableContainer from './ExpandableContainer';
2
+
3
+ export default ExpandableContainer;
@@ -0,0 +1,12 @@
1
+ import { SvgIconComponent } from '@mui/icons-material';
2
+ import { CSSProperties, ForwardedRef } from 'react';
3
+
4
+ export interface Parameters {
5
+ toggleExpand: () => void;
6
+ Icon: SvgIconComponent;
7
+ isExpanded: boolean;
8
+ label: string;
9
+ style?: CSSProperties;
10
+ ref: ForwardedRef<HTMLDivElement>;
11
+ key: string;
12
+ }
@@ -0,0 +1,2 @@
1
+ export const labelExpand = 'Expand';
2
+ export const labelReduce = 'Reduce';
@@ -1,42 +1,45 @@
1
+ import { type MutableRefObject } from 'react';
1
2
  import { Zoom as VisxZoom } from '@visx/zoom';
3
+ import { TransformMatrix } from '@visx/zoom/lib/types';
2
4
 
3
5
  import { ParentSize } from '../..';
4
6
 
5
7
  import ZoomContent from './ZoomContent';
6
- import type { ChildrenProps, MinimapPosition } from './models';
8
+ import type { MinimapPosition, ZoomChildren } from './models';
7
9
 
8
- export interface ZoomProps {
9
- children: (args: ChildrenProps) => JSX.Element;
10
+ export interface ZoomProps extends ZoomChildren {
10
11
  id?: number | string;
11
12
  minimapPosition?: MinimapPosition;
12
13
  scaleMax?: number;
13
14
  scaleMin?: number;
14
15
  showMinimap?: boolean;
16
+ contentRef?: MutableRefObject<SVGGElement | null>;
17
+ transformMatrix?: TransformMatrix;
15
18
  }
16
19
 
17
- const initialTransform = {
18
- scaleX: 1,
19
- scaleY: 1,
20
- skewX: 0,
21
- skewY: 0,
22
- translateX: 0,
23
- translateY: 0
24
- };
25
-
26
20
  const Zoom = ({
27
21
  children,
28
22
  scaleMin = 0.5,
29
23
  scaleMax = 4,
30
24
  showMinimap = false,
31
25
  minimapPosition = 'top-left',
32
- id = 0
26
+ id = 0,
27
+ contentRef,
28
+ transformMatrix = {
29
+ scaleX: 1,
30
+ scaleY: 1,
31
+ skewX: 0,
32
+ skewY: 0,
33
+ translateX: 0,
34
+ translateY: 0
35
+ }
33
36
  }: ZoomProps): JSX.Element => {
34
37
  return (
35
38
  <ParentSize>
36
39
  {({ width, height }) => (
37
40
  <VisxZoom<SVGSVGElement>
38
41
  height={height}
39
- initialTransformMatrix={initialTransform}
42
+ initialTransformMatrix={transformMatrix}
40
43
  scaleXMax={scaleMax}
41
44
  scaleXMin={scaleMin}
42
45
  scaleYMax={scaleMax}
@@ -51,6 +54,7 @@ const Zoom = ({
51
54
  showMinimap={showMinimap}
52
55
  width={width}
53
56
  zoom={zoom}
57
+ ref={contentRef}
54
58
  >
55
59
  {children}
56
60
  </ZoomContent>
@@ -1,4 +1,4 @@
1
- import { useEffect, useRef, useState } from 'react';
1
+ import { type ForwardedRef, forwardRef, MutableRefObject, useEffect, useRef, useState } from 'react';
2
2
 
3
3
  import { RectClipPath } from '@visx/clip-path';
4
4
 
@@ -8,38 +8,38 @@ import ReplayIcon from '@mui/icons-material/Replay';
8
8
 
9
9
  import { IconButton } from '../Button';
10
10
 
11
- import Minimap from './Minimap';
12
- import { useZoomStyles } from './Zoom.styles';
13
11
  import { minimapScale, radius } from './constants';
14
- import type { ChildrenProps, MinimapPosition, ZoomInterface } from './models';
15
12
  import { useZoom } from './useZoom';
13
+ import { useZoomStyles } from './Zoom.styles';
14
+ import Minimap from './Minimap';
15
+ import { ZoomChildren, type Dimension, type MinimapPosition, type ZoomInterface } from './models';
16
16
 
17
- export interface Props extends ZoomInterface {
18
- children: (args: ChildrenProps) => JSX.Element;
19
- height: number;
17
+ export interface Props extends Dimension, ZoomInterface, ZoomChildren {
20
18
  id?: number | string;
21
19
  minimapPosition: MinimapPosition;
22
20
  showMinimap?: boolean;
23
- width: number;
24
21
  }
25
22
 
26
- const ZoomContent = ({
27
- zoom,
28
- width,
29
- height,
30
- children,
31
- showMinimap,
32
- minimapPosition,
33
- id
34
- }: Props): JSX.Element => {
23
+ const ZoomContent = forwardRef(
24
+ (
25
+ {
26
+ zoom,
27
+ width,
28
+ height,
29
+ children,
30
+ showMinimap,
31
+ minimapPosition,
32
+ id
33
+ }: Props,
34
+ ref?: ForwardedRef<SVGGElement | null>
35
+ ) : JSX.Element => {
35
36
  const { classes } = useZoomStyles();
36
- const contentRef = useRef<SVGGElement | null>(null);
37
+
38
+ const fallbackRef = useRef<SVGGElement | null>(null)
39
+ const contentRef = (ref || fallbackRef) as MutableRefObject<SVGGElement | null>;
37
40
  const minimapSvgRef = useRef<SVGSVGElement | null>(null);
38
41
  const minimapContentRef = useRef<SVGSVGElement | null>(null);
39
- const [contentClientRect, setContentClientRect] = useState<{
40
- height: number;
41
- width: number;
42
- } | null>(null);
42
+ const [contentClientRect, setContentClientRect] = useState<Dimension | null>(null);
43
43
 
44
44
  const resizeObserver = new ResizeObserver(() => {
45
45
  const contentBoundingClientRect = (
@@ -105,8 +105,8 @@ const ZoomContent = ({
105
105
  contentClientRect,
106
106
  height,
107
107
  transformMatrix: zoom.transformMatrix,
108
- setTransformMatrix: zoom.setTransformMatrix,
109
- width
108
+ width,
109
+ zoom
110
110
  })}
111
111
  </g>
112
112
  </svg>
@@ -135,8 +135,8 @@ const ZoomContent = ({
135
135
  contentClientRect,
136
136
  height,
137
137
  transformMatrix: zoom.transformMatrix,
138
- setTransformMatrix: zoom.setTransformMatrix,
139
- width
138
+ width,
139
+ zoom
140
140
  })}
141
141
  </g>
142
142
  </Minimap>
@@ -165,6 +165,6 @@ const ZoomContent = ({
165
165
  </div>
166
166
  </div>
167
167
  );
168
- };
168
+ });
169
169
 
170
170
  export default ZoomContent;
@@ -1,15 +1,12 @@
1
- import type { ProvidedZoom } from '@visx/zoom/lib/types';
1
+ import { ProvidedZoom, TransformMatrix } from '@visx/zoom/lib/types';
2
2
 
3
3
  export interface ZoomState {
4
- transformMatrix: {
5
- scaleX: number;
6
- scaleY: number;
7
- skewX: number;
8
- skewY: number;
9
- translateX: number;
10
- translateY: number;
11
- };
12
- setTransformMatrix?: ProvidedZoom<SVGSVGElement>['setTransformMatrix'];
4
+ transformMatrix: TransformMatrix;
5
+ }
6
+
7
+ export interface Dimension {
8
+ height: number;
9
+ width: number;
13
10
  }
14
11
 
15
12
  export type MinimapPosition =
@@ -22,11 +19,12 @@ export interface ZoomInterface {
22
19
  zoom: ProvidedZoom<SVGSVGElement> & ZoomState;
23
20
  }
24
21
 
25
- export interface ChildrenProps extends ZoomState {
26
- contentClientRect: {
27
- height: number;
28
- width: number;
29
- } | null;
30
- height: number;
31
- width: number;
22
+ export interface ChildrenProps extends ZoomState, Dimension, ZoomInterface {
23
+ contentClientRect: Dimension | null;
24
+ }
25
+
26
+ export interface ZoomChildren {
27
+ children: (args: ChildrenProps) => JSX.Element;
32
28
  }
29
+
30
+