feat: open saved queries in a tab

This commit is contained in:
Fabio Di Stasio 2023-12-25 10:54:41 +01:00
parent a52fc3fd92
commit 9a732ea197
5 changed files with 85 additions and 10 deletions

View File

@ -3,7 +3,7 @@ name: Test end-to-end [WINDOWS]
on:
push:
branches:
- master
- develop
jobs:
release:

View File

@ -67,6 +67,17 @@
:size="22"
/> {{ t('general.undo') }}
</button>
<button
v-if="note.type === 'query'"
class="btn btn-link pl-1"
@click.stop="$emit('select-query', note.note)"
>
<BaseIcon
icon-name="mdiOpenInApp"
class="pr-1"
:size="22"
/> {{ t('general.select') }}
</button>
<button
v-if="note.type === 'query'"
class="btn btn-link pl-1"
@ -139,7 +150,8 @@ defineEmits([
'select-note',
'toggle-note',
'archive-note',
'restore-note'
'restore-note',
'select-query'
]);
const noteParagraph: Ref<HTMLDivElement> = ref(null);

View File

@ -113,6 +113,7 @@
@delete-note="deleteNote"
@archive-note="archiveNote"
@restore-note="restoreNote"
@select-query="selectQuery"
/>
</template>
</BaseVirtualScroll>
@ -179,13 +180,15 @@ const { t } = useI18n();
const applicationStore = useApplicationStore();
const scratchpadStore = useScratchpadStore();
const workspacesStore = useWorkspacesStore();
const { connectionNotes, selectedTag } = storeToRefs(scratchpadStore);
const { changeNotes } = scratchpadStore;
const { hideScratchpad } = applicationStore;
const { getConnectionName } = useConnectionsStore();
const { connections } = storeToRefs(useConnectionsStore());
const { getSelected: selectedWorkspace } = storeToRefs(useWorkspacesStore());
const { getSelected: selectedWorkspace } = storeToRefs(workspacesStore);
const { getWorkspaceTab, getWorkspace, newTab, updateTabContent } = workspacesStore;
const localConnection = ref(null);
const table: Ref<HTMLDivElement> = ref(null);
@ -276,6 +279,32 @@ const deleteNote = (uid: string) => {
changeNotes(otherNotes);
};
const selectQuery = (query: string) => {
const workspace = getWorkspace(selectedWorkspace.value);
const selectedTab = getWorkspaceTab(workspace.selectedTab);
if (selectedTab.type === 'query') {
updateTabContent({
tab: selectedTab.uid,
uid: selectedWorkspace.value,
type: 'query',
content: query,
schema: workspace.breadcrumbs.schema
});
}
else {
newTab({
uid: selectedWorkspace.value,
type: 'query',
content: query,
autorun: false,
schema: workspace.breadcrumbs.schema
});
}
hideScratchpad();
};
const closeEditModal = () => {
isEditModal.value = false;
noteToEdit.value = null;

View File

@ -345,6 +345,7 @@ watch(query, (val) => {
schema: selectedSchema.value,
content: val
});
isQuerySaved.value = false;
}, 200);
});
@ -368,6 +369,14 @@ watch(databaseSchemas, () => {
selectedSchema.value = null;
}, { deep: true });
watch(() => props.tab.content, () => {
query.value = props.tab.content;
const editorValue = queryEditor.value.editor.session.getValue();
if (editorValue !== query.value)// If change not rendered in editor
queryEditor.value.editor.session.setValue(query.value);
});
const runQuery = async (query: string) => {
if (!query || isQuering.value) return;
isQuering.value = true;

View File

@ -67,7 +67,7 @@ export interface Workspace {
client?: ClientCode;
database?: string;
connectionStatus: string;
selectedTab: string | number;
selectedTab: string;
searchTerm: string;
tabs: WorkspaceTab[];
structure: WorkspaceStructure[];
@ -119,12 +119,12 @@ export const useWorkspacesStore = defineStore('workspaces', {
return state.workspaces.find(workspace => workspace.uid === uid).variables.find(variable => variable.name === name);
},
getWorkspaceTab (state) {
return (tUid: string) => {
return (tUid: string): WorkspaceTab => {
if (!this.getSelected) return;
const workspace = state.workspaces.find(workspace => workspace.uid === this.getSelected);
if ('tabs' in workspace)
return workspace.tabs.find(tab => tab.uid === tUid);
return {};
return null;
};
},
getConnected: state => {
@ -410,7 +410,7 @@ export const useWorkspacesStore = defineStore('workspaces', {
const workspace: Workspace = {
uid,
connectionStatus: 'disconnected',
selectedTab: 0,
selectedTab: '0',
searchTerm: '',
tabs: [],
structure: [],
@ -629,18 +629,43 @@ export const useWorkspacesStore = defineStore('workspaces', {
: false;
if (existentTab) {
this._replaceTab({ uid, tab: existentTab.uid, type, database: workspaceTabs.database, schema, elementName, elementType });
this._replaceTab({ uid,
tab: existentTab.uid,
type,
database: workspaceTabs.database,
schema,
elementName,
elementType
});
tabUid = existentTab.uid;
}
else {
tabUid = uidGen('T');
this._addTab({ uid, tab: tabUid, content, type, autorun, database: workspaceTabs.database, schema, elementName, elementType });
this._addTab({ uid,
tab: tabUid,
content,
type,
autorun,
database: workspaceTabs.database,
schema,
elementName,
elementType
});
}
}
break;
default:
tabUid = uidGen('T');
this._addTab({ uid, tab: tabUid, content, type, autorun, database: workspaceTabs.database, schema, elementName, elementType });
this._addTab({ uid,
tab: tabUid,
content,
type,
autorun,
database: workspaceTabs.database,
schema,
elementName,
elementType
});
break;
}