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

View File

@ -41,7 +41,7 @@
/>
<span>{{ field.alias || field.name }}</span>
<i
v-if="currentSort === field.name"
v-if="currentSort === field.name || currentSort === `${field.table}.${field.name}`"
class="mdi sort-icon"
:class="currentSortDir === 'asc' ? 'mdi-sort-ascending':'mdi-sort-descending'"
/>
@ -94,7 +94,9 @@ export default {
},
props: {
results: Array,
tabUid: [String, Number]
tabUid: [String, Number],
connUid: String,
mode: String
},
data () {
return {
@ -112,8 +114,12 @@ export default {
},
computed: {
...mapGetters({
getWorkspaceTab: 'workspaces/getWorkspaceTab'
getWorkspaceTab: 'workspaces/getWorkspaceTab',
getWorkspace: 'workspaces/getWorkspace'
}),
workspaceSchema () {
return this.getWorkspace(this.connUid).breadcrumbs.schema;
},
primaryField () {
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 '';
},
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) {
const primaryFieldName = Object.keys(row).find(prop => [
this.primaryField.alias,
@ -237,6 +248,7 @@ export default {
else {
const params = {
primary: this.primaryField.name,
schema: this.getSchema(this.resultsetIndex),
table: this.getTable(this.resultsetIndex),
id,
...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 params = {
primary: this.primaryField.name,
schema: this.getSchema(this.resultsetIndex),
table: this.getTable(this.resultsetIndex),
rows: rowIDs
};
@ -304,6 +317,9 @@ export default {
this.isContext = true;
},
sort (field) {
if (this.mode === 'query')
field = `${this.getTable(this.resultsetIndex)}.${field}`;
if (field === this.currentSort) {
if (this.currentSortDir === 'asc')
this.currentSortDir = 'desc';

View File

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

View File

@ -3,12 +3,6 @@ import Tables from '@/ipc-api/Tables';
export default {
computed: {
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;
}
},
@ -18,7 +12,6 @@ export default {
const params = {
uid: this.connection.uid,
schema: this.schema,
...payload
};
@ -44,33 +37,14 @@ export default {
const params = {
uid: this.connection.uid,
schema: this.schema,
...payload
};
try {
const { status, response } = await Tables.deleteTableRows(params);
if (status === 'success') {
const { primary, rows } = params;
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
}
if (status === 'success')
this.reloadTable();
else
this.addNotification({ status: 'error', message: response });
}