Skip to content

Commit

Permalink
Disable approve/merge/close buttons for merged Proposed Changes (#4633)
Browse files Browse the repository at this point in the history
  • Loading branch information
bilalabbad authored Oct 15, 2024
1 parent cffafd3 commit 05aab68
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog/3495.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Disable approve/merge/close buttons for merged Proposed Changes
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@ import { useAtomValue } from "jotai/index";
import React, { useState } from "react";
import { toast } from "react-toastify";

interface PcMergeButtonProps extends ButtonProps {
interface PcApproveButtonProps extends ButtonProps {
proposedChangeId: string;
approvers: Array<any>;
state: "closed" | "open" | "merged";
}

export const PcApproveButton = ({
approvers = [],
proposedChangeId,
state,
...props
}: PcMergeButtonProps) => {
}: PcApproveButtonProps) => {
const branch = useAtomValue(currentBranchAtom);
const date = useAtomValue(datetimeAtom);
const auth = useAuth();
Expand Down Expand Up @@ -81,7 +83,13 @@ export const PcApproveButton = ({
variant="outline"
onClick={handleApprove}
isLoading={isLoadingApprove}
disabled={!auth?.permissions?.write || !approverId || !canApprove}
disabled={
!auth?.permissions?.write ||
!approverId ||
!canApprove ||
state === "closed" ||
state === "merged"
}
{...props}
>
Approve
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ export const ProposedChangeDetails = ({ className, ...props }: HTMLAttributes<HT
name: "Actions",
value: (
<div className="flex flex-wrap gap-2">
<PcApproveButton approvers={approvers} proposedChangeId={proposedChangeId!} />
<PcApproveButton
approvers={approvers}
proposedChangeId={proposedChangeId!}
state={state}
/>
<PcMergeButton
proposedChangeId={proposedChangeId!}
state={state}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ test.describe("/proposed-changes", () => {
});

await test.step("not able to edit proposed change", async () => {
await expect(page.getByRole("button", { name: "Approve" })).toBeDisabled();
await expect(page.getByRole("button", { name: "Merge" })).toBeDisabled();
await expect(page.getByRole("button", { name: "Close" })).toBeDisabled();
await expect(page.getByTestId("edit-button")).toBeDisabled();
});
});
Expand Down

0 comments on commit 05aab68

Please sign in to comment.