Skip to content

Commit

Permalink
fix: fix wrong review trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
gregberge committed Nov 17, 2024
1 parent f77006d commit bf4d510
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 36 deletions.
6 changes: 4 additions & 2 deletions apps/frontend/src/pages/Build/BuildReviewButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ function BaseReviewButton(props: {
}) {
const markAllDiffsAsAccepted = useMarkAllDiffsAsAccepted();
const [setValidationStatus, { loading }] = useSetValidationStatusMutation({
onCompleted: () => {
markAllDiffsAsAccepted();
onCompleted: (data) => {
if (data.setValidationStatus.status === BuildStatus.Accepted) {
markAllDiffsAsAccepted();
}
props.onCompleted?.();
},
});
Expand Down
6 changes: 1 addition & 5 deletions apps/frontend/src/pages/Build/BuildReviewDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ import { Modal, ModalProps } from "@/ui/Modal";

import { useSetValidationStatusMutation } from "./BuildReviewAction";
import { BuildReviewButton } from "./BuildReviewButton";
import {
ReviewCompleteWatcher,
useBuildReviewSummary,
} from "./BuildReviewState";
import { useBuildReviewSummary } from "./BuildReviewState";

const ProjectFragment = graphql(`
fragment BuildReviewDialog_Project on Project {
Expand Down Expand Up @@ -157,7 +154,6 @@ export function BuildReviewDialogProvider(props: {
const value = useMemo(() => ({ setIsOpen }), []);
return (
<>
<ReviewCompleteWatcher onReviewComplete={() => setIsOpen(true)} />
{project && (
<BuildReviewDialog
isOpen={isOpen}
Expand Down
28 changes: 0 additions & 28 deletions apps/frontend/src/pages/Build/BuildReviewState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,34 +77,6 @@ function useReviewStatus() {
}, [stats, diffStatuses]);
}

/**
* Triggers the callback when the review becomes "complete".
* Switching from "pending" to "complete" state.
*/
function useWatchReviewComplete(callback: () => void) {
const reviewStatus = useReviewStatus();
const previousReviewStatus = usePrevious(reviewStatus);
const { buildStatus } = useBuildReviewState();
const evtCallback = useEventCallback(callback);
useEffect(() => {
if (
buildStatus === BuildStatus.DiffDetected &&
previousReviewStatus === "pending" &&
reviewStatus === "complete"
) {
evtCallback();
}
}, [reviewStatus, previousReviewStatus, evtCallback, buildStatus]);
}

/**
* Watch the review status and trigger the callback when the review is complete.
*/
export function ReviewCompleteWatcher(props: { onReviewComplete: () => void }) {
useWatchReviewComplete(props.onReviewComplete);
return null;
}

export function useWatchItemReview() {
const { listenersRef } = useBuildReviewState();
return useCallback(
Expand Down
7 changes: 6 additions & 1 deletion apps/frontend/src/pages/Build/toolbar/TrackButtons.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { memo, useEffect } from "react";
import { memo, useEffect, useRef } from "react";
import { ThumbsDownIcon, ThumbsUpIcon } from "lucide-react";

import { ProjectPermission } from "@/gql/graphql";
Expand Down Expand Up @@ -27,8 +27,12 @@ function useEvaluationToggle(props: {
diffId,
diffGroup,
});
const toggledRef = useRef(false);
const previous = usePrevious({ diffId, status });
useEffect(() => {
if (!toggledRef.current) {
return;
}
if (!previous || previous.status === status || previous.diffId !== diffId) {
return;
}
Expand All @@ -37,6 +41,7 @@ function useEvaluationToggle(props: {
}
}, [status, acknowledgeMarkedDiff, target, previous, diffId]);
const toggle = useEventCallback(() => {
toggledRef.current = true;
setStatus(
status === EvaluationStatus.Pending ? target : EvaluationStatus.Pending,
);
Expand Down

0 comments on commit bf4d510

Please sign in to comment.