Database diagrams editor that allows you to visualize and design your DB with a single query.
TypeScript databasedbdb-migrationeditorerdmariadbmssqlmysqlpostgresqlreactreact-flowschema-migrationssqlsqlitetypescriptvisualizationxyflow
allow create dependency only from view + allow dependency to view (#251)
Guy Ben-Aharonf0e4a871897f
diff --git a/src/pages/editor-page/canvas/canvas.tsx b/src/pages/editor-page/canvas/canvas.tsxindex 971a034a..22e9cf66 100644--- a/src/pages/editor-page/canvas/canvas.tsx+++ b/src/pages/editor-page/canvas/canvas.tsx@@ -123,7 +123,6 @@ export const Canvas: React.FC<CanvasProps> = ({ initialTables }) => {removeRelationships,removeDependencies,getField,- getTable,databaseType,filteredSchemas,events,@@ -338,23 +337,8 @@ export const Canvas: React.FC<CanvasProps> = ({ initialTables }) => {BOTTOM_SOURCE_HANDLE_ID_PREFIX)) {- const tableOne = getTable(params.source);- const tableTwo = getTable(params.target);-- if (!tableOne || !tableTwo) {- return;- }-- let tableId;- let dependentTableId;-- if (tableOne.isMaterializedView || tableOne.isView) {- tableId = tableTwo.id;- dependentTableId = tableOne.id;- } else {- tableId = tableOne.id;- dependentTableId = tableTwo.id;- }+ const tableId = params.target;+ const dependentTableId = params.source;createDependency({tableId,@@ -398,14 +382,7 @@ export const Canvas: React.FC<CanvasProps> = ({ initialTables }) => {targetFieldId,});},- [- createRelationship,- createDependency,- getField,- getTable,- toast,- databaseType,- ]+ [createRelationship, createDependency, getField, toast, databaseType]);const onEdgesChangeHandler: OnEdgesChange<EdgeType> = useCallback(diff --git a/src/pages/editor-page/canvas/table-node/table-node-dependency-indicator.tsx b/src/pages/editor-page/canvas/table-node/table-node-dependency-indicator.tsxindex 9b664160..02815a33 100644--- a/src/pages/editor-page/canvas/table-node/table-node-dependency-indicator.tsx+++ b/src/pages/editor-page/canvas/table-node/table-node-dependency-indicator.tsx@@ -19,43 +19,22 @@ export interface TableNodeDependencyIndicatorProps {export const TableNodeDependencyIndicator: React.FC<TableNodeDependencyIndicatorProps> =React.memo(({ table, focused }) => {- const { getTable, dependencies } = useChartDB();+ const { dependencies } = useChartDB();const updateNodeInternals = useUpdateNodeInternals();const connection = useConnection();- const isTarget = useMemo(() => {- if (!connection.inProgress) {- return false;- }-- const sourceTable = connection.fromNode?.id- ? getTable(connection.fromNode.id)- : null;- if (!sourceTable) {- return false;- }-- const isSourceTableView =- sourceTable.isView || sourceTable.isMaterializedView;- const isTableView = table.isView || table.isMaterializedView;- return (- ((isSourceTableView && !isTableView) ||- (!isSourceTableView && isTableView)) &&+ const isTarget = useMemo(+ () =>+ connection.inProgress &&connection.fromNode.id !== table.id &&(connection.fromHandle.id?.startsWith(TOP_SOURCE_HANDLE_ID_PREFIX) ||connection.fromHandle.id?.startsWith(BOTTOM_SOURCE_HANDLE_ID_PREFIX- ))- );- }, [- connection,- table.id,- getTable,- table.isMaterializedView,- table.isView,- ]);+ )),+ [connection, table.id]+ );const numberOfEdgesToTable = useMemo(() =>@@ -78,12 +57,14 @@ export const TableNodeDependencyIndicator: React.FC<TableNodeDependencyIndicatorreturn (<>- <Handle- id={`${TOP_SOURCE_HANDLE_ID_PREFIX}${table.id}`}- className={`!h-4 !w-4 !border-2 !bg-pink-600 ${!focused ? '!invisible' : ''}`}- position={Position.Top}- type="source"- />+ {table.isView || table.isMaterializedView ? (+ <Handle+ id={`${TOP_SOURCE_HANDLE_ID_PREFIX}${table.id}`}+ className={`!h-4 !w-4 !border-2 !bg-pink-600 ${!focused ? '!invisible' : ''}`}+ position={Position.Top}+ type="source"+ />+ ) : null}{Array.from({ length: numberOfEdgesToTable },(_, index) => index