Skip to content

Commit

Permalink
Add F2 shortcut for editing action name
Browse files Browse the repository at this point in the history
Additionally, focus on action name input when there is no record button to focus on when switching row focus via up/down keys.
  • Loading branch information
microbit-grace committed Dec 2, 2024
1 parent 16fda1b commit dcd9ebb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/components/ActionNameCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ interface ActionNameCardProps {

const actionNameMaxLength = 18;

export const actionNameInputId = (action: Action) =>
`action-name-input-${action.ID}`;

const ActionNameCard = ({
value,
onDeleteAction,
Expand Down Expand Up @@ -129,6 +132,7 @@ const ActionNameCard = ({
)}
</HStack>
<Input
id={actionNameInputId(value)}
autoFocus={localName.length === 0}
isTruncated
readOnly={readOnly}
Expand Down
22 changes: 20 additions & 2 deletions src/pages/DataSamplesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { RiAddLine, RiArrowRightLine } from "react-icons/ri";
import { FormattedMessage, useIntl } from "react-intl";
import { useNavigate } from "react-router";
import { recordButtonId } from "../components/ActionDataSamplesCard";
import { actionNameInputId } from "../components/ActionNameCard";
import DataSamplesTable from "../components/DataSamplesTable";
import DefaultPageLayout, {
ProjectMenuItems,
Expand Down Expand Up @@ -53,17 +54,29 @@ const DataSamplesPage = () => {
handleAddNewAction,
globalShortcutConfig
);
const focusActionNameInput = useCallback(
(actionIdx: number) => {
const inputId = actionNameInputId(actions[actionIdx]);
const actionNameInputEl = document.getElementById(inputId);
actionNameInputEl?.focus();
},
[actions]
);
const focusAction = useCallback(
(idx: number) => {
if (idx >= 0 && idx < actions.length) {
setSelectedActionIdx(idx);
const recordButton = document.getElementById(
recordButtonId(actions[idx])
);
recordButton?.focus();
if (recordButton) {
recordButton?.focus();
} else {
focusActionNameInput(idx);
}
}
},
[actions]
[actions, focusActionNameInput]
);
useHotkeys(
keyboardShortcuts.nextAction,
Expand All @@ -75,6 +88,11 @@ const DataSamplesPage = () => {
() => focusAction(selectedActionIdx - 1),
globalShortcutConfig
);
useHotkeys(
keyboardShortcuts.renameAction,
() => focusActionNameInput(selectedActionIdx),
globalShortcutConfig
);
const intl = useIntl();
return (
<>
Expand Down

0 comments on commit dcd9ebb

Please sign in to comment.