@@ -2,8 +2,12 @@ import {
22 readAdminSystemHealthStatus ,
33 runAdminSystemHealthStorageConnectivityAction ,
44} from "../../../src/api/admin-system-health-api-client.js" ;
5+ import {
6+ applyStatusNode ,
7+ normalizeStatusValue ,
8+ statusText ,
9+ } from "../../js/shared/status.js" ;
510
6- const STATUS_VALUES = Object . freeze ( [ "PASS" , "WARN" , "FAIL" , "PENDING" , "INFO" , "SKIP" ] ) ;
711const STORAGE_DIAGNOSTIC_ACTIONS = Object . freeze ( [
812 Object . freeze ( { actionId : "storage-list" , key : "list" } ) ,
913 Object . freeze ( { actionId : "storage-write-test-object" , key : "write" } ) ,
@@ -12,18 +16,7 @@ const STORAGE_DIAGNOSTIC_ACTIONS = Object.freeze([
1216] ) ;
1317
1418function asText ( value , fallback = "not available" ) {
15- const text = String ( value ?? "" ) . trim ( ) ;
16- return text || fallback ;
17- }
18-
19- function statusValue ( value , fallback = "PENDING" ) {
20- const normalized = String ( value || "" ) . trim ( ) . toUpperCase ( ) ;
21- return STATUS_VALUES . includes ( normalized ) ? normalized : fallback ;
22- }
23-
24- function reasonText ( status , reason ) {
25- const message = asText ( reason , "Safe server diagnostics did not provide a reason." ) ;
26- return `${ status } : ${ message } ` ;
19+ return statusText ( value , fallback ) ;
2720}
2821
2922class AdminSystemHealthController {
@@ -80,20 +73,7 @@ class AdminSystemHealthController {
8073 }
8174
8275 setStatusNode ( node , status , reason = "" ) {
83- if ( ! node ) {
84- return ;
85- }
86- const normalized = statusValue ( status ) ;
87- node . textContent = normalized ;
88- node . dataset . healthStatus = normalized ;
89- if ( normalized === "PASS" && ! reason ) {
90- node . removeAttribute ( "title" ) ;
91- node . removeAttribute ( "aria-label" ) ;
92- return ;
93- }
94- const resolvedReason = reasonText ( normalized , reason ) ;
95- node . setAttribute ( "title" , `Reason: ${ asText ( reason , "Safe server diagnostics returned this non-PASS status." ) } ` ) ;
96- node . setAttribute ( "aria-label" , resolvedReason ) ;
76+ applyStatusNode ( node , status , { reason } ) ;
9777 }
9878
9979 renderPending ( reason ) {
@@ -176,7 +156,7 @@ class AdminSystemHealthController {
176156
177157 createStatusCell ( status , reason ) {
178158 const cell = document . createElement ( "td" ) ;
179- cell . dataset . healthStatus = statusValue ( status ) ;
159+ cell . dataset . healthStatus = normalizeStatusValue ( status ) ;
180160 this . setStatusNode ( cell , status , reason ) ;
181161 return cell ;
182162 }
0 commit comments