Skip to content

Commit

Permalink
ReadyWidget generalized
Browse files Browse the repository at this point in the history
  • Loading branch information
laszlocph committed Jan 15, 2024
1 parent 45c2821 commit 14ea5e8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 28 deletions.
32 changes: 7 additions & 25 deletions web/src/FluxState.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function Kustomizations(props){
</span>
</div>
<div className="col-span-5">
<span className="block"><ReadyWidget gitRepository={kustomization} displayMessage={true}/></span>
<span className="block"><ReadyWidget resource={kustomization} displayMessage={true} label="Applied" /></span>
</div>
<div className="col-span-5">
<div className="font-medium text-neutral-700"><RevisionWidget kustomization={kustomization} gitRepository={gitRepository} /></div>
Expand Down Expand Up @@ -87,14 +87,11 @@ export function HelmReleases(props) {
</span>
</div>
<div className="col-span-5">
<span className="block font-medium text-neutral-700"><HelmStatusWidget helmRelease={helmRelease}/></span>
<span className="block font-medium text-neutral-700"><ReadyWidget resource={helmRelease} label="Installed" /></span>
<span className="block text-neutral-600 field">{message}</span>
</div>
<div className="col-span-5">
<div className="font-medium text-neutral-700"><HelmRevisionWidget helmRelease={helmRelease} /></div>
{/* { !ready && */}
<span className="block field text-yellow-500">Attempted applying {lastAttemptedHash.slice(0, 8)} at {dateLabel}</span>
{/* } */}
</div>
</div>
)
Expand Down Expand Up @@ -158,7 +155,7 @@ export function GitRepositories(props){
</span>
</div>
<div className="col-span-5">
<ReadyWidget gitRepository={gitRepository} displayMessage={true}/>
<ReadyWidget resource={gitRepository} displayMessage={true}/>
</div>
<div className="col-span-5">
<ArtifactWidget gitRepository={gitRepository} displayMessage={true}/>
Expand All @@ -172,12 +169,13 @@ export function GitRepositories(props){
}

export function ReadyWidget(props) {
const { gitRepository, displayMessage } = props
const readyConditions = jp.query(gitRepository.status, '$..conditions[?(@.type=="Ready")]');
const { resource, displayMessage, label } = props

const readyConditions = jp.query(resource.status, '$..conditions[?(@.type=="Ready")]');
const readyCondition = readyConditions.length === 1 ? readyConditions[0] : undefined

const ready = readyCondition && readyConditions[0].status === "True"
const readyLabel = ready ? "Ready" : "Not Ready"
const readyLabel = ready ? label ? label : "Ready" : "Not Ready"
const color = ready ? "bg-teal-400" : "bg-orange-400 animate-pulse"
const messageColor = ready ? "text-neutral-600 field" : "bg-orange-400"

Expand Down Expand Up @@ -237,22 +235,6 @@ export function ArtifactWidget(props) {
)
}

export function HelmStatusWidget(props) {
const { helmRelease } = props

const readyConditions = jp.query(helmRelease.status, '$..conditions[?(@.type=="Ready")].status');
const ready = readyConditions.includes("True")

const label = ready ? "Installed" : "Not Ready"

return (
<span className="relative">
<span className="absolute -left-4 top-1 rounded-full h-3 w-3 bg-teal-400 inline-block"></span>
<span>{label}</span>
</span>
)
}

export function HelmRevisionWidget(props) {
const { helmRelease } = props

Expand Down
6 changes: 3 additions & 3 deletions web/src/Service.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState } from 'react';
import { RevisionWidget, ReadyWidget, HelmStatusWidget } from './FluxState';
import { RevisionWidget, ReadyWidget } from './FluxState';
import jp from 'jsonpath';
import { Logs } from './Logs'
import { Describe } from './Describe'
Expand Down Expand Up @@ -209,15 +209,15 @@ function Service(props) {
<div>
<p className="text-base text-neutral-600">Sync</p>
<div className="flex text-sm text-neutral-600">
<div className="ml-4"><ReadyWidget gitRepository={kustomization}/></div>
<div className="ml-4"><ReadyWidget resource={kustomization} label="Applied" /></div>
<div className="ml-2"><RevisionWidget kustomization={kustomization} gitRepository={gitRepository} /></div>
</div>
</div>
{ helmRelease &&
<div>
<p className="text-base text-neutral-600">Helm Status</p>
<div className="flex text-sm text-neutral-600">
<div className="ml-4"><HelmStatusWidget helmRelease={helmRelease} /></div>
<div className="ml-4"><ReadyWidget resource={helmRelease} label="Installed" /></div>
<div className="ml-4">({helmRelease.metadata.namespace}/{helmRelease.metadata.name})</div>
</div>
</div>
Expand Down

0 comments on commit 14ea5e8

Please sign in to comment.