Files
kandev/apps/web/components/task/changes-panel.tsx
T

77 lines
3.2 KiB
TypeScript

"use client";
import { memo } from "react";
import { PanelRoot } from "./panel-primitives";
import { useIsTaskArchived, ArchivedPanelPlaceholder } from "./task-archived-context";
import { ChangesPanelHeader } from "./changes-panel-header";
import {
filterUnpushedCommits,
mergeCommits,
separateCommitHistories,
} from "./changes-panel-helpers";
import { useChangesPanelData, buildChangesPanelBodyProps } from "./changes-panel-data";
import { ChangesPanelBody } from "./changes-panel-body";
import type { CommitDetailTarget, OpenDiffOptions } from "./changes-diff-target";
import { useRequestChangesWalkthrough } from "@/hooks/domains/session/use-request-changes-walkthrough";
export { filterUnpushedCommits, mergeCommits, separateCommitHistories };
type ChangesPanelProps = {
onOpenDiffFile: (path: string, options?: OpenDiffOptions) => void;
onEditFile: (path: string, repo?: string) => void;
onOpenCommitDetail?: (target: CommitDetailTarget) => void;
onOpenDiffAll?: () => void;
onOpenReview?: () => void;
};
const ChangesPanel = memo(function ChangesPanel(props: ChangesPanelProps) {
const isArchived = useIsTaskArchived();
const data = useChangesPanelData();
const requestWalkthrough = useRequestChangesWalkthrough({
taskId: data.activeTaskId,
sessionId: data.activeSessionId,
ready: data.walkthroughRequestReady,
});
if (isArchived) return <ArchivedPanelPlaceholder />;
return (
<PanelRoot className="@container/changes-panel" data-testid="changes-panel">
<ChangesPanelHeader
hasChanges={data.git.hasChanges}
hasCommits={data.git.hasCommits}
hasPRFiles={data.hasPRFiles}
displayBranch={data.git.branch}
baseBranchDisplay={data.baseBranchDisplay}
baseBranchByRepo={data.baseBranchByRepo}
behindCount={data.git.pullBehind}
pullDisabled={data.pullDisabled}
pullDisabledReason={data.pullDisabledReason}
isLoading={data.git.isLoading}
loadingOperation={data.git.loadingOperation}
onOpenDiffAll={props.onOpenDiffAll}
onOpenReview={props.onOpenReview}
onRequestWalkthrough={requestWalkthrough}
requestWalkthroughDisabled={!data.walkthroughRequestReady}
repoNames={data.git.repoNames}
perRepoStatus={data.git.perRepoStatus}
onRepoPull={data.repoCallbacks.onRepoPull}
onRepoRebase={data.repoCallbacks.onRepoRebase}
onRepoMerge={data.repoCallbacks.onRepoMerge}
onRenameBranch={data.git.renameBranch}
repoDisplayName={data.repoDisplayName}
taskId={data.activeTaskId}
credentialDisplay={data.gitCredentialDisplay}
comparisonTargets={data.git.comparisonTargets}
relation={data.relation}
resolution={data.resolution}
resolutionTarget={data.resolutionTarget}
remoteContributionUrl={data.selectedPR?.pr_url ?? data.existingPrUrl}
remoteContributionNumber={data.selectedPR?.pr_number}
/>
<ChangesPanelBody {...buildChangesPanelBodyProps(data, props)} />
</PanelRoot>
);
});
export { ChangesPanel, ChangesPanelBody, useChangesPanelData, buildChangesPanelBodyProps };
export type { ChangesPanelBodyProps } from "./changes-panel-data";