forked from redhat-developer/gitops-console-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplicationSetNode.tsx
More file actions
193 lines (187 loc) · 5.8 KB
/
Copy pathApplicationSetNode.tsx
File metadata and controls
193 lines (187 loc) · 5.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import * as React from 'react';
import { observer } from 'mobx-react';
import SvgTextWithOverflow from '@gitops/components/graph/SvgTextWithOverflow';
import { dangerColor, successColor, warningColor } from '@gitops/utils/components/Icons/Icons';
import { HealthStatus } from '@gitops/utils/constants';
import ApplicationSetIcon from '@images/resources/applicationset.svg';
import { Tooltip } from '@patternfly/react-core';
import {
GhostIcon,
HeartBrokenIcon,
HeartIcon,
OutlinedCircleIcon,
PauseIcon,
} from '@patternfly/react-icons';
import {
BadgeLocation,
DefaultNode,
LabelBadge,
LabelPosition,
Node,
RectAnchor,
ShapeProps,
useAnchor,
useCombineRefs,
useSvgAnchor,
WithContextMenuProps,
WithSelectionProps,
} from '@patternfly/react-topology';
import { StatusSvgIcon } from '../../../application/graph/icons/resource-icons';
interface CustomNodeProps {
element: Node;
}
const ApplicationHealthStatusIcon = ({ status }: { status: HealthStatus }) => {
let icon = null;
switch (status) {
case HealthStatus.HEALTHY:
icon = <HeartIcon style={{ fill: `${successColor}` }} />;
break;
case HealthStatus.MISSING:
icon = <GhostIcon style={{ fill: `${warningColor}` }} />;
break;
case HealthStatus.DEGRADED:
icon = <HeartBrokenIcon style={{ fill: `${dangerColor}` }} />;
break;
case HealthStatus.PROGRESSING:
icon = (
<g transform={`translate(74, 40)`}>
<StatusSvgIcon status={HealthStatus.PROGRESSING} />
</g>
);
return <>{icon}</>;
case HealthStatus.UNKNOWN:
icon = <OutlinedCircleIcon style={{ fill: 'gray' }} />;
break;
case HealthStatus.SUSPENDED:
icon = <PauseIcon style={{ fill: `${warningColor}` }} />;
break;
default:
return <></>;
}
return (
<foreignObject x={74} y={40} width={16} height={16}>
<div
style={{
width: '16px',
height: '16px',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}}
>
<Tooltip content={status}>{icon}</Tooltip>
</div>
</foreignObject>
);
};
const ApplicationSetShape: React.FunctionComponent<ShapeProps> = observer(
({ element, className, width, height, filter, dndDropRef }) => {
useAnchor(RectAnchor);
const data = element.getData();
const anchorRef = useSvgAnchor();
const refs = useCombineRefs(dndDropRef, anchorRef);
// Arc first and then draw rectangular part
const applicationShapePath = `M 35 0 A 45 45 200 1 0 35 75 l 0 0 ${
width - 35
} 0 l 0 0 0 ${-height} l 0 0 ${-width + 35} 0`;
return (
<g>
<g>
<path filter={filter} ref={refs} className={className} d={applicationShapePath} />
</g>
<g transform={`translate(-2, 11)`}>
<circle
transform={'translate(12, 26)'}
r="37"
fill="var(--pf-t--global--background--color--floating--default)"
stroke="var(--pf-topology__node__background--Stroke)"
strokeWidth="2"
/>
<ApplicationSetIcon
className={className}
x={-12}
y={0}
width={50}
height={50}
style={{ color: 'var(--pf-topology__node__background--Stroke)' }}
/>
</g>
<g>
<svg
xmlns="http://www.w3.org/2000/svg"
width="280"
height="50"
viewBox="0 0 280 50"
overflow="hidden"
>
<SvgTextWithOverflow text={element.getData().name} maxWidth={200} x="75" y="30" />
</svg>
<ApplicationHealthStatusIcon status={data.appHealthStatus} />
<svg
xmlns="http://www.w3.org/2000/svg"
width="280"
height="60"
viewBox="0 0 280 60"
overflow="hidden"
>
<SvgTextWithOverflow
text={element.getData().appHealthStatus}
maxWidth={200}
x="95"
y="52"
/>
</svg>
</g>
</g>
);
},
);
export const ApplicationSetNode: React.FC<
CustomNodeProps & WithSelectionProps & WithContextMenuProps
> = observer(({ element, onContextMenu, contextMenuOpen, onSelect, selected }) => {
const data = element.getData();
const resourceNodeLayout = data.resourceNodeLayout as boolean;
return (
<DefaultNode
element={element}
showStatusDecorator={false}
badge={data.badge}
badgeLocation={resourceNodeLayout ? BadgeLocation.below : BadgeLocation.inner}
labelPosition={resourceNodeLayout ? LabelPosition.left : LabelPosition.top}
labelClassName={
resourceNodeLayout
? 'gitops-resource-node-label gitops-application-node-menu'
: 'gitops-node-layout'
}
badgeClassName={resourceNodeLayout ? 'gitops-resource-node-label-badge-opaque' : ''}
onContextMenu={onContextMenu}
contextMenuOpen={contextMenuOpen}
badgeColor={data.badgeColor}
badgeTextColor={data.badgeTextColor}
badgeBorderColor={data.badgeBorderColor}
onSelect={onSelect}
selected={selected}
nodeStatus={data.nodeStatus}
hover={false} // Need this to allow selection
getCustomShape={() => {
return ApplicationSetShape;
}}
>
{resourceNodeLayout && (
<>
<g id="argocd-application-node-badge" transform={`scale(0.85)`}>
<LabelBadge
x={-3}
y={74}
badge={data.badge}
badgeClassName={'gitops-resource-node-label-badge'}
badgeColor={data.badgeColor}
badgeTextColor={data.badgeTextColor}
badgeBorderColor={'var(--pf-topology__node__background--Stroke)'}
/>
</g>
</>
)}
</DefaultNode>
);
});