Skip to content

Commit

Permalink
Port next/previous tab hotkeys
Browse files Browse the repository at this point in the history
The old admin ui featured two hotkeys that would
let you move forward and backward between the
different steps in a create modal. This ports them
over to our ui.

Unfortunately, they are not that useful currently,
as switching tabs almost always results in an
element being autofocused that will eat our
hotkey inputs (<input>, <select>, etc.). Not sure
currently how to get hotkeys to work despite that
in a general fashion.
  • Loading branch information
Arnei committed Jul 12, 2024
1 parent 675dc70 commit 70b2634
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 8 deletions.
16 changes: 16 additions & 0 deletions src/components/events/partials/ModalTabsAndPages/NewAccessPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { filterRoles, getAclTemplateText } from "../../../../utils/aclUtils";
import { useAppDispatch, useAppSelector } from "../../../../store";
import { fetchSeriesDetailsAcls } from "../../../../slices/seriesDetailsSlice";
import { getSeriesDetailsAcl } from "../../../../selectors/seriesDetailsSelectors";
import { useHotkeys } from "react-hotkeys-hook";
import { availableHotkeys } from "../../../../configs/hotkeysConfig";

/**
* This component renders the access page for new events and series in the wizards.
Expand Down Expand Up @@ -97,6 +99,20 @@ const NewAccessPage = ({
await dispatch(checkAcls(formik.values.acls));
};

useHotkeys(
availableHotkeys.general.NEXT_TAB.sequence,
() => nextPage(formik.values),
{ description: t(availableHotkeys.general.NEXT_TAB.description) ?? undefined },
[nextPage],
);

useHotkeys(
availableHotkeys.general.PREVIOUS_TAB.sequence,
() => previousPage(formik.values),
{ description: t(availableHotkeys.general.PREVIOUS_TAB.description) ?? undefined },
[previousPage],
);

return (
<>
<div className="modal-content">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const NewAssetUploadPage = <T extends RequiredFormProps>({
formik.setFieldValue(assetId, e.target.files[0]);
}
};

return (
<>
<div className="modal-content">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import DropDown from "../../../shared/DropDown";
import { useAppDispatch, useAppSelector } from "../../../../store";
import { fetchWorkflowDef } from "../../../../slices/workflowSlice";
import { FormikProps } from "formik";
import { useHotkeys } from "react-hotkeys-hook";
import { availableHotkeys } from "../../../../configs/hotkeysConfig";

/**
* This component renders the processing page for new events in the new event wizard.
Expand Down Expand Up @@ -57,6 +59,20 @@ const NewProcessingPage = <T extends RequiredFormProps>({
formik.setFieldValue("processingWorkflow", workflowId);
};

useHotkeys(
availableHotkeys.general.NEXT_TAB.sequence,
() => nextPage(formik.values),
{ description: t(availableHotkeys.general.NEXT_TAB.description) ?? undefined },
[nextPage],
);

useHotkeys(
availableHotkeys.general.PREVIOUS_TAB.sequence,
() => previousPage(formik.values),
{ description: t(availableHotkeys.general.PREVIOUS_TAB.description) ?? undefined },
[previousPage],
);

return (
<>
<div className="modal-content">
Expand Down
16 changes: 16 additions & 0 deletions src/components/events/partials/ModalTabsAndPages/NewSourcePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import { Recording, fetchRecordings } from "../../../../slices/recordingSlice";
import { removeNotificationWizardForm } from "../../../../slices/notificationSlice";
import { parseISO } from "date-fns";
import { checkConflicts } from "../../../../slices/eventSlice";
import { useHotkeys } from "react-hotkeys-hook";
import { availableHotkeys } from "../../../../configs/hotkeysConfig";

/**
* This component renders the source page for new events in the new event wizard.
Expand Down Expand Up @@ -98,6 +100,20 @@ const NewSourcePage = <T extends RequiredFormProps>({
return inputDevices.length > 0 && hasAnyDeviceAccess(user, inputDevices);
};

useHotkeys(
availableHotkeys.general.NEXT_TAB.sequence,
() => nextPage(formik.values),
{ description: t(availableHotkeys.general.NEXT_TAB.description) ?? undefined },
[nextPage],
);

useHotkeys(
availableHotkeys.general.PREVIOUS_TAB.sequence,
() => previousPage(formik.values),
{ description: t(availableHotkeys.general.PREVIOUS_TAB.description) ?? undefined },
[previousPage],
);

return (
<>
<div className="modal-content">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ const EventDetailsModal = ({
);

return (
// todo: add hotkeys
<>
<div className="modal-animation modal-overlay" />
<section
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const SeriesDetailsModal = ({
[close],
);

// todo: add hotkeys
return (
<>
<div className="modal-animation modal-overlay" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const RecordingDetailsModal = ({
};

return (
// todo: add hotkeys
<>
<div className="modal-animation modal-overlay" />
<section
Expand Down
1 change: 0 additions & 1 deletion src/components/shared/NewResourceModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const NewResourceModal = ({
};

return (
// todo: add hotkeys
<>
<div className="modal-animation modal-overlay" />
<section
Expand Down
16 changes: 16 additions & 0 deletions src/components/shared/wizard/WizardNavigationButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React from "react";
import { useTranslation } from "react-i18next";
import cn from "classnames";
import { FormikProps } from "formik";
import { useHotkeys } from "react-hotkeys-hook";
import { availableHotkeys } from "../../../configs/hotkeysConfig";

const WizardNavigationButtons = <T,>({
isFirst,
Expand Down Expand Up @@ -29,6 +31,20 @@ const WizardNavigationButtons = <T,>({

const disabled = !(formik.dirty && formik.isValid);

useHotkeys(
availableHotkeys.general.NEXT_TAB.sequence,
() => nextPage && nextPage(formik.values),
{ description: t(availableHotkeys.general.NEXT_TAB.description) ?? undefined },
[nextPage],
);

useHotkeys(
availableHotkeys.general.PREVIOUS_TAB.sequence,
() => previousPage && previousPage(formik.values),
{ description: t(availableHotkeys.general.PREVIOUS_TAB.description) ?? undefined },
[previousPage],
);

return (
<>
<footer>
Expand Down
1 change: 0 additions & 1 deletion src/components/users/partials/modal/AclDetailsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const AclDetailsModal = ({
};

return (
// todo: add hotkeys
<>
<div className="modal-animation modal-overlay" />
<section
Expand Down
1 change: 0 additions & 1 deletion src/components/users/partials/modal/GroupDetailsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const GroupDetailsModal = ({
};

return (
// todo: add hotkeys
<>
<div className="modal-animation modal-overlay" />
<section
Expand Down
1 change: 0 additions & 1 deletion src/components/users/partials/modal/UserDetailsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const UserDetailsModal = ({
};

return (
// todo: add hotkeys
<>
<div className="modal-animation modal-overlay" />
<section
Expand Down
10 changes: 10 additions & 0 deletions src/configs/hotkeysConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ export const availableHotkeys: HotkeyMapType = {
name: "close_modal",
description: "HOTKEYS.DESCRIPTIONS.GENERAL.CLOSE_MODAL",
sequence: ["Esc"],
},
NEXT_TAB: {
name: "next_tab",
description: "HOTKEYS.DESCRIPTIONS.GENERAL.NEXT_TAB",
sequence: ["alt+enter"]
},
PREVIOUS_TAB: {
name: "previous_tab",
description: "HOTKEYS.DESCRIPTIONS.GENERAL.PREVIOUS_TAB",
sequence: ["alt+backspace"]
}
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -2112,7 +2112,9 @@
"NEW_EVENT": "Add event",
"NEW_SERIES": "Add series",
"CHEAT_SHEET": "Keyboard shortcuts",
"CLOSE_MODAL": "Close dialog"
"CLOSE_MODAL": "Close dialog",
"NEXT_TAB": "Switch to next tab",
"PREVIOUS_TAB": "Switch to previous tab"
}
}
},
Expand Down

0 comments on commit 70b2634

Please sign in to comment.