mongo changeset WIP

This commit is contained in:
Jan Prochazka 2021-04-05 13:21:52 +02:00
parent c160fdb628
commit 29e6dad713
5 changed files with 38 additions and 11 deletions

View File

@ -6,6 +6,7 @@ export interface ChangeSetItem {
pureName: string;
schemaName?: string;
insertedRowIndex?: number;
document?: any;
condition?: { [column: string]: string };
fields?: { [column: string]: string };
}
@ -77,6 +78,7 @@ export function setChangeSetValue(
definition: ChangeSetFieldDefinition,
value: string
): ChangeSet {
console.log('SET', changeSet, definition, value);
if (!changeSet || !definition) return changeSet;
let [fieldName, existingItem] = findExistingChangeSetItem(changeSet, definition);
if (fieldName == 'deletes') {
@ -332,6 +334,7 @@ export function getChangeSetInsertedRows(changeSet: ChangeSet, name?: NamedObjec
}
export function changeSetInsertNewRow(changeSet: ChangeSet, name?: NamedObjectInfo): ChangeSet {
console.log('INSERT', name);
const insertedRows = getChangeSetInsertedRows(changeSet, name);
return {
...changeSet,

View File

@ -39,9 +39,11 @@ export class CollectionGridDisplay extends GridDisplay {
this.columns = this.getDisplayColumns(loadedRows || []);
this.filterable = true;
this.sortable = true;
this.editable = false;
this.editable = true;
this.supportsReload = true;
this.isDynamicStructure = true;
this.changeSetKeyFields = ['_id'];
this.baseCollection = collection;
}
getDisplayColumns(rows) {
@ -95,6 +97,8 @@ export class CollectionGridDisplay extends GridDisplay {
isStructured: true,
parentHeaderText: createHeaderText(basePath),
filterType: 'mongo',
pureName: this.collection.pureName,
schemaName: this.collection.schemaName,
};
}
}

View File

@ -1,6 +1,14 @@
import _ from 'lodash';
import { GridConfig, GridCache, GridConfigColumns, createGridCache, GroupFunc } from './GridConfig';
import { ForeignKeyInfo, TableInfo, ColumnInfo, EngineDriver, NamedObjectInfo, DatabaseInfo } from 'dbgate-types';
import {
ForeignKeyInfo,
TableInfo,
ColumnInfo,
EngineDriver,
NamedObjectInfo,
DatabaseInfo,
CollectionInfo,
} from 'dbgate-types';
import { parseFilter, getFilterType } from 'dbgate-filterparser';
import { filterName } from './filterName';
import { ChangeSetFieldDefinition, ChangeSetRowDefinition } from './ChangeSet';
@ -56,6 +64,10 @@ export abstract class GridDisplay {
) {}
columns: DisplayColumn[];
baseTable?: TableInfo;
baseCollection?: CollectionInfo;
get baseTableOrCollection(): NamedObjectInfo {
return this.baseTable || this.baseCollection;
}
changeSetKeyFields: string[] = null;
sortable = false;
filterable = false;
@ -391,8 +403,12 @@ export abstract class GridDisplay {
getChangeSetField(row, uniqueName, insertedRowIndex): ChangeSetFieldDefinition {
const col = this.columns.find(x => x.uniqueName == uniqueName);
if (!col) return null;
if (!this.baseTable) return null;
if (this.baseTable.pureName != col.pureName || this.baseTable.schemaName != col.schemaName) return null;
const baseTableOrCollection = this.baseTableOrCollection;
if (!baseTableOrCollection) return null;
if (baseTableOrCollection.pureName != col.pureName || baseTableOrCollection.schemaName != col.schemaName) {
return null;
}
return {
...this.getChangeSetRow(row, insertedRowIndex),
uniqueName: uniqueName,
@ -401,10 +417,11 @@ export abstract class GridDisplay {
}
getChangeSetRow(row, insertedRowIndex): ChangeSetRowDefinition {
if (!this.baseTable) return null;
const baseTableOrCollection = this.baseTableOrCollection;
if (!baseTableOrCollection) return null;
return {
pureName: this.baseTable.pureName,
schemaName: this.baseTable.schemaName,
pureName: baseTableOrCollection.pureName,
schemaName: baseTableOrCollection.schemaName,
insertedRowIndex,
condition: insertedRowIndex == null ? this.getChangeSetCondition(row) : null,
};

View File

@ -39,7 +39,7 @@ export default class ChangeSetGrider extends Grider {
) {
super();
this.changeSet = changeSetState && changeSetState.value;
this.insertedRows = getChangeSetInsertedRows(this.changeSet, display?.baseTable);
this.insertedRows = getChangeSetInsertedRows(this.changeSet, display?.baseTableOrCollection);
this.setChangeSet = value => dispatchChangeSet({ type: 'set', value });
this.rowCacheIndexes = new Set();
this.rowDataCache = {};
@ -47,6 +47,8 @@ export default class ChangeSetGrider extends Grider {
this.rowDefinitionsCache = {};
this.batchChangeSet = null;
this.compiledMacroFunc = compileMacroFunction(macro, this._errors);
console.log('changeSet', this.changeSet);
}
get errors() {
@ -110,7 +112,7 @@ export default class ChangeSetGrider extends Grider {
}
get canInsert() {
return !!this.display.baseTable;
return !!this.display.baseTableOrCollection;
}
getRowData(index: number) {
@ -157,7 +159,7 @@ export default class ChangeSetGrider extends Grider {
insertRow(): number {
const res = this.rowCountInUpdate;
this.applyModification(chs => changeSetInsertNewRow(chs, this.display.baseTable));
this.applyModification(chs => changeSetInsertNewRow(chs, this.display.baseTableOrCollection));
return res;
}

View File

@ -98,9 +98,10 @@
<style>
.toolbar {
background: var(--theme-bg-3);
background: var(--theme-bg-1);
display: flex;
border-bottom: 1px solid var(--theme-border);
border-top: 2px solid var(--theme-border);
margin-bottom: 3px;
}