@@ -57,6 +57,7 @@ import {
5757 resolveLiveThreadBranchUpdate ,
5858 resolveThreadBranchMetadataPatch ,
5959 resolveQuickAction ,
60+ resolveChangesTotals ,
6061 resolveThreadBranchUpdate ,
6162} from "./GitActionsControl.logic" ;
6263import { WizardPopup , WizardHeader , WizardSteps , WizardPanel , WizardFooter } from "./ui/wizard" ;
@@ -119,6 +120,10 @@ import { getSourceControlPresentation, sourceControlIcon } from "~/sourceControl
119120import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients" ;
120121import { formatDiffCount } from "@t3tools/client-runtime/diff-count" ;
121122import { useOpenLink } from "~/browser/useOpenLink" ;
123+ import { selectThreadDiffPanelBaseRef , useDiffPanelStore } from "~/diffPanelStore" ;
124+ import { useClientSettings } from "~/hooks/useSettings" ;
125+ import { useFilesystemReadAccess } from "~/state/filesystem" ;
126+ import { reviewEnvironment } from "~/state/review" ;
122127
123128interface GitActionsControlProps {
124129 presentation ?: "toolbar" | "menu" ;
@@ -991,6 +996,66 @@ function PublishRepositoryDialog(props: PublishRepositoryDialogProps) {
991996 ) ;
992997}
993998
999+ function ThreadChangesControl ( {
1000+ gitCwd,
1001+ activeThreadRef,
1002+ gitStatus,
1003+ onOpenChanges,
1004+ } : Pick < GitActionsControlProps , "gitCwd" | "activeThreadRef" > & {
1005+ gitStatus : VcsStatusResult | null ;
1006+ onOpenChanges : GitActionsControlProps [ "onOpenChanges" ] ;
1007+ } ) {
1008+ const baseRef = useDiffPanelStore ( ( state ) =>
1009+ selectThreadDiffPanelBaseRef ( state , activeThreadRef ) ,
1010+ ) ;
1011+ const ignoreWhitespace = useClientSettings ( ( settings ) => settings . diffIgnoreWhitespace ) ;
1012+ // Status totals use the automatic base; a base picked in the diff panel needs its preview.
1013+ const useDiffPreview = baseRef !== null ;
1014+ const { canReadFiles } = useFilesystemReadAccess (
1015+ useDiffPreview ? ( activeThreadRef ?. environmentId ?? null ) : null ,
1016+ ) ;
1017+ // Same atom and key as the diff panel, so an open or recently closed panel's result is reused.
1018+ const changesDiffPreview = useEnvironmentQuery (
1019+ canReadFiles && useDiffPreview && activeThreadRef && gitCwd
1020+ ? reviewEnvironment . diffPreview ( {
1021+ environmentId : activeThreadRef . environmentId ,
1022+ input : {
1023+ cwd : gitCwd ,
1024+ ...( baseRef ? { baseRef } : { } ) ,
1025+ ignoreWhitespace,
1026+ } ,
1027+ } )
1028+ : null ,
1029+ ) ;
1030+ const changesTotals = useMemo (
1031+ ( ) =>
1032+ resolveChangesTotals ( {
1033+ gitStatus,
1034+ useDiffPreview,
1035+ diffPreview : canReadFiles ? changesDiffPreview . data : null ,
1036+ } ) ,
1037+ [ canReadFiles , changesDiffPreview . data , gitStatus , useDiffPreview ] ,
1038+ ) ;
1039+
1040+ return (
1041+ < ThreadDetailsControl
1042+ type = "button"
1043+ variant = "ghost"
1044+ size = "sm"
1045+ part = "row"
1046+ disabled = { ! onOpenChanges }
1047+ onClick = { onOpenChanges }
1048+ >
1049+ < FileDiffIcon className = { THREAD_DETAILS_PANEL_ICON_CLASS } aria-hidden />
1050+ < span className = { cn ( "flex-1 text-left" , THREAD_DETAILS_PANEL_LABEL_CLASS ) } > Changes</ span >
1051+ < span className = "flex items-center gap-1 font-mono text-2xs tabular-nums" >
1052+ < span className = "text-success" > +{ formatDiffCount ( changesTotals ?. insertions ?? 0 ) } </ span >
1053+ < span className = "text-destructive" > -{ formatDiffCount ( changesTotals ?. deletions ?? 0 ) } </ span >
1054+ </ span >
1055+ </ ThreadDetailsControl >
1056+ ) ;
1057+ }
1058+
9941059export default function GitActionsControl ( {
9951060 presentation = "toolbar" ,
9961061 gitCwd,
@@ -1145,8 +1210,6 @@ export default function GitActionsControl({
11451210 const isRepo = gitStatus ?. isRepo ?? true ;
11461211 const hasPrimaryRemote = gitStatus ?. hasPrimaryRemote ?? false ;
11471212 const gitStatusForActions = gitStatus ;
1148- // Matches the diff panel's Changes view. Older servers only report uncommitted totals.
1149- const changesTotals = gitStatusForActions ?. branchChanges ?? gitStatusForActions ?. workingTree ;
11501213
11511214 const allFiles = gitStatusForActions ?. workingTree . files ?? [ ] ;
11521215 const selectedFiles = allFiles . filter ( ( f ) => ! excludedFiles . has ( f . path ) ) ;
@@ -1907,23 +1970,12 @@ export default function GitActionsControl({
19071970 ) }
19081971
19091972 { isPanel && isRepo ? (
1910- < ThreadDetailsControl
1911- type = "button"
1912- variant = "ghost"
1913- size = "sm"
1914- part = "row"
1915- disabled = { ! onOpenChanges }
1916- onClick = { onOpenChanges }
1917- >
1918- < FileDiffIcon className = { THREAD_DETAILS_PANEL_ICON_CLASS } aria-hidden />
1919- < span className = { cn ( "flex-1 text-left" , THREAD_DETAILS_PANEL_LABEL_CLASS ) } > Changes</ span >
1920- < span className = "flex items-center gap-1 font-mono text-2xs tabular-nums" >
1921- < span className = "text-success" > +{ formatDiffCount ( changesTotals ?. insertions ?? 0 ) } </ span >
1922- < span className = "text-destructive" >
1923- -{ formatDiffCount ( changesTotals ?. deletions ?? 0 ) }
1924- </ span >
1925- </ span >
1926- </ ThreadDetailsControl >
1973+ < ThreadChangesControl
1974+ gitCwd = { gitCwd }
1975+ activeThreadRef = { activeThreadRef }
1976+ gitStatus = { gitStatusForActions }
1977+ onOpenChanges = { onOpenChanges }
1978+ />
19271979 ) : null }
19281980
19291981 < Dialog
0 commit comments