From a006fb83a7000ca3b925f7b39ca4114176ecfac2 Mon Sep 17 00:00:00 2001 From: Mirjam Aulbach Date: Thu, 17 Aug 2023 15:55:41 +0200 Subject: [PATCH] Fix handling for open CLAIM request in promotion. Signed-off-by: Mirjam Aulbach --- .../components/PromotionBanner.test.tsx | 94 ++++++++++++++++++- .../details/components/PromotionBanner.tsx | 81 +++++++++++----- .../topics/details/overview/TopicOverview.tsx | 8 +- .../components/TopicPromotionBanner.test.tsx | 29 +++++- .../components/TopicPromotionBanner.tsx | 3 + .../details/schema/TopicDetailsSchema.tsx | 4 +- .../components/SchemaPromotionBanner.test.tsx | 34 ++++++- .../components/SchemaPromotionBanner.tsx | 8 ++ 8 files changed, 234 insertions(+), 27 deletions(-) diff --git a/coral/src/app/features/topics/details/components/PromotionBanner.test.tsx b/coral/src/app/features/topics/details/components/PromotionBanner.test.tsx index c84bb3c85f..51168ccf31 100644 --- a/coral/src/app/features/topics/details/components/PromotionBanner.test.tsx +++ b/coral/src/app/features/topics/details/components/PromotionBanner.test.tsx @@ -23,6 +23,7 @@ describe("PromotionBanner", () => { type={"schema"} promoteElement={<>} hasOpenRequest={false} + hasOpenClaimRequest={false} hasError={false} errorMessage={""} />, @@ -40,6 +41,7 @@ describe("PromotionBanner", () => { type={"schema"} promoteElement={<>} hasOpenRequest={false} + hasOpenClaimRequest={false} hasError={false} errorMessage={""} />, @@ -57,6 +59,7 @@ describe("PromotionBanner", () => { type={"schema"} promoteElement={<>} hasOpenRequest={false} + hasOpenClaimRequest={false} hasError={false} errorMessage={""} />, @@ -74,6 +77,7 @@ describe("PromotionBanner", () => { type={"schema"} promoteElement={<>} hasOpenRequest={false} + hasOpenClaimRequest={false} hasError={false} errorMessage={""} />, @@ -91,6 +95,7 @@ describe("PromotionBanner", () => { type={"schema"} promoteElement={<>} hasOpenRequest={false} + hasOpenClaimRequest={false} hasError={false} errorMessage={""} />, @@ -108,6 +113,7 @@ describe("PromotionBanner", () => { type={"schema"} promoteElement={<>} hasOpenRequest={false} + hasOpenClaimRequest={false} hasError={false} errorMessage={""} />, @@ -126,6 +132,7 @@ describe("PromotionBanner", () => { promotionDetails={promotionDetails} type={"schema"} promoteElement={<>} + hasOpenClaimRequest={false} hasOpenRequest={true} hasError={false} errorMessage={""} @@ -150,7 +157,7 @@ describe("PromotionBanner", () => { expect(link).toBeVisible(); expect(link).toHaveAttribute( "href", - "/requests/schemas?search=my-test-topic&status=CREATED&page=1" + "/requests/schemas?search=my-test-topic&requestType=ALL&status=CREATED&page=1" ); }); }); @@ -163,6 +170,7 @@ describe("PromotionBanner", () => { promotionDetails={promotionDetails} type={"topic"} promoteElement={<>} + hasOpenClaimRequest={false} hasOpenRequest={true} hasError={false} errorMessage={""} @@ -187,7 +195,83 @@ describe("PromotionBanner", () => { expect(link).toBeVisible(); expect(link).toHaveAttribute( "href", - "/requests/topics?search=my-test-topic&status=CREATED&page=1" + "/requests/topics?search=my-test-topic&requestType=ALL&status=CREATED&page=1" + ); + }); + }); + + describe("handles banner for entity with an open claim request (type schema)", () => { + beforeAll(() => { + customRender( + } + hasOpenClaimRequest={true} + hasOpenRequest={false} + hasError={false} + errorMessage={""} + />, + { browserRouter: true } + ); + }); + + afterAll(cleanup); + + it("shows information about the open request", () => { + const information = screen.getByText( + `A claim request for ${testTopicName} is in progress.` + ); + + expect(information).toBeVisible(); + }); + + it("shows a link to open requests", () => { + const link = screen.getByRole("link", { name: "View request" }); + + expect(link).toBeVisible(); + expect(link).toHaveAttribute( + "href", + "/approvals/schemas?search=my-test-topic&requestType=CLAIM&status=CREATED&page=1" + ); + }); + }); + + describe("handles banner for entity with an open claim request (type topic)", () => { + beforeAll(() => { + customRender( + } + hasOpenClaimRequest={true} + hasOpenRequest={false} + hasError={false} + errorMessage={""} + />, + { browserRouter: true } + ); + }); + + afterAll(cleanup); + + it("shows information about the open request", () => { + const information = screen.getByText( + `A claim request for ${testTopicName} is in progress.` + ); + + expect(information).toBeVisible(); + }); + + it("shows a link to open requests", () => { + const link = screen.getByRole("link", { name: "View request" }); + + expect(link).toBeVisible(); + expect(link).toHaveAttribute( + "href", + "/approvals/topics?search=my-test-topic&requestType=CLAIM&status=CREATED&page=1" ); }); }); @@ -200,6 +284,7 @@ describe("PromotionBanner", () => { promotionDetails={{ ...promotionDetails, status: "REQUEST_OPEN" }} type={"schema"} promoteElement={<>} + hasOpenClaimRequest={false} hasOpenRequest={false} hasError={false} errorMessage={""} @@ -238,6 +323,7 @@ describe("PromotionBanner", () => { type={"topic"} promoteElement={<>} hasOpenRequest={false} + hasOpenClaimRequest={false} hasError={false} errorMessage={""} />, @@ -277,6 +363,7 @@ describe("PromotionBanner", () => { promotionDetails={promotionDetails} type={"schema"} promoteElement={promoteElement} + hasOpenClaimRequest={false} hasOpenRequest={false} hasError={false} errorMessage={""} @@ -314,6 +401,7 @@ describe("PromotionBanner", () => { type={"topic"} promoteElement={promoteElement} hasOpenRequest={false} + hasOpenClaimRequest={false} hasError={false} errorMessage={""} />, @@ -360,6 +448,7 @@ describe("PromotionBanner", () => { type={"schema"} promoteElement={<>} hasOpenRequest={false} + hasOpenClaimRequest={false} hasError={true} errorMessage={testErrorMessage} />, @@ -381,6 +470,7 @@ describe("PromotionBanner", () => { type={"schema"} promoteElement={<>} hasOpenRequest={false} + hasOpenClaimRequest={false} hasError={true} errorMessage={""} />, diff --git a/coral/src/app/features/topics/details/components/PromotionBanner.tsx b/coral/src/app/features/topics/details/components/PromotionBanner.tsx index f3edecff06..3c5217271a 100644 --- a/coral/src/app/features/topics/details/components/PromotionBanner.tsx +++ b/coral/src/app/features/topics/details/components/PromotionBanner.tsx @@ -13,13 +13,62 @@ interface PromotionBannerProps { promotionDetails: PromotionStatus; type: "schema" | "topic"; promoteElement: ReactElement; + hasOpenClaimRequest: boolean; hasOpenRequest: boolean; hasError: boolean; errorMessage: string; } +type RequestTypeLocal = "CLAIM" | "ALL" | "PROMOTE"; +function getRequestType({ + hasOpenClaimRequest, + hasOpenPromotionRequest, +}: { + hasOpenClaimRequest: boolean; + hasOpenPromotionRequest: boolean; +}): RequestTypeLocal { + if (hasOpenPromotionRequest) { + return "PROMOTE"; + } + if (hasOpenClaimRequest) { + return "CLAIM"; + } + return "ALL"; +} + +function createLink({ + type, + entityName, + requestType, +}: { + type: "schema" | "topic"; + entityName: string; + requestType: RequestTypeLocal; +}): string { + const table = requestType === "CLAIM" ? "approvals" : "requests"; + + return `/${table}/${type}s?search=${entityName}&requestType=${requestType}&status=CREATED&page=1`; +} + +function createText({ + entityName, + requestType, +}: { + entityName: string; + requestType: RequestTypeLocal; +}): string { + if (requestType === "PROMOTE") { + return `An promotion request for ${entityName} is already in progress.`; + } + if (requestType === "CLAIM") { + return `A claim request for ${entityName} is in progress.`; + } + return `${entityName} has a pending request.`; +} + const PromotionBanner = ({ promotionDetails, + hasOpenClaimRequest, hasOpenRequest, type, promoteElement, @@ -44,35 +93,25 @@ const PromotionBanner = ({ entityName !== undefined; const hasOpenPromotionRequest = status === "REQUEST_OPEN"; + const hasPendingRequest = + hasOpenRequest || hasOpenPromotionRequest || hasOpenClaimRequest; if (!isPromotable) return null; - if (hasOpenRequest) { - return ( - - - {entityName} has a pending request. - - - View request - - - ); - } + if (hasPendingRequest) { + const requestType = getRequestType({ + hasOpenClaimRequest, + hasOpenPromotionRequest, + }); + const link = createLink({ type, entityName, requestType }); + const text = createText({ entityName, requestType }); - if (hasOpenPromotionRequest) { return ( - An promotion request for {entityName} is already in progress. + {text} - - View request - + View request ); } diff --git a/coral/src/app/features/topics/details/overview/TopicOverview.tsx b/coral/src/app/features/topics/details/overview/TopicOverview.tsx index 4755043ca0..d7168f594e 100644 --- a/coral/src/app/features/topics/details/overview/TopicOverview.tsx +++ b/coral/src/app/features/topics/details/overview/TopicOverview.tsx @@ -34,7 +34,12 @@ function TopicOverview() { } = useTopicDetails(); const { - topicInfo: { topicOwner = false, hasOpenTopicRequest, clusterId }, + topicInfo: { + topicOwner = false, + hasOpenTopicRequest, + hasOpenClaimRequest, + clusterId, + }, topicPromotionDetails, } = topicOverview; @@ -75,6 +80,7 @@ function TopicOverview() { diff --git a/coral/src/app/features/topics/details/overview/components/TopicPromotionBanner.test.tsx b/coral/src/app/features/topics/details/overview/components/TopicPromotionBanner.test.tsx index ed8fc2de4f..452e00128b 100644 --- a/coral/src/app/features/topics/details/overview/components/TopicPromotionBanner.test.tsx +++ b/coral/src/app/features/topics/details/overview/components/TopicPromotionBanner.test.tsx @@ -13,6 +13,7 @@ const promotionDetailForPromote: TopicOverview["topicPromotionDetails"] = { const promoteProps = { topicPromotionDetails: promotionDetailForPromote, hasOpenTopicRequest: false, + hasOpenClaimRequest: false, topicName: "topic-hello", }; @@ -27,6 +28,14 @@ const promotionDetailForSeeOpenRequest: TopicOverview["topicPromotionDetails"] = const seeOpenRequestProps = { topicPromotionDetails: promotionDetailForSeeOpenRequest, hasOpenTopicRequest: true, + hasOpenClaimRequest: false, + topicName: "topic-hello", +}; + +const seeOpenClaimRequestProps = { + topicPromotionDetails: promotionDetailForSeeOpenRequest, + hasOpenTopicRequest: false, + hasOpenClaimRequest: true, topicName: "topic-hello", }; @@ -41,6 +50,7 @@ const promotionDetailForSeeOpenPromotionRequest: TopicOverview["topicPromotionDe const seeOpenPromotionRequestProps = { topicPromotionDetails: promotionDetailForSeeOpenPromotionRequest, hasOpenTopicRequest: false, + hasOpenClaimRequest: false, topicName: "topic-hello", }; @@ -51,6 +61,7 @@ const promotionDetailForNoPromotion: TopicOverview["topicPromotionDetails"] = { const nullProps = { topicPromotionDetails: promotionDetailForNoPromotion, hasOpenTopicRequest: false, + hasOpenClaimRequest: false, topicName: "topic-hello", }; @@ -88,7 +99,23 @@ describe("TopicPromotionBanner", () => { expect(link).toBeVisible(); expect(link).toHaveAttribute( "href", - `/requests/topics?search=${promoteProps.topicName}&status=CREATED&page=1` + `/requests/topics?search=${promoteProps.topicName}&requestType=ALL&status=CREATED&page=1` + ); + }); + + it("renders correct banner (see open claim request)", () => { + customRender(, { + browserRouter: true, + }); + + const link = screen.getByRole("link", { + name: "View request", + }); + + expect(link).toBeVisible(); + expect(link).toHaveAttribute( + "href", + `/approvals/topics?search=${promoteProps.topicName}&requestType=CLAIM&status=CREATED&page=1` ); }); diff --git a/coral/src/app/features/topics/details/overview/components/TopicPromotionBanner.tsx b/coral/src/app/features/topics/details/overview/components/TopicPromotionBanner.tsx index 1f8e29f08f..44ee6b0b31 100644 --- a/coral/src/app/features/topics/details/overview/components/TopicPromotionBanner.tsx +++ b/coral/src/app/features/topics/details/overview/components/TopicPromotionBanner.tsx @@ -9,11 +9,13 @@ interface TopicPromotionBannerProps { * information to the user. */ hasOpenTopicRequest: boolean; + hasOpenClaimRequest: boolean; topicName: string; } const TopicPromotionBanner = ({ topicPromotionDetails, + hasOpenClaimRequest, hasOpenTopicRequest, topicName, }: TopicPromotionBannerProps) => { @@ -23,6 +25,7 @@ const TopicPromotionBanner = ({ entityName={topicName} promotionDetails={topicPromotionDetails} hasOpenRequest={hasOpenTopicRequest} + hasOpenClaimRequest={hasOpenClaimRequest} type={"topic"} promoteElement={ setShowSchemaPromotionModal(!showSchemaPromotionModal) diff --git a/coral/src/app/features/topics/details/schema/components/SchemaPromotionBanner.test.tsx b/coral/src/app/features/topics/details/schema/components/SchemaPromotionBanner.test.tsx index f34068094f..4738431e01 100644 --- a/coral/src/app/features/topics/details/schema/components/SchemaPromotionBanner.test.tsx +++ b/coral/src/app/features/topics/details/schema/components/SchemaPromotionBanner.test.tsx @@ -28,6 +28,7 @@ describe("SchemaPromotionBanner", () => { topicName={"my-test-topic"} setShowSchemaPromotionModal={mockSetShowSchemaPromotionModal} hasOpenSchemaRequest={false} + hasOpenClaimRequest={false} />, { browserRouter: true } ); @@ -46,6 +47,7 @@ describe("SchemaPromotionBanner", () => { topicName={"my-test-topic"} setShowSchemaPromotionModal={mockSetShowSchemaPromotionModal} hasOpenSchemaRequest={false} + hasOpenClaimRequest={false} />, { browserRouter: true } ); @@ -66,6 +68,7 @@ describe("SchemaPromotionBanner", () => { topicName={"my-test-topic"} setShowSchemaPromotionModal={mockSetShowSchemaPromotionModal} hasOpenSchemaRequest={true} + hasOpenClaimRequest={false} />, { browserRouter: true } ); @@ -80,7 +83,34 @@ describe("SchemaPromotionBanner", () => { expect(linkSeeRequest).toBeVisible(); expect(linkSeeRequest).toHaveAttribute( "href", - `/requests/schemas?search=my-test-topic&status=CREATED&page=1` + `/requests/schemas?search=my-test-topic&requestType=ALL&status=CREATED&page=1` + ); + expect(buttonPromote).not.toBeInTheDocument(); + }); + + it("renders correct banner (see open claim request)", () => { + customRender( + , + { browserRouter: true } + ); + + const buttonPromote = screen.queryByRole("button", { + name: "Promote", + }); + const linkSeeRequest = screen.getByRole("link", { + name: "View request", + }); + + expect(linkSeeRequest).toBeVisible(); + expect(linkSeeRequest).toHaveAttribute( + "href", + `/approvals/schemas?search=my-test-topic&requestType=CLAIM&status=CREATED&page=1` ); expect(buttonPromote).not.toBeInTheDocument(); }); @@ -95,6 +125,7 @@ describe("SchemaPromotionBanner", () => { topicName={"my-test-topic"} setShowSchemaPromotionModal={mockSetShowSchemaPromotionModal} hasOpenSchemaRequest={false} + hasOpenClaimRequest={false} />, { browserRouter: true } ); @@ -124,6 +155,7 @@ describe("SchemaPromotionBanner", () => { topicName={"my-test-topic"} setShowSchemaPromotionModal={mockSetShowSchemaPromotionModal} hasOpenSchemaRequest={false} + hasOpenClaimRequest={false} />, { browserRouter: true } ); diff --git a/coral/src/app/features/topics/details/schema/components/SchemaPromotionBanner.tsx b/coral/src/app/features/topics/details/schema/components/SchemaPromotionBanner.tsx index 3b55cc0bff..8a63294135 100644 --- a/coral/src/app/features/topics/details/schema/components/SchemaPromotionBanner.tsx +++ b/coral/src/app/features/topics/details/schema/components/SchemaPromotionBanner.tsx @@ -1,6 +1,7 @@ import { Button } from "@aivenio/aquarium"; import { TopicSchemaOverview } from "src/domain/topic"; import { PromotionBanner } from "src/app/features/topics/details/components/PromotionBanner"; +import { useEffect } from "react"; interface SchemaPromotionBannerProps { schemaPromotionDetails: TopicSchemaOverview["schemaPromotionDetails"]; @@ -9,6 +10,7 @@ interface SchemaPromotionBannerProps { * information to the user. */ hasOpenSchemaRequest: boolean; + hasOpenClaimRequest: boolean; topicName: string; setShowSchemaPromotionModal: () => void; hasError?: boolean; @@ -18,17 +20,23 @@ interface SchemaPromotionBannerProps { const SchemaPromotionBanner = ({ schemaPromotionDetails, hasOpenSchemaRequest, + hasOpenClaimRequest, topicName, setShowSchemaPromotionModal, hasError = false, errorMessage = "", }: SchemaPromotionBannerProps) => { + useEffect(() => { + console.log("hasOpenClaimRequest", hasOpenClaimRequest); + console.log("hasOpenSchemaRequest", hasOpenSchemaRequest); + }); return (