Skip to content

Commit bd20293

Browse files
authored
Merge pull request #23 from oslabs-beta/Reactflow
Make handle placement dynamic
2 parents a2e0835 + 8e90c75 commit bd20293

File tree

3 files changed

+31
-19
lines changed

3 files changed

+31
-19
lines changed

src/components/ReactFlow/TableNode.jsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,50 @@ import useSettingsStore from '../../store/settingsStore';
77

88
export default function TableNode({ data }) {
99
const tableName = data.table[0];
10+
1011
// columnData is an array of objects with each column in the table as an element
1112
const columnData = Object.values(data.table[1]);
1213
const [tableColumns, setTableColumns] = useState(columnData);
1314
const { setInputModalState } = useSettingsStore((state) => state);
15+
1416
// function to generate handles on the table by iterating through all
1517
// schema edges to match source and target handles of edges to handle id
1618
const tableHandles = [];
1719
for (let i = 0; i < data.edges.length; i++) {
1820
if (data.edges[i].source === tableName) {
21+
//make handle placement dynamic, we need to know the row of our source
22+
let rowNumberSource = rowData.findIndex(obj => obj.Name === data.edges[i].sourceHandle) + 1;
23+
if (rowNumberSource === 0) rowNumberSource = 1;
24+
console.log('rowNumberSource', rowNumberSource)
25+
console.log('data.edges[i].sourceHandle', data.edges[i].sourceHandle);
1926
tableHandles.push(
2027
<Handle
2128
key={`${data.edges[i]}-source-${[i]}`}
2229
type="source"
2330
position={Position.Right}
2431
id={data.edges[i].sourceHandle}
25-
style={{ bottom: 9, top: 'auto' }}
32+
style={{ background: 'transparent',
33+
top: 96 + rowNumberSource * 21,
34+
bottom: 'auto'}}
2635
/>
2736
);
2837
}
2938
if (data.edges[i].target === tableName) {
39+
//make handle placement dynamic, we need to know the row of our target
40+
let rowNumberTarget = rowData.findIndex(obj => obj.Name === data.edges[i].targetHandle) + 1;
41+
if (rowNumberTarget === 0) rowNumberTarget = 1;
42+
console.log('rowNumberTarget', rowNumberTarget)
43+
console.log('data.edges[i].targetHandle', data.edges[i].targetHandle);
3044
tableHandles.push(
3145
<Handle
3246
key={`${data.edges[i]}-target-${[i]}`}
3347
type="target"
3448
position={Position.Left}
3549
id={data.edges[i].targetHandle}
36-
style={{ bottom: 'auto', top: 113 }}
50+
style={{
51+
background: 'transparent',
52+
top: 96 + rowNumberTarget * 21,
53+
bottom: 'auto'}}
3754
/>
3855
);
3956
}

src/components/ReactFlow/createEdges.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ export default function createEdges(schemaObject: SchemaStore) {
3636
label: `${row.References[0].ReferencesPropertyName}-to-${row.References[0].PrimaryKeyName}`,
3737
style: {
3838
strokeWidth: 2,
39-
stroke: '#FF0072',
39+
stroke: '#085c84',
4040
},
4141
markerEnd: {
4242
type: 'arrowclosed',
4343
orient: 'auto',
4444
width: 20,
4545
height: 20,
46-
color: '#FF0072',
46+
color: '#085c84',
4747
},
4848
});
4949
}

src/components/ReactFlow/createNodes.ts

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,17 @@ type TableTuple = [TableKey: string, ColumnData: { [ColumnName: string]: ColumnS
1515
//hard-coded xy positioning of each node in the canvas
1616
export default function createNodes(schemaObject: SchemaStore, edges: Edge[]): Node[] {
1717
const nodePositions = [
18+
{ x: 1000, y: 400 },
19+
{ x: 1000, y: 0 },
20+
{ x: 0, y: 600 },
1821
{ x: 0, y: 0 },
19-
{ x: 500, y: 0 },
20-
{ x: 0, y: 350 },
21-
{ x: 500, y: 350 },
22-
{ x: 0, y: 700 },
23-
{ x: 500, y: 700 },
22+
{ x: 2500, y: 200 },
23+
{ x: 0, y: 200 },
24+
{ x: 2000, y: 800 },
25+
{ x: 0, y: 400 },
26+
{ x: 0, y: 800 },
27+
{ x: 1000, y: 800 },
2428
{ x: 0, y: 1050 },
25-
{ x: 500, y: 1050 },
26-
{ x: 0, y: 1400 },
27-
{ x: 500, y: 1400 },
28-
{ x: 0, y: 1750 },
29-
{ x: 500, y: 1750 },
30-
{ x: 0, y: 2100 },
31-
{ x: 500, y: 2100 },
32-
{ x: 0, y: 2450 },
33-
{ x: 500, y: 2450 },
34-
{ x: 0, y: 2450 },
3529
];
3630
// renders each table on the React Flow canvas
3731
const nodes: Node[] = [];
@@ -41,6 +35,7 @@ export default function createNodes(schemaObject: SchemaStore, edges: Edge[]): N
4135
nodes.push({
4236
id: tableKey,
4337
type: 'table',
38+
4439
position: nodePositions[i],
4540
// position: {x: Math.random() * window.innerWidth, y: Math.random() * window.innerWidth},
4641
data: { table: [tableKey, columnData], edges },

0 commit comments

Comments
 (0)