Port regex client authorization policy to new form controls (#27569)
Signed-off-by: Jon Koops <jonkoops@gmail.com>
This commit is contained in:
parent
658c033cf7
commit
3e46810b37
2 changed files with 18 additions and 71 deletions
|
@ -117,7 +117,7 @@ describe("Client authentication subtab", () => {
|
|||
name: "Regex policy",
|
||||
description: "Policy for regex",
|
||||
targetClaim: "I don't know",
|
||||
regexPattern: ".*?",
|
||||
pattern: ".*?",
|
||||
})
|
||||
.formUtils()
|
||||
.save();
|
||||
|
|
|
@ -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")}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue