fix: duplicate header fields on join result tables

This commit is contained in:
Fabio 2020-10-21 14:58:22 +02:00
parent 1658432fd3
commit ea9b489f5f
4 changed files with 67 additions and 19 deletions

View File

@ -139,7 +139,13 @@ export default {
if (result.rows) { // if is a select
const paramsArr = this.getResultParams(qI);
selectedFields = result.fields.map(field => field.orgName || field.name);
selectedFields = result.fields.map(field => {
return {
name: field.orgName || field.name,
table: field.orgTable || field.table
};
});
this.resultsCount += result.rows.length;
for (const paramObj of paramsArr) {
@ -153,8 +159,8 @@ export default {
if (status === 'success') {
let fields = response.length ? selectedFields.map(selField => {
return response.find(field => field.name === selField);
}) : [];
return response.find(field => field.name === selField.name && field.table === selField.table);
}).filter(el => !!el) : [];
if (selectedFields.length) {
fields = fields.map(field => {
@ -169,11 +175,15 @@ export default {
if (!fields.length) {
fields = result.fields.map(field => {
return { ...field, alias: field.name };
return {
...field,
alias: field.name,
tableAlias: field.table
};
});
}
fieldsArr[qI] = fieldsArr[qI] ? [...fieldsArr[qI], ...fields] : fields.length >= result.fields.length ? fields : result.fields;
fieldsArr[qI] = fieldsArr[qI] ? [...fieldsArr[qI], ...fields] : fields;
}
else
this.addNotification({ status: 'error', message: response });

View File

@ -212,7 +212,7 @@ export default {
},
getTable (index) {
if (this.resultsWithRows[index] && this.resultsWithRows[index].fields && this.resultsWithRows[index].fields.length)
return this.resultsWithRows[index].fields[0].table;
return this.resultsWithRows[index].fields[0].orgTable;
return '';
},
getSchema (index) {
@ -221,11 +221,14 @@ export default {
return this.workspaceSchema;
},
getPrimaryValue (row) {
console.log(row);
const primaryFieldName = Object.keys(row).find(prop => [
this.primaryField.alias,
this.primaryField.name,
`${this.primaryField.table}.${this.primaryField.alias}`,
`${this.primaryField.table}.${this.primaryField.name}`
`${this.primaryField.table}.${this.primaryField.name}`,
`${this.primaryField.tableAlias}.${this.primaryField.alias}`,
`${this.primaryField.tableAlias}.${this.primaryField.name}`
].includes(prop));
return row[primaryFieldName];
},

View File

@ -285,21 +285,24 @@ export default {
return length;
},
getFieldObj (cKey) {
return this.fields.filter(field =>
field.name === cKey ||
field.alias === cKey ||
return this.fields.filter(field => {
let fieldNames = [
field.name,
field.alias,
`${field.table}.${field.name}`,
`${field.table}.${field.alias}`,
`${field.tableAlias}.${field.name}`,
`${field.tableAlias}.${field.alias}`
];
`${field.table}.${field.name}` === cKey ||
`${field.table}.${field.alias}` === cKey ||
if (field.table)
fieldNames = [...fieldNames, `${field.table.toLowerCase()}.${field.name}`, `${field.table.toLowerCase()}.${field.alias}`];
`${field.table.toLowerCase()}.${field.name}` === cKey ||
`${field.table.toLowerCase()}.${field.alias}` === cKey ||
if (field.tableAlias)
fieldNames = [...fieldNames, `${field.tableAlias.toLowerCase()}.${field.name}`, `${field.tableAlias.toLowerCase()}.${field.alias}`];
`${field.tableAlias}.${field.name}` === cKey ||
`${field.tableAlias}.${field.alias}` === cKey ||
`${field.tableAlias.toLowerCase()}.${field.name}` === cKey ||
`${field.tableAlias.toLowerCase()}.${field.alias}` === cKey)[0];
return fieldNames.includes(cKey);
})[0];
},
isNull (value) {
return value === null ? ' is-null' : '';

View File

@ -64,6 +64,38 @@ body {
background-size: 2em 2em;
}
.workspace-tabs {
align-content: baseline;
.workspace-query-runner {
.workspace-query-runner-footer {
display: flex;
justify-content: space-between;
padding: 0.3rem 0.6rem 0.4rem;
align-items: center;
.workspace-query-buttons {
display: flex;
.btn {
display: flex;
align-self: center;
color: $body-font-color;
margin-right: 0.4rem;
}
}
.workspace-query-info {
display: flex;
> div + div {
padding-left: 0.6rem;
}
}
}
}
}
// Scrollbars
::-webkit-scrollbar {
width: 10px;