import _ from 'lodash'; import { GridDisplay, ChangeCacheFunc, ChangeConfigFunc } from './GridDisplay'; import { EngineDriver, ViewInfo, ColumnInfo } from '@dbgate/types'; import { GridConfig, GridCache } from './GridConfig'; export class ViewGridDisplay extends GridDisplay { constructor( public view: ViewInfo, driver: EngineDriver, config: GridConfig, setConfig: ChangeConfigFunc, cache: GridCache, setCache: ChangeCacheFunc ) { super(config, setConfig, cache, setCache, driver); this.columns = this.getDisplayColumns(view); this.filterable = true; this.sortable = true; this.editable = false; } getDisplayColumns(view: ViewInfo) { return ( view?.columns ?.map((col) => this.getDisplayColumn(view, col)) ?.map((col) => ({ ...col, isChecked: this.isColumnChecked(col), })) || [] ); } getDisplayColumn(view: ViewInfo, col: ColumnInfo) { const uniquePath = [col.columnName]; const uniqueName = uniquePath.join('.'); return { ...col, pureName: view.pureName, schemaName: view.schemaName, headerText: col.columnName, uniqueName, uniquePath, }; } createSelect(options = {}) { const select = this.createSelectBase(this.view, this.view.columns, options); return select; } }