feat: option to select schema in query tabs

This commit is contained in:
Fabio Di Stasio 2021-07-20 19:19:54 +02:00
parent 0a9983d30d
commit a73a2f483e
4 changed files with 41 additions and 27 deletions

View File

@ -21,11 +21,16 @@ export default {
name: 'WorkspaceEmptyState', name: 'WorkspaceEmptyState',
computed: { computed: {
...mapGetters({ ...mapGetters({
applicationTheme: 'settings/getApplicationTheme' applicationTheme: 'settings/getApplicationTheme',
}) getWorkspace: 'workspaces/getWorkspace',
selectedWorkspace: 'workspaces/getSelected'
}),
workspace () {
return this.getWorkspace(this.selectedWorkspace);
}
}, },
created () { created () {
this.changeBreadcrumbs({}); this.changeBreadcrumbs({ schema: this.workspace.breadcrumbs.schema });
}, },
methods: { methods: {
...mapActions({ ...mapActions({

View File

@ -14,7 +14,7 @@
:auto-focus="true" :auto-focus="true"
:value.sync="query" :value.sync="query"
:workspace="workspace" :workspace="workspace"
:schema="schema" :schema="breadcrumbsSchema"
:is-selected="isSelected" :is-selected="isSelected"
:height="editorHeight" :height="editorHeight"
/> />
@ -86,12 +86,16 @@
<div v-if="affectedCount"> <div v-if="affectedCount">
{{ $t('message.affectedRows') }}: <b>{{ affectedCount }}</b> {{ $t('message.affectedRows') }}: <b>{{ affectedCount }}</b>
</div> </div>
<div <div class="input-group" :title="$t('word.schema')">
v-if="workspace.breadcrumbs.schema" <i class="input-group-addon addon-sm mdi mdi-24px mdi-database" />
class="d-flex" <select v-model="selectedSchema" class="form-select select-sm text-bold">
:title="$t('word.schema')" <option :value="null">
> {{ $t('message.noSchema') }}
<i class="mdi mdi-18px mdi-database mr-1" /><b>{{ workspace.breadcrumbs.schema }}</b> </option>
<option v-for="schemaName in databaseSchemas" :key="schemaName">
{{ schemaName }}
</option>
</select>
</div> </div>
</div> </div>
</div> </div>
@ -142,6 +146,7 @@ export default {
lastQuery: '', lastQuery: '',
isQuering: false, isQuering: false,
results: [], results: [],
selectedSchema: null,
resultsCount: 0, resultsCount: 0,
durationsCount: 0, durationsCount: 0,
affectedCount: 0, affectedCount: 0,
@ -156,9 +161,15 @@ export default {
workspace () { workspace () {
return this.getWorkspace(this.connection.uid); return this.getWorkspace(this.connection.uid);
}, },
schema () { breadcrumbsSchema () {
return this.workspace.breadcrumbs.schema; return this.workspace.breadcrumbs.schema;
}, },
databaseSchemas () {
return this.workspace.structure.reduce((acc, curr) => {
acc.push(curr.name);
return acc;
}, []);
},
isWorkspaceSelected () { isWorkspaceSelected () {
return this.workspace.uid === this.selectedWorkspace; return this.workspace.uid === this.selectedWorkspace;
} }
@ -166,12 +177,16 @@ export default {
watch: { watch: {
isSelected (val) { isSelected (val) {
if (val) if (val)
this.changeBreadcrumbs({ schema: this.schema, query: `Query #${this.tab.index}` }); this.changeBreadcrumbs({ schema: this.selectedSchema, query: `Query #${this.tab.index}` });
},
selectedSchema () {
this.changeBreadcrumbs({ schema: this.selectedSchema, query: `Query #${this.tab.index}` });
} }
}, },
created () { created () {
this.query = this.tab.content; this.query = this.tab.content;
this.changeBreadcrumbs({ schema: this.schema, query: `Query #${this.tab.index}` }); this.selectedSchema = this.breadcrumbsSchema;
this.changeBreadcrumbs({ schema: this.selectedSchema, query: `Query #${this.tab.index}` });
window.addEventListener('keydown', this.onKey); window.addEventListener('keydown', this.onKey);
}, },
@ -205,7 +220,7 @@ export default {
try { // Query Data try { // Query Data
const params = { const params = {
uid: this.connection.uid, uid: this.connection.uid,
schema: this.schema, schema: this.selectedSchema,
query query
}; };
@ -314,8 +329,10 @@ export default {
align-items: center; align-items: center;
height: 42px; height: 42px;
.workspace-query-buttons { .workspace-query-buttons,
.workspace-query-info {
display: flex; display: flex;
align-items: center;
.btn { .btn {
display: flex; display: flex;
@ -325,7 +342,7 @@ export default {
} }
.workspace-query-info { .workspace-query-info {
display: flex; overflow: visible;
> div + div { > div + div {
padding-left: 0.6rem; padding-left: 0.6rem;

View File

@ -225,7 +225,8 @@ module.exports = {
enableSsh: 'Enable SSH', enableSsh: 'Enable SSH',
pageNumber: 'Page number', pageNumber: 'Page number',
duplicateTable: 'Duplicate table', duplicateTable: 'Duplicate table',
noOpenTabs: 'There are no open tabs, navigate on the left bar or:' noOpenTabs: 'There are no open tabs, navigate on the left bar or:',
noSchema: 'No schema'
}, },
faker: { faker: {
address: 'Address', address: 'Address',

View File

@ -4,7 +4,6 @@ import Schema from '@/ipc-api/Schema';
import Users from '@/ipc-api/Users'; import Users from '@/ipc-api/Users';
import { uidGen } from 'common/libs/uidGen'; import { uidGen } from 'common/libs/uidGen';
const tabIndex = []; const tabIndex = [];
let lastBreadcrumbs = {};
export default { export default {
namespaced: true, namespaced: true,
@ -503,6 +502,7 @@ export default {
schema: null, schema: null,
table: null, table: null,
trigger: null, trigger: null,
triggerFunction: null,
procedure: null, procedure: null,
function: null, function: null,
scheduler: null, scheduler: null,
@ -510,16 +510,7 @@ export default {
query: null query: null
}; };
const hasLastChildren = Object.keys(lastBreadcrumbs).filter(b => b !== 'schema').some(b => lastBreadcrumbs[b]);
const hasChildren = Object.keys(payload).filter(b => b !== 'schema').some(b => payload[b]);
if (lastBreadcrumbs.schema === payload.schema && hasLastChildren && !hasChildren) return;
if (lastBreadcrumbs.schema !== payload.schema)
Schema.useSchema({ uid: getters.getSelected, schema: payload.schema });
commit('CHANGE_BREADCRUMBS', { uid: getters.getSelected, breadcrumbs: { ...breadcrumbsObj, ...payload } }); commit('CHANGE_BREADCRUMBS', { uid: getters.getSelected, breadcrumbs: { ...breadcrumbsObj, ...payload } });
lastBreadcrumbs = { ...breadcrumbsObj, ...payload };
if (payload.schema) if (payload.schema)
commit('ADD_LOADED_SCHEMA', { uid: getters.getSelected, schema: payload.schema }); commit('ADD_LOADED_SCHEMA', { uid: getters.getSelected, schema: payload.schema });