ditch more FE enums for clarity and cleanliness

This commit is contained in:
Matt Hill
2024-03-30 10:37:31 -06:00
parent 2c308ccd35
commit 8dfc5052e9
9 changed files with 80 additions and 170 deletions

View File

@@ -3,7 +3,6 @@ import { ConnectionService } from 'src/app/services/connection.service'
import { InstallingInfo } from 'src/app/services/patch-db/data-model'
import {
PrimaryRendering,
PrimaryStatus,
StatusRendering,
} from 'src/app/services/pkg-status-rendering.service'
@@ -13,7 +12,6 @@ import {
styleUrls: ['./status.component.scss'],
})
export class StatusComponent {
PS = PrimaryStatus
PR = PrimaryRendering
@Input() rendering!: StatusRendering

View File

@@ -17,9 +17,9 @@
<ion-item-group *ngIf="pkgPlus.status as status">
<!-- ** status ** -->
<app-show-status [pkg]="pkg" [status]="status"></app-show-status>
<!-- ** installed && !backing-up ** -->
<!-- ** installed && !backingUp ** -->
<ng-container
*ngIf="isInstalled(pkg) && status.primary !== 'backing-up'"
*ngIf="isInstalled(pkg) && status.primary !== 'backingUp'"
>
<!-- ** health checks ** -->
<app-show-health-checks

View File

@@ -15,7 +15,6 @@ import { ModalService } from 'src/app/services/modal.service'
import { DependentInfo } from 'src/app/types/dependent-info'
import {
DepErrorService,
DependencyErrorType,
PkgDependencyErrors,
} from 'src/app/services/dep-error.service'
import { combineLatest } from 'rxjs'
@@ -132,24 +131,24 @@ export class AppShowPage {
let fixAction: (() => any) | null = null
if (depError) {
if (depError.type === DependencyErrorType.NotInstalled) {
if (depError.type === 'notInstalled') {
errorText = 'Not installed'
fixText = 'Install'
fixAction = () => this.fixDep(pkg, manifest, 'install', depId)
} else if (depError.type === DependencyErrorType.IncorrectVersion) {
} else if (depError.type === 'incorrectVersion') {
errorText = 'Incorrect version'
fixText = 'Update'
fixAction = () => this.fixDep(pkg, manifest, 'update', depId)
} else if (depError.type === DependencyErrorType.ConfigUnsatisfied) {
} else if (depError.type === 'configUnsatisfied') {
errorText = 'Config not satisfied'
fixText = 'Auto config'
fixAction = () => this.fixDep(pkg, manifest, 'configure', depId)
} else if (depError.type === DependencyErrorType.NotRunning) {
} else if (depError.type === 'notRunning') {
errorText = 'Not running'
fixText = 'Start'
} else if (depError.type === DependencyErrorType.HealthChecksFailed) {
} else if (depError.type === 'healthChecksFailed') {
errorText = 'Required health check not passing'
} else if (depError.type === DependencyErrorType.Transitive) {
} else if (depError.type === 'transitive') {
errorText = 'Dependency has a dependency issue'
}
}

View File

@@ -3,7 +3,6 @@ import { UiLauncherService } from 'src/app/services/ui-launcher.service'
import {
PackageStatus,
PrimaryRendering,
PrimaryStatus,
} from 'src/app/services/pkg-status-rendering.service'
import {
DataModel,
@@ -67,19 +66,15 @@ export class AppShowStatusComponent {
}
get isRunning(): boolean {
return this.status.primary === PrimaryStatus.Running
return this.status.primary === 'running'
}
get canStop(): boolean {
return [
PrimaryStatus.Running,
PrimaryStatus.Starting,
PrimaryStatus.Restarting,
].includes(this.status.primary)
return ['running', 'starting', 'restarting'].includes(this.status.primary)
}
get isStopped(): boolean {
return this.status.primary === PrimaryStatus.Stopped
return this.status.primary === 'stopped'
}
get sigtermTimeout(): string | null {

View File

@@ -5,7 +5,6 @@ import {
DataModel,
PackageDataEntry,
} from 'src/app/services/patch-db/data-model'
import { PrimaryStatus } from 'src/app/services/pkg-status-rendering.service'
import { getPackageInfo, PkgInfo } from '../../../../util/get-package-info'
import { combineLatest } from 'rxjs'
import { DepErrorService } from 'src/app/services/dep-error.service'
@@ -56,14 +55,11 @@ export class HealthComponent {
private getCount(label: string, pkgs: PkgInfo[]): number {
switch (label) {
case 'Error':
return pkgs.filter(
a => a.primaryStatus !== PrimaryStatus.Stopped && a.error,
).length
return pkgs.filter(a => a.primaryStatus !== 'stopped' && a.error).length
case 'Needs Attention':
return pkgs.filter(a => a.warning).length
case 'Stopped':
return pkgs.filter(a => a.primaryStatus === PrimaryStatus.Stopped)
.length
return pkgs.filter(a => a.primaryStatus === 'stopped').length
case 'Transitioning':
return pkgs.filter(a => a.transitioning).length
default:

View File

@@ -495,40 +495,29 @@ export type DependencyError =
| DependencyErrorHealthChecksFailed
| DependencyErrorTransitive
export enum DependencyErrorType {
NotInstalled = 'not-installed',
NotRunning = 'not-running',
IncorrectVersion = 'incorrect-version',
ConfigUnsatisfied = 'config-unsatisfied',
HealthChecksFailed = 'health-checks-failed',
InterfaceHealthChecksFailed = 'interface-health-checks-failed',
Transitive = 'transitive',
}
export interface DependencyErrorNotInstalled {
type: DependencyErrorType.NotInstalled
type: 'notInstalled'
}
export interface DependencyErrorNotRunning {
type: DependencyErrorType.NotRunning
type: 'notRunning'
}
export interface DependencyErrorIncorrectVersion {
type: DependencyErrorType.IncorrectVersion
type: 'incorrectVersion'
expected: string // version range
received: string // version
}
export interface DependencyErrorConfigUnsatisfied {
type: DependencyErrorType.ConfigUnsatisfied
error: string
type: 'configUnsatisfied'
}
export interface DependencyErrorHealthChecksFailed {
type: DependencyErrorType.HealthChecksFailed
type: 'healthChecksFailed'
check: HealthCheckResult
}
export interface DependencyErrorTransitive {
type: DependencyErrorType.Transitive
type: 'transitive'
}

View File

@@ -9,6 +9,7 @@ import {
} from './patch-db/data-model'
import * as deepEqual from 'fast-deep-equal'
import { isInstalled } from '../util/get-package-data'
import { DependencyError } from './api/api.types'
export type AllDependencyErrors = Record<string, PkgDependencyErrors>
export type PkgDependencyErrors = Record<string, DependencyError | null>
@@ -78,7 +79,7 @@ export class DepErrorService {
// not installed
if (!dep || dep.stateInfo.state !== 'installed') {
return {
type: DependencyErrorType.NotInstalled,
type: 'notInstalled',
}
}
@@ -88,7 +89,7 @@ export class DepErrorService {
// incorrect version
if (!this.emver.satisfies(depManifest.version, versionSpec)) {
return {
type: DependencyErrorType.IncorrectVersion,
type: 'incorrectVersion',
expected: versionSpec,
received: depManifest.version,
}
@@ -97,7 +98,7 @@ export class DepErrorService {
// invalid config
if (Object.values(pkg.status.dependencyConfigErrors).some(err => !!err)) {
return {
type: DependencyErrorType.ConfigUnsatisfied,
type: 'configUnsatisfied',
}
}
@@ -106,7 +107,7 @@ export class DepErrorService {
// not running
if (depStatus !== 'running' && depStatus !== 'starting') {
return {
type: DependencyErrorType.NotRunning,
type: 'notRunning',
}
}
@@ -115,9 +116,11 @@ export class DepErrorService {
// health check failure
if (depStatus === 'running' && currentDep.kind === 'running') {
for (let id of currentDep.healthChecks) {
if (dep.status.main.health[id]?.result !== 'success') {
const check = dep.status.main.health[id]
if (check?.result !== 'success') {
return {
type: DependencyErrorType.HealthChecksFailed,
type: 'healthChecksFailed',
check,
}
}
}
@@ -130,7 +133,7 @@ export class DepErrorService {
if (transitiveError) {
return {
type: DependencyErrorType.Transitive,
type: 'transitive',
}
}
@@ -154,46 +157,3 @@ function dependencyDepth(
depth,
)
}
export type DependencyError =
| DependencyErrorNotInstalled
| DependencyErrorNotRunning
| DependencyErrorIncorrectVersion
| DependencyErrorConfigUnsatisfied
| DependencyErrorHealthChecksFailed
| DependencyErrorTransitive
export enum DependencyErrorType {
NotInstalled = 'notInstalled',
NotRunning = 'notRunning',
IncorrectVersion = 'incorrectVersion',
ConfigUnsatisfied = 'configUnsatisfied',
HealthChecksFailed = 'healthChecksFailed',
Transitive = 'transitive',
}
export interface DependencyErrorNotInstalled {
type: DependencyErrorType.NotInstalled
}
export interface DependencyErrorNotRunning {
type: DependencyErrorType.NotRunning
}
export interface DependencyErrorIncorrectVersion {
type: DependencyErrorType.IncorrectVersion
expected: string // version range
received: string // version
}
export interface DependencyErrorConfigUnsatisfied {
type: DependencyErrorType.ConfigUnsatisfied
}
export interface DependencyErrorHealthChecksFailed {
type: DependencyErrorType.HealthChecksFailed
}
export interface DependencyErrorTransitive {
type: DependencyErrorType.Transitive
}

View File

@@ -1,12 +1,12 @@
import { isEmptyObject } from '@start9labs/shared'
import { PackageDataEntry } from 'src/app/services/patch-db/data-model'
import { PkgDependencyErrors } from './dep-error.service'
import { Status } from '../../../../../../core/startos/bindings/Status'
import { T } from '@start9labs/start-sdk'
export interface PackageStatus {
primary: PrimaryStatus
dependency: DependencyStatus | null
health: HealthStatus | null
health: T.HealthStatus | null
}
export function renderPkgStatus(
@@ -15,59 +15,51 @@ export function renderPkgStatus(
): PackageStatus {
let primary: PrimaryStatus
let dependency: DependencyStatus | null = null
let health: HealthStatus | null = null
let health: T.HealthStatus | null = null
if (pkg.stateInfo.state === 'installed') {
primary = getPrimaryStatus(pkg.status)
primary = getInstalledPrimaryStatus(pkg.status)
dependency = getDependencyStatus(depErrors)
health = getHealthStatus(pkg.status)
} else {
primary = pkg.stateInfo.state as string as PrimaryStatus
primary = pkg.stateInfo.state
}
return { primary, dependency, health }
}
function getPrimaryStatus(status: Status): PrimaryStatus {
function getInstalledPrimaryStatus(status: Status): PrimaryStatus {
if (!status.configured) {
return PrimaryStatus.NeedsConfig
} else if (status.main.status === 'restarting') {
return PrimaryStatus.Restarting
return 'needsConfig'
} else {
return status.main.status as any as PrimaryStatus
}
}
function getDependencyStatus(depErrors: PkgDependencyErrors): DependencyStatus {
return Object.values(depErrors).some(err => !!err)
? DependencyStatus.Warning
: DependencyStatus.Satisfied
return Object.values(depErrors).some(err => !!err) ? 'warning' : 'satisfied'
}
function getHealthStatus(status: Status): HealthStatus | null {
function getHealthStatus(status: Status): T.HealthStatus | null {
if (status.main.status !== 'running' || !status.main.health) {
return null
}
const values = Object.values(status.main.health)
if (values.some(h => !h.result)) {
return HealthStatus.Waiting
}
if (values.some(h => h.result === 'failure')) {
return HealthStatus.Failure
return 'failure'
}
if (values.some(h => h.result === 'loading')) {
return HealthStatus.Loading
return 'loading'
}
if (values.some(h => h.result === 'starting')) {
return HealthStatus.Starting
return 'starting'
}
return HealthStatus.Healthy
return 'success'
}
export interface StatusRendering {
@@ -76,102 +68,88 @@ export interface StatusRendering {
showDots?: boolean
}
export enum PrimaryStatus {
// state
Installing = 'installing',
Updating = 'updating',
Removing = 'removing',
Restoring = 'restoring',
// status
Starting = 'starting',
Running = 'running',
Stopping = 'stopping',
Restarting = 'restarting',
Stopped = 'stopped',
BackingUp = 'backing-up',
// config
NeedsConfig = 'needs-config',
}
export type PrimaryStatus =
| 'installing'
| 'updating'
| 'removing'
| 'restoring'
| 'starting'
| 'running'
| 'stopping'
| 'restarting'
| 'stopped'
| 'backingUp'
| 'needsConfig'
export enum DependencyStatus {
Warning = 'warning',
Satisfied = 'satisfied',
}
export type DependencyStatus = 'warning' | 'satisfied'
export enum HealthStatus {
Failure = 'failure',
Waiting = 'waiting',
Starting = 'starting',
Loading = 'loading',
Healthy = 'healthy',
}
export const PrimaryRendering: Record<string, StatusRendering> = {
[PrimaryStatus.Installing]: {
export const PrimaryRendering: Record<PrimaryStatus, StatusRendering> = {
installing: {
display: 'Installing',
color: 'primary',
showDots: true,
},
[PrimaryStatus.Updating]: {
updating: {
display: 'Updating',
color: 'primary',
showDots: true,
},
[PrimaryStatus.Removing]: {
removing: {
display: 'Removing',
color: 'danger',
showDots: true,
},
[PrimaryStatus.Restoring]: {
restoring: {
display: 'Restoring',
color: 'primary',
showDots: true,
},
[PrimaryStatus.Stopping]: {
stopping: {
display: 'Stopping',
color: 'dark-shade',
showDots: true,
},
[PrimaryStatus.Restarting]: {
restarting: {
display: 'Restarting',
color: 'tertiary',
showDots: true,
},
[PrimaryStatus.Stopped]: {
stopped: {
display: 'Stopped',
color: 'dark-shade',
showDots: false,
},
[PrimaryStatus.BackingUp]: {
backingUp: {
display: 'Backing Up',
color: 'primary',
showDots: true,
},
[PrimaryStatus.Starting]: {
starting: {
display: 'Starting',
color: 'primary',
showDots: true,
},
[PrimaryStatus.Running]: {
running: {
display: 'Running',
color: 'success',
showDots: false,
},
[PrimaryStatus.NeedsConfig]: {
needsConfig: {
display: 'Needs Config',
color: 'warning',
showDots: false,
},
}
export const DependencyRendering: Record<string, StatusRendering> = {
[DependencyStatus.Warning]: { display: 'Issue', color: 'warning' },
[DependencyStatus.Satisfied]: { display: 'Satisfied', color: 'success' },
export const DependencyRendering: Record<DependencyStatus, StatusRendering> = {
warning: { display: 'Issue', color: 'warning' },
satisfied: { display: 'Satisfied', color: 'success' },
}
export const HealthRendering: Record<string, StatusRendering> = {
[HealthStatus.Failure]: { display: 'Failure', color: 'danger' },
[HealthStatus.Starting]: { display: 'Starting', color: 'primary' },
[HealthStatus.Loading]: { display: 'Loading', color: 'primary' },
[HealthStatus.Healthy]: { display: 'Healthy', 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' },
}

View File

@@ -1,7 +1,5 @@
import { PackageDataEntry } from '../services/patch-db/data-model'
import {
DependencyStatus,
HealthStatus,
PrimaryRendering,
PrimaryStatus,
renderPkgStatus,
@@ -21,15 +19,12 @@ export function getPackageInfo(
entry,
primaryRendering,
primaryStatus: statuses.primary,
error:
statuses.health === HealthStatus.Failure ||
statuses.dependency === DependencyStatus.Warning,
warning: statuses.primary === PrimaryStatus.NeedsConfig,
error: statuses.health === 'failure' || statuses.dependency === 'warning',
warning: statuses.primary === 'needsConfig',
transitioning:
primaryRendering.showDots ||
statuses.health === HealthStatus.Waiting ||
statuses.health === HealthStatus.Loading ||
statuses.health === HealthStatus.Starting,
statuses.health === 'loading' ||
statuses.health === 'starting',
}
}