|
1 | 1 | import * as React from "react";
|
2 | 2 | import { Result } from "../PipelineGraphModel";
|
3 |
| -import { SvgStatus } from "./SvgStatus"; |
4 | 3 |
|
5 | 4 | export const nodeStrokeWidth = 3.5; // px.
|
6 | 5 |
|
7 |
| -// Returns the correct <g> element for the result / progress percent. |
8 |
| -export function getGroupForResult( |
9 |
| - result: Result, |
10 |
| - percentage: number, |
11 |
| - radius: number, |
12 |
| - centerX: number, |
13 |
| - centerY: number, |
14 |
| - outerStyle: React.CSSProperties, |
15 |
| -): React.ReactElement<SvgStatus> { |
| 6 | +function mapResultToCore(result: Result): string { |
16 | 7 | switch (result) {
|
17 |
| - case Result.running: |
18 |
| - case Result.queued: |
19 |
| - case Result.not_built: |
20 |
| - case Result.skipped: |
21 | 8 | case Result.success:
|
| 9 | + return "blue"; |
| 10 | + case Result.running: |
| 11 | + return "nobuilt-anime"; |
22 | 12 | case Result.failure:
|
23 |
| - case Result.paused: |
| 13 | + return "red"; |
24 | 14 | case Result.unstable:
|
| 15 | + return "yellow"; |
25 | 16 | case Result.aborted:
|
26 |
| - case Result.unknown: |
27 |
| - return ( |
28 |
| - <SvgStatus |
29 |
| - radius={radius} |
30 |
| - result={result} |
31 |
| - outerStyle={outerStyle} |
32 |
| - centerX={centerX} |
33 |
| - centerY={centerY} |
34 |
| - /> |
35 |
| - ); |
| 17 | + return "aborted"; |
| 18 | + case Result.not_built: |
| 19 | + return "nobuilt"; |
36 | 20 | default:
|
37 |
| - badResult(result); |
38 |
| - return ( |
39 |
| - <SvgStatus |
40 |
| - radius={radius} |
41 |
| - result={Result.unknown} |
42 |
| - outerStyle={outerStyle} |
43 |
| - centerX={centerX} |
44 |
| - centerY={centerY} |
45 |
| - /> |
46 |
| - ); |
| 21 | + throw new Error(`Unhandled result: ${result}`); |
47 | 22 | }
|
48 | 23 | }
|
49 | 24 |
|
50 |
| -function badResult(x: never) { |
51 |
| - console.error("Unexpected Result value", x); |
52 |
| -} |
| 25 | +export function getSymbolForResult(result: Result): React.ReactElement { |
| 26 | + // Handle non-core symbols |
| 27 | + if (result === Result.paused) { |
| 28 | + return ( |
| 29 | + <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"> |
| 30 | + <ellipse |
| 31 | + cx="256" |
| 32 | + cy="256" |
| 33 | + rx="210" |
| 34 | + ry="210" |
| 35 | + fill="none" |
| 36 | + stroke="var(--text-color-secondary)" |
| 37 | + strokeLinecap="round" |
| 38 | + strokeMiterlimit="10" |
| 39 | + strokeWidth="36" |
| 40 | + /> |
| 41 | + <path |
| 42 | + fill="none" |
| 43 | + stroke="var(--text-color-secondary)" |
| 44 | + strokeLinecap="round" |
| 45 | + strokeMiterlimit="10" |
| 46 | + strokeWidth="32" |
| 47 | + d="M208 192v128M304 192v128" |
| 48 | + /> |
| 49 | + </svg> |
| 50 | + ); |
| 51 | + } |
53 | 52 |
|
54 |
| -export const getClassForResult = (result: Result) => { |
55 |
| - // These come from the themes icons.less |
56 |
| - switch (result) { |
57 |
| - case Result.aborted: |
58 |
| - return "icon-aborted"; |
59 |
| - case Result.unstable: |
60 |
| - return "icon-yellow"; |
61 |
| - case Result.failure: |
62 |
| - return "icon-red"; |
63 |
| - case Result.success: |
64 |
| - return "icon-blue"; |
65 |
| - case Result.running: |
66 |
| - case Result.queued: |
67 |
| - return "icon-grey"; |
68 |
| - case Result.skipped: |
69 |
| - return "icon-skipped"; |
70 |
| - case Result.not_built: |
71 |
| - case Result.paused: |
72 |
| - case Result.unknown: |
73 |
| - default: |
74 |
| - return "icon-nobuilt"; |
| 53 | + if (result === Result.unknown) { |
| 54 | + return ( |
| 55 | + <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"> |
| 56 | + <ellipse |
| 57 | + cx="256" |
| 58 | + cy="256" |
| 59 | + rx="210" |
| 60 | + ry="210" |
| 61 | + fill="none" |
| 62 | + stroke="var(--text-color-secondary)" |
| 63 | + strokeLinecap="round" |
| 64 | + strokeMiterlimit="10" |
| 65 | + strokeWidth="36" |
| 66 | + /> |
| 67 | + <path |
| 68 | + d="M200 202.29s.84-17.5 19.57-32.57C230.68 160.77 244 158.18 256 158c10.93-.14 20.69 1.67 26.53 4.45 10 4.76 29.47 16.38 29.47 41.09 0 26-17 37.81-36.37 50.8S251 281.43 251 296" |
| 69 | + fill="none" |
| 70 | + stroke="var(--text-color-secondary)" |
| 71 | + strokeLinecap="round" |
| 72 | + strokeMiterlimit="10" |
| 73 | + strokeWidth="28" |
| 74 | + /> |
| 75 | + <circle cx="250" cy="348" r="20" fill="var(--text-color-secondary)" /> |
| 76 | + </svg> |
| 77 | + ); |
75 | 78 | }
|
76 |
| -}; |
| 79 | + |
| 80 | + if (result === Result.skipped) { |
| 81 | + return ( |
| 82 | + <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"> |
| 83 | + <ellipse |
| 84 | + cx="256" |
| 85 | + cy="256" |
| 86 | + rx="210" |
| 87 | + ry="210" |
| 88 | + fill="none" |
| 89 | + stroke="var(--text-color-secondary)" |
| 90 | + strokeLinecap="round" |
| 91 | + strokeMiterlimit="10" |
| 92 | + strokeWidth="36" |
| 93 | + /> |
| 94 | + </svg> |
| 95 | + ); |
| 96 | + } |
| 97 | + |
| 98 | + // Map the result to retrieve the appropriate symbol from core |
| 99 | + const symbols = document.querySelector<HTMLTemplateElement>( |
| 100 | + "#pgv-build-status-icons", |
| 101 | + ); |
| 102 | + const mappedResult = mapResultToCore(result); |
| 103 | + |
| 104 | + return ( |
| 105 | + <div |
| 106 | + dangerouslySetInnerHTML={{ |
| 107 | + // This fails in React tests without the Jelly context |
| 108 | + __html: |
| 109 | + symbols?.content?.querySelector("#" + mappedResult)?.outerHTML || |
| 110 | + `<div></div>`, |
| 111 | + }} |
| 112 | + /> |
| 113 | + ); |
| 114 | +} |
0 commit comments