1- import {
2- resolveEnvironmentMachineKind ,
3- type StorageCleanupReport ,
4- type StorageCleanupSettings ,
5- type WorktreeCleanupRules ,
1+ import type {
2+ StorageCleanupReport ,
3+ StorageCleanupSettings ,
4+ WorktreeCleanupRules ,
65} from "@t3tools/contracts" ;
76import { resolveWorktreeCleanup } from "@t3tools/shared/projectSettings" ;
87import { useMemo , useRef , useState } from "react" ;
98import { useAtomValue } from "@effect/atom-react" ;
109import { Atom } from "effect/reactivity" ;
11- import { ChevronRightIcon } from "lucide-react" ;
1210import {
1311 isAtomCommandInterrupted ,
1412 squashAtomCommandFailure ,
@@ -18,7 +16,6 @@ import { serverEnvironment } from "../../state/server";
1816import { useAtomCommand } from "../../state/use-atom-command" ;
1917import { formatRelativeTimeLabel } from "../../timestampFormat" ;
2018import { Button } from "../ui/button" ;
21- import { Collapsible , CollapsiblePanel , CollapsibleTrigger } from "../ui/collapsible" ;
2219import { toastManager } from "../ui/toast" ;
2320
2421import { Input } from "../ui/input" ;
@@ -39,19 +36,18 @@ import {
3936 useRelativeTimeTick ,
4037} from "./settingsLayout" ;
4138import { SettingsScopeNotice } from "./SettingsScopeNotice" ;
42- import { EnvironmentRow } from "./EnvironmentRow" ;
4339import { FoldedSettingsSection } from "./FoldedSettingsSection" ;
4440import { SettingsGroup } from "./SettingsGroup" ;
4541import type { ScopedSettingsTarget } from "./scopedSettings" ;
4642import { useSettingsScope } from "./SettingsScopeContext" ;
4743import { searchableSetting } from "./settingsSearch" ;
48- import { settingsScopeEnvironmentLabels } from "./settingsScopeAxis" ;
4944import {
5045 useClearScopedSettings ,
5146 useScopedSettings ,
5247 useScopedSettingsMixed ,
5348 useUpdateScopedSettings ,
5449} from "./useScopedSettings" ;
50+ import { settingsScopeEnvironmentLabel } from "./settingsScopeAxis" ;
5551
5652function WorktreesDirectoryRow ( ) {
5753 const { connectedEnvironments, targets } = useSettingsScope ( ) ;
@@ -174,6 +170,20 @@ const KEEP_WHEN_LABELS = {
174170 "tracked-changes" : "Edited tracked files" ,
175171} as const ;
176172
173+ /** One line for the last-run fold; identical results across machines collapse into one. */
174+ function lastRunSummary (
175+ entries : readonly { readonly label : string ; readonly counts : string } [ ] ,
176+ machineCount : number ,
177+ ) {
178+ const first = entries [ 0 ] ;
179+ if ( ! first ) return "" ;
180+ if ( machineCount <= 1 ) return first . counts ;
181+ if ( entries . length === machineCount && entries . every ( ( entry ) => entry . counts === first . counts ) ) {
182+ return `${ first . counts } on every machine` ;
183+ }
184+ return entries . map ( ( entry ) => `${ entry . label } : ${ entry . counts } ` ) . join ( " · " ) ;
185+ }
186+
177187function CleanupResults ( {
178188 report,
179189 environmentLabel,
@@ -295,7 +305,6 @@ function CleanupSection() {
295305 const report = query ?. report ?? null ;
296306 return {
297307 environment,
298- labels : settingsScopeEnvironmentLabels ( environment , connectedEnvironments ) ,
299308 report,
300309 description : report
301310 ? `Last run ${ formatRelativeTimeLabel ( report . finishedAt ) } . ${ formatBytes ( report . bytesFreed ) } recovered.${ report . counts . failed > 0 ? ` ${ report . counts . failed } ${ report . counts . failed === 1 ? "item" : "items" } couldn't be removed.` : "" } `
@@ -306,22 +315,6 @@ function CleanupSection() {
306315 : "Cleanup hasn't run yet." ,
307316 } ;
308317 } ) ;
309- const latestReport = summaries
310- . map ( ( { report } ) => report )
311- . reduce (
312- ( latest , report ) =>
313- report && ( latest === null || Date . parse ( report . finishedAt ) > Date . parse ( latest . finishedAt ) )
314- ? report
315- : latest ,
316- null ,
317- ) ;
318- const latestRunSummary = latestReport
319- ? `Latest run ${ formatRelativeTimeLabel ( latestReport . finishedAt ) } .`
320- : state . some ( ( entry ) => entry . failed )
321- ? "Could not load the last run on some machines."
322- : state . some ( ( entry ) => entry . loading )
323- ? "Loading last runs…"
324- : "Cleanup hasn't run yet." ;
325318 const deleteNow = async ( ) => {
326319 if ( pending ) return ;
327320 setPending ( true ) ;
@@ -363,13 +356,14 @@ function CleanupSection() {
363356 { ...searchableSetting ( "storage-delete-now" ) }
364357 description = {
365358 < span >
366- { ! hasRules ? (
367- "Turn on a cleanup rule to use this."
368- ) : supported . length > 1 ? (
369- latestRunSummary
370- ) : (
371- < span className = "block" > { summaries [ 0 ] ?. description } </ span >
372- ) }
359+ { ! hasRules
360+ ? "Turn on a cleanup rule to use this."
361+ : summaries . map ( ( { environment, description } ) => (
362+ < span key = { environment . environmentId } className = "block" >
363+ { supported . length > 1 ? `${ environment . label } : ` : "" }
364+ { description }
365+ </ span >
366+ ) ) }
373367 </ span >
374368 }
375369 control = {
@@ -383,62 +377,25 @@ function CleanupSection() {
383377 </ Button >
384378 }
385379 />
386- { supported . length > 1 &&
387- summaries . map ( ( { environment, labels, report, description } ) => (
388- < Collapsible key = { environment . environmentId } >
389- < EnvironmentRow
390- kind = { resolveEnvironmentMachineKind ( environment . serverConfig ) }
391- label = { labels . primary }
392- subtitle = {
393- < >
394- { labels . secondary ? (
395- < span className = "block truncate" > { labels . secondary } </ span >
396- ) : null }
397- < span className = "block truncate" >
398- { report
399- ? `${ formatBytes ( report . bytesFreed ) } recovered${ report . counts . failed > 0 ? ` · ${ report . counts . failed } failed` : "" } · ${ formatRelativeTimeLabel ( report . finishedAt ) } `
400- : description }
401- </ span >
402- </ >
403- }
404- >
405- { report ? (
406- < CollapsibleTrigger
407- render = { < Button variant = "ghost-muted" size = "xs" /> }
408- aria-label = { `Cleanup details for ${ labels . primary } ${ labels . secondary ? ` (${ labels . secondary } )` : "" } ` }
409- >
410- Details
411- < ChevronRightIcon
412- aria-hidden
413- className = "size-3.5 [[data-panel-open]_&]:rotate-90"
414- />
415- </ CollapsibleTrigger >
416- ) : null }
417- </ EnvironmentRow >
418- { report ? (
419- < CollapsiblePanel >
420- < div className = "border-t border-border/50 [&>*+*]:border-t [&>*+*]:border-border/50" >
421- < CleanupResults report = { report } environmentLabel = { undefined } />
422- </ div >
423- </ CollapsiblePanel >
424- ) : null }
425- </ Collapsible >
426- ) ) }
427380 </ SettingsGroup >
428- { supported . length === 1 && summaries . some ( ( { report } ) => report !== null ) && (
381+ { summaries . some ( ( { report } ) => report !== null ) && (
429382 < FoldedSettingsSection
430383 id = "storage-cleanup-last-run"
431384 title = "Last run"
432385 headerPlacement = "inside"
433- summary = { summaries
434- . flatMap ( ( { environment, report } ) =>
386+ summary = { lastRunSummary (
387+ summaries . flatMap ( ( { environment, report } ) =>
435388 report
436389 ? [
437- `${ connectedEnvironments . length > 1 ? `${ environment . label } : ` : "" } ${ report . counts . removed } removed, ${ report . counts . kept } kept${ report . counts . failed > 0 ? `, ${ report . counts . failed } failed` : "" } ` ,
390+ {
391+ label : settingsScopeEnvironmentLabel ( environment , connectedEnvironments ) ,
392+ counts : `${ report . counts . removed } removed, ${ report . counts . kept } kept${ report . counts . failed > 0 ? `, ${ report . counts . failed } failed` : "" } ` ,
393+ } ,
438394 ]
439395 : [ ] ,
440- )
441- . join ( " · " ) }
396+ ) ,
397+ connectedEnvironments . length ,
398+ ) }
442399 >
443400 { summaries . map (
444401 ( { environment, report } ) =>
@@ -447,7 +404,9 @@ function CleanupSection() {
447404 key = { environment . environmentId }
448405 report = { report }
449406 environmentLabel = {
450- connectedEnvironments . length > 1 ? environment . label : undefined
407+ connectedEnvironments . length > 1
408+ ? settingsScopeEnvironmentLabel ( environment , connectedEnvironments )
409+ : undefined
451410 }
452411 />
453412 ) ,
0 commit comments