@@ -4,6 +4,22 @@ import {SvgIcon} from '../svg.ts';
4
4
import {GET } from ' ../modules/fetch.ts' ;
5
5
import {generateAriaId } from ' ../modules/fomantic/base.ts' ;
6
6
7
+ type Commit = {
8
+ id: string ,
9
+ hovered: boolean ,
10
+ selected: boolean ,
11
+ summary: string ,
12
+ committer_or_author_name: string ,
13
+ time: string ,
14
+ short_sha: string ,
15
+ }
16
+
17
+ type CommitListResult = {
18
+ commits: Array <Commit >,
19
+ last_review_commit_sha: string ,
20
+ locale: Record <string , string >,
21
+ }
22
+
7
23
export default defineComponent ({
8
24
components: {SvgIcon },
9
25
data : () => {
@@ -16,9 +32,9 @@ export default defineComponent({
16
32
locale: {
17
33
filter_changes_by_commit: el .getAttribute (' data-filter_changes_by_commit' ),
18
34
} as Record <string , string >,
19
- commits: [],
35
+ commits: [] as Array < Commit > ,
20
36
hoverActivated: false ,
21
- lastReviewCommitSha: null ,
37
+ lastReviewCommitSha: ' ' ,
22
38
uniqueIdMenu: generateAriaId (),
23
39
uniqueIdShowAll: generateAriaId (),
24
40
};
@@ -71,7 +87,7 @@ export default defineComponent({
71
87
if (event .key === ' ArrowDown' || event .key === ' ArrowUp' ) {
72
88
const item = document .activeElement ; // try to highlight the selected commits
73
89
const commitIdx = item ?.matches (' .item' ) ? item .getAttribute (' data-commit-idx' ) : null ;
74
- if (commitIdx ) this .highlight (this .commits [commitIdx ]);
90
+ if (commitIdx ) this .highlight (this .commits [Number ( commitIdx ) ]);
75
91
}
76
92
},
77
93
onKeyUp(event : KeyboardEvent ) {
@@ -87,7 +103,7 @@ export default defineComponent({
87
103
}
88
104
}
89
105
},
90
- highlight(commit ) {
106
+ highlight(commit : Commit ) {
91
107
if (! this .hoverActivated ) return ;
92
108
const indexSelected = this .commits .findIndex ((x ) => x .selected );
93
109
const indexCurrentElem = this .commits .findIndex ((x ) => x .id === commit .id );
@@ -125,10 +141,11 @@ export default defineComponent({
125
141
}
126
142
});
127
143
},
144
+
128
145
/** Load the commits to show in this dropdown */
129
146
async fetchCommits() {
130
147
const resp = await GET (` ${this .issueLink }/commits/list ` );
131
- const results = await resp .json ();
148
+ const results = await resp .json () as CommitListResult ;
132
149
this .commits .push (... results .commits .map ((x ) => {
133
150
x .hovered = false ;
134
151
return x ;
@@ -166,7 +183,7 @@ export default defineComponent({
166
183
* the diff from beginning of PR up to the second clicked commit is
167
184
* opened
168
185
*/
169
- commitClickedShift(commit ) {
186
+ commitClickedShift(commit : Commit ) {
170
187
this .hoverActivated = ! this .hoverActivated ;
171
188
commit .selected = true ;
172
189
// Second click -> determine our range and open links accordingly
0 commit comments