inter-hub-haskell/Web/View/Annotations/New.hs

47 lines
1.5 KiB
Haskell
Raw Normal View History

module Web.View.Annotations.New where
import Web.Types
import Generated.Types
import IHP.Prelude
import IHP.ViewPrelude
data NewView = NewView
{ widget :: !Widget
, annotation :: !Annotation
, categories :: ![AnnotationCategoryRegistry]
}
instance View NewView where
html NewView { .. } = [hsx|
<div class="max-w-lg">
<div class="flex items-center gap-2 text-sm text-gray-500 mb-4">
<a href={ShowWidgetAction { widgetId = widget.id }} class="hover:text-gray-700">{widget.name}</a>
<span>/</span>
<a href={WidgetAnnotationsAction { widgetId = widget.id }} class="hover:text-gray-700">Annotations</a>
<span>/</span>
<span>New</span>
</div>
<h1 class="text-2xl font-semibold mb-6">Add Annotation</h1>
{renderForm annotation widget.id categories}
</div>
|]
renderForm :: Annotation -> Id Widget -> [AnnotationCategoryRegistry] -> Html
renderForm annotation widgetId categories = formFor annotation [hsx|
{(textareaField #body) { fieldLabel = "Comment" }}
{selectField #category (categoryOptions categories)}
{selectField #severity severityOptions}
{submitButton}
|]
categoryOptions :: [AnnotationCategoryRegistry] -> [(Text, Text)]
categoryOptions = map (\r -> (r.label, r.name))
severityOptions :: [(Text, Text)]
severityOptions =
[ ("Low", "low")
, ("Medium", "medium")
, ("High", "high")
, ("Critical", "critical")
]