From c8d4effb34ddc7a3ba440ed44513ee0aee1d6fa4 Mon Sep 17 00:00:00 2001 From: Jenny <32821331+jenny-s51@users.noreply.github.com> Date: Tue, 9 Nov 2021 14:36:27 -0500 Subject: [PATCH] Realm settings(Client policies -> policies): Add switch for enabling/disabling policy (#1495) * add switch for enabling/disabling policy fix tests * testing duplicate policy test with added wait * unskip tests * ccomment out JSON policies test --- .../integration/realm_settings_test.spec.ts | 10 +- .../realm_settings/RealmSettingsPage.ts | 1 + src/realm-settings/NewClientPolicyForm.tsx | 113 ++++++++++++++---- src/realm-settings/messages.ts | 4 + 4 files changed, 97 insertions(+), 31 deletions(-) diff --git a/cypress/integration/realm_settings_test.spec.ts b/cypress/integration/realm_settings_test.spec.ts index a1ff5e083d..611785d1d1 100644 --- a/cypress/integration/realm_settings_test.spec.ts +++ b/cypress/integration/realm_settings_test.spec.ts @@ -602,10 +602,10 @@ describe("Realm settings tests", () => { realmSettingsPage.shouldNavigateBetweenFormAndJSONViewPolicies(); }); - /* it("Check saving changed JSON policies", () => { - realmSettingsPage.shouldSaveChangedJSONPolicies(); - realmSettingsPage.shouldDeleteClientPolicyDialog(); - }); */ + /* it("Check saving changed JSON policies", () => { + realmSettingsPage.shouldSaveChangedJSONPolicies(); + realmSettingsPage.shouldDeleteClientPolicyDialog(); + }); */ it("Should not create duplicate client profile", () => { realmSettingsPage.shouldCompleteAndCreateNewClientPolicyFromEmptyState(); @@ -615,7 +615,7 @@ describe("Realm settings tests", () => { cy.findByTestId("rs-policies-clientPolicies-tab").click(); realmSettingsPage.shouldCompleteAndCreateNewClientPolicy(); realmSettingsPage.shouldNotCreateDuplicateClientPolicy(); - + cy.wait(200); sidebarPage.goToRealmSettings(); cy.findByTestId("rs-clientPolicies-tab").click(); cy.findByTestId("rs-policies-clientPolicies-tab").click(); diff --git a/cypress/support/pages/admin_console/manage/realm_settings/RealmSettingsPage.ts b/cypress/support/pages/admin_console/manage/realm_settings/RealmSettingsPage.ts index 485204b908..7b7e9f94d8 100644 --- a/cypress/support/pages/admin_console/manage/realm_settings/RealmSettingsPage.ts +++ b/cypress/support/pages/admin_console/manage/realm_settings/RealmSettingsPage.ts @@ -951,6 +951,7 @@ export default class RealmSettingsPage { ); cy.findByTestId(this.saveNewClientPolicyBtn).click(); cy.get(this.alertMessage).should("be.visible", "New client policy created"); + cy.wait(200); cy.findByTestId(this.clientPolicyDrpDwn).contains("Action").click(); cy.findByTestId("deleteClientPolicyDropdown").click(); cy.findByTestId("modalConfirm").contains("Delete").click(); diff --git a/src/realm-settings/NewClientPolicyForm.tsx b/src/realm-settings/NewClientPolicyForm.tsx index 9f8d0f8f2d..273300f70f 100644 --- a/src/realm-settings/NewClientPolicyForm.tsx +++ b/src/realm-settings/NewClientPolicyForm.tsx @@ -22,7 +22,7 @@ import { ValidatedOptions, } from "@patternfly/react-core"; import { useTranslation } from "react-i18next"; -import { useForm } from "react-hook-form"; +import { Controller, useForm } from "react-hook-form"; import { FormAccess } from "../components/form-access/FormAccess"; import { ViewHeader } from "../components/view-header/ViewHeader"; import { Link, useHistory, useParams } from "react-router-dom"; @@ -96,6 +96,72 @@ export default function NewClientPolicyForm() { const formValues = form.getValues(); + type ClientPoliciesHeaderProps = { + onChange: (value: boolean) => void; + value: boolean; + save: () => void; + realmName: string; + refresh: () => void; + }; + + const ClientPoliciesHeader = ({ + save, + onChange, + value, + }: ClientPoliciesHeaderProps) => { + const { t } = useTranslation("realm-settings"); + + const [toggleDisableDialog, DisableConfirm] = useConfirmDialog({ + titleKey: "realm-settings:disablePolicyConfirmTitle", + messageKey: "realm-settings:disablePolicyConfirm", + continueButtonLabel: "common:disable", + onConfirm: () => { + onChange(!value); + save(); + }, + }); + + return ( + <> + + + { + toggleDeleteDialog(); + }} + data-testid="deleteClientPolicyDropdown" + > + {t("deleteClientPolicy")} + , + ] + : undefined + } + isEnabled={value} + onToggle={(value) => { + if (!value) { + toggleDisableDialog(); + } else { + onChange(value); + save(); + } + }} + /> + + ); + }; + useFetch( async () => { const [policies, profiles] = await Promise.all([ @@ -176,7 +242,9 @@ export default function NewClientPolicyForm() { policies: getAllPolicies(), }); addAlert( - t("realm-settings:createClientPolicySuccess"), + policyName + ? t("realm-settings:updateClientPolicySuccess") + : t("realm-settings:createClientPolicySuccess"), AlertVariant.success ); history.push( @@ -299,6 +367,10 @@ export default function NewClientPolicyForm() { form.setValue("description", currentPolicy?.description); }; + const refreshHeader = () => { + setKey(new Date().getTime()); + }; + const toggleModal = () => { setProfilesModalOpen(!profilesModalOpen); }; @@ -343,7 +415,6 @@ export default function NewClientPolicyForm() { return ( <> - - { - toggleDeleteDialog(); - }} - data-testid="deleteClientPolicyDropdown" - > - {t("deleteClientPolicy")} - , - ] - : undefined - } + ( + + )} />