module Web.View.Widgets.Show where import Web.Types import Generated.Types import IHP.Prelude import IHP.ViewPrelude import Application.Helper.View (widgetEnvelope) data ShowView = ShowView { widget :: !Widget , hub :: !Hub , versions :: ![WidgetVersion] , events :: ![InteractionEvent] , annotations :: ![Annotation] } instance View ShowView where html ShowView { .. } = [hsx|
Hubs / {hub.name} / {widget.name}
{widgetEnvelope widget [hsx|

{widget.name}

{widget.widgetType} {widget.policyScope} {widget.status} v{show widget.version}

Edit
|]}

Total Events

{length events}

Annotations

{length annotations}

Versions

{length versions}

Annotations

+ Add
{forEach rootAnnotations (renderAnnotation childrenOf)}

Annotation Breakdown

{forEach categoryBreakdown renderCategoryRow}

Interaction Events

{forEach events renderEventRow}
Event Actor Occurred

Version History

{forEach versions renderVersionRow}
Version Recorded
|] where rootAnnotations = filter (\a -> isNothing a.parentId) annotations childrenOf parent = filter (\a -> a.parentId == Just parent.id) annotations categoryBreakdown = [ (cat, length (filter (\a -> a.category == cat) annotations)) | cat <- ["friction","defect","wish","policy_concern","doc_gap","trust","other"] , any (\a -> a.category == cat) annotations ] renderAnnotation :: (Annotation -> [Annotation]) -> Annotation -> Html renderAnnotation childrenOf a = [hsx|
{a.category} {a.actorType} {show a.createdAt}

{a.body}

{forEach (childrenOf a) (renderAnnotation childrenOf)}
|] renderEventRow :: InteractionEvent -> Html renderEventRow e = [hsx| {e.eventType} {e.actorType} {show e.occurredAt} |] renderVersionRow :: WidgetVersion -> Html renderVersionRow v = [hsx| v{show v.version} {show v.createdAt} |] renderCategoryRow :: (Text, Int) -> Html renderCategoryRow (cat, count) = [hsx|
{cat} {show count}
|]