@centreon/ui 25.2.2 → 25.2.4

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.
@@ -1,4 +1,11 @@
1
- import { type ForwardedRef, forwardRef, MutableRefObject, useEffect, useRef, useState } from 'react';
1
+ import {
2
+ type ForwardedRef,
3
+ MutableRefObject,
4
+ forwardRef,
5
+ useEffect,
6
+ useRef,
7
+ useState
8
+ } from 'react';
2
9
 
3
10
  import { RectClipPath } from '@visx/clip-path';
4
11
 
@@ -8,11 +15,16 @@ import ReplayIcon from '@mui/icons-material/Replay';
8
15
 
9
16
  import { IconButton } from '../Button';
10
17
 
18
+ import Minimap from './Minimap';
19
+ import { useZoomStyles } from './Zoom.styles';
11
20
  import { minimapScale, radius } from './constants';
21
+ import {
22
+ type Dimension,
23
+ type MinimapPosition,
24
+ ZoomChildren,
25
+ type ZoomInterface
26
+ } from './models';
12
27
  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
28
 
17
29
  export interface Props extends Dimension, ZoomInterface, ZoomChildren {
18
30
  id?: number | string;
@@ -22,149 +34,144 @@ export interface Props extends Dimension, ZoomInterface, ZoomChildren {
22
34
 
23
35
  const ZoomContent = forwardRef(
24
36
  (
25
- {
26
- zoom,
27
- width,
28
- height,
29
- children,
30
- showMinimap,
31
- minimapPosition,
32
- id
33
- }: Props,
37
+ { zoom, width, height, children, showMinimap, minimapPosition, id }: Props,
34
38
  ref?: ForwardedRef<SVGGElement | null>
35
- ) : JSX.Element => {
36
- const { classes } = useZoomStyles();
39
+ ): JSX.Element => {
40
+ const { classes } = useZoomStyles();
37
41
 
38
- const fallbackRef = useRef<SVGGElement | null>(null)
39
- const contentRef = (ref || fallbackRef) as MutableRefObject<SVGGElement | null>;
40
- const minimapSvgRef = useRef<SVGSVGElement | null>(null);
41
- const minimapContentRef = useRef<SVGSVGElement | null>(null);
42
- const [contentClientRect, setContentClientRect] = useState<Dimension | null>(null);
42
+ const fallbackRef = useRef<SVGGElement | null>(null);
43
+ const contentRef = (ref ||
44
+ fallbackRef) as MutableRefObject<SVGGElement | null>;
45
+ const minimapSvgRef = useRef<SVGSVGElement | null>(null);
46
+ const minimapContentRef = useRef<SVGSVGElement | null>(null);
47
+ const [contentClientRect, setContentClientRect] =
48
+ useState<Dimension | null>(null);
43
49
 
44
- const resizeObserver = new ResizeObserver(() => {
45
- const contentBoundingClientRect = (
46
- contentRef.current as SVGGElement
47
- ).getBoundingClientRect();
50
+ const resizeObserver = new ResizeObserver(() => {
51
+ const contentBoundingClientRect = (
52
+ contentRef.current as SVGGElement
53
+ ).getBoundingClientRect();
48
54
 
49
- setContentClientRect({
50
- height: contentBoundingClientRect.height,
51
- width: contentBoundingClientRect.width
55
+ setContentClientRect({
56
+ height: contentBoundingClientRect.height,
57
+ width: contentBoundingClientRect.width
58
+ });
52
59
  });
53
- });
54
60
 
55
- useEffect(() => {
56
- if (contentRef.current) {
57
- resizeObserver.disconnect();
58
- resizeObserver.observe(contentRef.current);
59
- }
61
+ useEffect(() => {
62
+ if (contentRef.current) {
63
+ resizeObserver.disconnect();
64
+ resizeObserver.observe(contentRef.current);
65
+ }
60
66
 
61
- return () => {
62
- resizeObserver.disconnect();
63
- };
64
- }, [contentRef.current]);
67
+ return () => {
68
+ resizeObserver.disconnect();
69
+ };
70
+ }, [contentRef.current]);
65
71
 
66
- const { move, dragEnd, dragStart, isDragging } = useZoom();
72
+ const { move, dragEnd, dragStart, isDragging } = useZoom();
67
73
 
68
- const diffBetweenContentAndSvg = minimapSvgRef.current &&
69
- minimapContentRef.current && {
70
- left:
71
- minimapContentRef.current.getBoundingClientRect().left -
72
- minimapSvgRef.current.getBoundingClientRect().left,
73
- top:
74
- minimapContentRef.current.getBoundingClientRect().top -
75
- minimapSvgRef.current.getBoundingClientRect().top
76
- };
74
+ const diffBetweenContentAndSvg = minimapSvgRef.current &&
75
+ minimapContentRef.current && {
76
+ left:
77
+ minimapContentRef.current.getBoundingClientRect().left -
78
+ minimapSvgRef.current.getBoundingClientRect().left,
79
+ top:
80
+ minimapContentRef.current.getBoundingClientRect().top -
81
+ minimapSvgRef.current.getBoundingClientRect().top
82
+ };
77
83
 
78
- return (
79
- <div style={{ position: 'relative' }}>
80
- <svg
81
- className={classes.svg}
82
- data-is-grabbing={isDragging}
83
- data-testid="zoom-container"
84
- height={height}
85
- width={width}
86
- onMouseDown={dragStart(zoom)}
87
- onMouseEnter={dragStart(zoom)}
88
- onMouseLeave={dragEnd}
89
- onMouseMove={move(zoom)}
90
- onMouseUp={dragEnd}
91
- onWheel={zoom.handleWheel}
92
- >
93
- <RectClipPath
94
- height={Math.max(contentClientRect?.height || 0, height)}
95
- id={`zoom-clip-${id}`}
96
- rx={radius}
97
- width={Math.max(contentClientRect?.width || 0, width)}
98
- />
99
- <g
100
- data-testid="zoom-content"
101
- ref={contentRef}
102
- transform={zoom.toString()}
84
+ return (
85
+ <div style={{ position: 'relative' }}>
86
+ <svg
87
+ className={classes.svg}
88
+ data-is-grabbing={isDragging}
89
+ data-testid="zoom-container"
90
+ height={height}
91
+ width={width}
92
+ onMouseDown={dragStart(zoom)}
93
+ onMouseEnter={dragStart(zoom)}
94
+ onMouseLeave={dragEnd}
95
+ onMouseMove={move(zoom)}
96
+ onMouseUp={dragEnd}
97
+ onWheel={zoom.handleWheel}
103
98
  >
104
- {children({
105
- contentClientRect,
106
- height,
107
- transformMatrix: zoom.transformMatrix,
108
- width,
109
- zoom
110
- })}
111
- </g>
112
- </svg>
113
- <div className={classes.actionsAndZoom} data-position={minimapPosition}>
114
- {showMinimap && contentClientRect && (
115
- <svg
116
- className={classes.minimapContainer}
117
- data-testid="minimap"
118
- height={height * minimapScale}
119
- ref={minimapSvgRef}
120
- width={width * minimapScale}
99
+ <RectClipPath
100
+ height={Math.max(contentClientRect?.height || 0, height)}
101
+ id={`zoom-clip-${id}`}
102
+ rx={radius}
103
+ width={Math.max(contentClientRect?.width || 0, width)}
104
+ />
105
+ <g
106
+ data-testid="zoom-content"
107
+ ref={contentRef}
108
+ transform={zoom.toString()}
121
109
  >
122
- <Minimap
123
- contentClientRect={contentClientRect}
124
- diffBetweenContentAndSvg={
125
- diffBetweenContentAndSvg || { left: 0, top: 0 }
126
- }
127
- height={height}
128
- id={id}
129
- isDraggingFromContainer={isDragging}
130
- width={width}
131
- zoom={zoom}
110
+ {children({
111
+ contentClientRect,
112
+ height,
113
+ transformMatrix: zoom.transformMatrix,
114
+ width,
115
+ zoom
116
+ })}
117
+ </g>
118
+ </svg>
119
+ <div className={classes.actionsAndZoom} data-position={minimapPosition}>
120
+ {showMinimap && contentClientRect && (
121
+ <svg
122
+ className={classes.minimapContainer}
123
+ data-testid="minimap"
124
+ height={height * minimapScale}
125
+ ref={minimapSvgRef}
126
+ width={width * minimapScale}
132
127
  >
133
- <g ref={minimapContentRef}>
134
- {children({
135
- contentClientRect,
136
- height,
137
- transformMatrix: zoom.transformMatrix,
138
- width,
139
- zoom
140
- })}
141
- </g>
142
- </Minimap>
143
- </svg>
144
- )}
145
- <div className={classes.actions}>
146
- <IconButton
147
- data-testid="zoom in"
148
- icon={<ZoomInIcon />}
149
- size="small"
150
- onClick={() => zoom.scale({ scaleX: 1.2, scaleY: 1.2 })}
151
- />
152
- <IconButton
153
- data-testid="zoom out"
154
- icon={<ZoomOutIcon />}
155
- size="small"
156
- onClick={() => zoom.scale({ scaleX: 0.8, scaleY: 0.8 })}
157
- />
158
- <IconButton
159
- data-testid="clear"
160
- icon={<ReplayIcon />}
161
- size="small"
162
- onClick={zoom.reset}
163
- />
128
+ <Minimap
129
+ contentClientRect={contentClientRect}
130
+ diffBetweenContentAndSvg={
131
+ diffBetweenContentAndSvg || { left: 0, top: 0 }
132
+ }
133
+ height={height}
134
+ id={id}
135
+ isDraggingFromContainer={isDragging}
136
+ width={width}
137
+ zoom={zoom}
138
+ >
139
+ <g ref={minimapContentRef}>
140
+ {children({
141
+ contentClientRect,
142
+ height,
143
+ transformMatrix: zoom.transformMatrix,
144
+ width,
145
+ zoom
146
+ })}
147
+ </g>
148
+ </Minimap>
149
+ </svg>
150
+ )}
151
+ <div className={classes.actions}>
152
+ <IconButton
153
+ data-testid="zoom in"
154
+ icon={<ZoomInIcon />}
155
+ size="small"
156
+ onClick={() => zoom.scale({ scaleX: 1.2, scaleY: 1.2 })}
157
+ />
158
+ <IconButton
159
+ data-testid="zoom out"
160
+ icon={<ZoomOutIcon />}
161
+ size="small"
162
+ onClick={() => zoom.scale({ scaleX: 0.8, scaleY: 0.8 })}
163
+ />
164
+ <IconButton
165
+ data-testid="clear"
166
+ icon={<ReplayIcon />}
167
+ size="small"
168
+ onClick={zoom.reset}
169
+ />
170
+ </div>
164
171
  </div>
165
172
  </div>
166
- </div>
167
- );
168
- });
173
+ );
174
+ }
175
+ );
169
176
 
170
177
  export default ZoomContent;
@@ -26,5 +26,3 @@ export interface ChildrenProps extends ZoomState, Dimension, ZoomInterface {
26
26
  export interface ZoomChildren {
27
27
  children: (args: ChildrenProps) => JSX.Element;
28
28
  }
29
-
30
-