Database diagrams editor that allows you to visualize and design your DB with a single query.
TypeScript databasedbdb-migrationeditorerdmariadbmssqlmysqlpostgresqlreactreact-flowschema-migrationssqlsqlitetypescriptvisualizationxyflow
expand and shrink table
Guy Ben-Aharon24798ec7b4e4
diff --git a/src/index.css b/src/index.cssindex 7ae7a440..8c7a396b 100644--- a/src/index.css+++ b/src/index.css@@ -6,4 +6,9 @@.react-flow.canvas-cursor-default .react-flow__pane {@apply cursor-default;}++ .react-flow.nodes-animated .react-flow__node {+ @apply transition-all;+ @apply duration-300;+ }}diff --git a/src/pages/editor-page/canvas/canvas.tsx b/src/pages/editor-page/canvas/canvas.tsxindex 393bca94..6bf27787 100644--- a/src/pages/editor-page/canvas/canvas.tsx+++ b/src/pages/editor-page/canvas/canvas.tsx@@ -240,7 +240,7 @@ export const Canvas: React.FC<CanvasProps> = () => {return (<div className="flex h-full"><ReactFlow- className="canvas-cursor-default"+ className="canvas-cursor-default nodes-animated"nodes={nodes}edges={edges}onNodesChange={onNodesChangeHandler}diff --git a/src/pages/editor-page/canvas/table-node.tsx b/src/pages/editor-page/canvas/table-node.tsxindex 551e83f4..8c71b103 100644--- a/src/pages/editor-page/canvas/table-node.tsx+++ b/src/pages/editor-page/canvas/table-node.tsx@@ -1,11 +1,17 @@-import React from 'react';+import React, { useCallback } from 'react';import { NodeProps, Node, NodeResizer } from '@xyflow/react';import { Button } from '@/components/button/button';-import { Pencil, Table2 } from 'lucide-react';+import {+ ChevronsLeftRight,+ ChevronsRightLeft,+ Pencil,+ Table2,+} from 'lucide-react';import { Label } from '@/components/label/label';import { DBTable } from '@/lib/domain/db-table';import { TableNodeField } from './table-node-field';import { useLayout } from '@/hooks/use-layout';+import { useChartDB } from '@/hooks/use-chartdb';export type TableNodeType = Node<{@@ -14,12 +20,16 @@ export type TableNodeType = Node<'table'>;+const MAX_TABLE_SIZE = 600;+const MIN_TABLE_SIZE = 224;+export const TableNode: React.FC<NodeProps<TableNodeType>> = ({selected,dragging,id,data: { table },}) => {+ const { updateTable } = useChartDB();const { openTableFromSidebar, selectSidebarSection } = useLayout();const focused = !!selected && !dragging;@@ -28,6 +38,18 @@ export const TableNode: React.FC<NodeProps<TableNodeType>> = ({openTableFromSidebar(table.id);};+ const expandTable = useCallback(() => {+ updateTable(table.id, {+ width: MAX_TABLE_SIZE,+ });+ }, [table.id, updateTable]);++ const shrinkTable = useCallback(() => {+ updateTable(table.id, {+ width: MIN_TABLE_SIZE,+ });+ }, [table.id, updateTable]);+return (<divclassName={`flex flex-col w-full bg-slate-50 border-2 ${selected ? 'border-pink-600' : 'border-slate-500'} rounded-lg shadow-sm`}@@ -40,8 +62,8 @@ export const TableNode: React.FC<NodeProps<TableNodeType>> = ({<NodeResizerisVisible={focused}lineClassName="!border-none !w-2"- minWidth={224}- maxWidth={600}+ minWidth={MIN_TABLE_SIZE}+ maxWidth={MAX_TABLE_SIZE}shouldResize={(event) => event.dy === 0}handleClassName="!hidden"/>@@ -62,6 +84,21 @@ export const TableNode: React.FC<NodeProps<TableNodeType>> = ({><Pencil className="h-4 w-4" /></Button>+ <Button+ variant="ghost"+ className="hover:bg-primary-foreground p-0 w-6 h-6 text-slate-500 hover:text-slate-700"+ onClick={+ table.width !== MAX_TABLE_SIZE+ ? expandTable+ : shrinkTable+ }+ >+ {table.width !== MAX_TABLE_SIZE ? (+ <ChevronsLeftRight className="h-4 w-4" />+ ) : (+ <ChevronsRightLeft className="h-4 w-4" />+ )}+ </Button></div></div>{table.fields.map((field) => (