From dd0165ce81ecc032aef54d0630d61bf91b7d4641 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9B=A7=E5=9B=A7?= Date: Tue, 13 Feb 2024 21:17:57 +0800 Subject: [PATCH] Persist query history (#81) --- src/components/ShellView/CypherEditor.vue | 11 +++- src/components/ShellView/ShellCell.vue | 13 +++- src/components/ShellView/ShellMainView.vue | 42 +++++++++++++ src/server/Cypher.js | 22 +++++-- src/server/Gpt.js | 14 ++++- src/server/Session.js | 18 ++++++ src/server/utils/SessionDatabase.js | 70 ++++++++++++++++++++-- 7 files changed, 177 insertions(+), 13 deletions(-) diff --git a/src/components/ShellView/CypherEditor.vue b/src/components/ShellView/CypherEditor.vue index 9fc30d7..13a394f 100644 --- a/src/components/ShellView/CypherEditor.vue +++ b/src/components/ShellView/CypherEditor.vue @@ -108,7 +108,7 @@ export default { default: false, }, }, -emits: ['remove', 'evaluateCypher', 'toggleMaximize', 'generateAndEvaluateQuery'], + emits: ['remove', 'evaluateCypher', 'toggleMaximize', 'generateAndEvaluateQuery'], data: () => { return { name: "CypherEditor", @@ -229,10 +229,15 @@ emits: ['remove', 'evaluateCypher', 'toggleMaximize', 'generateAndEvaluateQuery' removeCell() { this.$emit("remove"); }, - isActive(){ + isActive() { return (this.isQueryGenerationMode && this.$refs.gptQuestionTextArea === document.activeElement) || (!this.isQueryGenerationMode && this.editor && this.editor.hasTextFocus()); - } + }, + loadFromHistory(history) { + this.isQueryGenerationMode = history.isQueryGenerationMode; + this.gptQuestion = history.gptQuestion; + this.setEditorContent(history.cypherQuery); + }, }, } diff --git a/src/components/ShellView/ShellCell.vue b/src/components/ShellView/ShellCell.vue index c314e27..981d3b2 100644 --- a/src/components/ShellView/ShellCell.vue +++ b/src/components/ShellView/ShellCell.vue @@ -85,12 +85,21 @@ export default { isActive() { return this.$refs.editor.isActive(); }, + loadEditorFromHistory(history) { + this.isEvaluated = true; + this.$refs.editor.loadFromHistory(history); + }, evaluateCypher(query) { this.queryResult = null; this.errorMessage = ""; this.isLoading = true; this.loadingText = "Evaluating query..."; - Axios.post("/api/cypher", { query }) + Axios.post("/api/cypher", + { + query, + uuid: this.cellId, + isQueryGenerationMode: this.$refs.editor.isQueryGenerationMode + }) .then((res) => { this.queryResult = res.data; this.queryString = query; @@ -158,6 +167,8 @@ export default { question, token, model, + uuid: this.cellId, + isQueryGenerationMode: this.$refs.editor.isQueryGenerationMode }; Axios.post(url, data) .then((res) => { diff --git a/src/components/ShellView/ShellMainView.vue b/src/components/ShellView/ShellMainView.vue index d6a6bdc..2bce1d1 100644 --- a/src/components/ShellView/ShellMainView.vue +++ b/src/components/ShellView/ShellMainView.vue @@ -23,6 +23,7 @@