Skip to content

Commit

Permalink
more cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
bilalabbad committed Feb 4, 2025
1 parent efa2f63 commit b65cc75
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
24 changes: 7 additions & 17 deletions frontend/app/src/entities/diff/node-diff/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { PROPOSED_CHANGES_OBJECT_THREAD_OBJECT } from "@/config/constants";
import { QSP } from "@/config/qsp";
import { useAuth } from "@/entities/authentication/ui/useAuth";
import { BRANCH_REBASE } from "@/entities/branches/api/rebaseBranch";
import { DIFF_UPDATE } from "@/entities/diff/api/diff-update";
import { useUpdateDiffMutation } from "@/entities/diff/domain/update-diff.mutation";
import { DIFF_STATUS, DiffNode as DiffNodeType } from "@/entities/diff/node-diff/types";
import { DiffComputing } from "@/entities/diff/ui/diff-computing";
import { DiffEmpty } from "@/entities/diff/ui/diff-empty";
import { DiffNoFound } from "@/entities/diff/ui/diff-no-found";
import { DiffRefreshButton } from "@/entities/diff/ui/diff-refresh-button";
import DiffTree from "@/entities/diff/ui/diff-tree";
import { getProposedChangesDiffTree } from "@/entities/proposed-changes/api/getProposedChangesDiffTree";
import { proposedChangedState } from "@/entities/proposed-changes/stores/proposedChanges.atom";
Expand All @@ -19,7 +19,7 @@ import ErrorScreen from "@/shared/components/errors/error-screen";
import LoadingScreen from "@/shared/components/loading-screen";
import { ALERT_TYPES, Alert } from "@/shared/components/ui/alert";
import { datetimeAtom } from "@/shared/stores/time.atom";
import { NetworkStatus, useMutation } from "@apollo/client";
import { NetworkStatus } from "@apollo/client";
import { useAtomValue } from "jotai";
import { createContext, useState } from "react";
import { toast } from "react-toastify";
Expand Down Expand Up @@ -51,7 +51,6 @@ const buildFilters = (filters: DiffFilter, qsp?: string | null) => {
};

export const NodeDiff = ({ branchName, filters }: NodeDiffProps) => {
const { isAuthenticated } = useAuth();
const [qspStatus] = useQueryParam(QSP.STATUS, StringParam);
const date = useAtomValue(datetimeAtom);
const proposedChangesDetails = useAtomValue(proposedChangedState);
Expand All @@ -60,9 +59,7 @@ export const NodeDiff = ({ branchName, filters }: NodeDiffProps) => {

const branch = proposedChangesDetails?.source_branch?.value || branchName; // Used in proposed changes view and branch view

const [scheduleDiffTreeUpdate] = useMutation(DIFF_UPDATE, {
variables: { branchName: branch, wait: true },
});
const updateDiffMutation = useUpdateDiffMutation();

const schemaData = nodeSchemas.find((s) => s.kind === PROPOSED_CHANGES_OBJECT_THREAD_OBJECT);

Expand All @@ -84,7 +81,7 @@ export const NodeDiff = ({ branchName, filters }: NodeDiffProps) => {
const handleRefresh = async () => {
setIsLoadingUpdate(true);
try {
await scheduleDiffTreeUpdate();
await updateDiffMutation.mutateAsync(branch);

await graphqlClient.refetchQueries({
include: ["GET_PROPOSED_CHANGES_DIFF_TREE", "GET_PROPOSED_CHANGES_DIFF_SUMMARY"],
Expand Down Expand Up @@ -136,7 +133,7 @@ export const NodeDiff = ({ branchName, filters }: NodeDiffProps) => {
}

if (!qspStatus && diffTreeData.nodes.length === 0) {
return <DiffEmpty branchName={branchName} lastRefreshedAt={diffTreeData.to_time} />;
return <DiffEmpty branchName={branch} lastRefreshedAt={diffTreeData.to_time} />;
}

// Manually filter conflicts items since it's not available yet in the backend filters
Expand All @@ -161,14 +158,7 @@ export const NodeDiff = ({ branchName, filters }: NodeDiffProps) => {
<DateDisplay date={diffTreeData?.to_time} />
</div>

<Button
size="sm"
variant="primary"
onClick={handleRefresh}
disabled={!isAuthenticated || isLoadingUpdate}
>
Refresh diff
</Button>
<DiffRefreshButton size="sm" variant="primary" branchName={branch} />
</div>

<Button
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/entities/diff/ui/diff-computing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function DiffComputing({ sourceBranch, destinationBranch }: DiffComputing
<p>Once completed, you&apos;ll be able to view the detailed changes.</p>
</div>

<DiffRefreshButton branchName={destinationBranch} />
<DiffRefreshButton branchName={sourceBranch} />
</div>
);
}
16 changes: 12 additions & 4 deletions frontend/app/src/entities/diff/ui/diff-refresh-button.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
import { useUpdateDiffMutation } from "@/entities/diff/domain/update-diff.mutation";
import { Button } from "@/shared/components/buttons/button-primitive";
import { Button, ButtonProps } from "@/shared/components/buttons/button-primitive";
import { classNames } from "@/shared/utils/common";
import { Icon } from "@iconify-icon/react";

export function DiffRefreshButton({ branchName }: { branchName: string }) {
export interface DiffRefreshButtonProps extends Omit<ButtonProps, "onClick"> {
branchName: string;
}

export function DiffRefreshButton({ branchName, ...props }: DiffRefreshButtonProps) {
const updateDiffMutation = useUpdateDiffMutation();

return (
<Button variant="primary-outline" onClick={() => updateDiffMutation.mutate(branchName)}>
<Button
variant="primary-outline"
onClick={() => updateDiffMutation.mutate(branchName)}
{...props}
>
<Icon
icon="mdi:reload"
className={classNames("mr-1", updateDiffMutation.isPending && "animate-spin")}
/>
{updateDiffMutation.isPending ? "Refreshing..." : "Refresh"}
{updateDiffMutation.isPending ? "Refreshing diff..." : "Refresh diff"}
</Button>
);
}

0 comments on commit b65cc75

Please sign in to comment.