Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Import collection modal closes when click on ENTER #3830

Merged
merged 1 commit into from
Jan 17, 2025
Merged
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
6 changes: 3 additions & 3 deletions packages/bruno-app/src/components/Modal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const Modal = ({
confirmText,
cancelText,
handleCancel,
handleConfirm,
handleConfirm = () => {},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a quick check around the code will show that this was already optional and this change is not necessary.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i thought about just removing it initially, without adding a default value for the prop, it would have worked fine keypress "Enter" case, it is bounded by the if check, but no such condtional is there when is called from modal footer. @ramki-bruno

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undefined for onClick would be absolutely fine

children,
confirmDisabled,
hideCancel,
Expand Down Expand Up @@ -92,7 +92,7 @@ const Modal = ({
};

useFocusTrap(modalRef);

const closeModal = (args) => {
setIsClosing(true);
setTimeout(() => handleCancel(args), closeModalFadeTimeout);
Expand All @@ -103,7 +103,7 @@ const Modal = ({
return () => {
document.removeEventListener('keydown', handleKeydown);
};
}, [disableEscapeKey, document]);
}, [disableEscapeKey, document, handleConfirm]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have just handleKeydown itself in the dependenc-array, instead of manually finding all the dependencies of its dependencies.
Its still missing, closeModal at this moment.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i will have to move handleKeyDown to a useCallback function with handleConfirm, closeModal, disableEscKey as deps, before adding it as a dependency right? else, the useEffect will get called with each render?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i will have to move handleKeyDown to a useCallback function with handleConfirm, closeModal, disableEscKey as deps, before adding it as a dependency right?

yes, that will be even better

else, the useEffect will get called with each render?

yes, but at least it won't have any unexpected behaviors


let classes = 'bruno-modal';
if (isClosing) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const ImportCollection = ({ onClose, handleSubmit }) => {
);
};
return (
<Modal size="sm" title="Import Collection" hideFooter={true} handleConfirm={onClose} handleCancel={onClose}>
<Modal size="sm" title="Import Collection" hideFooter={true} handleCancel={onClose}>
<div className="flex flex-col">
<h3 className="text-sm">Select the type of your existing collection :</h3>
<div className="mt-4 grid grid-rows-2 grid-flow-col gap-2">
Expand Down
Loading