1
+ import { type Theme , useTheme } from "@emotion/react" ;
1
2
import { type FC , useState } from "react" ;
2
3
import { Bar } from "./Chart/Bar" ;
3
4
import {
@@ -28,30 +29,6 @@ import {
28
29
} from "./Chart/utils" ;
29
30
import type { StageCategory } from "./StagesChart" ;
30
31
31
- const legendsByStatus : Record < string , ChartLegend > = {
32
- ok : {
33
- label : "success" ,
34
- colors : {
35
- fill : "#022C22" ,
36
- stroke : "#BBF7D0" ,
37
- } ,
38
- } ,
39
- exit_failure : {
40
- label : "failure" ,
41
- colors : {
42
- fill : "#450A0A" ,
43
- stroke : "#F87171" ,
44
- } ,
45
- } ,
46
- timeout : {
47
- label : "timed out" ,
48
- colors : {
49
- fill : "#422006" ,
50
- stroke : "#FDBA74" ,
51
- } ,
52
- } ,
53
- } ;
54
-
55
32
type ScriptTiming = {
56
33
name : string ;
57
34
status : string ;
@@ -77,6 +54,8 @@ export const ScriptsChart: FC<ScriptsChartProps> = ({
77
54
const [ ticks , scale ] = makeTicks ( totalTime ) ;
78
55
const [ filter , setFilter ] = useState ( "" ) ;
79
56
const visibleTimings = timings . filter ( ( t ) => t . name . includes ( filter ) ) ;
57
+ const theme = useTheme ( ) ;
58
+ const legendsByStatus = getLegendsByStatus ( theme ) ;
80
59
const visibleLegends = [ ...new Set ( visibleTimings . map ( ( t ) => t . status ) ) ] . map (
81
60
( s ) => legendsByStatus [ s ] ,
82
61
) ;
@@ -151,3 +130,29 @@ export const ScriptsChart: FC<ScriptsChartProps> = ({
151
130
</ Chart >
152
131
) ;
153
132
} ;
133
+
134
+ function getLegendsByStatus ( theme : Theme ) : Record < string , ChartLegend > {
135
+ return {
136
+ ok : {
137
+ label : "success" ,
138
+ colors : {
139
+ fill : theme . roles . success . background ,
140
+ stroke : theme . roles . success . outline ,
141
+ } ,
142
+ } ,
143
+ exit_failure : {
144
+ label : "failure" ,
145
+ colors : {
146
+ fill : theme . roles . error . background ,
147
+ stroke : theme . roles . error . outline ,
148
+ } ,
149
+ } ,
150
+ timeout : {
151
+ label : "timed out" ,
152
+ colors : {
153
+ fill : theme . roles . warning . background ,
154
+ stroke : theme . roles . warning . outline ,
155
+ } ,
156
+ } ,
157
+ } ;
158
+ }
0 commit comments