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

feat(WarningModal): add text confirmation option #540

Merged
merged 8 commits into from
Jan 14, 2025

Conversation

InsaneZein
Copy link
Collaborator

@InsaneZein InsaneZein commented Jan 7, 2025

closes #411

for RHCLOUD-36638: adds a text confirmation option to the Warning Modal

@patternfly-build
Copy link

patternfly-build commented Jan 7, 2025

@InsaneZein InsaneZein requested a review from fhlavac January 7, 2025 20:12
Comment on lines 21 to 26
/** Whether modal requires a text confirmation */
textConfirmation?: TextInputProps;
/** Label for the text confirmation */
textConfirmationLabel?: (deleteName?: string) => ReactNode;
/** Text the user should type to confirm selection when using textConfirmation */
deleteName?: string;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
/** Whether modal requires a text confirmation */
textConfirmation?: TextInputProps;
/** Label for the text confirmation */
textConfirmationLabel?: (deleteName?: string) => ReactNode;
/** Text the user should type to confirm selection when using textConfirmation */
deleteName?: string;
/** Confirmation text input props */
confirmationInputProps?: TextInputProps;
/** Label for the text confirmation input */
confirmationInputLabel?: (deleteName?: string) => ReactNode;
/** Text the user should type to confirm selection when using confirmation input */
confirmationText?: string;

how about renaming the props like so? Mabe it's a little bit more descriptive

Comment on lines 56 to 67
const isConfirmButtonDisabled = () => {
if(withCheckbox && textConfirmation) {
return !checked || !textConfirmed;
}
if(withCheckbox && !textConfirmation) {
return !checked;
}
if(!withCheckbox && textConfirmation) {
return !textConfirmed;
}
else {return false;}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
const isConfirmButtonDisabled = () => {
if(withCheckbox && textConfirmation) {
return !checked || !textConfirmed;
}
if(withCheckbox && !textConfirmation) {
return !checked;
}
if(!withCheckbox && textConfirmation) {
return !textConfirmed;
}
else {return false;}
}
const isConfirmButtonDisabled = React.useMemo(() => {
if (withCheckbox) {
return !checked || (textConfirmation && !textConfirmed);
}
return textConfirmation ? !textConfirmed : false;
}, [checked, textConfirmed, withCheckbox, textConfirmation]);

Comment on lines 83 to 84
setChecked(false);
setInputValue('');
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this cleanup needed? it causes unnecessary re-renders.


### Warning modal with a text confirmation

To confirm that a user wishes to initiate a selected action, you can add a text confirmation.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
To confirm that a user wishes to initiate a selected action, you can add a text confirmation.
To ensure the user intentionally initiates a selected action, you can add a confirmation text input.

cancelButtonLabel='No'
onClose={() => setIsOpen(false)}
onConfirm={() => setIsOpen(false)}
textConfirmation={{ type: 'text', isRequired: true }}
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe these two props could be set as default and made overwritable using custom input props

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If we wanted to do this, I think we'd have to add something like a withTextConfirmation boolean prop for this to work.

@fhlavac
Copy link
Collaborator

fhlavac commented Jan 8, 2025

@InsaneZein just some little suggestions. Otherwise, it looks great!

ouiaId={`${ouiaId}-confirmation-text-input`}
value={inputValue}
onChange={(_e, value) => setInputValue(value)}
{...confirmationInputProps}
Copy link
Collaborator

@fhlavac fhlavac Jan 10, 2025

Choose a reason for hiding this comment

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

@InsaneZein for the input default props mentioned above, we could do this.
What do you think?

Suggested change
{...confirmationInputProps}
{{ type: 'text', isRequired: true, ...confirmationInputProps}}

{confirmationInputProps ? (
<Flex direction={{ default: 'column' }} spaceItems={{ default: 'spaceItemsSm' }}>
<FlexItem>
{confirmationInputProps && confirmationInputLabel(deleteNameSanitized)}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
{confirmationInputProps && confirmationInputLabel(deleteNameSanitized)}
{confirmationInputLabel(deleteNameSanitized)}

the check is probably not needed, since you have it above

Comment on lines 23 to 24
/** Label for the text confirmation input */
confirmationInputLabel?: (deleteName?: string) => ReactNode;
Copy link
Collaborator

Choose a reason for hiding this comment

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

not sure if this one has to be a function - if the user of our component uses this prop, he can pass the confirmation text directly, not using another prop. I would just make it a ReactNode

Copy link
Collaborator

@fhlavac fhlavac left a comment

Choose a reason for hiding this comment

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

Two final comments and we are golden! 🎉

<Stack hasGutter>
<StackItem>{children}</StackItem>
<StackItem>
{confirmationInputProps ? (
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
{confirmationInputProps ? (
{confirmationText ? (

we probably want to show the confirmation input only if the text is passed, not necessarily the input props

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

Comment on lines 43 to 44
confirmationInputLabel = 'Type to confirm',
confirmationText,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
confirmationInputLabel = 'Type to confirm',
confirmationText,
confirmationText,
confirmationInputLabel = <>Type <strong>{confirmationText} </strong> to confirm the action:</>,

I would keep your previous default there - it makes sense to have the confirmation text present

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

Copy link
Collaborator

@fhlavac fhlavac left a comment

Choose a reason for hiding this comment

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

Looks great!

@InsaneZein InsaneZein merged commit c758701 into main Jan 14, 2025
6 checks passed
Copy link

🎉 This PR is included in version 6.2.0-prerelease.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add 'extra destructive' variant to WarningModal
4 participants