This repository has been archived by the owner on Dec 16, 2024. It is now read-only.
generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Module nodes should be draggable now <img width="954" alt="Screenshot 2023-05-12 at 12 22 20 AM" src="https://github.com/TBD54566975/ftl/assets/51647/f377cbb8-a923-4c61-9c49-9b21a7e3618a"> <img width="954" alt="Screenshot 2023-05-12 at 12 22 31 AM" src="https://github.com/TBD54566975/ftl/assets/51647/96189f76-30d2-4959-aaac-e1719e9e7096">
- Loading branch information
1 parent
0c50b11
commit c75c0cc
Showing
4 changed files
with
123 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export function GroupNode({ data }) { | ||
return ( | ||
<> | ||
<div className="h-full bg-indigo-800 rounded-md"> | ||
<div className="flex justify-center text-xs text-gray-100 pt-2">{data.title}</div> | ||
</div> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Handle, Position } from 'reactflow' | ||
|
||
export function VerbNode({ data }) { | ||
return ( | ||
<> | ||
<Handle | ||
type="target" | ||
position={Position.Top} | ||
style={{ border: 0 }} | ||
className="bg-indigo-600" | ||
isConnectable={true} | ||
/> | ||
|
||
<div className="grid h-full w-full bg-indigo-600 rounded-md"> | ||
<div className="place-self-center text-xs text-gray-100">{data.title}</div> | ||
</div> | ||
|
||
<Handle | ||
type="source" | ||
position={Position.Bottom} | ||
style={{ border: 0 }} | ||
className="bg-indigo-600" | ||
isConnectable={true} | ||
/> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { Edge, Node } from 'reactflow' | ||
import { PullSchemaResponse } from '../../protos/xyz/block/ftl/v1/ftl_pb' | ||
import { MetadataCalls } from '../../protos/xyz/block/ftl/v1/schema/schema_pb' | ||
|
||
const groupWidth = 200 | ||
|
||
export function layoutNodes(schema: PullSchemaResponse[]) { | ||
let x = 0 | ||
const nodes: Node[] = [] | ||
const edges: Edge[] = [] | ||
schema.forEach(module => { | ||
const verbs = module.schema?.decls.filter(decl => decl.value.case === 'verb') | ||
nodes.push({ | ||
id: module.schema?.name ?? '', | ||
position: { x: x, y: 0 }, | ||
data: { title: module.schema?.name }, | ||
type: 'groupNode', | ||
style: { | ||
width: groupWidth, | ||
height: (verbs?.length ?? 1) * 50 + 50, | ||
zIndex: -1, | ||
}, | ||
}) | ||
let y = 40 | ||
module.schema?.decls | ||
.filter(decl => decl.value.case === 'verb') | ||
.forEach(verb => { | ||
const calls = verb?.value.value?.metadata | ||
.filter(meta => meta.value.case === 'calls') | ||
.map(meta => meta.value.value as MetadataCalls) | ||
|
||
nodes.push({ | ||
id: `${module.schema?.name}-${verb.value.value?.name}`, | ||
position: { x: 20, y: y }, | ||
connectable: false, | ||
data: { title: verb.value.value?.name }, | ||
type: 'verbNode', | ||
parentNode: module.schema?.name, | ||
style: { | ||
width: groupWidth - 40, | ||
height: 40, | ||
}, | ||
}) | ||
|
||
calls?.map(call => | ||
call.calls.forEach(call => { | ||
edges.push({ | ||
id: `${module.schema?.name}-${verb.value.value?.name}-${call.module}-${call.name}`, | ||
source: `${module.schema?.name}-${verb.value.value?.name}`, | ||
target: `${call.module}-${call.name}`, | ||
style: { stroke: 'rgb(251 113 133)' }, | ||
animated: true, | ||
}) | ||
call.name | ||
call.module | ||
}), | ||
) | ||
|
||
y += 50 | ||
}) | ||
x += 300 | ||
}) | ||
return { nodes, edges } | ||
} |