@centreon/ui 24.4.1-MON-34377-implement-tree-chart-on-centreon-ui.12 → 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-
|
|
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",
|
package/src/Graph/Tree/Links.tsx
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import {
|
|
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
|
-
<
|
|
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
|
package/src/Graph/Tree/models.ts
CHANGED
|
@@ -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
|
}
|