feat: improved data table sorts

This commit is contained in:
Fabio Di Stasio 2020-12-07 17:51:48 +01:00
parent d38583262e
commit 5712b80022
4 changed files with 25 additions and 8 deletions

View File

@ -14,14 +14,18 @@ export default (connections) => {
}
});
ipcMain.handle('get-table-data', async (event, { uid, schema, table }) => {
ipcMain.handle('get-table-data', async (event, { uid, schema, table, sortParams }) => {
try {
const result = await connections[uid]
const query = connections[uid]
.select('*')
.schema(schema)
.from(table)
.limit(1000)
.run({ details: true });
.limit(1000);
if (sortParams && sortParams.field && sortParams.dir)
query.orderBy({ [sortParams.field]: sortParams.dir.toUpperCase() });
const result = await query.run({ details: true });
return { status: 'success', response: result };
}

View File

@ -99,6 +99,7 @@ export default {
if (!query || this.isQuering) return;
this.isQuering = true;
this.clearTabData();
this.$refs.queryTable.resetSort();
try { // Query Data
const params = {

View File

@ -123,8 +123,11 @@ export default {
primaryField () {
return this.fields.filter(field => ['pri', 'uni'].includes(field.key))[0] || false;
},
isHardSort () {
return this.mode === 'table' && this.localResults.length === 1000;
},
sortedResults () {
if (this.currentSort) {
if (this.currentSort && !this.isHardSort) {
return [...this.localResults].sort((a, b) => {
let modifier = 1;
const valA = typeof a[this.currentSort] === 'string' ? a[this.currentSort].toLowerCase() : a[this.currentSort];
@ -228,7 +231,7 @@ export default {
return row[primaryFieldName];
},
setLocalResults () {
this.resetSort();
// this.resetSort();
this.localResults = this.resultsWithRows[this.resultsetIndex] && this.resultsWithRows[this.resultsetIndex].rows
? this.resultsWithRows[this.resultsetIndex].rows.map(item => {
return { ...item, _id: uidGen() };
@ -342,6 +345,9 @@ export default {
this.currentSortDir = 'asc';
this.currentSort = field;
}
if (this.isHardSort)
this.$emit('hard-sort', { field: this.currentSort, dir: this.currentSortDir });
},
resetSort () {
this.currentSort = '';

View File

@ -63,6 +63,7 @@
mode="table"
@update-field="updateField"
@delete-selected="deleteSelected"
@hard-sort="hardSort"
/>
</div>
<ModalNewTableRow
@ -135,6 +136,7 @@ export default {
if (this.isSelected) {
this.getTableData();
this.lastTable = this.table;
this.$refs.queryTable.resetSort();
}
},
isSelected (val) {
@ -156,7 +158,7 @@ export default {
...mapActions({
addNotification: 'notifications/addNotification'
}),
async getTableData () {
async getTableData (sortParams) {
if (!this.table) return;
this.isQuering = true;
@ -167,7 +169,8 @@ export default {
const params = {
uid: this.connection.uid,
schema: this.schema,
table: this.workspace.breadcrumbs.table
table: this.workspace.breadcrumbs.table,
sortParams
};
try { // Table data
@ -190,6 +193,9 @@ export default {
reloadTable () {
this.getTableData();
},
hardSort (sortParams) {
this.getTableData(sortParams);
},
showAddModal () {
this.isAddModal = true;
},