github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/web/src/SidebarItem.tsx (about)

     1  import moment from "moment"
     2  import { buildAlerts, runtimeAlerts } from "./alerts"
     3  import { Hold } from "./Hold"
     4  import { getResourceLabels } from "./labels"
     5  import { LogAlertIndex } from "./LogStore"
     6  import { resourceTargetType } from "./ResourceStatus"
     7  import { buildStatus, runtimeStatus } from "./status"
     8  import { timeDiff } from "./time"
     9  import {
    10    ResourceName,
    11    ResourceStatus,
    12    TriggerMode,
    13    UIBuild,
    14    UIButton,
    15    UIResource,
    16    UIResourceStatus,
    17  } from "./types"
    18  
    19  class SidebarItem {
    20    name: string
    21    isTiltfile: boolean
    22    buildStatus: ResourceStatus
    23    buildAlertCount: number
    24    runtimeStatus: ResourceStatus
    25    runtimeAlertCount: number
    26    hasEndpoints: boolean
    27    labels: string[]
    28    lastBuildDur: moment.Duration | null
    29    lastDeployTime: string
    30    pendingBuildSince: string
    31    currentBuildStartTime: string
    32    triggerMode: TriggerMode
    33    hasPendingChanges: boolean
    34    queued: boolean
    35    lastBuild: UIBuild | null = null
    36    hold: Hold | null = null
    37    targetType: string
    38    stopBuildButton?: UIButton
    39  
    40    /**
    41     * Create a pared down SidebarItem from a ResourceView
    42     */
    43    constructor(
    44      res: UIResource,
    45      logAlertIndex: LogAlertIndex,
    46      stopBuildButton?: UIButton
    47    ) {
    48      let status = (res.status || {}) as UIResourceStatus
    49      let buildHistory = status.buildHistory || []
    50      let lastBuild = buildHistory.length > 0 ? buildHistory[0] : null
    51      this.name = res.metadata?.name ?? ""
    52      this.isTiltfile = this.name === ResourceName.tiltfile
    53      this.buildStatus = buildStatus(res, logAlertIndex)
    54      this.buildAlertCount = buildAlerts(res, logAlertIndex).length
    55      this.runtimeStatus = runtimeStatus(res, logAlertIndex)
    56      this.runtimeAlertCount = runtimeAlerts(res, logAlertIndex).length
    57      this.hasEndpoints = (status.endpointLinks || []).length > 0
    58      this.labels = getResourceLabels(res)
    59      this.lastBuildDur =
    60        lastBuild && lastBuild.startTime && lastBuild.finishTime
    61          ? timeDiff(lastBuild.startTime, lastBuild.finishTime)
    62          : null
    63      this.lastDeployTime = status.lastDeployTime ?? ""
    64      this.pendingBuildSince = status.pendingBuildSince ?? ""
    65      this.currentBuildStartTime = status.currentBuild?.startTime ?? ""
    66      this.triggerMode = status.triggerMode ?? TriggerMode.TriggerModeAuto
    67      this.hasPendingChanges = !!status.hasPendingChanges
    68      this.queued = !!status.queued
    69      this.lastBuild = lastBuild
    70      this.hold = status.waiting ? new Hold(status.waiting) : null
    71      this.targetType = resourceTargetType(res)
    72      this.stopBuildButton = stopBuildButton
    73    }
    74  }
    75  
    76  export default SidebarItem