Port common authorization policy fields to new form controls (#27571)

Signed-off-by: Jon Koops <jonkoops@gmail.com>
This commit is contained in:
Jon Koops 2024-03-06 10:25:24 +01:00 committed by GitHub
parent b486972485
commit 658c033cf7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 62 deletions

View file

@ -1,76 +1,29 @@
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { useFormContext } from "react-hook-form"; import { TextAreaControl, TextControl } from "ui-shared";
import { FormGroup, ValidatedOptions } from "@patternfly/react-core";
import { HelpItem } from "ui-shared";
import { KeycloakTextInput } from "../../../components/keycloak-text-input/KeycloakTextInput";
import { KeycloakTextArea } from "../../../components/keycloak-text-area/KeycloakTextArea";
type NameDescriptionProps = { type NameDescriptionProps = {
prefix: string;
isDisabled: boolean; isDisabled: boolean;
}; };
export const NameDescription = ({ export const NameDescription = ({ isDisabled }: NameDescriptionProps) => {
prefix,
isDisabled,
}: NameDescriptionProps) => {
const { t } = useTranslation(); const { t } = useTranslation();
const {
register,
formState: { errors },
} = useFormContext();
return ( return (
<> <>
<FormGroup <TextControl
name="name"
label={t("name")} label={t("name")}
fieldId="kc-name" rules={{ required: t("required") }}
helperTextInvalid={t("required")} isDisabled={isDisabled}
validated={ />
errors.name ? ValidatedOptions.error : ValidatedOptions.default <TextAreaControl
} name="description"
isRequired
labelIcon={
<HelpItem helpText={t(`${prefix}-nameHelp`)} fieldLabelId="name" />
}
>
<KeycloakTextInput
isDisabled={isDisabled}
id="kc-name"
data-testid="name"
validated={
errors.name ? ValidatedOptions.error : ValidatedOptions.default
}
{...register("name", { required: true })}
/>
</FormGroup>
<FormGroup
label={t("description")} label={t("description")}
fieldId="kc-description" rules={{
labelIcon={ maxLength: { message: t("maxLength", { length: 255 }), value: 255 },
<HelpItem }}
helpText={t(`${prefix}-descriptionHelp`)} isDisabled={isDisabled}
fieldLabelId="description" />
/>
}
validated={
errors.description ? ValidatedOptions.error : ValidatedOptions.default
}
helperTextInvalid={t("maxLength", { length: 255 })}
>
<KeycloakTextArea
isDisabled={isDisabled}
id="kc-description"
data-testid="description"
validated={
errors.description
? ValidatedOptions.error
: ValidatedOptions.default
}
{...register("description", { maxLength: 255 })}
/>
</FormGroup>
</> </>
); );
}; };

View file

@ -201,7 +201,7 @@ export default function PolicyDetails() {
role="anyone" // if you get this far it means you have access role="anyone" // if you get this far it means you have access
> >
<FormProvider {...form}> <FormProvider {...form}>
<NameDescription isDisabled={isDisabled} prefix="policy" /> <NameDescription isDisabled={isDisabled} />
<ComponentType /> <ComponentType />
<LogicSelector isDisabled={isDisabled} /> <LogicSelector isDisabled={isDisabled} />
</FormProvider> </FormProvider>