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

[Active users][Settings][Account settings] Add functionality for text inputs with buttons #140

Merged

Conversation

carma12
Copy link
Collaborator

@carma12 carma12 commented Aug 25, 2023

The functionality to take data directly from the metadata has been implemented for the Text inputs with buttons (list of text inputs retrieved from the API call). This has been applied to the following field: 'Principal alias' (krbprincipalname).

@carma12 carma12 requested a review from pvoborni August 25, 2023 13:42
@carma12 carma12 force-pushed the account-settings-textinput-with-buttons branch 2 times, most recently from fe5f100 to 63249bd Compare August 31, 2023 08:02
@carma12 carma12 force-pushed the account-settings-textinput-with-buttons branch 3 times, most recently from 16e24fb to c5e5c62 Compare September 5, 2023 15:52
@pvoborni pvoborni self-assigned this Sep 5, 2023
@carma12 carma12 force-pushed the account-settings-textinput-with-buttons branch from c5e5c62 to 28ad7ab Compare September 6, 2023 07:36

const deletionConfModalActions = [
<Button
key="add-principal-alias"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this key name be something like: "del-principal-alias", just making sure its not a copy/paste issue

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch! You are right, I copy-pasted that and forgot to change the name. Fixing that...

const textInputModalActions = [
<SecondaryButton
key="add-principal-alias"
onClickHandler={onAddPrincipalAlias}
Copy link
Collaborator

@mreynolds389 mreynolds389 Sep 7, 2023

Choose a reason for hiding this comment

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

Is there anyway to disable this button if the "Add" value is empty?

isDisabled={add_value === "" : true ? false}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually I think you can do it like this using the prop newValue:

isDisabled={newValue === "" : true ? false}

onChange={props.setNewValue}
type="text"
aria-label={props.textInputName}
isRequired={true}
Copy link
Collaborator

@mreynolds389 mreynolds389 Sep 7, 2023

Choose a reason for hiding this comment

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

Not sure if it applies in all cases but when the value is empty you can make the input field "invalidated":

 validated={props.newValue === "" ? ValidatedOptions.error : ValidatedOptions.default}

Need to import PF component: ValidatedOptions

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's a good idea. I went further and included another validation check: the validation of the value should be correct only if this is not empty AND if the given realm (if specified) matches with the current one in the system.

I have done that by defining the getRealmFromKrbPolicy function (utils.ts) that retrieves the current realm from the krbtpolicy value in the metadata. The logic is handled from the PrincipalAliasMultiTextboxComponent as follows:

// Current realm
  const currentRealm = getRealmFromKrbPolicy(props.metadata); // <--- Already defined function in 'utils.ts'

  // Get realm from 'newAliasValue' (if any)
  const getRealmNewAliasValue = () => {
    const realm = newAliasValue.split("@")[1];
    return realm;
  };

  const newAliasValueRealm = getRealmNewAliasValue();

  // Validation for textInput: realm matches with the current realm (if specified)
  const areRealmsMatching =
    newAliasValue !== "" &&
    newAliasValue.includes("@") &&
    currentRealm !== "" &&
    newAliasValueRealm !== undefined &&
    newAliasValueRealm === currentRealm;

(...)

return (
    (...)
    <AddTextInputFromListModal
        newValue={newAliasValue}
        setNewValue={setNewAliasValue}
        title={"Add kerberos principal alias"}
        isOpen={isTextInputModalOpen}
        onClose={onCloseTextInputModal}
        actions={textInputModalActions}
        textInputTitle={"New kerberos principal alias"}
        textInputName="krbprincalname"
        textInputValidator={areRealmsMatching} // <-- Passing the validation via props
      />
);

The functionality to take data directly from
the metadata needs to be implemented for the
Text inputs with buttons (list of text inputs).
This should be applied to the following
field: 'Principal alias' (`krbprincipalname`).

Signed-off-by: Carla Martinez <[email protected]>
@carma12 carma12 force-pushed the account-settings-textinput-with-buttons branch from 28ad7ab to c9e299f Compare September 8, 2023 09:00
@carma12
Copy link
Collaborator Author

carma12 commented Sep 8, 2023

@mreynolds389 - Thanks for the review. I have already updated the code based on your comments.

onClickHandler={onAddPrincipalAlias}
// isDisabled={newAliasValue === "" ? true : false}
isDisabled={
(newAliasValue !== "" && !newAliasValue.includes("@")) ||
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry didn't test this yet, but isn't this backwards? Shouldn't it be: newAliasValue === "" || !newAliasValue.includes("@") || ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not really. This line is trying to test if any of the following cases is happening (one OR the other):

  • The inserted text (newAliasValue) is not empty and this text doesn't include the '@' symbol --> Enable the 'Add' button
  • The inserted text is not empty, has the '@' symbol, and what it follows to that symbol matches with the current realm --> Enable the 'Add' button

I have tried the same code on my local instance and it seems to work fine.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for confirming!

Copy link
Collaborator

@mreynolds389 mreynolds389 left a comment

Choose a reason for hiding this comment

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

LGTM

@carma12 carma12 merged commit 73bd268 into freeipa:main Sep 12, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants