fix: several fix on data and query tabs

This commit is contained in:
Fabio 2020-09-18 12:54:02 +02:00
parent ac4941fa5e
commit 530907d097
4 changed files with 39 additions and 37 deletions

View File

@ -34,6 +34,8 @@
ref="queryTable" ref="queryTable"
:results="results" :results="results"
:tab-uid="tabUid" :tab-uid="tabUid"
:conn-uid="connection.uid"
mode="query"
@update-field="updateField" @update-field="updateField"
@delete-selected="deleteSelected" @delete-selected="deleteSelected"
/> />
@ -115,10 +117,10 @@ export default {
let selectedFields = []; let selectedFields = [];
const fieldsArr = []; const fieldsArr = [];
const keysArr = []; const keysArr = [];
let qI = 0; let qI = 0;// queries index
for (const result of this.results) { // cycle queries for (const result of this.results) { // cycle queries
let fI = 0; let fI = 0;// fields index
if (result.rows) { // if is a select if (result.rows) { // if is a select
const paramsArr = this.getResultParams(qI); const paramsArr = this.getResultParams(qI);
@ -143,7 +145,7 @@ export default {
}); });
} }
fieldsArr.push(fields); fieldsArr[qI] = fieldsArr[qI] ? [...fieldsArr[qI], ...fields] : fields;
} }
else else
this.addNotification({ status: 'error', message: response }); this.addNotification({ status: 'error', message: response });
@ -160,7 +162,7 @@ export default {
const { status, response } = await Tables.getKeyUsage(params); const { status, response } = await Tables.getKeyUsage(params);
if (status === 'success') if (status === 'success')
keysArr.push(response); keysArr[qI] = keysArr[qI] ? [...keysArr[qI], ...response] : response;
else else
this.addNotification({ status: 'error', message: response }); this.addNotification({ status: 'error', message: response });
} }
@ -176,8 +178,16 @@ export default {
qI++; qI++;
} }
this.setTabFields({ cUid: this.connection.uid, tUid: this.tabUid, fields: [fieldsArr.flat()] }); this.setTabFields({
this.setTabKeyUsage({ cUid: this.connection.uid, tUid: this.tabUid, keyUsage: [keysArr.flat()] }); cUid: this.connection.uid,
tUid: this.tabUid,
fields: fieldsArr
});
this.setTabKeyUsage({
cUid: this.connection.uid,
tUid: this.tabUid,
keyUsage: keysArr
});
} }
else else
this.addNotification({ status: 'error', message: response }); this.addNotification({ status: 'error', message: response });

View File

@ -41,7 +41,7 @@
/> />
<span>{{ field.alias || field.name }}</span> <span>{{ field.alias || field.name }}</span>
<i <i
v-if="currentSort === field.name" v-if="currentSort === field.name || currentSort === `${field.table}.${field.name}`"
class="mdi sort-icon" class="mdi sort-icon"
:class="currentSortDir === 'asc' ? 'mdi-sort-ascending':'mdi-sort-descending'" :class="currentSortDir === 'asc' ? 'mdi-sort-ascending':'mdi-sort-descending'"
/> />
@ -94,7 +94,9 @@ export default {
}, },
props: { props: {
results: Array, results: Array,
tabUid: [String, Number] tabUid: [String, Number],
connUid: String,
mode: String
}, },
data () { data () {
return { return {
@ -112,8 +114,12 @@ export default {
}, },
computed: { computed: {
...mapGetters({ ...mapGetters({
getWorkspaceTab: 'workspaces/getWorkspaceTab' getWorkspaceTab: 'workspaces/getWorkspaceTab',
getWorkspace: 'workspaces/getWorkspace'
}), }),
workspaceSchema () {
return this.getWorkspace(this.connUid).breadcrumbs.schema;
},
primaryField () { primaryField () {
return this.fields.filter(field => ['pri', 'uni'].includes(field.key))[0] || false; return this.fields.filter(field => ['pri', 'uni'].includes(field.key))[0] || false;
}, },
@ -201,6 +207,11 @@ export default {
return this.resultsWithRows[index].fields[0].orgTable; return this.resultsWithRows[index].fields[0].orgTable;
return ''; return '';
}, },
getSchema (index) {
if (this.resultsWithRows[index] && this.resultsWithRows[index].fields && this.resultsWithRows[index].fields.length)
return this.resultsWithRows[index].fields[0].db;
return this.workspaceSchema;
},
getPrimaryValue (row) { getPrimaryValue (row) {
const primaryFieldName = Object.keys(row).find(prop => [ const primaryFieldName = Object.keys(row).find(prop => [
this.primaryField.alias, this.primaryField.alias,
@ -237,6 +248,7 @@ export default {
else { else {
const params = { const params = {
primary: this.primaryField.name, primary: this.primaryField.name,
schema: this.getSchema(this.resultsetIndex),
table: this.getTable(this.resultsetIndex), table: this.getTable(this.resultsetIndex),
id, id,
...payload ...payload
@ -251,6 +263,7 @@ export default {
const rowIDs = this.localResults.filter(row => this.selectedRows.includes(row._id)).map(row => row[this.primaryField.name]); const rowIDs = this.localResults.filter(row => this.selectedRows.includes(row._id)).map(row => row[this.primaryField.name]);
const params = { const params = {
primary: this.primaryField.name, primary: this.primaryField.name,
schema: this.getSchema(this.resultsetIndex),
table: this.getTable(this.resultsetIndex), table: this.getTable(this.resultsetIndex),
rows: rowIDs rows: rowIDs
}; };
@ -304,6 +317,9 @@ export default {
this.isContext = true; this.isContext = true;
}, },
sort (field) { sort (field) {
if (this.mode === 'query')
field = `${this.getTable(this.resultsetIndex)}.${field}`;
if (field === this.currentSort) { if (field === this.currentSort) {
if (this.currentSortDir === 'asc') if (this.currentSortDir === 'asc')
this.currentSortDir = 'desc'; this.currentSortDir = 'desc';

View File

@ -37,6 +37,8 @@
ref="queryTable" ref="queryTable"
:results="results" :results="results"
:tab-uid="tabUid" :tab-uid="tabUid"
:conn-uid="connection.uid"
mode="table"
@update-field="updateField" @update-field="updateField"
@delete-selected="deleteSelected" @delete-selected="deleteSelected"
/> />

View File

@ -3,12 +3,6 @@ import Tables from '@/ipc-api/Tables';
export default { export default {
computed: { computed: {
schema () { schema () {
if (Array.isArray(this.results)) {
const resultsWithRows = this.results.filter(result => result.rows);
if (resultsWithRows[this.selectedResultsset] && resultsWithRows[this.selectedResultsset].fields.length)
return resultsWithRows[this.selectedResultsset].fields[0].db;
}
return this.workspace.breadcrumbs.schema; return this.workspace.breadcrumbs.schema;
} }
}, },
@ -18,7 +12,6 @@ export default {
const params = { const params = {
uid: this.connection.uid, uid: this.connection.uid,
schema: this.schema,
...payload ...payload
}; };
@ -44,33 +37,14 @@ export default {
const params = { const params = {
uid: this.connection.uid, uid: this.connection.uid,
schema: this.schema,
...payload ...payload
}; };
try { try {
const { status, response } = await Tables.deleteTableRows(params); const { status, response } = await Tables.deleteTableRows(params);
if (status === 'success') { if (status === 'success')
const { primary, rows } = params; this.reloadTable();
if (Array.isArray(this.results)) {
this.results = this.results.map((result, index) => {
if (index === this.selectedResultsset) {
return {
...result,
rows: result.rows.filter(row => !rows.includes(row[primary]))
};
}
else
return result;
});
}
else
this.results = { ...this.results, rows: this.results.rows.filter(row => !rows.includes(row[primary])) };
this.$refs.queryTable.refreshScroller();// Necessary to re-render virtual scroller
}
else else
this.addNotification({ status: 'error', message: response }); this.addNotification({ status: 'error', message: response });
} }