Skip to content

Commit 024dbdd

Browse files
committed
feat(visualizer): improve default layout with dagrejs
Improve default layout with dagrejs
1 parent 9d56df5 commit 024dbdd

File tree

13 files changed

+72
-80
lines changed

13 files changed

+72
-80
lines changed

packages/extension-shared/src/hooks/schema.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ export const useSchema = (): {
2323

2424
if (message.key !== schemaKey) {
2525
// update stores
26-
tableCoordsStore.switchTo(message.key, message.payload.tables);
26+
tableCoordsStore.switchTo(
27+
message.key,
28+
message.payload.tables,
29+
message.payload.refs,
30+
);
2731
stageStateStore.switchTo(message.key);
2832
detailLevelStore.switchTo(message.key);
2933

packages/json-table-schema-visualizer/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"main": "index.js",
55
"license": "MIT",
66
"dependencies": {
7+
"@dagrejs/dagre": "^1.1.2",
78
"eventemitter3": "^5.0.1",
89
"konva": "^9.3.6",
910
"lucide-react": "^0.365.0",

packages/json-table-schema-visualizer/src/components/DiagramViewer/DiagramViewer.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const DiagramViewerStory: Story = {
3333
},
3434
decorators: [
3535
(Story) => {
36-
tableCoordsStore.resetPositions(tables);
36+
tableCoordsStore.resetPositions(tables, exampleData.refs);
3737

3838
return <Story />;
3939
},

packages/json-table-schema-visualizer/src/components/DiagramViewer/DiagramViewer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const DiagramViewer = ({ refs, tables, enums }: DiagramViewerProps) => {
2727

2828
return (
2929
<TableLevelDetailProvider>
30-
<TablesPositionsProvider tables={tables}>
30+
<TablesPositionsProvider tables={tables} refs={refs}>
3131
<MainProviders tables={tables} enums={enums}>
3232
<DiagramWrapper>
3333
<RelationsConnections refs={refs} />

packages/json-table-schema-visualizer/src/components/DiagramViewer/DiagramWrapper.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const DiagramWrapperWrapper: Story = {
2424
},
2525
decorators: [
2626
(Story) => (
27-
<TablesPositionsProvider tables={[]}>
27+
<TablesPositionsProvider tables={[]} refs={[]}>
2828
<Story />
2929
</TablesPositionsProvider>
3030
),

packages/json-table-schema-visualizer/src/components/RelationConnection/RelationConnection.stories.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ type Story = StoryObj<typeof RelationConnection>;
1919

2020
export const RelationConnectionStory: Story = {
2121
render: (props) => (
22-
<TablesPositionsProvider tables={exampleData.tables}>
22+
<TablesPositionsProvider
23+
tables={exampleData.tables}
24+
refs={exampleData.refs}
25+
>
2326
<MainProviders enums={exampleData.enums} tables={exampleData.tables}>
2427
<RelationConnection {...props} />
2528

packages/json-table-schema-visualizer/src/components/Table.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type Story = StoryObj<typeof Table>;
1717

1818
export const TableStory: Story = {
1919
render: (props) => (
20-
<TablesPositionsProvider tables={[]}>
20+
<TablesPositionsProvider tables={[]} refs={[]}>
2121
<MainProviders enums={exampleData.enums} tables={exampleData.tables}>
2222
<Table {...props} />
2323
</MainProviders>

packages/json-table-schema-visualizer/src/components/Toolbar/AutoArrage/AutoArrangeTables.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const AutoArrangeTableButtonStory: Story = {
1717
render: () => <AutoArrangeTableButton />,
1818
decorators: [
1919
(Story) => (
20-
<TablesPositionsProvider tables={[]}>
20+
<TablesPositionsProvider tables={[]} refs={[]}>
2121
<Story />
2222
</TablesPositionsProvider>
2323
),

packages/json-table-schema-visualizer/src/components/Toolbar/Toolbar.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const ToolbarStory: Story = {
1818
decorators: [
1919
(Story) => (
2020
<div className="py-32">
21-
<TablesPositionsProvider tables={[]}>
21+
<TablesPositionsProvider tables={[]} refs={[]}>
2222
<Story />
2323
</TablesPositionsProvider>
2424
</div>

packages/json-table-schema-visualizer/src/providers/TablesPositionsProvider.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createContext, useMemo, type PropsWithChildren } from "react";
2-
import { type JSONTableTable } from "shared/types/tableSchema";
32

3+
import type { JSONTableRef, JSONTableTable } from "shared/types/tableSchema";
44
import type { TablesPositionsContextValue } from "@/types/dimension";
55

66
import { tableCoordsStore } from "@/stores/tableCoords";
@@ -10,14 +10,16 @@ export const TablesPositionsContext =
1010

1111
interface TablesPositionsProviderProps extends PropsWithChildren {
1212
tables: JSONTableTable[];
13+
refs: JSONTableRef[];
1314
}
1415

1516
const TablesPositionsProvider = ({
1617
tables,
18+
refs,
1719
children,
1820
}: TablesPositionsProviderProps) => {
1921
const resetPositions = () => {
20-
tableCoordsStore.resetPositions(tables);
22+
tableCoordsStore.resetPositions(tables, refs);
2123
};
2224

2325
const contextValue = useMemo(() => ({ resetPositions }), [resetPositions]);

0 commit comments

Comments
 (0)