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 { useFormContext } from "react-hook-form";
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";
import { TextAreaControl, TextControl } from "ui-shared";
type NameDescriptionProps = {
prefix: string;
isDisabled: boolean;
};
export const NameDescription = ({
prefix,
isDisabled,
}: NameDescriptionProps) => {
export const NameDescription = ({ isDisabled }: NameDescriptionProps) => {
const { t } = useTranslation();
const {
register,
formState: { errors },
} = useFormContext();
return (
<>
<FormGroup
<TextControl
name="name"
label={t("name")}
fieldId="kc-name"
helperTextInvalid={t("required")}
validated={
errors.name ? ValidatedOptions.error : ValidatedOptions.default
}
isRequired
labelIcon={
<HelpItem helpText={t(`${prefix}-nameHelp`)} fieldLabelId="name" />
}
>
<KeycloakTextInput
rules={{ required: t("required") }}
isDisabled={isDisabled}
id="kc-name"
data-testid="name"
validated={
errors.name ? ValidatedOptions.error : ValidatedOptions.default
}
{...register("name", { required: true })}
/>
</FormGroup>
<FormGroup
<TextAreaControl
name="description"
label={t("description")}
fieldId="kc-description"
labelIcon={
<HelpItem
helpText={t(`${prefix}-descriptionHelp`)}
fieldLabelId="description"
/>
}
validated={
errors.description ? ValidatedOptions.error : ValidatedOptions.default
}
helperTextInvalid={t("maxLength", { length: 255 })}
>
<KeycloakTextArea
rules={{
maxLength: { message: t("maxLength", { length: 255 }), value: 255 },
}}
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
>
<FormProvider {...form}>
<NameDescription isDisabled={isDisabled} prefix="policy" />
<NameDescription isDisabled={isDisabled} />
<ComponentType />
<LogicSelector isDisabled={isDisabled} />
</FormProvider>