Skip to content

Commit 31ea2be

Browse files
committed
x on edge should work, no self connecting node and * on unsaved files
1 parent 9108b2b commit 31ea2be

File tree

4 files changed

+43
-25
lines changed

4 files changed

+43
-25
lines changed

src/components/atoms/Tabs.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ import ConfirmActionModal from 'components/molecules/modals/ConfirmActionModal';
55
import { isEqual } from 'lodash';
66
import { OBJ_TYPES } from 'constants/Common';
77

8+
const tabUnsavedChanges = (tab) => {
9+
if (tab.type === OBJ_TYPES.flowtest && tab.flowDataDraft && !isEqual(tab.flowData, tab.flowDataDraft)) {
10+
return true;
11+
} else if (tab.type === OBJ_TYPES.environment && tab.variablesDraft && !isEqual(tab.variables, tab.variablesDraft)) {
12+
return true;
13+
} else {
14+
false;
15+
}
16+
};
17+
818
const Tabs = () => {
919
const tabs = useTabStore((state) => state.tabs);
1020
const setFocusTab = useTabStore((state) => state.setFocusTab);
@@ -28,18 +38,10 @@ const Tabs = () => {
2838
setClosingTabId(tab.id);
2939
setClosingCollectionId(tab.collectionId);
3040

31-
if (tab.type === OBJ_TYPES.flowtest) {
32-
if (tab.flowDataDraft && !isEqual(tab.flowData, tab.flowDataDraft)) {
33-
console.debug(`Confirm close for tabId: ${tab.id} : collectionId: ${tab.collectionId}`);
34-
setConfirmActionModalOpen(true);
35-
return;
36-
}
37-
} else if (tab.type === OBJ_TYPES.environment) {
38-
if (tab.variablesDraft && !isEqual(tab.variables, tab.variablesDraft)) {
39-
console.debug(`Confirm close for tabId: ${tab.id} : collectionId: ${tab.collectionId}`);
40-
setConfirmActionModalOpen(true);
41-
return;
42-
}
41+
if (tabUnsavedChanges(tab)) {
42+
console.debug(`Confirm close for tabId: ${tab.id} : collectionId: ${tab.collectionId}`);
43+
setConfirmActionModalOpen(true);
44+
return;
4345
}
4446
closeTab(tab.id, tab.collectionId);
4547
};
@@ -63,7 +65,10 @@ const Tabs = () => {
6365
data-id={tab.id}
6466
data-collection-id={tab.collectionId}
6567
>
66-
<a className='text-nowrap'>{tab.name}</a>
68+
<a className='text-nowrap'>
69+
{tabUnsavedChanges(tab) ? '*' : ''}
70+
{tab.name}
71+
</a>
6772
{/* close needs to be a separate clickable component other wise it gets confused with above */}
6873
<div
6974
className='flex items-center h-full px-2 hover:rounded hover:rounded-l-none hover:bg-slate-200'

src/components/molecules/flow/edges/ButtonEdge.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
import React from 'react';
22
import { BaseEdge, EdgeLabelRenderer, getSmoothStepPath } from 'reactflow';
3+
import useCanvasStore from 'stores/CanvasStore';
34

45
import './buttonedge.css';
56

6-
const onEdgeClick = (evt, id) => {
7-
evt.stopPropagation();
8-
alert(`remove ${id}`);
9-
};
10-
117
// eslint-disable-next-line react/prop-types
128
export default function CustomEdge({
139
id,
@@ -20,6 +16,8 @@ export default function CustomEdge({
2016
style = {},
2117
markerEnd,
2218
}) {
19+
const setEdges = useCanvasStore((state) => state.setEdges);
20+
2321
const [edgePath, labelX, labelY] = getSmoothStepPath({
2422
sourceX,
2523
sourceY,
@@ -44,7 +42,14 @@ export default function CustomEdge({
4442
}}
4543
className='nodrag nopan'
4644
>
47-
<button className='edgebutton' onClick={(event) => onEdgeClick(event, id)}>
45+
<button
46+
className='edgebutton'
47+
onClick={(evt) => {
48+
evt.stopPropagation();
49+
// alert(`remove ${id}`);
50+
setEdges(useCanvasStore.getState().edges.filter((e) => e.id !== id));
51+
}}
52+
>
4853
×
4954
</button>
5055
</div>

src/components/molecules/flow/index.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,26 +177,34 @@ const Flow = ({ collectionId }) => {
177177
);
178178

179179
const isValidConnection = (connection) => {
180-
let canConnect = true;
181180
// Only 1 outgoing edge from each (source, sourceHandle) is allowed
182181
// as we only support sequential graphs for now
183182
reactFlowInstance.getEdges().map((edge) => {
184183
if (connection.source === edge.source && connection.sourceHandle === edge.sourceHandle) {
185-
canConnect = false;
184+
return false;
186185
}
187186
});
188187

189-
// multiple incoming edges are only allowed for request nodes
190188
const nodes = reactFlowInstance.getNodes();
189+
190+
// self connecting edge not allowed
191+
const sourceNode = nodes.find((node) => node.id === connection.source).id;
192+
const targetNode = nodes.find((node) => node.id === connection.target).id;
193+
if (sourceNode === targetNode) {
194+
return false;
195+
}
196+
197+
// multiple incoming edges are only allowed for request nodes
191198
const nodeType = nodes.find((node) => node.id === connection.target).type;
192199
if (nodeType != 'requestNode') {
193200
reactFlowInstance.getEdges().map((edge) => {
194201
if (connection.target === edge.target) {
195-
canConnect = false;
202+
return false;
196203
}
197204
});
198205
}
199-
return canConnect;
206+
207+
return true;
200208
};
201209

202210
const onGraphComplete = (result, logs) => {

src/stores/TabStore.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const useTabStore = create((set, get) => ({
5050
const existingTab = get().tabs.find((t) => t.id === get().focusTabId);
5151
if (existingTab) {
5252
if (!existingTab.flowDataDraft) {
53-
existingTab.flowDataDraft = cloneDeep(existingTab.flowData);
53+
existingTab.flowDataDraft = existingTab.flowData ? cloneDeep(existingTab.flowData) : {};
5454
}
5555
existingTab.flowDataDraft.edges = edges;
5656
}

0 commit comments

Comments
 (0)