view data improvements

This commit is contained in:
Jan Prochazka
2021-12-09 10:10:58 +01:00
parent 4958c49147
commit 014274f4c6
5 changed files with 31 additions and 21 deletions

View File

@@ -9,6 +9,7 @@ import {
DatabaseInfo, DatabaseInfo,
CollectionInfo, CollectionInfo,
SqlDialect, SqlDialect,
ViewInfo,
} from 'dbgate-types'; } from 'dbgate-types';
import { parseFilter, getFilterType } from 'dbgate-filterparser'; import { parseFilter, getFilterType } from 'dbgate-filterparser';
import { filterName } from 'dbgate-tools'; import { filterName } from 'dbgate-tools';
@@ -69,10 +70,17 @@ export abstract class GridDisplay {
dialect: SqlDialect; dialect: SqlDialect;
columns: DisplayColumn[]; columns: DisplayColumn[];
baseTable?: TableInfo; baseTable?: TableInfo;
baseView?: ViewInfo;
baseCollection?: CollectionInfo; baseCollection?: CollectionInfo;
get baseTableOrSimilar(): NamedObjectInfo {
return this.baseTable || this.baseCollection || this.baseView;
}
get baseTableOrCollection(): NamedObjectInfo { get baseTableOrCollection(): NamedObjectInfo {
return this.baseTable || this.baseCollection; return this.baseTable || this.baseCollection;
} }
get baseTableOrView(): TableInfo | ViewInfo {
return this.baseTable || this.baseView;
}
changeSetKeyFields: string[] = null; changeSetKeyFields: string[] = null;
sortable = false; sortable = false;
groupable = false; groupable = false;
@@ -373,7 +381,7 @@ export abstract class GridDisplay {
getGrouping(uniqueName): GroupFunc { getGrouping(uniqueName): GroupFunc {
if (this.isGrouped) { if (this.isGrouped) {
if (this.config.grouping[uniqueName]) return this.config.grouping[uniqueName]; if (this.config.grouping[uniqueName]) return this.config.grouping[uniqueName];
const column = this.baseTable.columns.find(x => x.columnName == uniqueName); const column = (this.baseTable || this.baseView)?.columns?.find(x => x.columnName == uniqueName);
if (isTypeLogical(column?.dataType)) return 'COUNT DISTINCT'; if (isTypeLogical(column?.dataType)) return 'COUNT DISTINCT';
if (column?.autoIncrement) return 'COUNT'; if (column?.autoIncrement) return 'COUNT';
return 'MAX'; return 'MAX';
@@ -413,9 +421,9 @@ export abstract class GridDisplay {
getChangeSetField(row, uniqueName, insertedRowIndex): ChangeSetFieldDefinition { getChangeSetField(row, uniqueName, insertedRowIndex): ChangeSetFieldDefinition {
const col = this.columns.find(x => x.uniqueName == uniqueName); const col = this.columns.find(x => x.uniqueName == uniqueName);
if (!col) return null; if (!col) return null;
const baseTableOrCollection = this.baseTableOrCollection; const baseObj = this.baseTableOrSimilar;
if (!baseTableOrCollection) return null; if (!baseObj) return null;
if (baseTableOrCollection.pureName != col.pureName || baseTableOrCollection.schemaName != col.schemaName) { if (baseObj.pureName != col.pureName || baseObj.schemaName != col.schemaName) {
return null; return null;
} }
@@ -427,11 +435,11 @@ export abstract class GridDisplay {
} }
getChangeSetRow(row, insertedRowIndex): ChangeSetRowDefinition { getChangeSetRow(row, insertedRowIndex): ChangeSetRowDefinition {
const baseTableOrCollection = this.baseTableOrCollection; const baseObj = this.baseTableOrSimilar;
if (!baseTableOrCollection) return null; if (!baseObj) return null;
return { return {
pureName: baseTableOrCollection.pureName, pureName: baseObj.pureName,
schemaName: baseTableOrCollection.schemaName, schemaName: baseObj.schemaName,
insertedRowIndex, insertedRowIndex,
condition: insertedRowIndex == null ? this.getChangeSetCondition(row) : null, condition: insertedRowIndex == null ? this.getChangeSetCondition(row) : null,
}; };

View File

@@ -20,6 +20,7 @@ export class ViewGridDisplay extends GridDisplay {
this.groupable = true; this.groupable = true;
this.editable = false; this.editable = false;
this.supportsReload = true; this.supportsReload = true;
this.baseView = view;
} }
getDisplayColumns(view: ViewInfo) { getDisplayColumns(view: ViewInfo) {

View File

@@ -52,7 +52,7 @@ export default class ChangeSetGrider extends Grider {
) { ) {
super(); super();
this.changeSet = changeSetState && changeSetState.value; this.changeSet = changeSetState && changeSetState.value;
this.insertedRows = getChangeSetInsertedRows(this.changeSet, display?.baseTableOrCollection); this.insertedRows = getChangeSetInsertedRows(this.changeSet, display?.baseTableOrSimilar);
this.setChangeSet = value => dispatchChangeSet({ type: 'set', value }); this.setChangeSet = value => dispatchChangeSet({ type: 'set', value });
this.rowCacheIndexes = new Set(); this.rowCacheIndexes = new Set();
this.rowDataCache = {}; this.rowDataCache = {};
@@ -169,7 +169,7 @@ export default class ChangeSetGrider extends Grider {
get rowCountInUpdate() { get rowCountInUpdate() {
if (this.batchChangeSet) { if (this.batchChangeSet) {
const newRows = getChangeSetInsertedRows(this.batchChangeSet, this.display.baseTable); const newRows = getChangeSetInsertedRows(this.batchChangeSet, this.display.baseTableOrSimilar);
return this.sourceRows.length + newRows.length; return this.sourceRows.length + newRows.length;
} else { } else {
return this.rowCount; return this.rowCount;
@@ -178,13 +178,13 @@ export default class ChangeSetGrider extends Grider {
insertRow(): number { insertRow(): number {
const res = this.rowCountInUpdate; const res = this.rowCountInUpdate;
this.applyModification(chs => changeSetInsertNewRow(chs, this.display.baseTableOrCollection)); this.applyModification(chs => changeSetInsertNewRow(chs, this.display.baseTableOrSimilar));
return res; return res;
} }
insertDocuments(documents: any[]): number { insertDocuments(documents: any[]): number {
const res = this.rowCountInUpdate; const res = this.rowCountInUpdate;
this.applyModification(chs => changeSetInsertDocuments(chs, documents, this.display.baseTableOrCollection)); this.applyModification(chs => changeSetInsertDocuments(chs, documents, this.display.baseTableOrSimilar));
return res; return res;
} }

View File

@@ -758,15 +758,18 @@
// $: console.log('DISPLAY.config', display.config); // $: console.log('DISPLAY.config', display.config);
$: { $: {
if (display?.groupColumns && display?.baseTable) { if (display?.groupColumns && display?.baseTableOrSimilar && onReferenceClick) {
onReferenceClick({ onReferenceClick({
referenceId: stableStringify(display && display.groupColumns), referenceId: stableStringify(display && display.groupColumns),
schemaName: display.baseTable.schemaName, schemaName: display.baseTableOrSimilar?.schemaName,
pureName: display.baseTable.pureName, pureName: display.baseTableOrSimilar?.pureName,
columns: display.groupColumns.map(col => ({ columns: display.groupColumns.map(col => ({
baseName: col, baseName: col,
refName: col, refName: col,
dataType: _.get(display.baseTable && display.baseTable.columns.find(x => x.columnName == col), 'dataType'), dataType: _.get(
display.baseTableOrView?.columns?.find(x => x.columnName == col),
'dataType'
),
})), })),
}); });
} }

View File

@@ -68,7 +68,6 @@
return parseInt(response.data.rows[0].count); return parseInt(response.data.rows[0].count);
} }
</script> </script>
<script lang="ts"> <script lang="ts">
@@ -128,7 +127,7 @@
initialValues.sourceConnectionId = conid; initialValues.sourceConnectionId = conid;
initialValues.sourceDatabaseName = database; initialValues.sourceDatabaseName = database;
initialValues.sourceSql = display.getExportQuery(); initialValues.sourceSql = display.getExportQuery();
initialValues.sourceList = display.baseTable ? [display.baseTable.pureName] : []; initialValues.sourceList = display.baseTableOrSimilar ? [display.baseTableOrSimilar.pureName] : [];
showModal(ImportExportModal, { initialValues }); showModal(ImportExportModal, { initialValues });
} }
@@ -139,8 +138,8 @@
icon: 'img sql-file', icon: 'img sql-file',
tabComponent: 'QueryTab', tabComponent: 'QueryTab',
props: { props: {
schemaName: display.baseTable.schemaName, schemaName: display.baseTableOrSimilar?.schemaName,
pureName: display.baseTable.pureName, pureName: display.baseTableOrSimilar?.pureName,
conid, conid,
database, database,
}, },
@@ -198,7 +197,6 @@
}, },
{ command: 'sqlDataGrid.export', tag: 'export' } { command: 'sqlDataGrid.export', tag: 'export' }
); );
</script> </script>
<LoadingDataGridCore <LoadingDataGridCore