From 2dac036812ff80fd95bfe8e4b6d9687f8c0a0b6d Mon Sep 17 00:00:00 2001 From: Johan Berggren Date: Fri, 23 Aug 2024 11:01:20 +0000 Subject: [PATCH] Deep link to question --- .../src/components/Scenarios/QuestionCard.vue | 55 ++++++++++++------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/timesketch/frontend-ng/src/components/Scenarios/QuestionCard.vue b/timesketch/frontend-ng/src/components/Scenarios/QuestionCard.vue index 61a303309a..f64f43f8b8 100644 --- a/timesketch/frontend-ng/src/components/Scenarios/QuestionCard.vue +++ b/timesketch/frontend-ng/src/components/Scenarios/QuestionCard.vue @@ -411,7 +411,7 @@ export default { }, getSketchQuestions() { this.isLoading = true - ApiClient.getOrphanQuestions(this.sketch.id) + return ApiClient.getOrphanQuestions(this.sketch.id) .then((response) => { this.sketchQuestions = response.data.objects[0] this.isLoading = false @@ -536,27 +536,40 @@ export default { }, mounted() { EventBus.$on('createBranch', this.getSearchHistory) + let questionUUID = this.$route.query.question_uuid this.getQuestionTemplates() - this.getSketchQuestions() - // Restore active question from local storage - let storageKey = 'sketchContext' + this.sketch.id.toString() - let storedContext = localStorage.getItem(storageKey) - let context = {} - if (storedContext) { - context = JSON.parse(storedContext) - } - if (Object.keys(context).length) { - this.isLoading = true - ApiClient.getQuestion(this.sketch.id, context.questionId) - .then((response) => { - this.setActiveQuestion(response.data.objects[0]) - this.isLoading = false - }) - .catch((e) => { - console.error(e) - }) - } else { - this.showEmptySelect = true + this.getSketchQuestions().then(() => { + if (questionUUID) { + const question = this.sketchQuestions.find((question) => question.uuid === questionUUID) + if (!question) { + this.errorSnackBar('No question found with that UUID') + this.showEmptySelect = true + return + } + this.setActiveQuestion(question) + } + }) + if (!questionUUID) { + // Restore active question from local storage + let storageKey = 'sketchContext' + this.sketch.id.toString() + let storedContext = localStorage.getItem(storageKey) + let context = {} + if (storedContext) { + context = JSON.parse(storedContext) + } + if (Object.keys(context).length) { + this.isLoading = true + ApiClient.getQuestion(this.sketch.id, context.questionId) + .then((response) => { + this.setActiveQuestion(response.data.objects[0]) + this.isLoading = false + }) + .catch((e) => { + console.error(e) + }) + } else { + this.showEmptySelect = true + } } }, }