Skip to content

Commit 671a6f8

Browse files
authored
Add hotkey to assign empty label (#1414)
1 parent 734c334 commit 671a6f8

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

web_ui/src/pages/annotator/components/main-content/labels-shortcuts/labels-shortcuts.component.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useCallback, useMemo } from 'react';
55

66
import { Flex, Tooltip, TooltipTrigger } from '@geti/ui';
77
import { isEmpty } from 'lodash-es';
8+
import { useHotkeys } from 'react-hotkeys-hook';
89
import { useLocalStorage } from 'usehooks-ts';
910

1011
import { Annotation } from '../../../../../core/annotations/annotation.interface';
@@ -15,6 +16,8 @@ import { useProjectIdentifier } from '../../../../../hooks/use-project-identifie
1516
import { LOCAL_STORAGE_KEYS } from '../../../../../shared/local-storage-keys';
1617
import { getId, getIds, hasEqualId } from '../../../../../shared/utils';
1718
import { AnnotationToolContext, ToolSettings, ToolType } from '../../../core/annotation-tool-context.interface';
19+
import { useAnnotatorHotkeys } from '../../../hooks/use-hotkeys-configuration.hook';
20+
import { HOTKEY_OPTIONS } from '../../../hot-keys/utils';
1821
import { getOutputFromTask } from '../../../providers/task-chain-provider/utils';
1922
import { useTask } from '../../../providers/task-provider/task-provider.component';
2023
import { LabelsHotkeys } from '../../labels/labels-hotkeys/labels-hotkeys.component';
@@ -39,6 +42,7 @@ const hasNotAnomalousNorLocalLabels = (annotation: Annotation) =>
3942
export const LabelsShortcuts = ({ labels, annotationToolContext, isDisabled = false }: LabelsShortcutsProps) => {
4043
const { selectedTask, tasks, setDefaultLabel } = useTask();
4144
const { projectId } = useProjectIdentifier();
45+
const { hotkeys } = useAnnotatorHotkeys();
4246
const {
4347
isDrawing,
4448
annotations: annotationsScene,
@@ -111,6 +115,21 @@ export const LabelsShortcuts = ({ labels, annotationToolContext, isDisabled = fa
111115
return isDrawingSmartTool ? smartToolHandler(label) : clickHandler(label);
112116
};
113117

118+
const emptyLabel = labels.find((label) => isEmptyLabel(label));
119+
120+
useHotkeys(
121+
hotkeys['empty-label'],
122+
(event) => {
123+
event.preventDefault();
124+
125+
if (emptyLabel) {
126+
handleSelectLabelShortcut(emptyLabel);
127+
}
128+
},
129+
HOTKEY_OPTIONS,
130+
[emptyLabel, handleSelectLabelShortcut, hotkeys]
131+
);
132+
114133
return (
115134
<div aria-label='Label shortcuts' role='list'>
116135
{!isDisabled && (

web_ui/src/pages/annotator/components/primary-toolbar/hot-keys-button/use-availability-of-hotkeys.hook.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export const useAvailabilityOfHotkeys = (domains: DOMAIN[]): Record<HotKeyAction
4848
close: true,
4949
hideAllAnnotations: true,
5050
accept: true,
51+
['empty-label']: true,
5152
[ToolType.EditTool]: false, // we do not have hotkey for edit tool
5253
[ToolType.SelectTool]: true,
5354
[SelectingToolType.SelectionTool]: false, // we do not have hotkey for selection tool

web_ui/src/pages/annotator/providers/annotator-provider/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ export type HotKeyActions =
4848
| 'pasteAnnotation'
4949
| 'close'
5050
| 'accept'
51-
| 'hideAllAnnotations';
51+
| 'hideAllAnnotations'
52+
| 'empty-label';
5253

5354
export type Hotkeys = Record<HotKeyActions, string>;
5455

@@ -76,6 +77,7 @@ export const DefaultHotkeys = (
7677
close: 'escape',
7778
hideAllAnnotations: 'a',
7879
accept: 'enter',
80+
['empty-label']: 'n',
7981
[ToolType.SelectTool]: 'v',
8082
[ToolType.SSIMTool]: 'd',
8183
[ToolType.RITMTool]: 'i',

0 commit comments

Comments
 (0)