@@ -4,6 +4,22 @@ import {SvgIcon} from '../svg.ts';
44import {GET } from ' ../modules/fetch.ts' ;
55import {generateAriaId } from ' ../modules/fomantic/base.ts' ;
66
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+
723export default defineComponent ({
824 components: {SvgIcon },
925 data : () => {
@@ -16,9 +32,9 @@ export default defineComponent({
1632 locale: {
1733 filter_changes_by_commit: el .getAttribute (' data-filter_changes_by_commit' ),
1834 } as Record <string , string >,
19- commits: [],
35+ commits: [] as Array < Commit > ,
2036 hoverActivated: false ,
21- lastReviewCommitSha: null ,
37+ lastReviewCommitSha: ' ' ,
2238 uniqueIdMenu: generateAriaId (),
2339 uniqueIdShowAll: generateAriaId (),
2440 };
@@ -71,7 +87,7 @@ export default defineComponent({
7187 if (event .key === ' ArrowDown' || event .key === ' ArrowUp' ) {
7288 const item = document .activeElement ; // try to highlight the selected commits
7389 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 ) ]);
7591 }
7692 },
7793 onKeyUp(event : KeyboardEvent ) {
@@ -87,7 +103,7 @@ export default defineComponent({
87103 }
88104 }
89105 },
90- highlight(commit ) {
106+ highlight(commit : Commit ) {
91107 if (! this .hoverActivated ) return ;
92108 const indexSelected = this .commits .findIndex ((x ) => x .selected );
93109 const indexCurrentElem = this .commits .findIndex ((x ) => x .id === commit .id );
@@ -125,10 +141,11 @@ export default defineComponent({
125141 }
126142 });
127143 },
144+
128145 /** Load the commits to show in this dropdown */
129146 async fetchCommits() {
130147 const resp = await GET (` ${this .issueLink }/commits/list ` );
131- const results = await resp .json ();
148+ const results = await resp .json () as CommitListResult ;
132149 this .commits .push (... results .commits .map ((x ) => {
133150 x .hovered = false ;
134151 return x ;
@@ -166,7 +183,7 @@ export default defineComponent({
166183 * the diff from beginning of PR up to the second clicked commit is
167184 * opened
168185 */
169- commitClickedShift(commit ) {
186+ commitClickedShift(commit : Commit ) {
170187 this .hoverActivated = ! this .hoverActivated ;
171188 commit .selected = true ;
172189 // Second click -> determine our range and open links accordingly
0 commit comments