Skip to content

Commit 14db434

Browse files
committed
add shortcut keys for windows platform
1 parent 621041a commit 14db434

5 files changed

Lines changed: 43 additions & 25 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"eslint-plugin-import": "^2.29.1",
5858
"immer": "^10.0.4",
5959
"lodash": "^4.17.21",
60+
"mousetrap": "^1.6.5",
6061
"notistack": "^3.0.1",
6162
"postcss": "^8.4.35",
6263
"react": "^18.2.0",

pnpm-lock.yaml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/molecules/environment/index.js

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { BUTTON_TYPES, OBJ_TYPES } from 'constants/Common';
99
import EditEnvVariableModal from '../modals/EditEnvVariableModal';
1010
import { useKeyPress } from 'reactflow';
1111
import { saveHandle } from '../modals/SaveFlowModal';
12+
import Mousetrap from 'mousetrap';
1213

1314
const Env = ({ tab }) => {
1415
const variables = useEnvStore((state) => state.variables);
@@ -23,45 +24,50 @@ const Env = ({ tab }) => {
2324
const [editKey, setEditKey] = useState('');
2425
const [editValue, setEditValue] = useState('');
2526

26-
const cmdAndSPressed = useKeyPress(['Meta+s', 'Strg+s']);
27+
//const cmdAndSPressed = useKeyPress(['Meta+s', 'Strg+s']);
28+
// Bind Ctrl+S and Cmd+S
29+
Mousetrap.bind(['ctrl+s', 'command+s'], function (e) {
30+
e.preventDefault();
31+
saveHandle(tab);
32+
return false;
33+
});
2734

2835
return (
2936
<div className='p-4'>
30-
{cmdAndSPressed && saveHandle(tab)}
3137
<table className='w-full leading-normal'>
3238
<thead>
33-
<tr className='text-xs font-bold tracking-wider text-left uppercase bg-ghost-50 text-ghost-600'>
34-
<th className='p-5 border border-ghost-200 max-w-4'>S. No.</th>
35-
<th className='p-5 border border-ghost-200 '>Key</th>
36-
<th className='p-5 border border-ghost-200'>Value</th>
37-
<th className='p-5 border border-ghost-200 max-w-4'>Action</th>
39+
<tr className='bg-ghost-50 text-ghost-600 text-left text-xs font-bold uppercase tracking-wider'>
40+
<th className='border-ghost-200 max-w-4 border p-5'>S. No.</th>
41+
<th className='border-ghost-200 border p-5 '>Key</th>
42+
<th className='border-ghost-200 border p-5'>Value</th>
43+
<th className='border-ghost-200 max-w-4 border p-5'>Action</th>
3844
</tr>
3945
</thead>
4046
<tbody>
4147
{Object.entries(variables).map(([key, value], index) => (
42-
<tr key={index} className='text-sm border-b border-gray-200 text-ghost-700 hover:bg-ghost-50'>
43-
<td className='p-5 whitespace-no-wrap max-w-4'>{index + 1}</td>
44-
<td className='p-5 whitespace-no-wrap'>{key}</td>
45-
<td className='p-5 whitespace-no-wrap'>{value}</td>
46-
<td className='p-5 whitespace-no-wrap max-w-4'>
48+
<tr key={index} className='text-ghost-700 hover:bg-ghost-50 border-b border-gray-200 text-sm'>
49+
<td className='whitespace-no-wrap max-w-4 p-5'>{index + 1}</td>
50+
<td className='whitespace-no-wrap p-5'>{key}</td>
51+
<td className='whitespace-no-wrap p-5'>{value}</td>
52+
<td className='whitespace-no-wrap max-w-4 p-5'>
4753
<div
48-
className='relative inline-block p-2 text-left transition duration-200 ease-out rounded-md cursor-pointer hover:bg-ghost-200'
54+
className='hover:bg-ghost-200 relative inline-block cursor-pointer rounded-md p-2 text-left transition duration-200 ease-out'
4955
onClick={() => {
5056
setDeleteKey(key);
5157
setConfirmActionModalOpen(true);
5258
}}
5359
>
54-
<TrashIcon className='w-4 h-4' aria-hidden='true' />
60+
<TrashIcon className='h-4 w-4' aria-hidden='true' />
5561
</div>
5662
<div
57-
className='relative inline-block p-2 text-left transition duration-200 ease-out rounded-md cursor-pointer hover:bg-ghost-200'
63+
className='hover:bg-ghost-200 relative inline-block cursor-pointer rounded-md p-2 text-left transition duration-200 ease-out'
5864
onClick={() => {
5965
setEditKey(key);
6066
setEditValue(value);
6167
setEditVariableModalOpen(true);
6268
}}
6369
>
64-
<PencilSquareIcon className='w-4 h-4' aria-hidden='true' />
70+
<PencilSquareIcon className='h-4 w-4' aria-hidden='true' />
6571
</div>
6672
</td>
6773
</tr>
@@ -75,7 +81,7 @@ const Env = ({ tab }) => {
7581
onClickHandle={() => setAddVariableModalOpen(true)}
7682
fullWidth={true}
7783
>
78-
<PlusIcon className='w-5 h-5' />
84+
<PlusIcon className='h-5 w-5' />
7985
<span>Add Variable</span>
8086
</Button>
8187
</div>

src/components/molecules/flow/index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { saveHandle } from '../modals/SaveFlowModal';
2626
import Button from 'components/atoms/common/Button';
2727
import { BUTTON_INTENT_TYPES, BUTTON_TYPES } from 'constants/Common';
2828
import GraphLogger, { LogLevel } from './graph/GraphLogger';
29+
import Mousetrap from 'mousetrap';
2930

3031
const StartNode = () => (
3132
<FlowNode title='Start' handleLeft={false} handleRight={true} handleRightData={{ type: 'source' }}></FlowNode>
@@ -203,11 +204,16 @@ const Flow = ({ tab, collectionId }) => {
203204

204205
reactFlowInstance?.setViewport(viewport);
205206

206-
const cmdAndSPressed = useKeyPress(['Meta+s', 'Strg+s']);
207+
//const cmdAndSPressed = useKeyPress(['Meta+s', 'Strg+s', 'Ctrl+s']);
208+
// Bind Ctrl+S and Cmd+S
209+
Mousetrap.bind(['ctrl+s', 'command+s'], function (e) {
210+
e.preventDefault();
211+
saveHandle(tab);
212+
return false;
213+
});
207214

208215
return (
209216
<div className='flex-auto'>
210-
{cmdAndSPressed && saveHandle(tab)}
211217
<ReactFlow
212218
nodes={nodes}
213219
edges={edges}
@@ -233,7 +239,7 @@ const Flow = ({ tab, collectionId }) => {
233239
>
234240
<Background variant='dots' gap={12} size={1} />
235241
<Controls
236-
className='flex shadow-none border-cyan-900'
242+
className='flex border-cyan-900 shadow-none'
237243
onFitView={() => setViewport(reactFlowInstance.getViewport())}
238244
></Controls>
239245
<Button

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ 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';
109
import { readFlowTest } from 'service/collection';
1110
import { toast } from 'react-toastify';
1211

@@ -27,10 +26,8 @@ const NestedFlowNode = ({ id, data }) => {
2726
}
2827
}
2928

30-
const cmdPressed = useKeyPress('Meta'); // 'Meta' key for Cmd on Mac
31-
3229
const handleMouseClick = (event, relativePath) => {
33-
if (cmdPressed && event.type === 'click') {
30+
if ((event.metaKey || event.ctrlKey) && event.type === 'click') {
3431
if (relativePath && relativePath.trim() != '') {
3532
readFlowTest(ipcRenderer.join(collection.pathname, relativePath), collectionId)
3633
.then((result) => {
@@ -66,7 +63,7 @@ const NestedFlowNode = ({ id, data }) => {
6663
}}
6764
name='flow'
6865
value={data.relativePath ? data.relativePath : ''}
69-
className='h-12 p-2 border rounded outline-none cursor-default max-w-48 border-cyan-950 bg-background-light'
66+
className='h-12 max-w-48 cursor-default rounded border border-cyan-950 bg-background-light p-2 outline-none'
7067
>
7168
<option key='None' value=''>
7269
Select a flow

0 commit comments

Comments
 (0)