Skip to content

Commit cc88c4e

Browse files
committed
Resize and edit features
1 parent c15090a commit cc88c4e

File tree

14 files changed

+325
-55
lines changed

14 files changed

+325
-55
lines changed

server/db/models.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class Flow(Base):
3636
name = sql.Column(sql.String, nullable=False)
3737
description = sql.Column(sql.Text, nullable=True)
3838
default = sql.Column(sql.Boolean, default=False)
39+
position = sql.Column(sql.JSON, nullable=True)
3940
created_at = sql.Column(sql.DateTime, default=datetime.now(timezone.utc))
4041
updated_at = sql.Column(sql.DateTime, default=datetime.now(timezone.utc), onupdate=lambda: datetime.now(timezone.utc))
4142

@@ -51,7 +52,7 @@ def validate_name(self, key, name):
5152
return name
5253

5354
def __repr__(self):
54-
return f'<Flow {self.id} {self.name} {self.description} {self.default} {self.created_at} {self.updated_at} {self.workspace_id}>'
55+
return f'<Flow {self.id} {self.name} {self.description} {self.default} {self.position} {self.created_at} {self.updated_at} {self.workspace_id}>'
5556

5657

5758
class NodeType(Base):
@@ -166,10 +167,11 @@ def __repr__(self):
166167
Session = sessionmaker(bind=engine)
167168
session = Session()
168169

169-
# Add column to the workspace table
170-
schema_update_handler(session.execute, text('ALTER TABLE workspaces ADD COLUMN icon TEXT;'))
170+
# Schema updates
171+
# schema_update_handler(session.execute, text('ALTER TABLE workspaces ADD COLUMN icon TEXT;'))
171172
# schema_update_handler(session.execute, text('ALTER TABLE node_types ADD COLUMN fields JSON;'))
172173
# schema_update_handler(session.execute, text('ALTER TABLE edge_types ADD COLUMN fields JSON;'))
174+
# schema_update_handler(session.execute, text('ALTER TABLE flows ADD COLUMN position JSON;'))
173175

174176
# Was to try to implement automatic schema updates
175177
metadata = MetaData()

server/gql/functions.gql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type Mutation {
4747

4848
# Flow
4949
createFlow(name: String!, description: String, workspace_id: ID!): FlowResult!
50-
updateFlow(id: ID!, name: String, description: String, workspace_id: ID): FlowResult!
50+
updateFlow(id: ID!, name: String, description: String, workspace_id: ID, position: JSON): FlowResult!
5151
deleteFlow(id: ID!): FlowResult!
5252

5353
# Node Type

server/gql/schema.gql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type Flow {
3838
name: String!
3939
description: String
4040
default: Boolean!
41+
position: JSON
4142
workspace_id: ID!
4243
created_at: String!
4344
updated_at: String!

server/resolvers.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,12 @@ def createFlow(_, info, **kwargs):
9090
@response_handler
9191
def updateFlow(_, info, **kwargs):
9292
flow = session.query(Flow).filter_by(id=kwargs.get('id')).first()
93-
flow.update(**kwargs)
93+
if position := kwargs.get('position', None):
94+
kwargs['position'] = loads(unquote(position))
95+
96+
for key, value in kwargs.items():
97+
setattr(flow, key, value)
98+
9499
session.commit()
95100
return {'flow': flow}
96101

src/custom/card.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
import "./custom.css";
2-
import { Handle, Position } from 'reactflow';
2+
import { memo } from "react";
3+
import { Handle, Position, NodeResizer } from 'reactflow';
34

45

5-
export function CardNode({ data }: { data: any; }) {
6+
function CardNode({ data, selected }: { data: any, selected: any }) {
67
return (
78
<>
8-
<div className="card">
9+
<NodeResizer
10+
color="#ff0071"
11+
isVisible={selected}
12+
minWidth={100}
13+
minHeight={100}
14+
/>
15+
<div className="source-node">
916
<div className="card-title">
1017
{data.title}
1118
</div>
@@ -18,3 +25,5 @@ export function CardNode({ data }: { data: any; }) {
1825
</>
1926
);
2027
}
28+
29+
export default memo(CardNode);

src/custom/custom.css

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,50 @@
1-
.card {
2-
border: 1px solid #ededed;
1+
/* .react_flow___source-node { */
2+
.react_flow___node {
3+
border: 1px solid #495057;
34
border-radius: 10px;
4-
max-width: 350px;
5+
background-color: rgba(255, 255, 255, 0.412);
6+
width: 100%;
7+
}
8+
9+
.react-flow__handle {
10+
padding: 3px !important;
11+
}
12+
13+
div.react-flow__node.react-flow__node-source, div.react-flow__node.react-flow__node-card {
14+
border: 1px solid #495057;
15+
border-radius: 10px;
16+
background-color: rgba(255, 255, 255, 1);
17+
}
518

19+
div.react-flow__resize-control {
20+
border-color: #495057 !important;
21+
border-width: 0.5px !important;
22+
}
23+
24+
div.react-flow__resize-control.handle {
25+
background-color: #495057 !important;
26+
width: 8px;
27+
height: 8px;
28+
}
29+
30+
.source-node {
31+
height: inherit;
632
}
733

834
.card-title {
9-
background-color: rgba(255, 255, 255, 0.412);
10-
/* background-color: red; */
35+
border-bottom: 1px solid #ededed;
1136
font-weight: 600;
1237
color: #000;
13-
border-bottom: 1px solid #ededed;
1438
padding: 5px 15px;
15-
border-radius: 10px 10px 0 0;
1639
}
1740

1841
.card-title p {
1942
margin: 0;
2043
}
2144

2245
.card-body {
23-
background-color: white;
2446
padding: 15px 15px;
25-
border-radius: 0 0 10px 10px;
47+
border: none;
2648
}
2749

2850
.card-body p {

src/custom/default.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import "./custom.css";
2+
import { memo } from "react";
3+
import { Handle, Position, NodeResizer } from 'reactflow';
4+
5+
6+
function Default({ data, selected }: { data: any, selected: any }) {
7+
return (
8+
<>
9+
<NodeResizer
10+
color="#ff0071"
11+
isVisible={selected}
12+
minWidth={150}
13+
minHeight={40}
14+
/>
15+
<div className="source-node">
16+
{data.label}
17+
<Handle type="target" position={Position.Top} id="a" />
18+
<Handle type="source" position={Position.Bottom} id="b" />
19+
</div>
20+
</>
21+
);
22+
}
23+
24+
export default memo(Default);

src/custom/input.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import "./custom.css";
2+
import { memo } from "react";
3+
import { Handle, Position, NodeResizer } from 'reactflow';
4+
5+
6+
function Input({ data, selected }: { data: any, selected: any }) {
7+
return (
8+
<>
9+
<NodeResizer
10+
color="#ff0071"
11+
isVisible={selected}
12+
minWidth={150}
13+
minHeight={40}
14+
/>
15+
<div className="source-node">
16+
{data.label}
17+
<Handle type="source" position={Position.Bottom} id="a" />
18+
</div>
19+
</>
20+
);
21+
}
22+
23+
export default memo(Input);

src/custom/output.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import "./custom.css";
2+
import { memo } from "react";
3+
import { Handle, Position, NodeResizer } from 'reactflow';
4+
5+
6+
function Output({ data, selected }: { data: any, selected: any }) {
7+
return (
8+
<>
9+
<NodeResizer
10+
color="#ff0071"
11+
isVisible={selected}
12+
minWidth={150}
13+
minHeight={40}
14+
/>
15+
<div className="source-node">
16+
{data.label}
17+
<Handle type="target" position={Position.Top} id="a" />
18+
</div>
19+
</>
20+
);
21+
}
22+
23+
export default memo(Output);

src/custom/source.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
import "./custom.css";
2-
import { Handle, Position } from 'reactflow';
2+
import { memo } from "react";
3+
import { Handle, Position, NodeResizer } from 'reactflow';
34

45

5-
export function Source({ data }: { data: any }) {
6+
function Source({ data, selected }: { data: any, selected: any }) {
7+
68
return (
79
<>
8-
<div className="card">
10+
<NodeResizer
11+
color="#ff0071"
12+
isVisible={selected}
13+
minWidth={100}
14+
minHeight={100}
15+
/>
16+
<div className="source-node">
917
<div className="card-title">
1018
{data.title}
1119
</div>
@@ -20,3 +28,5 @@ export function Source({ data }: { data: any }) {
2028
</>
2129
);
2230
}
31+
32+
export default memo(Source);

0 commit comments

Comments
 (0)