Port regex client authorization policy to new form controls (#27569)

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

View file

@ -117,7 +117,7 @@ describe("Client authentication subtab", () => {
name: "Regex policy",
description: "Policy for regex",
targetClaim: "I don't know",
regexPattern: ".*?",
pattern: ".*?",
})
.formUtils()
.save();

View file

@ -1,83 +1,30 @@
import { useTranslation } from "react-i18next";
import { Controller, useFormContext } from "react-hook-form";
import { Checkbox, FormGroup } from "@patternfly/react-core";
import { HelpItem } from "ui-shared";
import { KeycloakTextInput } from "../../../components/keycloak-text-input/KeycloakTextInput";
import { SwitchControl, TextControl } from "ui-shared";
export const Regex = () => {
const { t } = useTranslation();
const {
control,
register,
formState: { errors },
} = useFormContext();
return (
<>
<FormGroup
<TextControl
name="targetClaim"
label={t("targetClaim")}
fieldId="targetClaim"
helperTextInvalid={t("required")}
validated={errors.targetClaim ? "error" : "default"}
isRequired
labelIcon={
<HelpItem
helpText={t("targetClaimHelp")}
fieldLabelId="targetClaim"
/>
}
>
<KeycloakTextInput
id="targetClaim"
data-testid="targetClaim"
validated={errors.targetClaim ? "error" : "default"}
{...register("targetClaim", { required: true })}
/>
</FormGroup>
<FormGroup
labelIcon={t("targetClaimHelp")}
rules={{ required: t("required") }}
/>
<TextControl
name="pattern"
label={t("regexPattern")}
fieldId="pattern"
labelIcon={
<HelpItem
helpText={t("regexPatternHelp")}
fieldLabelId="regexPattern"
/>
}
isRequired
validated={errors.pattern ? "error" : "default"}
helperTextInvalid={t("required")}
>
<KeycloakTextInput
id="pattern"
data-testid="regexPattern"
validated={errors.pattern ? "error" : "default"}
{...register("pattern", { required: true })}
/>
</FormGroup>
<FormGroup
labelIcon={t("regexPatternHelp")}
rules={{ required: t("required") }}
/>
<SwitchControl
name="targetContextAttributes"
label={t("targetContextAttributes")}
fieldId="targetContextAttributes"
labelIcon={
<HelpItem
helpText={t("targetContextAttributesHelp")}
fieldLabelId="targetContextAttributes"
/>
}
>
<Controller
name="targetContextAttributes"
defaultValue={false}
control={control}
render={({ field }) => (
<Checkbox
id="targetContextAttributes"
isChecked={field.value}
onChange={field.onChange}
/>
)}
/>
</FormGroup>
labelIcon={t("targetContextAttributesHelp")}
labelOn={t("yes")}
labelOff={t("no")}
/>
</>
);
};