Reset actions should not be hard-coded. (#3499)

This commit is contained in:
Stan Silvert 2022-10-11 06:15:31 -04:00 committed by GitHub
parent d75753aa0c
commit 32f75ca109
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,5 +1,6 @@
import { useState } from "react"; import { useState } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { useAdminClient, useFetch } from "../../context/auth/AdminClient";
import { Controller, useFormContext } from "react-hook-form"; import { Controller, useFormContext } from "react-hook-form";
import { import {
FormGroup, FormGroup,
@ -8,13 +9,25 @@ import {
SelectVariant, SelectVariant,
} from "@patternfly/react-core"; } from "@patternfly/react-core";
import { RequiredActionAlias } from "@keycloak/keycloak-admin-client/lib/defs/requiredActionProviderRepresentation";
import { HelpItem } from "../../components/help-enabler/HelpItem"; import { HelpItem } from "../../components/help-enabler/HelpItem";
import type RequiredActionProviderRepresentation from "@keycloak/keycloak-admin-client/lib/defs/requiredActionProviderRepresentation";
export const CredentialsResetActionMultiSelect = () => { export const CredentialsResetActionMultiSelect = () => {
const { t } = useTranslation("users"); const { t } = useTranslation("users");
const { adminClient } = useAdminClient();
const { control } = useFormContext(); const { control } = useFormContext();
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const [requiredActions, setRequiredActions] = useState<
RequiredActionProviderRepresentation[]
>([]);
useFetch(
() => adminClient.authenticationManagement.getRequiredActions(),
(actions) => {
setRequiredActions(actions);
},
[]
);
return ( return (
<FormGroup <FormGroup
@ -55,13 +68,13 @@ export const CredentialsResetActionMultiSelect = () => {
}} }}
typeAheadAriaLabel={t("resetActions")} typeAheadAriaLabel={t("resetActions")}
> >
{Object.values(RequiredActionAlias).map((action, index) => ( {requiredActions.map(({ alias, name }) => (
<SelectOption <SelectOption
key={index} key={alias}
value={action} value={alias}
data-testid={`${action}-option`} data-testid={`${alias}-option`}
> >
{t(action)} {name}
</SelectOption> </SelectOption>
))} ))}
</Select> </Select>