fix(UI): elements from previous selected schemas in query suggestions

This commit is contained in:
Fabio Di Stasio 2021-02-22 19:14:02 +01:00
parent dbab06fcb8
commit c8545a250b
3 changed files with 62 additions and 28 deletions

View File

@ -12,7 +12,7 @@
import * as ace from 'ace-builds'; import * as ace from 'ace-builds';
import 'ace-builds/webpack-resolver'; import 'ace-builds/webpack-resolver';
import '../libs/ext-language_tools'; import '../libs/ext-language_tools';
import { mapGetters } from 'vuex'; import { mapGetters, mapActions } from 'vuex';
import Tables from '@/ipc-api/Tables'; import Tables from '@/ipc-api/Tables';
export default { export default {
@ -20,6 +20,7 @@ export default {
props: { props: {
value: String, value: String,
workspace: Object, workspace: Object,
isSelected: Boolean,
schema: { type: String, default: '' }, schema: { type: String, default: '' },
autoFocus: { type: Boolean, default: false }, autoFocus: { type: Boolean, default: false },
readOnly: { type: Boolean, default: false }, readOnly: { type: Boolean, default: false },
@ -29,15 +30,17 @@ export default {
return { return {
editor: null, editor: null,
fields: [], fields: [],
baseCompleter: [], customCompleter: [],
id: null id: null,
lastSchema: null
}; };
}, },
computed: { computed: {
...mapGetters({ ...mapGetters({
editorTheme: 'settings/getEditorTheme', editorTheme: 'settings/getEditorTheme',
autoComplete: 'settings/getAutoComplete', autoComplete: 'settings/getAutoComplete',
lineWrap: 'settings/getLineWrap' lineWrap: 'settings/getLineWrap',
baseCompleter: 'application/getBaseCompleter'
}), }),
tables () { tables () {
return this.workspace return this.workspace
@ -164,10 +167,21 @@ export default {
wrap: this.lineWrap wrap: this.lineWrap
}); });
} }
},
isSelected () {
if (this.isSelected)
this.lastSchema = this.schema;
},
lastSchema () {
if (this.editor) {
this.editor.completers = this.baseCompleter.map(el => Object.assign({}, el));
this.setCustomCompleter();
}
} }
}, },
created () { created () {
this.id = this._uid; this.id = this._uid;
this.lastSchema = this.schema;
}, },
mounted () { mounted () {
this.editor = ace.edit(`editor-${this.id}`, { this.editor = ace.edit(`editor-${this.id}`, {
@ -186,26 +200,10 @@ export default {
enableLiveAutocompletion: this.autoComplete enableLiveAutocompletion: this.autoComplete
}); });
this.editor.completers.push({ if (!this.baseCompleter.length)
getCompletions: (editor, session, pos, prefix, callback) => { this.setBaseCompleters(this.editor.completers.map(el => Object.assign({}, el)));
const completions = [];
[
...this.tables,
...this.triggers,
...this.procedures,
...this.functions,
...this.schedulers
].forEach(el => {
completions.push({
value: el.name,
meta: el.type
});
});
callback(null, completions);
}
});
this.baseCompleter = this.editor.completers; this.setCustomCompleter();
this.editor.commands.on('afterExec', e => { this.editor.commands.on('afterExec', e => {
if (['insertstring', 'backspace', 'del'].includes(e.command.name)) { if (['insertstring', 'backspace', 'del'].includes(e.command.name)) {
@ -228,13 +226,13 @@ export default {
}).catch(console.log); }).catch(console.log);
} }
else else
this.editor.completers = this.baseCompleter; this.editor.completers = this.customCompleter;
} }
else else
this.editor.completers = this.baseCompleter; this.editor.completers = this.customCompleter;
} }
else else
this.editor.completers = this.baseCompleter; this.editor.completers = this.customCompleter;
} }
}); });
@ -253,6 +251,33 @@ export default {
setTimeout(() => { setTimeout(() => {
this.editor.resize(); this.editor.resize();
}, 20); }, 20);
},
methods: {
...mapActions({
setBaseCompleters: 'application/setBaseCompleter'
}),
setCustomCompleter () {
this.editor.completers.push({
getCompletions: (editor, session, pos, prefix, callback) => {
const completions = [];
[
...this.tables,
...this.triggers,
...this.procedures,
...this.functions,
...this.schedulers
].forEach(el => {
completions.push({
value: el.name,
meta: el.type
});
});
callback(null, completions);
}
});
this.customCompleter = this.editor.completers;
}
} }
}; };
</script> </script>

View File

@ -2,12 +2,13 @@
<div v-show="isSelected" class="workspace-query-tab column col-12 columns col-gapless"> <div v-show="isSelected" class="workspace-query-tab column col-12 columns col-gapless">
<div class="workspace-query-runner column col-12"> <div class="workspace-query-runner column col-12">
<QueryEditor <QueryEditor
v-if="isSelected" v-show="isSelected"
ref="queryEditor" ref="queryEditor"
:auto-focus="true" :auto-focus="true"
:value.sync="query" :value.sync="query"
:workspace="workspace" :workspace="workspace"
:schema="schema" :schema="schema"
:is-selected="isSelected"
:height="editorHeight" :height="editorHeight"
/> />
<div ref="resizer" class="query-area-resizer" /> <div ref="resizer" class="query-area-resizer" />

View File

@ -11,12 +11,14 @@ export default {
selected_setting_tab: 'general', selected_setting_tab: 'general',
selected_conection: {}, selected_conection: {},
update_status: 'noupdate', // noupdate, available, checking, nocheck, downloading, downloaded update_status: 'noupdate', // noupdate, available, checking, nocheck, downloading, downloaded
download_progress: 0 download_progress: 0,
base_completer: [] // Needed to reset ace editor, due global-only ace completer
}, },
getters: { getters: {
isLoading: state => state.is_loading, isLoading: state => state.is_loading,
appName: state => state.app_name, appName: state => state.app_name,
appVersion: state => state.app_version, appVersion: state => state.app_version,
getBaseCompleter: state => state.base_completer,
getSelectedConnection: state => state.selected_conection, getSelectedConnection: state => state.selected_conection,
isNewModal: state => state.is_new_modal, isNewModal: state => state.is_new_modal,
isSettingModal: state => state.is_setting_modal, isSettingModal: state => state.is_setting_modal,
@ -28,6 +30,9 @@ export default {
SET_LOADING_STATUS (state, payload) { SET_LOADING_STATUS (state, payload) {
state.is_loading = payload; state.is_loading = payload;
}, },
SET_BASE_COMPLETER (state, payload) {
state.base_completer = payload;
},
SHOW_NEW_CONNECTION_MODAL (state) { SHOW_NEW_CONNECTION_MODAL (state) {
state.is_new_modal = true; state.is_new_modal = true;
}, },
@ -52,6 +57,9 @@ export default {
setLoadingStatus ({ commit }, payload) { setLoadingStatus ({ commit }, payload) {
commit('SET_LOADING_STATUS', payload); commit('SET_LOADING_STATUS', payload);
}, },
setBaseCompleter ({ commit }, payload) {
commit('SET_BASE_COMPLETER', payload);
},
// Modals // Modals
showNewConnModal ({ commit }) { showNewConnModal ({ commit }) {
commit('SHOW_NEW_CONNECTION_MODAL'); commit('SHOW_NEW_CONNECTION_MODAL');