module Web.View.Annotations.Index where import Web.Types import Generated.Types import IHP.Prelude import IHP.ViewPrelude import Web.Routes () import Data.Coerce (coerce) data IndexView = IndexView { widget :: !Widget , annotations :: ![Annotation] } instance View IndexView where html IndexView { .. } = let rootAnnotations = filter (\a -> isNothing a.parentId) annotations childrenOf parent = filter (\a -> a.parentId == Just (coerce parent.id :: UUID)) annotations in [hsx|
Widgets / {widget.name} / Annotations

Annotations for {widget.name}

Add Annotation
{forEach rootAnnotations (renderAnnotation childrenOf)}
|] renderAnnotation :: (Annotation -> [Annotation]) -> Annotation -> Html renderAnnotation childrenOf a = [hsx|
{a.category} {a.severity} {a.actorType} {if isJust a.retractedAt then retractedBadge else mempty} {show a.createdAt}

{a.body}

Reply Details / Escalate
{forEach (childrenOf a) (renderAnnotation childrenOf)}
|] retractedBadge :: Html retractedBadge = [hsx|retracted|] severityClass :: Text -> Text severityClass "low" = "text-xs px-2 py-0.5 rounded bg-gray-100 text-gray-500" severityClass "medium" = "text-xs px-2 py-0.5 rounded bg-blue-100 text-blue-700" severityClass "high" = "text-xs px-2 py-0.5 rounded bg-yellow-100 text-yellow-800" severityClass "critical" = "text-xs px-2 py-0.5 rounded bg-red-100 text-red-800 font-semibold" severityClass _ = "text-xs px-2 py-0.5 rounded bg-gray-100 text-gray-500"