Skip to content

Commit ebe9c73

Browse files
committed
use cmd + click shortcut to render complex node path
1 parent 12bc1ea commit ebe9c73

1 file changed

Lines changed: 59 additions & 36 deletions

File tree

src/components/molecules/flow/nodes/ComplexNode.js

Lines changed: 59 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import { getAllFlowTests } from 'stores/utils';
66
import useCollectionStore from 'stores/CollectionStore';
77
import Tippy from '@tippyjs/react';
88
import 'tippy.js/dist/tippy.css';
9+
import { useKeyPress } from 'reactflow';
10+
import { readFlowTest } from 'service/collection';
11+
import { toast } from 'react-toastify';
912

1013
// ToDo: Change standard select element(s) with headless list element
1114
const ComplexNode = ({ id, data }) => {
@@ -24,45 +27,65 @@ const ComplexNode = ({ id, data }) => {
2427
}
2528
}
2629

30+
const cmdPressed = useKeyPress('Meta'); // 'Meta' key for Cmd on Mac
31+
32+
const handleMouseClick = (event, relativePath) => {
33+
if (cmdPressed && event.type === 'click') {
34+
console.log('Cmd + Click action triggered ' + relativePath);
35+
if (relativePath && relativePath.trim() != '') {
36+
readFlowTest(ipcRenderer.join(collection.pathname, relativePath), collectionId)
37+
.then((result) => {
38+
console.log(`Read flowtest: path = ${relativePath}, collectionId = ${collectionId}`);
39+
})
40+
.catch((error) => {
41+
console.log(`Error reading flowtest: ${error}`);
42+
toast.error(`Error reading flowtest`);
43+
});
44+
}
45+
}
46+
};
47+
2748
return (
28-
<FlowNode
29-
title='Flow Node'
30-
handleLeft={true}
31-
handleLeftData={{ type: 'target' }}
32-
handleRight={true}
33-
handleRightData={{ type: 'source' }}
34-
>
35-
<div>
36-
<Tippy
37-
content={data.relativePath && data.relativePath !== '' ? data.relativePath : 'Select a flow'}
38-
placement='top'
39-
maxWidth='none'
40-
>
41-
<select
42-
onChange={(event) => {
43-
const value = event.target?.value;
44-
setFlowForComplexNode(id, value);
45-
}}
46-
name='flow'
47-
value={data.relativePath ? data.relativePath : ''}
48-
className='h-12 p-2 border rounded outline-none cursor-default bg-background-light max-w-48 border-cyan-950'
49+
<div onClick={(e) => handleMouseClick(e, data.relativePath)}>
50+
<FlowNode
51+
title='Flow Node'
52+
handleLeft={true}
53+
handleLeftData={{ type: 'target' }}
54+
handleRight={true}
55+
handleRightData={{ type: 'source' }}
56+
>
57+
<div>
58+
<Tippy
59+
content={data.relativePath && data.relativePath !== '' ? data.relativePath : 'Select a flow'}
60+
placement='top'
61+
maxWidth='none'
4962
>
50-
<option key='None' value=''>
51-
Select a flow
52-
</option>
53-
{flowTests.map((flowTestPath) => {
54-
return (
55-
<option key={flowTestPath} value={flowTestPath} className='overflow-scroll'>
56-
{flowTestPath}
57-
</option>
58-
);
59-
})}
60-
</select>
61-
</Tippy>
63+
<select
64+
onChange={(event) => {
65+
const value = event.target?.value;
66+
setFlowForComplexNode(id, value);
67+
}}
68+
name='flow'
69+
value={data.relativePath ? data.relativePath : ''}
70+
className='h-12 p-2 border rounded outline-none cursor-default bg-background-light max-w-48 border-cyan-950'
71+
>
72+
<option key='None' value=''>
73+
Select a flow
74+
</option>
75+
{flowTests.map((flowTestPath) => {
76+
return (
77+
<option key={flowTestPath} value={flowTestPath} className='overflow-scroll'>
78+
{flowTestPath}
79+
</option>
80+
);
81+
})}
82+
</select>
83+
</Tippy>
6284

63-
<p className='hidden'></p>
64-
</div>
65-
</FlowNode>
85+
<p className='hidden'></p>
86+
</div>
87+
</FlowNode>
88+
</div>
6689
);
6790
};
6891

0 commit comments

Comments
 (0)