module Web.View.DeploymentRecords.Index where
import Web.Types
import Generated.Types
import IHP.Prelude
import IHP.ViewPrelude
data IndexView = IndexView
{ records :: ![DeploymentRecord]
, decisions :: ![DecisionRecord]
, signals :: ![OutcomeSignal]
, evaluations :: ![ChangeEvaluation]
}
instance View IndexView where
html IndexView { .. } = [hsx|
{if null records
then [hsx|No deployment records yet.
|]
else renderTable records decisions signals evaluations}
|]
renderTable :: [DeploymentRecord] -> [DecisionRecord] -> [OutcomeSignal] -> [ChangeEvaluation] -> Html
renderTable records decisions signals evaluations = [hsx|
| Decision |
Version |
Deployed At |
Signals |
Evaluation |
{forEach records (renderRow decisions signals evaluations)}
|]
renderRow :: [DecisionRecord] -> [OutcomeSignal] -> [ChangeEvaluation] -> DeploymentRecord -> Html
renderRow decisions signals evaluations record = [hsx|
|
{decisionTitle}
|
{record.versionRef} |
{show record.deployedAt} |
{show signalCount} |
{maybe [hsx|—|] renderScoreBadge mScore}
|
|]
where
decisionTitle = maybe "(unknown)" (.title) $
find (\d -> d.id == record.decisionId) decisions
signalCount = length $ filter (\s -> s.deploymentId == record.id) signals
mScore :: Maybe Int16
mScore = fmap (.score) $ find (\e -> e.deploymentId == record.id) evaluations
renderScoreBadge :: Int16 -> Html
renderScoreBadge score = [hsx|
" text-xs px-2 py-0.5 rounded font-medium"}>
{starsFor score}
|]
starsFor :: Int16 -> Text
starsFor n = pack (Prelude.replicate (fromIntegral n) '★') <> pack (Prelude.replicate (5 - fromIntegral n) '☆')
scoreClass :: Int16 -> 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"