Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/flat-poets-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@orchestrator-ui/orchestrator-ui-components': patch
---

2355 Enable Ctrl/Cmd + Arrows to control form pages
2 changes: 1 addition & 1 deletion apps/wfo-ui
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Form footer component
*/
import React, { useContext } from 'react';
import React, { useContext, useEffect } from 'react';

import { useTranslations } from 'next-intl';
import type { PydanticFormFooterProps } from 'pydantic-forms';
Expand All @@ -21,6 +21,10 @@
isTask?: boolean;
};

const submitButtonId = 'button-submit-form-submit';
const previousButtonId = 'button-submit-form-previous';
const cancelButtonId = 'button-submit-form-cancel';

export const Footer = ({
onCancel,
onPrevious,
Expand All @@ -33,7 +37,7 @@
const t = useTranslations('pydanticForms.userInputForm');
const { showConfirmDialog } = useContext(ConfirmationDialogContext);

const handlePrevious = () => {

Check warning on line 40 in packages/orchestrator-ui-components/src/components/WfoPydanticForm/Footer.tsx

View workflow job for this annotation

GitHub Actions / linting-and-prettier

The 'handlePrevious' function makes the dependencies of useEffect Hook (at line 72) change on every render. To fix this, wrap the definition of 'handlePrevious' in its own useCallback() Hook
if (onCancel) {
showConfirmDialog({
question: t('previousQuestion'),
Expand All @@ -44,6 +48,29 @@

const { next, previous } = buttons || {};

useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => {
const isPrimary = event.metaKey || event.ctrlKey;

if (isPrimary && event.key === 'ArrowLeft') {
event.preventDefault();

if (hasPrevious) {
onPrevious?.();
} else {
handlePrevious();
}
}

if (isPrimary && event.key === 'ArrowRight') {
event.preventDefault();
document.getElementById(submitButtonId)?.click();
}
};
window.addEventListener('keydown', handleKeyDown);
return () => window.removeEventListener('keydown', handleKeyDown);
}, [hasPrevious, hasNext, onPrevious, onCancel, handlePrevious]);

const PreviousButton = () => {
const previousButtonColor =
theme.colors[
Expand All @@ -53,8 +80,8 @@

return (
<EuiButton
data-testid="button-submit-form-previous"
id="button-submit-form-submit"
data-testid={previousButtonId}
id={previousButtonId}
tabIndex={0}
fill
onClick={() => {
Expand All @@ -76,7 +103,7 @@

const CancelButton = () => (
<div
data-testid="button-submit-form-cancel"
data-testid={cancelButtonId}
onClick={handlePrevious}
css={{
cursor: 'pointer',
Expand Down Expand Up @@ -120,8 +147,8 @@

return (
<EuiButton
data-testid="button-submit-form-submit"
id="button-submit-form-submit"
data-testid={submitButtonId}
id={submitButtonId}
tabIndex={0}
fill
css={{
Expand Down
Loading