module Web.View.RequirementCandidates.Index where
import Web.View.Prelude
import Web.Routes ()
data IndexView = IndexView
{ candidates :: ![RequirementCandidate]
, assignments :: ![ReviewerAssignment]
, users :: ![User]
, widgets :: ![Widget]
, mStatusFilter :: !(Maybe Text)
}
instance View IndexView where
html IndexView { .. } = [hsx|
{renderFilterPills mStatusFilter}
{renderCandidatesTable candidates assignments users widgets}
|]
renderFilterPills :: Maybe Text -> Html
renderFilterPills current = [hsx|
{renderPill Nothing current "All"}
{renderPill (Just "open") current "Open"}
{renderPill (Just "in_review") current "In Review"}
{renderPill (Just "accepted") current "Accepted"}
{renderPill (Just "rejected") current "Rejected"}
{renderPill (Just "deferred") current "Deferred"}
|]
renderPill :: Maybe Text -> Maybe Text -> Text -> Html
renderPill target current label =
let isActive = target == current
baseClass = "text-xs px-3 py-1.5 rounded-full border " :: Text
cls = if isActive
then baseClass <> "bg-indigo-600 text-white border-indigo-600"
else baseClass <> "border-gray-300 text-gray-600 hover:bg-gray-50"
url = case target of
Nothing -> pathTo RequirementCandidatesAction
Just s -> pathTo RequirementCandidatesAction <> "?status=" <> s
in [hsx|{label}|]
renderCandidatesTable :: [RequirementCandidate] -> [ReviewerAssignment] -> [User] -> [Widget] -> Html
renderCandidatesTable [] _ _ _ = [hsx|No candidates found.
|]
renderCandidatesTable candidates assignments users ws = [hsx|
| Title |
Widget |
Category |
Status |
Reviewer |
Created |
{forEach candidates (renderRow assignments users ws)}
|]
renderRow :: [ReviewerAssignment] -> [User] -> [Widget] -> RequirementCandidate -> Html
renderRow assignments users widgets c =
let mAssignment = find (\ra -> ra.candidateId == c.id) assignments
mReviewer = mAssignment >>= \ra -> find (\u -> u.id == ra.userId) users
mWidget = find (\w -> w.id == c.sourceWidgetId) widgets
in [hsx|
|
{c.title}
|
{maybe "—" (.name) mWidget}
|
{c.category}
|
" text-xs px-2 py-0.5 rounded"}>{c.status}
|
{maybe "Unassigned" (.name) mReviewer}
|
{show c.createdAt} |
|]
statusClass :: Text -> Text
statusClass "open" = "bg-blue-100 text-blue-700"
statusClass "in_review" = "bg-yellow-100 text-yellow-800"
statusClass "accepted" = "bg-green-100 text-green-800"
statusClass "rejected" = "bg-red-100 text-red-800"
statusClass "deferred" = "bg-gray-100 text-gray-600"
statusClass _ = "bg-gray-100 text-gray-600"