@@ -77,27 +77,21 @@ export function useAutoBalanceUpdateBanner(
7777 } ) ;
7878 if ( machines . length === 0 ) return null ;
7979
80- const running = machines . filter ( ( machine ) => machine . state . status === "running" ) ;
81- const failed = machines . filter ( ( machine ) => machine . state . status === "failed" ) ;
82- const manual = machines . filter ( ( machine ) => ! machine . remoteUpdate ) ;
80+ const running = machines . filter ( ( machine ) => machine . state . status === "running" ) . length ;
81+ const failed = machines . filter ( ( machine ) => machine . state . status === "failed" ) . length ;
82+ const manual = machines . filter ( ( machine ) => ! machine . remoteUpdate ) . length ;
8383 const targets = machines . filter (
8484 ( machine ) => machine . connected && machine . remoteUpdate && machine . state . status !== "running" ,
8585 ) ;
86- const title =
87- running . length > 0
88- ? `Updating ${ running . length } ${ running . length === 1 ? "machine" : "machines" } `
89- : failed . length > 0
90- ? `Could not update ${ failed . length } ${ failed . length === 1 ? "machine" : "machines" } `
91- : `Update available for ${ machines . length } ${ machines . length === 1 ? "machine" : "machines" } ` ;
86+ const count = running || failed || machines . length ;
87+ const status = running ? "running" : failed ? "failed" : "idle" ;
88+ const prefix = running ? "Updating" : failed ? "Could not update" : "Update available for" ;
89+ const title = `${ prefix } ${ count } ${ count === 1 ? "machine" : "machines" } ` ;
9290 return {
9391 id : `auto-balance-server-updates-${ dismissedNotices . size } ` ,
94- variant : failed . length > 0 ? "error" : "default" ,
95- priority : running . length > 0 ? "urgent" : "notice" ,
96- icon : (
97- < ComposerServerUpdateIcon
98- status = { running . length > 0 ? "running" : failed . length > 0 ? "failed" : "idle" }
99- />
100- ) ,
92+ variant : failed ? "error" : "default" ,
93+ priority : running ? "urgent" : "notice" ,
94+ icon : < ComposerServerUpdateIcon status = { status } /> ,
10195 title : (
10296 < Popover >
10397 < PopoverTrigger
@@ -132,40 +126,34 @@ export function useAutoBalanceUpdateBanner(
132126 </ Popover >
133127 ) ,
134128 description :
135- manual . length > 0
136- ? `${ manual . length } ${ manual . length === 1 ? "needs" : "need" } a manual update`
137- : undefined ,
129+ manual > 0 ? `${ manual } ${ manual === 1 ? "needs" : "need" } a manual update` : undefined ,
138130 actions :
139- running . length === 0 && targets . length > 0 ? (
131+ running === 0 && targets . length > 0 ? (
140132 < ServerUpdatesAction
141133 targets = { targets }
142134 variant = "ghost"
143135 label = {
144- failed . length > 0
136+ failed > 0
145137 ? "Retry"
146138 : targets . length === machines . length
147139 ? "Update all"
148140 : `Update ${ targets . length } ${ targets . length === 1 ? "machine" : "machines" } `
149141 }
150142 />
151143 ) : undefined ,
152- ...( running . length > 0
144+ dismissLabel : "Dismiss update notice" ,
145+ ...( running
153146 ? { }
154147 : {
155- dismissLabel : "Dismiss update notice" ,
156148 onDismiss : ( ) => {
157- for ( const machine of machines ) {
158- dismissServerUpdateFailure ( machine . state ) ;
159- dismissVersionMismatch ( machine . dismissKey ) ;
149+ const next = new Set ( dismissedNotices ) ;
150+ for ( const { state, dismissKey } of machines ) {
151+ dismissServerUpdateFailure ( state ) ;
152+ dismissVersionMismatch ( dismissKey ) ;
153+ if ( dismissKey ) next . add ( dismissKey ) ;
154+ if ( state . status === "failed" ) next . add ( state ) ;
160155 }
161- setDismissedNotices ( ( current ) => {
162- const next = new Set ( current ) ;
163- for ( const machine of machines ) {
164- if ( machine . dismissKey ) next . add ( machine . dismissKey ) ;
165- if ( machine . state . status === "failed" ) next . add ( machine . state ) ;
166- }
167- return next ;
168- } ) ;
156+ setDismissedNotices ( next ) ;
169157 } ,
170158 } ) ,
171159 } ;
0 commit comments