aboutsummaryrefslogtreecommitdiffstats
path: root/web_src/js/components/DiffCommitSelector.vue
diff options
context:
space:
mode:
Diffstat (limited to 'web_src/js/components/DiffCommitSelector.vue')
-rw-r--r--web_src/js/components/DiffCommitSelector.vue44
1 files changed, 31 insertions, 13 deletions
diff --git a/web_src/js/components/DiffCommitSelector.vue b/web_src/js/components/DiffCommitSelector.vue
index 3a394955ca..a375343979 100644
--- a/web_src/js/components/DiffCommitSelector.vue
+++ b/web_src/js/components/DiffCommitSelector.vue
@@ -1,9 +1,26 @@
<script lang="ts">
+import {defineComponent} from 'vue';
import {SvgIcon} from '../svg.ts';
import {GET} from '../modules/fetch.ts';
import {generateAriaId} from '../modules/fomantic/base.ts';
-export default {
+type Commit = {
+ id: string,
+ hovered: boolean,
+ selected: boolean,
+ summary: string,
+ committer_or_author_name: string,
+ time: string,
+ short_sha: string,
+}
+
+type CommitListResult = {
+ commits: Array<Commit>,
+ last_review_commit_sha: string,
+ locale: Record<string, string>,
+}
+
+export default defineComponent({
components: {SvgIcon},
data: () => {
const el = document.querySelector('#diff-commit-select');
@@ -15,9 +32,9 @@ export default {
locale: {
filter_changes_by_commit: el.getAttribute('data-filter_changes_by_commit'),
} as Record<string, string>,
- commits: [],
+ commits: [] as Array<Commit>,
hoverActivated: false,
- lastReviewCommitSha: null,
+ lastReviewCommitSha: '',
uniqueIdMenu: generateAriaId(),
uniqueIdShowAll: generateAriaId(),
};
@@ -55,11 +72,11 @@ export default {
switch (event.key) {
case 'ArrowDown': // select next element
event.preventDefault();
- this.focusElem(item.nextElementSibling, item);
+ this.focusElem(item.nextElementSibling as HTMLElement, item);
break;
case 'ArrowUp': // select previous element
event.preventDefault();
- this.focusElem(item.previousElementSibling, item);
+ this.focusElem(item.previousElementSibling as HTMLElement, item);
break;
case 'Escape': // close menu
event.preventDefault();
@@ -70,7 +87,7 @@ export default {
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
const item = document.activeElement; // try to highlight the selected commits
const commitIdx = item?.matches('.item') ? item.getAttribute('data-commit-idx') : null;
- if (commitIdx) this.highlight(this.commits[commitIdx]);
+ if (commitIdx) this.highlight(this.commits[Number(commitIdx)]);
}
},
onKeyUp(event: KeyboardEvent) {
@@ -86,7 +103,7 @@ export default {
}
}
},
- highlight(commit) {
+ highlight(commit: Commit) {
if (!this.hoverActivated) return;
const indexSelected = this.commits.findIndex((x) => x.selected);
const indexCurrentElem = this.commits.findIndex((x) => x.id === commit.id);
@@ -118,16 +135,17 @@ export default {
// set correct tabindex to allow easier navigation
this.$nextTick(() => {
if (this.menuVisible) {
- this.focusElem(this.$refs.showAllChanges, this.$refs.expandBtn);
+ this.focusElem(this.$refs.showAllChanges as HTMLElement, this.$refs.expandBtn as HTMLElement);
} else {
- this.focusElem(this.$refs.expandBtn, this.$refs.showAllChanges);
+ this.focusElem(this.$refs.expandBtn as HTMLElement, this.$refs.showAllChanges as HTMLElement);
}
});
},
+
/** Load the commits to show in this dropdown */
async fetchCommits() {
const resp = await GET(`${this.issueLink}/commits/list`);
- const results = await resp.json();
+ const results = await resp.json() as CommitListResult;
this.commits.push(...results.commits.map((x) => {
x.hovered = false;
return x;
@@ -165,7 +183,7 @@ export default {
* the diff from beginning of PR up to the second clicked commit is
* opened
*/
- commitClickedShift(commit) {
+ commitClickedShift(commit: Commit) {
this.hoverActivated = !this.hoverActivated;
commit.selected = true;
// Second click -> determine our range and open links accordingly
@@ -188,13 +206,13 @@ export default {
}
},
},
-};
+});
</script>
<template>
<div class="ui scrolling dropdown custom diff-commit-selector">
<button
ref="expandBtn"
- class="ui basic button"
+ class="ui tiny basic button"
@click.stop="toggleMenu()"
:data-tooltip-content="locale.filter_changes_by_commit"
aria-haspopup="true"