@centreon/ui 24.4.1-MON-34377-implement-tree-chart-on-centreon-ui.11 → 24.4.1-MON-38245-ba-tree-widget.0

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.11",
3
+ "version": "24.4.1-MON-38245-ba-tree-widget.0",
4
4
  "description": "Centreon UI Components",
5
5
  "scripts": {
6
6
  "update:deps": "pnpx npm-check-updates -i --format group",
@@ -82,7 +82,7 @@
82
82
  "@vitejs/plugin-react": "^4.2.1",
83
83
  "@vitejs/plugin-react-swc": "^3.6.0",
84
84
  "axios-mock-adapter": "^1.22.0",
85
- "cypress": "^13.7.0",
85
+ "cypress": "^13.7.1",
86
86
  "identity-obj-proxy": "^3.0.0",
87
87
  "jest-transform-stub": "^2.0.0",
88
88
  "mochawesome": "^7.1.3",
@@ -1,5 +1,10 @@
1
- import { LinkHorizontal } from '@visx/shape';
1
+ import {
2
+ LinkHorizontal,
3
+ LinkHorizontalStep,
4
+ LinkHorizontalLine
5
+ } from '@visx/shape';
2
6
  import { HierarchyPointLink } from '@visx/hierarchy/lib/types';
7
+ import { always, cond, equals, T } from 'ramda';
3
8
 
4
9
  import { useTheme } from '@mui/material';
5
10
 
@@ -9,6 +14,12 @@ interface Props<TData> extends Pick<TreeProps<TData>, 'treeLink'> {
9
14
  links: Array<HierarchyPointLink<Node<TData>>>;
10
15
  }
11
16
 
17
+ const getLinkComponent = cond([
18
+ [equals('line'), always(LinkHorizontalLine)],
19
+ [equals('step'), always(LinkHorizontalStep)],
20
+ [T, always(LinkHorizontal)]
21
+ ]);
22
+
12
23
  const Links = <TData extends BaseProp>({
13
24
  links,
14
25
  treeLink
@@ -24,10 +35,12 @@ const Links = <TData extends BaseProp>({
24
35
  .descendants()
25
36
  .map((ancestor) => ancestor.data.data.id);
26
37
 
38
+ const LinkComponent = getLinkComponent(treeLink?.type);
39
+
27
40
  const key = `${link.source.data.data.id}-${link.source.data.data.name}-${ancestorIds}_${link.target.data.data.id}-${link.target.data.data.name}-${descendantIds}`;
28
41
 
29
42
  return (
30
- <LinkHorizontal
43
+ <LinkComponent
31
44
  data={link}
32
45
  data-testid={`${link.source.data.data.id}_to_${link.target.data.data.id}`}
33
46
  fill="none"
@@ -168,4 +168,28 @@ describe('Complex data tree', () => {
168
168
 
169
169
  cy.makeSnapshot();
170
170
  });
171
+
172
+ it('displays the tree with step links when a prop is set', () => {
173
+ initializeStandaloneTree({
174
+ treeLink: {
175
+ type: 'step'
176
+ }
177
+ });
178
+
179
+ cy.contains('T').should('be.visible');
180
+
181
+ cy.makeSnapshot();
182
+ });
183
+
184
+ it('displays the tree with line links when a prop is set', () => {
185
+ initializeStandaloneTree({
186
+ treeLink: {
187
+ type: 'line'
188
+ }
189
+ });
190
+
191
+ cy.contains('T').should('be.visible');
192
+
193
+ cy.makeSnapshot();
194
+ });
171
195
  });
@@ -82,6 +82,21 @@ export const WithDefaultExpandFilter: Story = {
82
82
  render: StandaloneTreeTemplate
83
83
  };
84
84
 
85
+ export const WithStepLink: Story = {
86
+ args: {
87
+ children: SimpleContent,
88
+ node: {
89
+ height: 90,
90
+ width: 90
91
+ },
92
+ tree: simpleData,
93
+ treeLink: {
94
+ type: 'step'
95
+ }
96
+ },
97
+ render: StandaloneTreeTemplate
98
+ };
99
+
85
100
  export const WithCustomLinks: Story = {
86
101
  args: {
87
102
  children: SimpleContent,
@@ -95,7 +110,8 @@ export const WithCustomLinks: Story = {
95
110
  getStrokeDasharray: ({ target }) =>
96
111
  target.status === 'ok' ? '5,5' : '0',
97
112
  getStrokeOpacity: ({ target }) => (target.status === 'ok' ? 0.8 : 1),
98
- getStrokeWidth: ({ target }) => (target.status === 'ok' ? 1 : 2)
113
+ getStrokeWidth: ({ target }) => (target.status === 'ok' ? 1 : 2),
114
+ type: 'line'
99
115
  }
100
116
  },
101
117
  render: StandaloneTreeTemplate
@@ -14,6 +14,8 @@ export interface BaseProp {
14
14
  name: string;
15
15
  }
16
16
 
17
+ export type Link = 'curve' | 'line' | 'step';
18
+
17
19
  export interface ChildrenProps<TData> {
18
20
  ancestors: Array<Node<TData>>;
19
21
  depth: number;
@@ -48,5 +50,6 @@ export interface TreeProps<TData> {
48
50
  ) => string | number | undefined;
49
51
  getStrokeOpacity?: (props: LinkProps<TData>) => string | number | undefined;
50
52
  getStrokeWidth?: (props: LinkProps<TData>) => string | number | undefined;
53
+ type?: Link;
51
54
  };
52
55
  }
@@ -196,7 +196,7 @@ describe('Zoom', () => {
196
196
  cy.findByTestId('zoom-content').should(
197
197
  'have.attr',
198
198
  'transform',
199
- 'matrix(1, 0, 0, 1, 200, 0)'
199
+ 'matrix(1, 0, 0, 1, 0, 0)'
200
200
  );
201
201
 
202
202
  cy.makeSnapshot();
@@ -6,6 +6,9 @@ import { equals, isNil } from 'ramda';
6
6
  import { localPoint } from './localPoint';
7
7
  import { ZoomState } from './models';
8
8
 
9
+ const isLeftMouseButtonClicked = (e): boolean =>
10
+ !isNil(e.nativeEvent.which) && equals(e.nativeEvent.which, 1);
11
+
9
12
  interface UseZoomState {
10
13
  dragEnd: () => void;
11
14
  dragStart: (zoom: ProvidedZoom<SVGSVGElement> & ZoomState) => (e) => void;
@@ -14,19 +17,17 @@ interface UseZoomState {
14
17
  }
15
18
 
16
19
  export const useZoom = (): UseZoomState => {
17
- const [startTranslate, setStartTranslate] = useState<Translate | undefined>(
18
- undefined
19
- );
20
- const [startPoint, setStartPoint] = useState<Point | undefined>(undefined);
20
+ const [startTranslate, setStartTranslate] = useState<Translate | null>(null);
21
+ const [startPoint, setStartPoint] = useState<Point | null>(null);
21
22
 
22
23
  const dragStart = useCallback(
23
24
  (zoom: ProvidedZoom<SVGSVGElement> & ZoomState) =>
24
25
  (e): void => {
25
- if (!isNil(e.nativeEvent.which) && !equals(e.nativeEvent.which, 1)) {
26
+ if (!isLeftMouseButtonClicked(e)) {
26
27
  return;
27
28
  }
28
29
  const { translateX, translateY } = zoom.transformMatrix;
29
- setStartPoint(localPoint(e) || undefined);
30
+ setStartPoint(localPoint(e) || null);
30
31
  setStartTranslate({ translateX, translateY });
31
32
  },
32
33
  []
@@ -56,8 +57,8 @@ export const useZoom = (): UseZoomState => {
56
57
  [startPoint, startTranslate]
57
58
  );
58
59
  const dragEnd = useCallback((): void => {
59
- setStartPoint(undefined);
60
- setStartTranslate(undefined);
60
+ setStartPoint(null);
61
+ setStartTranslate(null);
61
62
  }, []);
62
63
 
63
64
  return {