Skip to content

Commit

Permalink
Fix handling for open CLAIM request in promotion.
Browse files Browse the repository at this point in the history
Signed-off-by: Mirjam Aulbach <mirjam.aulbach@aiven.io>
  • Loading branch information
programmiri committed Aug 17, 2023
1 parent bbb4ee1 commit a006fb8
Show file tree
Hide file tree
Showing 8 changed files with 234 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe("PromotionBanner", () => {
type={"schema"}
promoteElement={<></>}
hasOpenRequest={false}
hasOpenClaimRequest={false}
hasError={false}
errorMessage={""}
/>,
Expand All @@ -40,6 +41,7 @@ describe("PromotionBanner", () => {
type={"schema"}
promoteElement={<></>}
hasOpenRequest={false}
hasOpenClaimRequest={false}
hasError={false}
errorMessage={""}
/>,
Expand All @@ -57,6 +59,7 @@ describe("PromotionBanner", () => {
type={"schema"}
promoteElement={<></>}
hasOpenRequest={false}
hasOpenClaimRequest={false}
hasError={false}
errorMessage={""}
/>,
Expand All @@ -74,6 +77,7 @@ describe("PromotionBanner", () => {
type={"schema"}
promoteElement={<></>}
hasOpenRequest={false}
hasOpenClaimRequest={false}
hasError={false}
errorMessage={""}
/>,
Expand All @@ -91,6 +95,7 @@ describe("PromotionBanner", () => {
type={"schema"}
promoteElement={<></>}
hasOpenRequest={false}
hasOpenClaimRequest={false}
hasError={false}
errorMessage={""}
/>,
Expand All @@ -108,6 +113,7 @@ describe("PromotionBanner", () => {
type={"schema"}
promoteElement={<></>}
hasOpenRequest={false}
hasOpenClaimRequest={false}
hasError={false}
errorMessage={""}
/>,
Expand All @@ -126,6 +132,7 @@ describe("PromotionBanner", () => {
promotionDetails={promotionDetails}
type={"schema"}
promoteElement={<></>}
hasOpenClaimRequest={false}
hasOpenRequest={true}
hasError={false}
errorMessage={""}
Expand All @@ -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"
);
});
});
Expand All @@ -163,6 +170,7 @@ describe("PromotionBanner", () => {
promotionDetails={promotionDetails}
type={"topic"}
promoteElement={<></>}
hasOpenClaimRequest={false}
hasOpenRequest={true}
hasError={false}
errorMessage={""}
Expand All @@ -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(
<PromotionBanner
entityName={testTopicName}
promotionDetails={promotionDetails}
type={"schema"}
promoteElement={<></>}
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(
<PromotionBanner
entityName={testTopicName}
promotionDetails={promotionDetails}
type={"topic"}
promoteElement={<></>}
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"
);
});
});
Expand All @@ -200,6 +284,7 @@ describe("PromotionBanner", () => {
promotionDetails={{ ...promotionDetails, status: "REQUEST_OPEN" }}
type={"schema"}
promoteElement={<></>}
hasOpenClaimRequest={false}
hasOpenRequest={false}
hasError={false}
errorMessage={""}
Expand Down Expand Up @@ -238,6 +323,7 @@ describe("PromotionBanner", () => {
type={"topic"}
promoteElement={<></>}
hasOpenRequest={false}
hasOpenClaimRequest={false}
hasError={false}
errorMessage={""}
/>,
Expand Down Expand Up @@ -277,6 +363,7 @@ describe("PromotionBanner", () => {
promotionDetails={promotionDetails}
type={"schema"}
promoteElement={promoteElement}
hasOpenClaimRequest={false}
hasOpenRequest={false}
hasError={false}
errorMessage={""}
Expand Down Expand Up @@ -314,6 +401,7 @@ describe("PromotionBanner", () => {
type={"topic"}
promoteElement={promoteElement}
hasOpenRequest={false}
hasOpenClaimRequest={false}
hasError={false}
errorMessage={""}
/>,
Expand Down Expand Up @@ -360,6 +448,7 @@ describe("PromotionBanner", () => {
type={"schema"}
promoteElement={<></>}
hasOpenRequest={false}
hasOpenClaimRequest={false}
hasError={true}
errorMessage={testErrorMessage}
/>,
Expand All @@ -381,6 +470,7 @@ describe("PromotionBanner", () => {
type={"schema"}
promoteElement={<></>}
hasOpenRequest={false}
hasOpenClaimRequest={false}
hasError={true}
errorMessage={""}
/>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 (
<Banner image={illustration} layout="vertical" title={""}>
<Box component={"p"} marginBottom={"l1"}>
{entityName} has a pending request.
</Box>
<InternalLinkButton
to={`/requests/${type}s?search=${entityName}&status=CREATED&page=1`}
>
View request
</InternalLinkButton>
</Banner>
);
}
if (hasPendingRequest) {
const requestType = getRequestType({
hasOpenClaimRequest,
hasOpenPromotionRequest,
});
const link = createLink({ type, entityName, requestType });
const text = createText({ entityName, requestType });

if (hasOpenPromotionRequest) {
return (
<Banner image={illustration} layout="vertical" title={""}>
<Box component={"p"} marginBottom={"l1"}>
An promotion request for {entityName} is already in progress.
{text}
</Box>
<InternalLinkButton
to={`/requests/${type}s?search=${entityName}&requestType=PROMOTE&status=CREATED&page=1`}
>
View request
</InternalLinkButton>
<InternalLinkButton to={link}>View request</InternalLinkButton>
</Banner>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ function TopicOverview() {
} = useTopicDetails();

const {
topicInfo: { topicOwner = false, hasOpenTopicRequest, clusterId },
topicInfo: {
topicOwner = false,
hasOpenTopicRequest,
hasOpenClaimRequest,
clusterId,
},
topicPromotionDetails,
} = topicOverview;

Expand Down Expand Up @@ -75,6 +80,7 @@ function TopicOverview() {
<TopicPromotionBanner
topicName={topicName}
topicPromotionDetails={topicPromotionDetails}
hasOpenClaimRequest={hasOpenClaimRequest}
hasOpenTopicRequest={hasOpenTopicRequest}
/>
</GridItem>
Expand Down
Loading

0 comments on commit a006fb8

Please sign in to comment.