From 3ad233b89007022310d0590495d52d6131b18a8e Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Fri, 22 Mar 2024 12:06:02 +0100 Subject: [PATCH] changed to use ui-shared (#27983) Signed-off-by: Erik Jan de Wit --- .../cypress/e2e/clients_saml_test.spec.ts | 2 +- .../client_details/tabs/SettingsTab.ts | 25 +-- .../admin-ui/src/clients/add/SamlConfig.tsx | 89 ++------- .../src/clients/add/SamlSignature.tsx | 169 ++++-------------- 4 files changed, 64 insertions(+), 221 deletions(-) diff --git a/js/apps/admin-ui/cypress/e2e/clients_saml_test.spec.ts b/js/apps/admin-ui/cypress/e2e/clients_saml_test.spec.ts index 4b29d96489..79d7ac87e8 100644 --- a/js/apps/admin-ui/cypress/e2e/clients_saml_test.spec.ts +++ b/js/apps/admin-ui/cypress/e2e/clients_saml_test.spec.ts @@ -47,7 +47,7 @@ describe("Clients SAML tests", () => { it("should save force name id format", () => { 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, }); cy.findByTestId("settings-save").click(); diff --git a/js/apps/admin-ui/cypress/support/pages/admin-ui/manage/clients/client_details/tabs/SettingsTab.ts b/js/apps/admin-ui/cypress/support/pages/admin-ui/manage/clients/client_details/tabs/SettingsTab.ts index c8c916ad67..8b20283f11 100644 --- a/js/apps/admin-ui/cypress/support/pages/admin-ui/manage/clients/client_details/tabs/SettingsTab.ts +++ b/js/apps/admin-ui/cypress/support/pages/admin-ui/manage/clients/client_details/tabs/SettingsTab.ts @@ -11,19 +11,20 @@ export enum NameIdFormat { const masthead = new Masthead(); export default class SettingsTab extends PageObject { - #samlNameIdFormat = "#samlNameIdFormat"; - #forceNameIdFormat = "forceNameIdFormat"; - #forcePostBinding = "forcePostBinding"; - #forceArtifactBinding = "forceArtifactBinding"; - #includeAuthnStatement = "includeAuthnStatement"; - #includeOneTimeUseCondition = "includeOneTimeUseCondition"; - #optimizeLookup = "optimizeLookup"; + #samlNameIdFormat = "#saml_name_id_format"; + #forceNameIdFormat = "attributes.saml_force_name_id_format"; + #forcePostBinding = "attributes.saml🍺force🍺post🍺binding"; + #forceArtifactBinding = "attributes.saml🍺artifact🍺binding"; + #includeAuthnStatement = "attributes.saml🍺authnstatement"; + #includeOneTimeUseCondition = "attributes.saml🍺onetimeuse🍺condition"; + #optimizeLookup = "attributes.saml🍺server🍺signature🍺keyinfo🍺ext"; - #signDocumentsSwitch = "signDocuments"; - #signAssertionsSwitch = "signAssertions"; - #signatureAlgorithm = "#signatureAlgorithm"; - #signatureKeyName = "#signatureKeyName"; - #canonicalization = "#canonicalization"; + #signDocumentsSwitch = "attributes.saml🍺server🍺signature"; + #signAssertionsSwitch = "attributes.saml🍺assertion🍺signature"; + #signatureAlgorithm = "#saml🍺signature🍺algorithm"; + #signatureKeyName = + "#saml🍺server🍺signature🍺keyinfo🍺xmlSigKeyInfoKeyNameTransformer"; + #canonicalization = "#saml_signature_canonicalization_method"; #loginTheme = "#loginTheme"; #consentSwitch = "#kc-consent-switch"; diff --git a/js/apps/admin-ui/src/clients/add/SamlConfig.tsx b/js/apps/admin-ui/src/clients/add/SamlConfig.tsx index a1fb1c3a31..847c26b56c 100644 --- a/js/apps/admin-ui/src/clients/add/SamlConfig.tsx +++ b/js/apps/admin-ui/src/clients/add/SamlConfig.tsx @@ -1,16 +1,8 @@ -import { - FormGroup, - Select, - SelectOption, - SelectVariant, - Switch, -} from "@patternfly/react-core"; -import { useState } from "react"; -import { Controller, Path, PathValue, useFormContext } from "react-hook-form"; +import { Path, PathValue } from "react-hook-form"; import { useTranslation } from "react-i18next"; - +import { SelectControl } from "ui-shared"; +import { DefaultSwitchControl } from "../../components/SwitchControl"; import { FormAccess } from "../../components/form/FormAccess"; -import { HelpItem } from "ui-shared"; import { convertAttributeNameToForm } from "../../util"; import { FormFields } from "../ClientDetails"; @@ -20,84 +12,35 @@ type ToggleProps = { }; export const Toggle = ({ name, label }: ToggleProps) => { const { t } = useTranslation(); - const { control } = useFormContext(); return ( - } - > - ( - field.onChange(value.toString())} - aria-label={t(label)} - /> - )} - /> - + labelIcon={t(`${label}Help`)} + stringify + /> ); }; export const SamlConfig = () => { const { t } = useTranslation(); - const { control } = useFormContext(); - const [nameFormatOpen, setNameFormatOpen] = useState(false); return ( - - } - > - ( - - )} - /> - + labelIcon={t("nameIdFormatHelp")} + controller={{ + defaultValue: "username", + }} + options={["username", "email", "transient", "persistent"]} + /> { const { t } = useTranslation(); - const [algOpen, setAlgOpen] = useState(false); - const [keyOpen, setKeyOpen] = useState(false); - const [canOpen, setCanOpen] = useState(false); - - const { control, watch } = useFormContext(); + const { watch } = useFormContext(); const signDocs = watch( convertAttributeNameToForm("attributes.saml.server.signature"), @@ -74,129 +62,40 @@ export const SamlSignature = () => { /> {(signDocs === "true" || signAssertion === "true") && ( <> - ( + "attributes.saml.signature.algorithm", + )} label={t("signatureAlgorithm")} - fieldId="signatureAlgorithm" - labelIcon={ - - } - > - ( - "attributes.saml.signature.algorithm", - )} - defaultValue={SIGNATURE_ALGORITHMS[0]} - control={control} - render={({ field }) => ( - - )} - /> - - + ( + "attributes.saml.server.signature.keyinfo.xmlSigKeyInfoKeyNameTransformer", + )} label={t("signatureKeyName")} - fieldId="signatureKeyName" - labelIcon={ - - } - > - ( - "attributes.saml.server.signature.keyinfo.xmlSigKeyInfoKeyNameTransformer", - )} - defaultValue={KEYNAME_TRANSFORMER[0]} - control={control} - render={({ field }) => ( - - )} - /> - - + - } - > - ( - - )} - /> - + labelIcon={t("canonicalizationHelp")} + controller={{ + defaultValue: CANONICALIZATION[0].value, + }} + options={CANONICALIZATION.map(({ name, value }) => ({ + key: value, + value: name, + }))} + /> )}