mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 03:45:59 +00:00
perspectives WIP
This commit is contained in:
50
packages/datalib/src/PerspectiveColumnDefinition.ts
Normal file
50
packages/datalib/src/PerspectiveColumnDefinition.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { ColumnInfo, ForeignKeyInfo, TableInfo } from 'dbgate-types';
|
||||
import { clearConfigCache } from 'prettier';
|
||||
import { ChangePerspectiveConfigFunc, PerspectiveConfig } from './PerspectiveConfig';
|
||||
|
||||
export abstract class PerspectiveColumnDefinition {
|
||||
abstract get title();
|
||||
abstract get props();
|
||||
abstract get isExpanded();
|
||||
abstract get isExpandable();
|
||||
abstract get level();
|
||||
abstract toggleExpanded();
|
||||
}
|
||||
|
||||
export class PerspectiveTableColumnDefinition extends PerspectiveColumnDefinition {
|
||||
foreignKey: ForeignKeyInfo;
|
||||
constructor(
|
||||
public column: ColumnInfo,
|
||||
public table: TableInfo,
|
||||
public config: PerspectiveConfig,
|
||||
public setConfig: ChangePerspectiveConfigFunc
|
||||
) {
|
||||
super();
|
||||
|
||||
this.foreignKey =
|
||||
table.foreignKeys &&
|
||||
table.foreignKeys.find(fk => fk.columns.length == 1 && fk.columns[0].columnName == column.columnName);
|
||||
}
|
||||
|
||||
get title() {
|
||||
return this.column.columnName;
|
||||
}
|
||||
|
||||
get props() {
|
||||
return this.column;
|
||||
}
|
||||
|
||||
get isExpanded() {
|
||||
return this.config.expandedColumns.includes(this.column.uniqueName);
|
||||
}
|
||||
|
||||
get isExpandable() {
|
||||
return !!this.foreignKey;
|
||||
}
|
||||
|
||||
get level() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
toggleExpanded() {}
|
||||
}
|
||||
17
packages/datalib/src/PerspectiveConfig.ts
Normal file
17
packages/datalib/src/PerspectiveConfig.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
export interface PerspectiveConfig {
|
||||
hiddenColumns: string[];
|
||||
shownColumns: string[];
|
||||
expandedColumns: string[];
|
||||
collapsedColumns: string[];
|
||||
}
|
||||
|
||||
export function createPerspectiveConfig(): PerspectiveConfig {
|
||||
return {
|
||||
hiddenColumns: [],
|
||||
shownColumns: [],
|
||||
expandedColumns: [],
|
||||
collapsedColumns: [],
|
||||
};
|
||||
}
|
||||
|
||||
export type ChangePerspectiveConfigFunc = (changeFunc: (config: PerspectiveConfig) => PerspectiveConfig) => void;
|
||||
@@ -1,5 +1,7 @@
|
||||
export * from './GridDisplay';
|
||||
export * from './GridConfig';
|
||||
export * from './PerspectiveConfig';
|
||||
export * from './PerspectiveColumnDefinition';
|
||||
export * from './TableGridDisplay';
|
||||
export * from './ViewGridDisplay';
|
||||
export * from './JslGridDisplay';
|
||||
|
||||
Reference in New Issue
Block a user