@@ -4,7 +4,7 @@ import type {
44 WorktreeCleanupRules ,
55} from "@t3tools/contracts" ;
66import { resolveWorktreeCleanup } from "@t3tools/shared/projectSettings" ;
7- import { useMemo , useRef , useState } from "react" ;
7+ import { useRef , useState } from "react" ;
88import { useAtomValue } from "@effect/atom-react" ;
99import { Atom } from "effect/reactivity" ;
1010import {
@@ -259,32 +259,28 @@ function CleanupSection() {
259259 ( environment ) => environment . serverConfig ?. environment . capabilities . storageCleanupRun === true ,
260260 ) ;
261261 const state = useAtomValue (
262- useMemo (
263- ( ) =>
264- Atom . make ( ( get ) =>
265- connectedEnvironments . flatMap ( ( environment ) => {
266- if ( environment . serverConfig ?. environment . capabilities . storageCleanupRun !== true )
267- return [ ] ;
268- const query = get (
269- serverEnvironment . storageCleanupReport ( {
270- environmentId : environment . environmentId ,
271- input : { } ,
272- } ) ,
273- ) ;
274- return [
275- {
276- environmentId : environment . environmentId ,
277- allowed : get (
278- serverEnvironment . runStorageCleanup . permissionAtom ( environment . environmentId ) ,
279- ) ,
280- report : query . _tag === "Success" ? query . value : null ,
281- loading : query . waiting ,
282- failed : query . _tag === "Failure" ,
283- } ,
284- ] ;
262+ Atom . make ( ( get ) =>
263+ connectedEnvironments . flatMap ( ( environment ) => {
264+ if ( environment . serverConfig ?. environment . capabilities . storageCleanupRun !== true )
265+ return [ ] ;
266+ const query = get (
267+ serverEnvironment . storageCleanupReport ( {
268+ environmentId : environment . environmentId ,
269+ input : { } ,
285270 } ) ,
286- ) ,
287- [ connectedEnvironments ] ,
271+ ) ;
272+ return [
273+ {
274+ environmentId : environment . environmentId ,
275+ allowed : get (
276+ serverEnvironment . runStorageCleanup . permissionAtom ( environment . environmentId ) ,
277+ ) ,
278+ report : query . _tag === "Success" ? query . value : null ,
279+ loading : query . waiting ,
280+ failed : query . _tag === "Failure" ,
281+ } ,
282+ ] ;
283+ } ) ,
288284 ) ,
289285 ) ;
290286 const hasRules = supported . some ( ( environment ) => {
@@ -329,36 +325,30 @@ function CleanupSection() {
329325 const deleteNow = async ( ) => {
330326 if ( pending ) return ;
331327 setPending ( true ) ;
332- try {
333- await Promise . all (
334- supported
335- . filter ( ( environment ) =>
336- state . some (
337- ( entry ) => entry . environmentId === environment . environmentId && entry . allowed ,
338- ) ,
339- )
340- . map ( async ( environment ) => {
341- const result = await run ( { environmentId : environment . environmentId , input : { } } ) ;
342- if ( result . _tag === "Success" ) {
343- const failures = result . value . entries . filter ( ( entry ) => entry . outcome === "failed" ) ;
344- if ( failures . length > 0 )
345- toastManager . add ( {
346- type : "error" ,
347- title : `Cleanup failed on ${ environment . label } ` ,
348- description : failures [ 0 ] ! . reason ,
349- } ) ;
350- } else if ( ! isAtomCommandInterrupted ( result ) ) {
328+ await Promise . all (
329+ supported
330+ . filter ( ( environment ) =>
331+ state . some ( ( entry ) => entry . environmentId === environment . environmentId && entry . allowed ) ,
332+ )
333+ . map ( async ( environment ) => {
334+ const result = await run ( { environmentId : environment . environmentId , input : { } } ) ;
335+ if ( result . _tag === "Success" ) {
336+ const failures = result . value . entries . filter ( ( entry ) => entry . outcome === "failed" ) ;
337+ if ( failures . length > 0 )
351338 toastManager . add ( {
352339 type : "error" ,
353- title : `Could not run cleanup on ${ environment . label } ` ,
354- description : String ( squashAtomCommandFailure ( result ) ) ,
340+ title : `Cleanup failed on ${ environment . label } ` ,
341+ description : failures [ 0 ] ! . reason ,
355342 } ) ;
356- }
357- } ) ,
358- ) ;
359- } finally {
360- setPending ( false ) ;
361- }
343+ } else if ( ! isAtomCommandInterrupted ( result ) ) {
344+ toastManager . add ( {
345+ type : "error" ,
346+ title : `Could not run cleanup on ${ environment . label } ` ,
347+ description : String ( squashAtomCommandFailure ( result ) ) ,
348+ } ) ;
349+ }
350+ } ) ,
351+ ) . finally ( ( ) => setPending ( false ) ) ;
362352 } ;
363353 return (
364354 < SettingsSection id = "storage-cleanup" title = "Cleanup" variant = "plain" >
0 commit comments