module Web.View.DeploymentRecords.Index where import Web.Types import Generated.Types import IHP.Prelude import IHP.ViewPrelude import Web.Routes () import Data.Int (Int16) data IndexView = IndexView { records :: ![DeploymentRecord] , decisions :: ![DecisionRecord] , signals :: ![OutcomeSignal] , evaluations :: ![ChangeEvaluation] } instance View IndexView where html IndexView { .. } = [hsx|

Deployments

New Deployment
{if null records then noDeployments else renderTable records decisions signals evaluations} |] noDeployments :: Html noDeployments = [hsx|

No deployment records yet.

|] renderTable :: [DeploymentRecord] -> [DecisionRecord] -> [OutcomeSignal] -> [ChangeEvaluation] -> Html renderTable records decisions signals evaluations = [hsx|
{forEach records (renderRow decisions signals evaluations)}
Decision Version Deployed At Signals Evaluation
|] renderRow :: [DecisionRecord] -> [OutcomeSignal] -> [ChangeEvaluation] -> DeploymentRecord -> Html renderRow decisions signals evaluations record = [hsx| {decisionTitle} {record.versionRef} {show record.deployedAt} {show signalCount} {renderMaybeScore mScore} |] where decisionTitle = maybe "(unknown)" (.title) $ find (\d -> d.id == record.decisionId) decisions signalCount = length $ filter (\s -> s.deploymentId == record.id) signals mScore :: Maybe Int mScore = fmap (.score) $ find (\e -> e.deploymentId == record.id) evaluations renderMaybeScore :: Maybe Int -> Html renderMaybeScore Nothing = [hsx||] renderMaybeScore (Just score) = renderScoreBadge score renderScoreBadge :: Int -> Html renderScoreBadge score = [hsx| " text-xs px-2 py-0.5 rounded font-medium"}> {starsFor score} |] starsFor :: Int -> Text starsFor n = cs (replicate n '★') <> cs (replicate (5 - n) '☆') scoreClass :: Int -> Text scoreClass n | n <= 2 = "bg-red-100 text-red-800" | n == 3 = "bg-yellow-100 text-yellow-800" | otherwise = "bg-green-100 text-green-800"