From 5ad85d38daba765868755bbe20f15eb1d1cf924d Mon Sep 17 00:00:00 2001 From: kris2kris <36845394+kris2kris@users.noreply.github.com> Date: Mon, 29 Aug 2022 14:40:36 +0200 Subject: [PATCH] Redirect to flow detail after duplicate (#3199) --- .../cypress/e2e/authentication_test.spec.ts | 2 +- .../src/authentication/DuplicateFlowModal.tsx | 21 +++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/apps/admin-ui/cypress/e2e/authentication_test.spec.ts b/apps/admin-ui/cypress/e2e/authentication_test.spec.ts index 5db5bf95df..ed06e528a8 100644 --- a/apps/admin-ui/cypress/e2e/authentication_test.spec.ts +++ b/apps/admin-ui/cypress/e2e/authentication_test.spec.ts @@ -52,7 +52,7 @@ describe("Authentication test", () => { duplicateFlowModal.fill("Copy of browser"); masthead.checkNotificationMessage("Flow successfully duplicated"); - listingPage.itemExist("Copy of browser"); + detailPage.flowExists("Copy of browser"); }); it("Should fail duplicate with empty flow name", () => { diff --git a/apps/admin-ui/src/authentication/DuplicateFlowModal.tsx b/apps/admin-ui/src/authentication/DuplicateFlowModal.tsx index d9aba69e69..fc014df5b1 100644 --- a/apps/admin-ui/src/authentication/DuplicateFlowModal.tsx +++ b/apps/admin-ui/src/authentication/DuplicateFlowModal.tsx @@ -1,6 +1,7 @@ import { useEffect } from "react"; import { useTranslation } from "react-i18next"; import { FormProvider, useForm } from "react-hook-form"; +import { useNavigate } from "react-router-dom-v5-compat"; import { AlertVariant, Button, @@ -13,6 +14,8 @@ import { import { useAdminClient } from "../context/auth/AdminClient"; import { useAlerts } from "../components/alert/Alerts"; import { NameDescription } from "./form/NameDescription"; +import { toFlow } from "./routes/Flow"; +import { useRealm } from "../context/realm-context/RealmContext"; type DuplicateFlowModalProps = { name: string; @@ -34,6 +37,8 @@ export const DuplicateFlowModal = ({ const { setValue, trigger, getValues } = form; const { adminClient } = useAdminClient(); const { addAlert, addError } = useAlerts(); + const navigate = useNavigate(); + const { realm } = useRealm(); useEffect(() => { setValue("description", description); @@ -48,11 +53,11 @@ export const DuplicateFlowModal = ({ flow: name, newName: form.alias, }); - if (form.description !== description) { - const newFlow = ( - await adminClient.authenticationManagement.getFlows() - ).find((flow) => flow.alias === form.alias)!; + const newFlow = ( + await adminClient.authenticationManagement.getFlows() + ).find((flow) => flow.alias === form.alias)!; + if (form.description !== description) { newFlow.description = form.description; await adminClient.authenticationManagement.updateFlow( { flowId: newFlow.id! }, @@ -60,6 +65,14 @@ export const DuplicateFlowModal = ({ ); } addAlert(t("copyFlowSuccess"), AlertVariant.success); + navigate( + toFlow({ + realm, + id: newFlow.id!, + usedBy: "notInUse", + builtIn: newFlow.builtIn ? "builtIn" : undefined, + }) + ); } catch (error) { addError("authentication:copyFlowError", error); }