github.com/tilt-dev/tilt@v0.36.0/web/src/status.tsx (about) 1 import { buildWarningCount, runtimeWarningCount } from "./alerts" 2 import { Hold } from "./Hold" 3 import { LogAlertIndex } from "./LogStore" 4 import { resourceIsDisabled } from "./ResourceStatus" 5 import { 6 ResourceStatus, 7 RuntimeStatus, 8 UIResource, 9 UIResourceStatus, 10 UpdateStatus, 11 } from "./types" 12 13 function buildStatus(r: UIResource, alertIndex: LogAlertIndex): ResourceStatus { 14 let res: UIResourceStatus = r.status || {} 15 16 if (resourceIsDisabled(r)) { 17 return ResourceStatus.Disabled 18 } else if (res.updateStatus == UpdateStatus.InProgress) { 19 return ResourceStatus.Building 20 } else if (res.updateStatus == UpdateStatus.Pending) { 21 return ResourceStatus.Pending 22 } else if ( 23 res.updateStatus == UpdateStatus.NotApplicable || 24 res.updateStatus == UpdateStatus.None 25 ) { 26 return ResourceStatus.None 27 } else if (res.updateStatus == UpdateStatus.Error) { 28 return ResourceStatus.Unhealthy 29 } else if (buildWarningCount(r, alertIndex) > 0) { 30 // Warnings are derived from the log store, so that clearing 31 // logs clears the warning indicator. 32 return ResourceStatus.Warning 33 } else if (res.updateStatus == UpdateStatus.Ok) { 34 return ResourceStatus.Healthy 35 } 36 return ResourceStatus.None 37 } 38 39 function runtimeStatus( 40 r: UIResource, 41 alertIndex: LogAlertIndex 42 ): ResourceStatus { 43 let res: UIResourceStatus = r.status || {} 44 45 // Regardless of warning logs, check if a resource 46 // is disabled to return a disabled status 47 if (resourceIsDisabled(r)) { 48 return ResourceStatus.Disabled 49 } 50 51 // Warnings are derived from the log store, so that clearing 52 // logs clears the warning indicator. 53 let hasWarnings = runtimeWarningCount(r, alertIndex) > 0 54 if (hasWarnings) { 55 if (res.runtimeStatus === RuntimeStatus.Error) { 56 return ResourceStatus.Unhealthy 57 } else { 58 return ResourceStatus.Warning 59 } 60 } 61 62 // Compose Healthchecks aren't currently part of the runtime status, 63 // so are handled separately. 64 if (res.composeResourceInfo?.healthStatus == "unhealthy") { 65 return ResourceStatus.Unhealthy 66 } 67 68 switch (res.runtimeStatus) { 69 case RuntimeStatus.Error: 70 return ResourceStatus.Unhealthy 71 case RuntimeStatus.Pending: 72 return ResourceStatus.Pending 73 case RuntimeStatus.Ok: 74 return ResourceStatus.Healthy 75 case RuntimeStatus.NotApplicable: 76 case RuntimeStatus.None: 77 return ResourceStatus.None 78 } 79 return ResourceStatus.None 80 } 81 82 // A combination of runtime status and build status over a resource view. 83 // 1) If there's a current or pending build, this is "pending". 84 // 2) Otherwise, if there's a build error or runtime error, this is "error". 85 // 3) Otherwise, we fallback to runtime status. 86 function combinedStatus( 87 buildStatus: ResourceStatus, 88 runtimeStatus: ResourceStatus 89 ): ResourceStatus { 90 if ( 91 buildStatus !== ResourceStatus.Healthy && 92 buildStatus !== ResourceStatus.None 93 ) { 94 return buildStatus 95 } 96 97 if (runtimeStatus === ResourceStatus.None) { 98 return buildStatus 99 } 100 101 return runtimeStatus 102 } 103 104 export function PendingBuildDescription(hold?: Hold | null): string { 105 let text = "Update: " 106 if (!hold?.count) { 107 text += "pending" 108 return text 109 } 110 111 text += "waiting on " 112 const maxToShow = 3 113 let toShow: string[] = [] 114 if (hold?.images.length) { 115 text += hold.images.length > 1 ? "images: " : "image: " 116 toShow = hold.images 117 } else if (hold?.resources.length) { 118 text += hold.resources.length > 1 ? "resources: " : "resource: " 119 toShow = hold.resources 120 } else if (hold?.clusters.length) { 121 text += hold.clusters.length > 1 ? "clusters: " : "cluster: " 122 toShow = hold.clusters 123 } else { 124 text += `${hold.count} object${hold.count > 1 ? "s" : ""}` 125 return text 126 } 127 128 text += toShow.slice(0, maxToShow).join(", ") 129 if (toShow.length > maxToShow) { 130 const extra = toShow.length - maxToShow 131 text += `, and ${extra} more` 132 } 133 134 return text 135 } 136 137 export { buildStatus, runtimeStatus, combinedStatus }