Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.

Commit 2a1f71a

Browse files
authored
feat(gui): keyboard shortcuts for annotation forms (#857)
* feat(gui): Keyboard shortcuts for annotation forms * style: apply automatic fixes of linters Co-authored-by: lars-reimann <[email protected]>
1 parent b10afb6 commit 2a1f71a

File tree

2 files changed

+34
-18
lines changed

2 files changed

+34
-18
lines changed

api-editor/gui/src/features/annotations/batchforms/AnnotationBatchForm.tsx

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { Button, Heading, HStack, Stack, Text as ChakraText } from '@chakra-ui/react';
1+
import { Button, Heading, HStack, Stack, Text as ChakraText, Tooltip } from '@chakra-ui/react';
22
import React from 'react';
3+
import { useKeyboardShortcut } from '../../../app/hooks';
34

45
interface AnnotationFormProps {
56
heading: string;
67
description: string;
7-
onConfirm: React.MouseEventHandler<HTMLButtonElement>;
8-
onCancel: React.MouseEventHandler<HTMLButtonElement>;
8+
onConfirm: () => void;
9+
onCancel: () => void;
910
children: React.ReactNode;
1011
}
1112

@@ -16,6 +17,9 @@ export const AnnotationBatchForm: React.FC<AnnotationFormProps> = function ({
1617
onConfirm,
1718
children,
1819
}) {
20+
useKeyboardShortcut(false, true, false, 'Enter', onConfirm);
21+
useKeyboardShortcut(false, false, false, 'Escape', onCancel);
22+
1923
return (
2024
<Stack spacing={8} p={4}>
2125
<Stack spacing={4}>
@@ -29,12 +33,16 @@ export const AnnotationBatchForm: React.FC<AnnotationFormProps> = function ({
2933
<Stack spacing={4}>{children}</Stack>
3034

3135
<HStack>
32-
<Button colorScheme="blue" onClick={onConfirm}>
33-
Confirm
34-
</Button>
35-
<Button colorScheme="red" onClick={onCancel}>
36-
Cancel
37-
</Button>
36+
<Tooltip label="Preview the elements changed by this batch operation. (Ctrl+Enter)">
37+
<Button colorScheme="blue" onClick={onConfirm}>
38+
Start Dry Run
39+
</Button>
40+
</Tooltip>
41+
<Tooltip label="Stop the batch operation. (Esc)">
42+
<Button colorScheme="red" onClick={onCancel}>
43+
Cancel
44+
</Button>
45+
</Tooltip>
3846
</HStack>
3947
</Stack>
4048
);

api-editor/gui/src/features/annotations/forms/AnnotationForm.tsx

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { Button, Heading, HStack, Stack, Text as ChakraText } from '@chakra-ui/react';
1+
import { Button, Heading, HStack, Stack, Text as ChakraText, Tooltip } from '@chakra-ui/react';
22
import React from 'react';
3+
import { useKeyboardShortcut } from '../../../app/hooks';
34

45
interface AnnotationFormProps {
56
heading: string;
67
description: string;
7-
onSave: React.MouseEventHandler<HTMLButtonElement>;
8-
onCancel: React.MouseEventHandler<HTMLButtonElement>;
8+
onSave: () => void;
9+
onCancel: () => void;
910
children: React.ReactNode;
1011
}
1112

@@ -16,6 +17,9 @@ export const AnnotationForm: React.FC<AnnotationFormProps> = function ({
1617
onSave,
1718
children,
1819
}) {
20+
useKeyboardShortcut(false, true, false, 'Enter', onSave);
21+
useKeyboardShortcut(false, false, false, 'Escape', onCancel);
22+
1923
return (
2024
<Stack spacing={8} p={4}>
2125
<Stack spacing={4}>
@@ -29,12 +33,16 @@ export const AnnotationForm: React.FC<AnnotationFormProps> = function ({
2933
<Stack spacing={4}>{children}</Stack>
3034

3135
<HStack>
32-
<Button colorScheme="blue" onClick={onSave}>
33-
Save
34-
</Button>
35-
<Button colorScheme="red" onClick={onCancel}>
36-
Cancel
37-
</Button>
36+
<Tooltip label="Confirm the change. (Ctrl+Enter)">
37+
<Button colorScheme="blue" onClick={onSave}>
38+
Save
39+
</Button>
40+
</Tooltip>
41+
<Tooltip label="Drop the change. (Esc)">
42+
<Button colorScheme="red" onClick={onCancel}>
43+
Cancel
44+
</Button>
45+
</Tooltip>
3846
</HStack>
3947
</Stack>
4048
);

0 commit comments

Comments
 (0)