1
+ import InfoOutlinedIcon from "@mui/icons-material/InfoOutlined" ;
1
2
import {
2
3
FormControl ,
3
4
InputLabel ,
4
5
MenuItem ,
5
6
Select ,
6
7
SelectChangeEvent ,
7
8
Skeleton ,
9
+ Tooltip ,
8
10
} from "@mui/material" ;
9
11
import { MAIN_BRANCH , SHA_DISPLAY_LENGTH } from "components/benchmark/common" ;
10
12
import dayjs from "dayjs" ;
11
13
import { fetcher } from "lib/GeneralUtils" ;
12
14
import { useEffect } from "react" ;
13
15
import useSWR from "swr" ;
16
+ import {
17
+ DEFAULT_HIGHLIGHT_MENU_ITEM_COLOR ,
18
+ getMatchedFilters ,
19
+ HighlightMenuItem ,
20
+ isCommitHighlight ,
21
+ isCommitStringHighlight ,
22
+ } from "./HighlightMenu" ;
14
23
15
24
// Keep the mapping from workflow ID to commit, so that we can use it to
16
25
// zoom in and out of the graph. NB: this is to avoid sending commit sha
@@ -20,16 +29,28 @@ import useSWR from "swr";
20
29
export const COMMIT_TO_WORKFLOW_ID : { [ k : string ] : number } = { } ;
21
30
export const WORKFLOW_ID_TO_COMMIT : { [ k : number ] : string } = { } ;
22
31
32
+ interface HighlightConfig {
33
+ keys ?: string [ ] ;
34
+ highlightColor ?: string ;
35
+ }
36
+
23
37
function groupCommitByBranch ( data : any ) {
24
38
const dedups : { [ k : string ] : Set < string > } = { } ;
25
39
const branches : { [ k : string ] : any [ ] } = { } ;
40
+
26
41
data . forEach ( ( r : any ) => {
27
42
const b = r . head_branch ;
28
43
if ( ! ( b in branches ) ) {
29
44
branches [ b ] = [ ] ;
30
45
dedups [ b ] = new Set < string > ( ) ;
31
46
}
47
+
32
48
if ( dedups [ b ] . has ( r . head_sha ) ) {
49
+ if ( r . filename ) {
50
+ branches [ b ]
51
+ ?. find ( ( c : any ) => c . head_sha === r . head_sha )
52
+ . filenames . push ( r . filename ) ;
53
+ }
33
54
return ;
34
55
}
35
56
@@ -38,10 +59,12 @@ function groupCommitByBranch(data: any) {
38
59
event_time : r . event_time ,
39
60
// This is used to sort the list of branches to show the main branch first
40
61
display_priority : r . head_branch === MAIN_BRANCH ? 99 : 1 ,
62
+ // store list of config files for the commit, this is used to highlight
63
+ filenames : r . filename ? [ r . filename ] : [ ] ,
64
+ id : r . id ,
41
65
} ) ;
42
66
dedups [ b ] . add ( r . head_sha ) ;
43
67
} ) ;
44
-
45
68
return branches ;
46
69
}
47
70
@@ -55,6 +78,7 @@ export function BranchAndCommitPicker({
55
78
titlePrefix,
56
79
fallbackIndex,
57
80
timeRange,
81
+ highlightConfig,
58
82
} : {
59
83
queryName : string ;
60
84
queryParams : { [ k : string ] : any } ;
@@ -65,6 +89,7 @@ export function BranchAndCommitPicker({
65
89
titlePrefix : string ;
66
90
fallbackIndex : number ;
67
91
timeRange : any ;
92
+ highlightConfig ?: HighlightConfig ;
68
93
} ) {
69
94
const url = `/api/clickhouse/${ queryName } ?parameters=${ encodeURIComponent (
70
95
JSON . stringify ( queryParams )
@@ -160,7 +185,6 @@ export function BranchAndCommitPicker({
160
185
) ) }
161
186
</ Select >
162
187
</ FormControl >
163
-
164
188
< FormControl >
165
189
< InputLabel id = { `commit-picker-input-label-${ commit } ` } >
166
190
{ titlePrefix } Commit
@@ -171,12 +195,32 @@ export function BranchAndCommitPicker({
171
195
labelId = { `commit-picker-select-label-${ commit } ` }
172
196
onChange = { handleCommitChange }
173
197
id = { `commit-picker-select-${ commit } ` }
198
+ sx = { {
199
+ ...( isCommitStringHighlight (
200
+ commit ,
201
+ branches [ branch ] ,
202
+ highlightConfig ?. keys
203
+ ) && { backgroundColor : DEFAULT_HIGHLIGHT_MENU_ITEM_COLOR } ) ,
204
+ } }
174
205
>
175
206
{ branches [ branch ] . map ( ( r : any ) => (
176
- < MenuItem key = { r . head_sha } value = { r . head_sha } >
207
+ < HighlightMenuItem
208
+ key = { r . head_sha }
209
+ value = { r . head_sha }
210
+ condition = { isCommitHighlight ( highlightConfig ?. keys , r ) }
211
+ customColor = { highlightConfig ?. highlightColor }
212
+ >
177
213
{ r . head_sha . substring ( 0 , SHA_DISPLAY_LENGTH ) } (
178
214
{ dayjs ( r . event_time ) . format ( "YYYY/MM/DD" ) } )
179
- </ MenuItem >
215
+ { isCommitHighlight ( highlightConfig ?. keys , r ) && (
216
+ < Tooltip
217
+ id = "button-report"
218
+ title = { getMatchedFilters ( highlightConfig ?. keys , r ) . join ( "," ) }
219
+ >
220
+ < InfoOutlinedIcon />
221
+ </ Tooltip >
222
+ ) }
223
+ </ HighlightMenuItem >
180
224
) ) }
181
225
</ Select >
182
226
</ FormControl >
0 commit comments