@centreon/ui 24.4.1-MON-34377-implement-tree-chart-on-centreon-ui.4 → 24.4.1-MON-34377-implement-tree-chart-on-centreon-ui.6

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.4.1-MON-34377-implement-tree-chart-on-centreon-ui.4",
3
+ "version": "24.4.1-MON-34377-implement-tree-chart-on-centreon-ui.6",
4
4
  "description": "Centreon UI Components",
5
5
  "scripts": {
6
6
  "update:deps": "pnpx npm-check-updates -i --format group",
@@ -29,13 +29,16 @@ const Minimap = ({
29
29
  zoom
30
30
  });
31
31
 
32
+ const finalHeight = Math.max(contentClientRect?.height || 0, height);
33
+ const finalWidth = Math.max(contentClientRect?.width || 0, width);
34
+
32
35
  return (
33
36
  <g className={classes.minimap} clipPath="url(#zoom-clip)">
34
37
  <rect
35
38
  className={classes.minimapBackground}
36
- height={Math.max(contentClientRect?.height || 0, height)}
39
+ height={finalHeight}
37
40
  rx={radius}
38
- width={Math.max(contentClientRect?.width || 0, width)}
41
+ width={finalWidth}
39
42
  />
40
43
  {children}
41
44
  <rect
@@ -49,9 +52,9 @@ const Minimap = ({
49
52
  <rect
50
53
  data-testid="minimap-interaction"
51
54
  fill="transparent"
52
- height={Math.max(contentClientRect?.height || 0, height)}
55
+ height={finalHeight}
53
56
  rx={radius}
54
- width={Math.max(contentClientRect?.width || 0, width)}
57
+ width={finalWidth}
55
58
  onMouseDown={transformTo}
56
59
  onMouseMove={move}
57
60
  onWheel={zoomInOut}
@@ -163,7 +163,7 @@ describe('Zoom', () => {
163
163
  cy.makeSnapshot();
164
164
  });
165
165
 
166
- it('moves the view when the mouse is hover the minimap with the correspondiong button pressed down', () => {
166
+ it('moves the view when the mouse is hover the minimap with the corresponding button pressed down', () => {
167
167
  initialize({ showMinimap: true });
168
168
 
169
169
  cy.get('g[clip-path="url(#zoom-clip)"]').should('be.visible');
@@ -181,4 +181,23 @@ describe('Zoom', () => {
181
181
 
182
182
  cy.makeSnapshot();
183
183
  });
184
+
185
+ it('moves the view when the mouse is hover the content with the corresponding button pressed down', () => {
186
+ initialize({ showMinimap: true });
187
+
188
+ cy.get('g[clip-path="url(#zoom-clip)"]').should('be.visible');
189
+ cy.get('svg').should('have.attr', 'height', '400');
190
+
191
+ cy.findByTestId('zoom-container')
192
+ .trigger('mousedown', 400, 200)
193
+ .trigger('mousemove', 600, 200);
194
+
195
+ cy.findByTestId('zoom-content').should(
196
+ 'have.attr',
197
+ 'transform',
198
+ 'matrix(1, 0, 0, 1, 200, 0)'
199
+ );
200
+
201
+ cy.makeSnapshot();
202
+ });
184
203
  });
@@ -94,6 +94,7 @@ const Zoom = ({
94
94
  <svg
95
95
  className={classes.svg}
96
96
  data-is-grabbing={isDragging}
97
+ data-testid="zoom-container"
97
98
  height={height}
98
99
  width={width}
99
100
  onMouseDown={dragStart(zoom)}
@@ -4,7 +4,6 @@ import type {
4
4
  TouchEvent as ReactTouchEvent
5
5
  } from 'react';
6
6
 
7
- import { has } from 'ramda';
8
7
  import { Point } from '@visx/point';
9
8
 
10
9
  type EventType =
@@ -44,16 +43,7 @@ const getXAndYFromEvent = (event?: EventType): PointCoords => {
44
43
  };
45
44
  }
46
45
 
47
- const boundingClientRect = has('getBoundingClientRect', event.target)
48
- ? event.target.getBoundingClientRect()
49
- : null;
50
-
51
- if (!boundingClientRect) return { ...DEFAULT_POINT };
52
-
53
- return {
54
- x: boundingClientRect.x + boundingClientRect.width / 2,
55
- y: boundingClientRect.y + boundingClientRect.height / 2
56
- };
46
+ return { ...DEFAULT_POINT };
57
47
  };
58
48
 
59
49
  export const localPoint = (event: EventType): PointCoords | null => {
@@ -1,7 +1,7 @@
1
1
  import { useCallback, useState } from 'react';
2
2
 
3
3
  import { Point, ProvidedZoom, Translate } from '@visx/zoom/lib/types';
4
- import { equals } from 'ramda';
4
+ import { equals, isNil } from 'ramda';
5
5
 
6
6
  import { localPoint } from './localPoint';
7
7
  import { ZoomState } from './models';
@@ -22,7 +22,7 @@ export const useZoom = (): UseZoomState => {
22
22
  const dragStart = useCallback(
23
23
  (zoom: ProvidedZoom<SVGSVGElement> & ZoomState) =>
24
24
  (e): void => {
25
- if (!equals(e.nativeEvent.which, 1)) {
25
+ if (!isNil(e.nativeEvent.which) && !equals(e.nativeEvent.which, 1)) {
26
26
  return;
27
27
  }
28
28
  const { translateX, translateY } = zoom.transformMatrix;