Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Transformerlab App
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
TransformerLab
Transformerlab App
Commits
e0174658
Commit
e0174658
authored
3 weeks ago
by
ali asaria
Browse files
Options
Downloads
Patches
Plain Diff
You can now move nodes
parent
90c68497
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/renderer/components/Experiment/Workflows/WorkflowCanvas.tsx
+26
-7
26 additions, 7 deletions
...nderer/components/Experiment/Workflows/WorkflowCanvas.tsx
with
26 additions
and
7 deletions
src/renderer/components/Experiment/Workflows/WorkflowCanvas.tsx
+
26
−
7
View file @
e0174658
...
@@ -5,6 +5,8 @@ import {
...
@@ -5,6 +5,8 @@ import {
Controls
,
Controls
,
ReactFlow
,
ReactFlow
,
ReactFlowProvider
,
ReactFlowProvider
,
useEdgesState
,
useNodesState
,
useReactFlow
,
useReactFlow
,
}
from
'
@xyflow/react
'
;
}
from
'
@xyflow/react
'
;
import
{
PlusCircleIcon
}
from
'
lucide-react
'
;
import
{
PlusCircleIcon
}
from
'
lucide-react
'
;
...
@@ -15,7 +17,7 @@ import { mutate } from 'swr';
...
@@ -15,7 +17,7 @@ import { mutate } from 'swr';
const
nodeTypes
=
{
customNode
:
CustomNode
};
const
nodeTypes
=
{
customNode
:
CustomNode
};
function
generateNodes
(
workflow
:
any
)
{
function
generateNodes
(
workflow
:
any
)
:
any
[]
{
const
workflowConfig
=
JSON
.
parse
(
workflow
?.
config
);
const
workflowConfig
=
JSON
.
parse
(
workflow
?.
config
);
if
(
workflowConfig
.
nodes
.
length
==
0
)
{
if
(
workflowConfig
.
nodes
.
length
==
0
)
{
...
@@ -26,11 +28,11 @@ function generateNodes(workflow: any) {
...
@@ -26,11 +28,11 @@ function generateNodes(workflow: any) {
let
currentTask
=
workflowConfig
.
nodes
[
0
].
id
;
let
currentTask
=
workflowConfig
.
nodes
[
0
].
id
;
let
position
=
0
;
let
position
=
0
;
console
.
log
(
workflowConfig
);
//
console.log(workflowConfig);
for
(
let
i
=
0
;
i
<
workflowConfig
.
nodes
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
workflowConfig
.
nodes
.
length
;
i
++
)
{
const
node
=
workflowConfig
.
nodes
[
i
];
const
node
=
workflowConfig
.
nodes
[
i
];
console
.
log
(
node
);
//
console.log(node);
const
data
=
{
const
data
=
{
id
:
node
?.
id
,
id
:
node
?.
id
,
label
:
node
.
name
,
label
:
node
.
name
,
...
@@ -62,7 +64,7 @@ function generateEdges(workflow: any) {
...
@@ -62,7 +64,7 @@ function generateEdges(workflow: any) {
let
currentTask
=
workflowConfig
.
nodes
[
0
].
id
;
let
currentTask
=
workflowConfig
.
nodes
[
0
].
id
;
let
ids
=
workflowConfig
.
nodes
[
0
].
id
;
let
ids
=
workflowConfig
.
nodes
[
0
].
id
;
console
.
log
(
workflowConfig
);
//
console.log(workflowConfig);
for
(
let
i
=
0
;
i
<
workflowConfig
.
nodes
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
workflowConfig
.
nodes
.
length
;
i
++
)
{
const
currentNode
=
workflowConfig
.
nodes
[
i
];
const
currentNode
=
workflowConfig
.
nodes
[
i
];
...
@@ -87,9 +89,24 @@ const Flow = ({
...
@@ -87,9 +89,24 @@ const Flow = ({
setNewNodeModalOpen
=
(
x
)
=>
{},
setNewNodeModalOpen
=
(
x
)
=>
{},
mutateWorkflows
,
mutateWorkflows
,
})
=>
{
})
=>
{
const
[
nodes
,
setNodes
,
onNodesChange
]
=
useNodesState
(
generateNodes
(
selectedWorkflow
)
);
const
[
edges
,
setEdges
,
onEdgesChange
]
=
useEdgesState
(
generateEdges
(
selectedWorkflow
)
);
const
reactFlowInstance
=
useReactFlow
();
const
reactFlowInstance
=
useReactFlow
();
const
workflowId
=
selectedWorkflow
?.
id
;
const
workflowId
=
selectedWorkflow
?.
id
;
// The workflow isn't updating when I switch workflows
// so I do this hack:
useEffect
(()
=>
{
setNodes
(
generateNodes
(
selectedWorkflow
));
setEdges
(
generateEdges
(
selectedWorkflow
));
},
[
selectedWorkflow
]);
// Use fitView after the component mounts
// Use fitView after the component mounts
useEffect
(()
=>
{
useEffect
(()
=>
{
// Wait a moment to ensure the flow is rendered before fitting
// Wait a moment to ensure the flow is rendered before fitting
...
@@ -106,8 +123,10 @@ const Flow = ({
...
@@ -106,8 +123,10 @@ const Flow = ({
return
(
return
(
<
ReactFlow
<
ReactFlow
nodes
=
{
generateNodes
(
selectedWorkflow
)
}
nodes
=
{
nodes
}
edges
=
{
generateEdges
(
selectedWorkflow
)
}
edges
=
{
edges
}
onNodesChange
=
{
onNodesChange
}
onEdgesChange
=
{
onEdgesChange
}
nodeTypes
=
{
nodeTypes
}
nodeTypes
=
{
nodeTypes
}
fitView
fitView
zoomOnScroll
=
{
false
}
zoomOnScroll
=
{
false
}
...
@@ -116,7 +135,7 @@ const Flow = ({
...
@@ -116,7 +135,7 @@ const Flow = ({
panOnScroll
=
{
false
}
panOnScroll
=
{
false
}
onDelete
=
{
async
({
nodes
,
edges
})
=>
{
onDelete
=
{
async
({
nodes
,
edges
})
=>
{
for
(
const
node
of
nodes
)
{
for
(
const
node
of
nodes
)
{
console
.
log
(
'
delete node:
'
+
node
?.
id
);
//
console.log('delete node: ' + node?.id);
await
fetch
(
await
fetch
(
chatAPI
.
Endpoints
.
Workflows
.
DeleteNode
(
workflowId
,
node
?.
id
)
chatAPI
.
Endpoints
.
Workflows
.
DeleteNode
(
workflowId
,
node
?.
id
)
);
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment