mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 02:11:53 +00:00
164 lines
3.6 KiB
TypeScript
164 lines
3.6 KiB
TypeScript
import { PackageDataEntry } from 'src/app/services/patch-db/data-model'
|
|
import { PkgDependencyErrors } from './dep-error.service'
|
|
import { T } from '@start9labs/start-sdk'
|
|
|
|
export interface PackageStatus {
|
|
primary: PrimaryStatus
|
|
dependency: DependencyStatus | null
|
|
health: T.HealthStatus | null
|
|
}
|
|
|
|
export function renderPkgStatus(
|
|
pkg: PackageDataEntry,
|
|
depErrors: PkgDependencyErrors = {},
|
|
): PackageStatus {
|
|
let primary: PrimaryStatus
|
|
let dependency: DependencyStatus | null = null
|
|
let health: T.HealthStatus | null = null
|
|
|
|
if (pkg.stateInfo.state === 'installed') {
|
|
primary = getInstalledPrimaryStatus(pkg)
|
|
dependency = getDependencyStatus(depErrors)
|
|
health = getHealthStatus(pkg.status)
|
|
} else {
|
|
primary = pkg.stateInfo.state
|
|
}
|
|
|
|
return { primary, dependency, health }
|
|
}
|
|
|
|
export function getInstalledPrimaryStatus({
|
|
requestedActions,
|
|
status,
|
|
}: T.PackageDataEntry): PrimaryStatus {
|
|
return Object.values(requestedActions).some(
|
|
r => r.active && r.request.severity === 'critical',
|
|
)
|
|
? 'actionRequired'
|
|
: status.main
|
|
}
|
|
|
|
function getDependencyStatus(depErrors: PkgDependencyErrors): DependencyStatus {
|
|
return Object.values(depErrors).some(err => !!err) ? 'warning' : 'satisfied'
|
|
}
|
|
|
|
function getHealthStatus(status: T.MainStatus): T.HealthStatus | null {
|
|
if (status.main !== 'running' || !status.main) {
|
|
return null
|
|
}
|
|
|
|
const values = Object.values(status.health)
|
|
|
|
if (values.some(h => h.result === 'failure')) {
|
|
return 'failure'
|
|
}
|
|
|
|
if (values.some(h => h.result === 'loading')) {
|
|
return 'loading'
|
|
}
|
|
|
|
if (values.some(h => h.result === 'starting')) {
|
|
return 'starting'
|
|
}
|
|
|
|
return 'success'
|
|
}
|
|
|
|
export interface StatusRendering {
|
|
display: string
|
|
color: string
|
|
showDots?: boolean
|
|
}
|
|
|
|
export type PrimaryStatus =
|
|
| 'installing'
|
|
| 'updating'
|
|
| 'removing'
|
|
| 'restoring'
|
|
| 'starting'
|
|
| 'running'
|
|
| 'stopping'
|
|
| 'restarting'
|
|
| 'stopped'
|
|
| 'backingUp'
|
|
| 'actionRequired'
|
|
| 'error'
|
|
|
|
export type DependencyStatus = 'warning' | 'satisfied'
|
|
|
|
export const PrimaryRendering: Record<PrimaryStatus, StatusRendering> = {
|
|
installing: {
|
|
display: 'Installing',
|
|
color: 'primary',
|
|
showDots: true,
|
|
},
|
|
updating: {
|
|
display: 'Updating',
|
|
color: 'primary',
|
|
showDots: true,
|
|
},
|
|
removing: {
|
|
display: 'Removing',
|
|
color: 'danger',
|
|
showDots: true,
|
|
},
|
|
restoring: {
|
|
display: 'Restoring',
|
|
color: 'primary',
|
|
showDots: true,
|
|
},
|
|
stopping: {
|
|
display: 'Stopping',
|
|
color: 'dark-shade',
|
|
showDots: true,
|
|
},
|
|
restarting: {
|
|
display: 'Restarting',
|
|
color: 'tertiary',
|
|
showDots: true,
|
|
},
|
|
stopped: {
|
|
display: 'Stopped',
|
|
color: 'dark-shade',
|
|
showDots: false,
|
|
},
|
|
backingUp: {
|
|
display: 'Backing Up',
|
|
color: 'primary',
|
|
showDots: true,
|
|
},
|
|
starting: {
|
|
display: 'Starting',
|
|
color: 'primary',
|
|
showDots: true,
|
|
},
|
|
running: {
|
|
display: 'Running',
|
|
color: 'success',
|
|
showDots: false,
|
|
},
|
|
actionRequired: {
|
|
display: 'Action Required',
|
|
color: 'warning',
|
|
showDots: false,
|
|
},
|
|
error: {
|
|
display: 'Service Launch Error',
|
|
color: 'danger',
|
|
showDots: false,
|
|
},
|
|
}
|
|
|
|
export const DependencyRendering: Record<DependencyStatus, StatusRendering> = {
|
|
warning: { display: 'Issue', color: 'warning' },
|
|
satisfied: { display: 'Satisfied', color: 'success' },
|
|
}
|
|
|
|
export const HealthRendering: Record<T.HealthStatus, StatusRendering> = {
|
|
failure: { display: 'Failure', color: 'danger' },
|
|
starting: { display: 'Starting', color: 'primary' },
|
|
loading: { display: 'Loading', color: 'primary' },
|
|
success: { display: 'Healthy', color: 'success' },
|
|
disabled: { display: 'Disabled', color: 'dark' },
|
|
}
|