-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathPipelineGraphModel.tsx
136 lines (117 loc) · 3.24 KB
/
PipelineGraphModel.tsx
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
export enum Result {
success = "success",
failure = "failure",
running = "running",
queued = "queued",
paused = "paused",
unstable = "unstable",
aborted = "aborted",
not_built = "not_built", // May be pending, or job was ended before this point
skipped = "skipped", // excluded via pipeline "when" clause
unknown = "unknown", // bad data or client code needs updating for new values
}
export function decodeResultValue(resultMaybe: any): Result {
const lcase = String(resultMaybe).toLowerCase();
// TODO: validate this
if ((Object.values(Result) as any).includes(lcase)) {
return lcase as Result;
}
return Result.unknown;
}
// Dimensions used for layout, px
export const defaultLayout = {
nodeSpacingH: 120,
parallelSpacingH: 120,
nodeSpacingV: 70,
nodeRadius: 12,
terminalRadius: 7,
curveRadius: 12,
connectorStrokeWidth: 3.5,
labelOffsetV: 20,
smallLabelOffsetV: 15,
ypStart: 55,
};
// Typedefs
export type StageType =
| "STAGE"
| "PARALLEL"
| "PARALLEL_BLOCK"
| "STEP"
| "PIPELINE_START";
/**
* StageInfo is the input, in the form of an Array<StageInfo> of the top-level stages of a pipeline
*/
export interface StageInfo {
name: string;
title: string;
state: Result;
completePercent: number;
id: number;
type: StageType;
children: Array<StageInfo>; // Used by the top-most stages with parallel branches
nextSibling?: StageInfo; // Used within a parallel branch to denote sequential stages
isSequential?: boolean;
synthetic?: boolean;
pauseDurationMillis: string;
startTimeMillis: string;
totalDurationMillis: string;
agent: string;
url: string;
}
interface BaseNodeInfo {
key: string;
x: number;
y: number;
id: number;
name: string;
// -- Marker
isPlaceholder: boolean;
}
export interface StageNodeInfo extends BaseNodeInfo {
// -- Marker
isPlaceholder: false;
// -- Unique
stage: StageInfo;
seqContainerName?: string; // Used within a parallel branch to denote the name of the container of the parallel sequential stages
}
export interface PlaceholderNodeInfo extends BaseNodeInfo {
// -- Marker
isPlaceholder: true;
// -- Unique
type: "start" | "end";
}
export type NodeInfo = StageNodeInfo | PlaceholderNodeInfo;
export interface NodeColumn {
topStage?: StageInfo; // Top-most stage for this column, which will have no rendered nodes if it's parallel
rows: Array<Array<NodeInfo>>;
centerX: number; // Center X position, for positioning top bigLabel
hasBranchLabels: boolean;
startX: number; // Where to put the branch labels, or if none, the center of the left-most node(s)
}
export interface CompositeConnection {
sourceNodes: Array<NodeInfo>;
destinationNodes: Array<NodeInfo>;
skippedNodes: Array<NodeInfo>;
hasBranchLabels: boolean;
}
export interface NodeLabelInfo {
x: number;
y: number;
text: string;
key: string;
stage?: StageInfo;
node: NodeInfo;
}
export type LayoutInfo = typeof defaultLayout;
/**
* The result of the graph layout algorithm
*/
export interface PositionedGraph {
nodeColumns: Array<NodeColumn>;
connections: Array<CompositeConnection>;
bigLabels: Array<NodeLabelInfo>;
smallLabels: Array<NodeLabelInfo>;
branchLabels: Array<NodeLabelInfo>;
measuredWidth: number;
measuredHeight: number;
}