This repository was archived by the owner on Jun 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathJobNode.tsx
More file actions
313 lines (291 loc) · 10.2 KB
/
JobNode.tsx
File metadata and controls
313 lines (291 loc) · 10.2 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
// import { Job, types, workflow } from '@circleci/circleci-config-sdk';
// import { WorkflowJob } from '@circleci/circleci-config-sdk/dist/src/lib/Components/Workflow';
// import React, { useRef } from 'react';
// import { Handle, isNode, NodeProps, Position } from 'react-flow-renderer';
// import JobIcon from '../../../icons/components/JobIcon';
// import JobOnHoldIcon from '../../../icons/components/JobOnHoldIcon';
// import DeleteItemIcon from '../../../icons/ui/DeleteItemIcon';
// import MinusIcon from '../../../icons/ui/MinusIcon';
// import PlusIcon from '../../../icons/ui/PlusIcon';
// import { JobMapping } from '../../../mappings/components/JobMapping';
// import { useStoreActions, useStoreState } from '../../../state/Hooks';
// import { StagedJobMenuNav } from '../../menus/stage/StagedJobMenu';
// import { flattenGenerable } from '../Definition';
// const formatPattern = (pattern: string) => {
// if (!pattern.startsWith('^')) {
// pattern = `^${pattern}`;
// }
// if (!pattern.endsWith('$')) {
// pattern = `${pattern}$`;
// }
// return pattern;
// };
// const ConnectorIcon = (props: { filled: boolean; subtraction?: boolean }) => {
// return (
// <>
// {props.subtraction ? (
// <MinusIcon
// filled={props.filled}
// color="rgb(150, 0, 8)"
// className="bg-white rounded-full w-full border border-white"
// />
// ) : (
// <PlusIcon
// filled={props.filled}
// color="rgb(0, 120, 202)"
// className="bg-white rounded-full w-full border border-white"
// />
// )}
// </>
// );
// };
// const JobNode: React.FunctionComponent<
// NodeProps & { data: workflow.WorkflowJob }
// > = (props) => {
// const elements = useStoreState(
// (state) =>
// state.definitions.workflows[state.selectedWorkflowId].value.elements,
// );
// const dragging = useStoreState((state) => state.dragging);
// // const setWorkflowElements = useStoreActions(
// // (actions) => actions.setWorkflowElements,
// // );
// const updateJob = useStoreActions((actions) => actions.update_jobs);
// const navigateTo = useStoreActions((actions) => actions.navigateTo);
// const setConnecting = useStoreActions((actions) => actions.setConnecting);
// const toolbox = useStoreState((state) => state.previewToolbox);
// const selectedWorkflow = useStoreState((state) => state.selectedWorkflowId);
// const altAction = useStoreState((state) => state.altAction);
// const removeWorkflowElement = useStoreActions(
// (actions) => actions.removeWorkflowElement,
// );
// const connecting = useStoreState((state) => state.connecting);
// const updateConnecting = useStoreActions(
// (actions) => actions.updateConnecting,
// );
// const updateWorkflowJob = (
// workflowJob: workflow.WorkflowJob,
// applyToData: {
// job?: Job;
// parameters?: types.workflow.WorkflowJobParameters;
// },
// ) =>
// elements.map((element) =>
// isNode(element) && element.data.job.name === workflowJob.job.name
// ? { ...element, data: { ...workflowJob, ...applyToData } }
// : element,
// );
// const [hovering, setHovering] = React.useState({
// handles: false,
// node: false,
// requiredBy: false,
// remove: false,
// requires: false,
// });
// let filtered = false;
// const workflowJob = props.data as WorkflowJob;
// const filters = workflowJob.parameters?.filters;
// if (filters && toolbox.filter.preview && filters[toolbox.filter.type]) {
// const jobFilter = filters[toolbox.filter.type];
// const sample = toolbox.filter.pattern;
// try {
// const ignoreFilter = jobFilter?.ignore?.some((pattern) =>
// sample.match(formatPattern(pattern)),
// );
// const onlyFilter = jobFilter?.only
// ? jobFilter?.only?.some((pattern) =>
// sample.match(formatPattern(pattern)),
// )
// : true;
// filtered = ignoreFilter || !onlyFilter;
// } catch (e) {
// console.warn('Invalid regex pattern');
// }
// } else if (toolbox.filter.type === 'tags') {
// filtered = true;
// }
// const jobIcon = (isApproval: boolean = false) => {
// const classNameValue = 'w-5 mr-2';
// if (isApproval) {
// return <JobOnHoldIcon className={classNameValue} />;
// } else {
// return <JobIcon className={classNameValue} />;
// }
// };
// const viewJobProperties = () => {
// navigateTo({
// component: StagedJobMenuNav,
// props: {
// source: workflowJob,
// values: flattenGenerable(workflowJob, true),
// id: props.id,
// overrideRoot: selectedWorkflow,
// },
// origin: true,
// });
// };
// const trackHovering = (
// entering: string[],
// leaving: string[],
// postEnter?: () => void,
// postLeave?: () => void,
// ) => {
// return {
// onMouseEnter: () => {
// setHovering(
// entering.reduce(
// (previous, n) => ({ ...previous, [n]: true }),
// hovering,
// ),
// );
// postEnter && postEnter();
// },
// onMouseLeave: () => {
// setHovering(
// leaving.reduce(
// (previous, n) => ({ ...previous, [n]: false }),
// hovering,
// ),
// );
// postLeave && postLeave();
// },
// };
// };
// const nodeRef = useRef(null);
// const startConnecting =
// (side: 'source' | 'target') => (e: React.DragEvent<HTMLButtonElement>) => {
// setConnecting({
// ref: nodeRef,
// id: {
// connectionNodeId: props.id,
// connectionHandleType: side,
// connectionHandleId: `${props.id}_${side}`,
// },
// name: props.data.parameters?.name || props.data.name,
// });
// e.preventDefault();
// };
// return (
// <div
// className={`p-8 flex flex-row cursor-default`}
// {...trackHovering(
// ['handles'],
// ['handles', 'node', 'requires', 'requiredBy'],
// () => {
// const startType = connecting?.start?.id.connectionHandleType;
// const side = startType === 'source' ? 'target' : 'source';
// updateConnecting({
// ref: nodeRef,
// id: {
// connectionNodeId: props.id,
// connectionHandleType: side,
// connectionHandleId: `${props.id}_${side}`,
// },
// name: props.data.parameters?.name || props.data.name,
// });
// },
// () => {
// updateConnecting(undefined);
// },
// )}
// onDragOver={(e) => {
// if (dragging && dragging.dataType?.dragTarget === JobMapping.key) {
// e.preventDefault();
// }
// }}
// onDrop={(e) => {
// if (
// dragging &&
// dragging.dataType?.dragTarget === JobMapping.key &&
// dragging.dataType.applyToNode
// ) {
// const applyToData = dragging.dataType.applyToNode(
// dragging.data,
// props.data,
// );
// if (JobMapping.key in applyToData) {
// updateJob({ old: props.data.job, new: applyToData.job });
// }
// if ('parameters' in applyToData) {
// updateWorkflowJob(props.data, applyToData);
// }
// }
// }}
// >
// <button
// className={`opacity-${hovering['handles'] && !hovering['node'] && !connecting?.start
// ? 100
// : 0
// } transition-opacity duration-300 w-4 h-4 my-auto mr-5`}
// id={`${props.id}_source`}
// {...trackHovering(['requires', 'handles'], ['requires'])}
// draggable
// onDragStart={startConnecting('target')}
// >
// <ConnectorIcon filled={hovering['requires']} subtraction={altAction} />
// </button>
// <div
// className={`p-2 bg-white node flex flex-row text-black rounded-md border cursor-pointer ${filtered ? 'bg-gray-200 opacity-60' : 'opacity-100'
// }
// ${(hovering['node'] && !hovering['remove']) ||
// (hovering['handles'] && connecting?.start)
// ? 'border-circle-blue'
// : 'border-circle-gray-300'
// }`}
// ref={nodeRef}
// {...trackHovering(['node'], ['node'])}
// >
// <button className="flex w-full" onClick={viewJobProperties}>
// {jobIcon(props.data.parameters?.type === 'approval')}
// {props.data.parameters?.name || props.data.name}
// </button>
// <button
// className={`my-auto
// opacity-${hovering['node'] ? 100 : 0}
// transition-opacity duration-150 w-8 h-full flex`}
// {...trackHovering(['remove'], ['remove'])}
// onClick={() => {
// removeWorkflowElement(props.id);
// }}
// >
// <DeleteItemIcon
// className="w-3 cursor-pointer m-auto"
// color={hovering['remove'] ? '#B5261F' : '#AAAAAA'}
// />
// </button>
// </div>
// <button
// className={`opacity-${hovering['handles'] && !hovering['node'] && !connecting?.start
// ? 100
// : 0
// } source transition-opacity duration-300 w-4 h-4 my-auto ml-5`}
// {...trackHovering(['requiredBy', 'handles'], ['requiredBy'])}
// id={`${props.id}_target`}
// // onClick={() => {--
// // TODO: Implement 'add job' menu functionality
// // }}
// draggable
// onDragStart={startConnecting('source')}
// >
// <ConnectorIcon
// filled={hovering['requiredBy']}
// subtraction={altAction}
// />
// </button>
// <Handle
// type="source"
// className="opacity-0 cursor-default"
// position={Position.Right}
// id={`${props.id}_source`}
// ></Handle>
// <Handle
// className="opacity-0 cursor-default"
// id={`${props.id}_target`}
// type="target"
// position={Position.Left}
// />
// </div>
// );
// };
// export default JobNode;
export default {}