Table overlap indication (#237)

* add find overlapping functionality

* add indication for tables overlapping

* fix reorder overlap

* add loading diagram event

* fix hidden nodes overlap bug
This commit is contained in:
Guy Ben-Aharon
2024-10-05 20:58:17 +03:00
committed by GitHub
parent 588543f324
commit a28fb4afa1
12 changed files with 599 additions and 30 deletions

View File

@@ -8,6 +8,58 @@ import type { DBRelationship } from '@/lib/domain/db-relationship';
import type { Diagram } from '@/lib/domain/diagram';
import type { DatabaseEdition } from '@/lib/domain/database-edition';
import type { DBSchema } from '@/lib/domain/db-schema';
import { EventEmitter } from 'ahooks/lib/useEventEmitter';
export type ChartDBEventType =
| 'add_tables'
| 'update_table'
| 'remove_tables'
| 'add_field'
| 'remove_field'
| 'load_diagram';
export type ChartDBEventBase<T extends ChartDBEventType, D> = {
action: T;
data: D;
};
export type CreateTableEvent = ChartDBEventBase<
'add_tables',
{ tables: DBTable[] }
>;
export type UpdateTableEvent = ChartDBEventBase<
'update_table',
{ id: string; table: Partial<DBTable> }
>;
export type RemoveTableEvent = ChartDBEventBase<
'remove_tables',
{ tableIds: string[] }
>;
export type AddFieldEvent = ChartDBEventBase<
'add_field',
{ tableId: string; field: DBField; fields: DBField[] }
>;
export type RemoveFieldEvent = ChartDBEventBase<
'remove_field',
{ tableId: string; fieldId: string; fields: DBField[] }
>;
export type LoadDiagramEvent = ChartDBEventBase<
'load_diagram',
{ diagram: Diagram }
>;
export type ChartDBEvent =
| CreateTableEvent
| UpdateTableEvent
| RemoveTableEvent
| AddFieldEvent
| RemoveFieldEvent
| LoadDiagramEvent;
export interface ChartDBContext {
diagramId: string;
@@ -17,6 +69,7 @@ export interface ChartDBContext {
schemas: DBSchema[];
relationships: DBRelationship[];
currentDiagram: Diagram;
events: EventEmitter<ChartDBEvent>;
filteredSchemas?: string[];
filterSchemas: (schemaIds: string[]) => void;
@@ -154,6 +207,7 @@ export const chartDBContext = createContext<ChartDBContext>({
createdAt: new Date(),
updatedAt: new Date(),
},
events: new EventEmitter(),
// General operations
updateDiagramId: emptyFn,