Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GSK-67 Give keyboard shortcuts for next and previous #47

Merged
merged 4 commits into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
"dependencies": {
"@babel/polyfill": "^7.2.5",
"@sentry/types": "^6.13.3",
"@types/mousetrap": "^1.6.9",
"axios": "^0.24.0",
"core-js": "^3.19.0",
"echarts": "^5.1.1",
"mousetrap": "^1.6.5",
"posthog-js": "^1.11.3",
"register-service-worker": "^1.0.0",
"rrweb-snapshot": "^1.1.9",
Expand Down
44 changes: 36 additions & 8 deletions frontend/src/views/main/project/InspectorWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<v-icon v-if="shuffleMode" color="primary">mdi-shuffle-variant</v-icon>
<v-icon v-else>mdi-shuffle-variant</v-icon>
</v-btn>
<v-btn icon @click="previous" :disabled="shuffleMode || rowNb == 0"><v-icon>mdi-skip-previous</v-icon></v-btn>
<v-btn icon @click="previous" :disabled="!canPrevious()"><v-icon>mdi-skip-previous</v-icon></v-btn>
<v-btn icon @click="next"><v-icon>mdi-skip-next</v-icon></v-btn>
<span class="caption grey--text">Entry #{{rowNb}}</span>
</v-toolbar>
Expand All @@ -25,8 +25,8 @@
<!-- For general feedback -->
<v-tooltip left>
<template v-slot:activator="{ on, attrs }">
<v-btn fab fixed bottom right
@click="feedbackPopupToggle = !feedbackPopupToggle"
<v-btn fab fixed bottom right
@click="feedbackPopupToggle = !feedbackPopupToggle"
:class="feedbackPopupToggle? 'secondary': 'primary'"
v-bind="attrs" v-on="on"
>
Expand Down Expand Up @@ -83,6 +83,7 @@ import { readToken } from '@/store/main/getters';
import { IFeedbackCreate } from '@/interfaces';
import FeedbackPopover from '@/components/FeedbackPopover.vue';
import Inspector from './Inspector.vue';
import Mousetrap from 'mousetrap';

@Component({
components: { OverlayLoader, Inspector, PredictionResults, FeedbackPopover, PredictionExplanations, TextExplanation }
Expand All @@ -92,6 +93,7 @@ export default class InspectorWrapper extends Vue {
@Prop({ required: true }) datasetId!: number
@Prop() targetFeature!: string

mouseTrap= new Mousetrap();
loadingData = false;
inputData = {}
originalData = {}
Expand All @@ -109,15 +111,41 @@ export default class InspectorWrapper extends Vue {
await this.fetchRowData(0);
}

bindKeys() {
this.mouseTrap.bind('left', this.previous);
this.mouseTrap.bind('right', this.next);
}

resetKeys() {
this.mouseTrap.reset();
}

public canPrevious(){ return !this.shuffleMode && this.rowNb> 0}


/**
* Call on active tab
*/
activated() {
this.bindKeys();
}

deactivated() {
this.resetKeys();
}

public next() {
this.clearFeedback();
this.fetchRowData(this.rowNb + 1);
}

public previous() {
this.clearFeedback();
this.fetchRowData(Math.max(0, this.rowNb - 1))
if (this.canPrevious()) {
this.clearFeedback();
this.fetchRowData(Math.max(0, this.rowNb - 1))
}
}

@Watch("datasetId")
async reload() {
await this.fetchRowData(0)
Expand All @@ -128,7 +156,7 @@ export default class InspectorWrapper extends Vue {
this.loadingData = true
const resp = this.shuffleMode
? await api.getDataRandom(readToken(this.$store), this.datasetId)
: await api.getDataByRowId(readToken(this.$store), this.datasetId, rowId)
: await api.getDataByRowId(readToken(this.$store), this.datasetId, rowId)
this.inputData = resp.data
this.originalData = {...this.inputData} // deep copy to avoid caching mechanisms
this.rowNb = resp.data.rowNb
Expand Down Expand Up @@ -168,7 +196,7 @@ export default class InspectorWrapper extends Vue {
...this.commonFeedbackData,
feedback_type: "general",
feedback_choice: this.feedbackChoice || undefined,
feedback_message: this.feedback
feedback_message: this.feedback
}
try {
await this.doSubmitFeedback(feedback)
Expand Down