grid load fix

This commit is contained in:
Jan Prochazka
2020-04-03 21:35:24 +02:00
parent aeacc2b170
commit f41383aa08
7 changed files with 49 additions and 12 deletions

View File

@@ -38,12 +38,14 @@ export function combineReferenceActions(a: ReferenceActionResult, b: ReferenceAc
return 'noAction';
}
export type ChangeCacheFunc = (changeFunc: (config: GridCache) => GridCache) => void;
export abstract class GridDisplay {
constructor(
public config: GridConfig,
protected setConfig: (config: GridConfig) => void,
public cache: GridCache,
protected setCache: (config: GridCache) => void,
protected setCache: ChangeCacheFunc,
protected getTableInfo: ({ schemaName, pureName }) => Promise<TableInfo>,
public driver: EngineDriver
) {}
@@ -67,10 +69,10 @@ export abstract class GridDisplay {
}
reload() {
this.setCache({
...this.cache,
this.setCache(cache => ({
...cache,
refreshTime: new Date().getTime(),
});
}));
}
includeInColumnSet(field: keyof GridConfigColumns, uniqueName: string, isIncluded: boolean) {
@@ -128,13 +130,13 @@ export abstract class GridDisplay {
requireFkTarget(column: DisplayColumn) {
const { uniqueName, foreignKey } = column;
this.getTableInfo({ schemaName: foreignKey.refSchemaName, pureName: foreignKey.refTableName }).then(table => {
this.setCache({
...this.cache,
this.setCache(cache => ({
...cache,
tables: {
...this.cache.tables,
...cache.tables,
[uniqueName]: table,
},
});
}));
});
}

View File

@@ -1,5 +1,5 @@
import _ from 'lodash';
import { GridDisplay, combineReferenceActions } from './GridDisplay';
import { GridDisplay, combineReferenceActions, ChangeCacheFunc } from './GridDisplay';
import { Select, treeToSql, dumpSqlSelect } from '@dbgate/sqltree';
import { TableInfo, EngineDriver } from '@dbgate/types';
import { GridConfig, GridCache } from './GridConfig';
@@ -11,7 +11,7 @@ export class TableGridDisplay extends GridDisplay {
config: GridConfig,
setConfig: (config: GridConfig) => void,
cache: GridCache,
setCache: (config: GridCache) => void,
setCache: ChangeCacheFunc,
getTableInfo: ({ schemaName, pureName }) => Promise<TableInfo>
) {
super(config, setConfig, cache, setCache, getTableInfo, driver);