Skip to content

Commit

Permalink
X
Browse files Browse the repository at this point in the history
  • Loading branch information
mewim committed Feb 13, 2024
1 parent b5c320f commit d18599c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 31 deletions.
36 changes: 13 additions & 23 deletions src/components/ShellView/CypherEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,10 @@
class="shell-editor__tools_container"
:style="{ width: toolbarWidth + 'px' }"
>
<div
v-show="!isMaximized"
class="shell-editor__button"
>
<i
class="fa-lg fa-solid fa-times"
@click="removeCell"
/>
<div v-show="!isMaximized" class="shell-editor__button">
<i class="fa-lg fa-solid fa-times" @click="removeCell" />
</div>
<div
v-show="!isLoading"
class="shell-editor__button"
>
<div v-show="!isLoading" class="shell-editor__button">
<i
class="fa-lg fa-solid fa-play"
data-bs-toggle="tooltip"
Expand All @@ -48,10 +39,7 @@
@click="evaluateCell"
/>
</div>
<div
v-show="!isLoading"
class="shell-editor__button"
>
<div v-show="!isLoading" class="shell-editor__button">
<i
:class="gptButtonClass"
data-bs-toggle="tooltip"
Expand All @@ -60,10 +48,7 @@
@click="toggleQueryGeneration"
/>
</div>
<div
v-show="isMaximizable"
class="shell-editor__button"
>
<div v-show="isMaximizable" class="shell-editor__button">
<i
:class="maximizeButtonClass"
data-bs-toggle="tooltip"
Expand Down Expand Up @@ -108,7 +93,7 @@ export default {
default: false,
},
},
emits: ['remove', 'evaluateCypher', 'toggleMaximize', 'generateAndEvaluateQuery'],
emits: ['remove', 'evaluateCypher', 'toggleMaximize', 'generateAndEvaluateQuery'],
data: () => {
return {
name: "CypherEditor",
Expand Down Expand Up @@ -229,10 +214,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);
},
},
}
</script>
Expand Down
9 changes: 5 additions & 4 deletions src/components/ShellView/ShellCell.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
:is-maximized="isMaximized"
:navbar-height="navbarHeight"
/>
<div
v-if="isLoading"
class="d-flex align-items-center"
>
<div v-if="isLoading" class="d-flex align-items-center">
<strong class="text-secondary">{{
loadingText ? loadingText : "Loading..."
}}</strong>
Expand Down Expand Up @@ -85,6 +82,10 @@ 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 = "";
Expand Down
34 changes: 30 additions & 4 deletions src/components/ShellView/ShellMainView.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<template>
<div
class="shell-main-view__wrapper"
:style="{ height: `${containerHeight}px` }"
>
<div class="shell-main-view__wrapper" :style="{ height: `${containerHeight}px` }">
<ShellCell
v-for="(cell, index) in shellCell"
v-show="index === maximizedCellIndex || maximizedCellIndex < 0"
Expand Down Expand Up @@ -59,6 +56,7 @@ export default {
});
window.addEventListener("resize", this.updateContainerHeight);
document.addEventListener("keydown", this.handleKeyDown);
this.loadCellsFromHistory();
},
beforeUnmount() {
Expand Down Expand Up @@ -95,6 +93,31 @@ export default {
removeCellFromHistory(uuid) {
return Axios.delete(`/api/session/history/${uuid}`);
},
loadCellHistoryFromServer() {
return Axios.get("/api/session/history").then(res => res.data);
},
async loadCellsFromHistory() {
const history = await this.loadCellHistoryFromServer();
history.map(cell => {
return {
cellId: cell.uuid,
};
}).forEach(cell => {
if (this.isCellAddedToTheEnd) {
this.shellCell.unshift(cell);
}
else {
this.shellCell.push(cell);
}
});
this.$nextTick(() => {
history.forEach((cell) => {
const uuid = cell.uuid;
const cellRef = this.$refs[this.getCellRefById(uuid)][0];
cellRef.loadEditorFromHistory(cell);
});
});
},
addCell() {
const cell = this.createCell();
if (this.isCellAddedToTheEnd) {
Expand All @@ -116,6 +139,9 @@ export default {
getCellRef(index) {
return `shell-cell-${this.shellCell[index].cellId}`;
},
getCellRefById(uuid) {
return `shell-cell-${uuid}`;
},
handleKeyDown(event) {
if (event.shiftKey && event.key === "Enter") {
event.preventDefault();
Expand Down

0 comments on commit d18599c

Please sign in to comment.