changed to use ui-shared (#27983)

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
This commit is contained in:
Erik Jan de Wit 2024-03-22 12:06:02 +01:00 committed by GitHub
parent 2d73c86306
commit 3ad233b890
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 64 additions and 221 deletions

View file

@ -47,7 +47,7 @@ describe("Clients SAML tests", () => {
it("should save force name id format", () => { it("should save force name id format", () => {
cy.get(".pf-c-jump-links__list").contains("SAML capabilities").click(); cy.get(".pf-c-jump-links__list").contains("SAML capabilities").click();
cy.findByTestId("forceNameIdFormat").click({ cy.findByTestId("attributes.saml🍺force🍺post🍺binding").click({
force: true, force: true,
}); });
cy.findByTestId("settings-save").click(); cy.findByTestId("settings-save").click();

View file

@ -11,19 +11,20 @@ export enum NameIdFormat {
const masthead = new Masthead(); const masthead = new Masthead();
export default class SettingsTab extends PageObject { export default class SettingsTab extends PageObject {
#samlNameIdFormat = "#samlNameIdFormat"; #samlNameIdFormat = "#saml_name_id_format";
#forceNameIdFormat = "forceNameIdFormat"; #forceNameIdFormat = "attributes.saml_force_name_id_format";
#forcePostBinding = "forcePostBinding"; #forcePostBinding = "attributes.saml🍺force🍺post🍺binding";
#forceArtifactBinding = "forceArtifactBinding"; #forceArtifactBinding = "attributes.saml🍺artifact🍺binding";
#includeAuthnStatement = "includeAuthnStatement"; #includeAuthnStatement = "attributes.saml🍺authnstatement";
#includeOneTimeUseCondition = "includeOneTimeUseCondition"; #includeOneTimeUseCondition = "attributes.saml🍺onetimeuse🍺condition";
#optimizeLookup = "optimizeLookup"; #optimizeLookup = "attributes.saml🍺server🍺signature🍺keyinfo🍺ext";
#signDocumentsSwitch = "signDocuments"; #signDocumentsSwitch = "attributes.saml🍺server🍺signature";
#signAssertionsSwitch = "signAssertions"; #signAssertionsSwitch = "attributes.saml🍺assertion🍺signature";
#signatureAlgorithm = "#signatureAlgorithm"; #signatureAlgorithm = "#saml🍺signature🍺algorithm";
#signatureKeyName = "#signatureKeyName"; #signatureKeyName =
#canonicalization = "#canonicalization"; "#saml🍺server🍺signature🍺keyinfo🍺xmlSigKeyInfoKeyNameTransformer";
#canonicalization = "#saml_signature_canonicalization_method";
#loginTheme = "#loginTheme"; #loginTheme = "#loginTheme";
#consentSwitch = "#kc-consent-switch"; #consentSwitch = "#kc-consent-switch";

View file

@ -1,16 +1,8 @@
import { import { Path, PathValue } from "react-hook-form";
FormGroup,
Select,
SelectOption,
SelectVariant,
Switch,
} from "@patternfly/react-core";
import { useState } from "react";
import { Controller, Path, PathValue, useFormContext } from "react-hook-form";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { SelectControl } from "ui-shared";
import { DefaultSwitchControl } from "../../components/SwitchControl";
import { FormAccess } from "../../components/form/FormAccess"; import { FormAccess } from "../../components/form/FormAccess";
import { HelpItem } from "ui-shared";
import { convertAttributeNameToForm } from "../../util"; import { convertAttributeNameToForm } from "../../util";
import { FormFields } from "../ClientDetails"; import { FormFields } from "../ClientDetails";
@ -20,84 +12,35 @@ type ToggleProps = {
}; };
export const Toggle = ({ name, label }: ToggleProps) => { export const Toggle = ({ name, label }: ToggleProps) => {
const { t } = useTranslation(); const { t } = useTranslation();
const { control } = useFormContext<FormFields>();
return ( return (
<FormGroup <DefaultSwitchControl
hasNoPaddingTop name={name}
label={t(label)} label={t(label)}
fieldId={label} labelIcon={t(`${label}Help`)}
labelIcon={<HelpItem helpText={t(`${label}Help`)} fieldLabelId={label} />} stringify
> />
<Controller
name={name}
defaultValue="false"
control={control}
render={({ field }) => (
<Switch
id={name!}
data-testid={label}
label={t("on")}
labelOff={t("off")}
isChecked={field.value === "true"}
onChange={(value) => field.onChange(value.toString())}
aria-label={t(label)}
/>
)}
/>
</FormGroup>
); );
}; };
export const SamlConfig = () => { export const SamlConfig = () => {
const { t } = useTranslation(); const { t } = useTranslation();
const { control } = useFormContext<FormFields>();
const [nameFormatOpen, setNameFormatOpen] = useState(false);
return ( return (
<FormAccess <FormAccess
isHorizontal isHorizontal
role="manage-clients" role="manage-clients"
className="keycloak__capability-config__form" className="keycloak__capability-config__form"
> >
<FormGroup <SelectControl
name="attributes.saml_name_id_format"
label={t("nameIdFormat")} label={t("nameIdFormat")}
fieldId="nameIdFormat" labelIcon={t("nameIdFormatHelp")}
labelIcon={ controller={{
<HelpItem defaultValue: "username",
helpText={t("nameIdFormatHelp")} }}
fieldLabelId="nameIdFormat" options={["username", "email", "transient", "persistent"]}
/> />
}
>
<Controller
name="attributes.saml_name_id_format"
defaultValue="username"
control={control}
render={({ field }) => (
<Select
toggleId="samlNameIdFormat"
onToggle={setNameFormatOpen}
onSelect={(_, value) => {
field.onChange(value.toString());
setNameFormatOpen(false);
}}
selections={field.value}
variant={SelectVariant.single}
aria-label={t("nameIdFormat")}
isOpen={nameFormatOpen}
>
{["username", "email", "transient", "persistent"].map((name) => (
<SelectOption
selected={name === field.value}
key={name}
value={name}
/>
))}
</Select>
)}
/>
</FormGroup>
<Toggle <Toggle
name="attributes.saml_force_name_id_format" name="attributes.saml_force_name_id_format"
label="forceNameIdFormat" label="forceNameIdFormat"

View file

@ -1,15 +1,7 @@
import { import { useFormContext } from "react-hook-form";
FormGroup,
Select,
SelectOption,
SelectVariant,
} from "@patternfly/react-core";
import { useState } from "react";
import { Controller, useFormContext } from "react-hook-form";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { SelectControl } from "ui-shared";
import { FormAccess } from "../../components/form/FormAccess"; import { FormAccess } from "../../components/form/FormAccess";
import { HelpItem } from "ui-shared";
import { convertAttributeNameToForm } from "../../util"; import { convertAttributeNameToForm } from "../../util";
import { FormFields } from "../ClientDetails"; import { FormFields } from "../ClientDetails";
import { Toggle } from "./SamlConfig"; import { Toggle } from "./SamlConfig";
@ -43,11 +35,7 @@ const CANONICALIZATION = [
export const SamlSignature = () => { export const SamlSignature = () => {
const { t } = useTranslation(); const { t } = useTranslation();
const [algOpen, setAlgOpen] = useState(false); const { watch } = useFormContext<FormFields>();
const [keyOpen, setKeyOpen] = useState(false);
const [canOpen, setCanOpen] = useState(false);
const { control, watch } = useFormContext<FormFields>();
const signDocs = watch( const signDocs = watch(
convertAttributeNameToForm<FormFields>("attributes.saml.server.signature"), convertAttributeNameToForm<FormFields>("attributes.saml.server.signature"),
@ -74,129 +62,40 @@ export const SamlSignature = () => {
/> />
{(signDocs === "true" || signAssertion === "true") && ( {(signDocs === "true" || signAssertion === "true") && (
<> <>
<FormGroup <SelectControl
name={convertAttributeNameToForm<FormFields>(
"attributes.saml.signature.algorithm",
)}
label={t("signatureAlgorithm")} label={t("signatureAlgorithm")}
fieldId="signatureAlgorithm" labelIcon={t("signatureAlgorithmHelp")}
labelIcon={ controller={{
<HelpItem defaultValue: SIGNATURE_ALGORITHMS[0],
helpText={t("signatureAlgorithmHelp")} }}
fieldLabelId="signatureAlgorithm" options={[...SIGNATURE_ALGORITHMS]}
/> />
} <SelectControl
> name={convertAttributeNameToForm<FormFields>(
<Controller "attributes.saml.server.signature.keyinfo.xmlSigKeyInfoKeyNameTransformer",
name={convertAttributeNameToForm<FormFields>( )}
"attributes.saml.signature.algorithm",
)}
defaultValue={SIGNATURE_ALGORITHMS[0]}
control={control}
render={({ field }) => (
<Select
toggleId="signatureAlgorithm"
onToggle={setAlgOpen}
onSelect={(_, value) => {
field.onChange(value.toString());
setAlgOpen(false);
}}
selections={field.value}
variant={SelectVariant.single}
aria-label={t("signatureAlgorithm")}
isOpen={algOpen}
>
{SIGNATURE_ALGORITHMS.map((algorithm) => (
<SelectOption
selected={algorithm === field.value}
key={algorithm}
value={algorithm}
/>
))}
</Select>
)}
/>
</FormGroup>
<FormGroup
label={t("signatureKeyName")} label={t("signatureKeyName")}
fieldId="signatureKeyName" labelIcon={t("signatureKeyNameHelp")}
labelIcon={ controller={{
<HelpItem defaultValue: KEYNAME_TRANSFORMER[0],
helpText={t("signatureKeyNameHelp")} }}
fieldLabelId="signatureKeyName" options={[...KEYNAME_TRANSFORMER]}
/> />
} <SelectControl
> name="attributes.saml_signature_canonicalization_method"
<Controller
name={convertAttributeNameToForm<FormFields>(
"attributes.saml.server.signature.keyinfo.xmlSigKeyInfoKeyNameTransformer",
)}
defaultValue={KEYNAME_TRANSFORMER[0]}
control={control}
render={({ field }) => (
<Select
toggleId="signatureKeyName"
onToggle={setKeyOpen}
onSelect={(_, value) => {
field.onChange(value.toString());
setKeyOpen(false);
}}
selections={field.value}
variant={SelectVariant.single}
aria-label={t("signatureKeyName")}
isOpen={keyOpen}
>
{KEYNAME_TRANSFORMER.map((key) => (
<SelectOption
selected={key === field.value}
key={key}
value={key}
/>
))}
</Select>
)}
/>
</FormGroup>
<FormGroup
label={t("canonicalization")} label={t("canonicalization")}
fieldId="canonicalization" labelIcon={t("canonicalizationHelp")}
labelIcon={ controller={{
<HelpItem defaultValue: CANONICALIZATION[0].value,
helpText={t("canonicalizationHelp")} }}
fieldLabelId="canonicalization" options={CANONICALIZATION.map(({ name, value }) => ({
/> key: value,
} value: name,
> }))}
<Controller />
name="attributes.saml_signature_canonicalization_method"
defaultValue={CANONICALIZATION[0].value}
control={control}
render={({ field }) => (
<Select
toggleId="canonicalization"
onToggle={setCanOpen}
onSelect={(_, value) => {
field.onChange(value.toString());
setCanOpen(false);
}}
selections={
CANONICALIZATION.find((can) => can.value === field.value)
?.name
}
variant={SelectVariant.single}
aria-label={t("canonicalization")}
isOpen={canOpen}
>
{CANONICALIZATION.map((can) => (
<SelectOption
selected={can.value === field.value}
key={can.name}
value={can.value}
>
{can.name}
</SelectOption>
))}
</Select>
)}
/>
</FormGroup>
</> </>
)} )}
</FormAccess> </FormAccess>