Skip to content

Commit

Permalink
Extracted edge config loading into a function
Browse files Browse the repository at this point in the history
  • Loading branch information
makaroni4 committed Jan 21, 2023
1 parent 35de8c8 commit 809c81a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
23 changes: 23 additions & 0 deletions src/Visualizer/helpers/loadEdgeConfigs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import fullTableName from "./fullTableName";

interface EdgeConfig {
source: string
sourceKey: string;
target: string;
targetKey: string;
relation: string;
sourcePosition?: string;
targetPosition?: string;
}

const loadEdgeConfigs = (edgeConfigs: EdgeConfig[]) => {
edgeConfigs.forEach(edgeConfig => {
const sourceTableName = fullTableName(edgeConfig.source);
const targetTableName = fullTableName(edgeConfig.target);

edgeConfig.source = sourceTableName;
edgeConfig.target = targetTableName;
});
}

export default loadEdgeConfigs;
11 changes: 3 additions & 8 deletions src/Visualizer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@ import edgeClassName from "./helpers/edgeClassName";
import edgeMarkerName from "./helpers/edgeMarkerName";
import calculateTargetPosition from "./helpers/calculateTargetPosition";
import calculateSourcePosition from "./helpers/calculateSourcePosition";
import loadEdgeConfigs from "./helpers/loadEdgeConfigs";

// this is important! You need to import the styles from the lib to make it work
import "reactflow/dist/style.css";
import "./Style";

loadEdgeConfigs(edgeConfigs);

interface Position {
x: number;
y: number;
Expand Down Expand Up @@ -82,14 +85,6 @@ tables.forEach(table => {
initialNodes.push(tableDefinition);
});

edgeConfigs.forEach(edgeConfig => {
const sourceTableName = fullTableName(edgeConfig.source);
const targetTableName = fullTableName(edgeConfig.target);

edgeConfig.source = sourceTableName;
edgeConfig.target = targetTableName;
})

function Flow() {
const store = useStoreApi();
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down

0 comments on commit 809c81a

Please sign in to comment.