module Web.View.AgentProposals.Index where import Web.Types import Generated.Types import IHP.Prelude import IHP.ViewPrelude data IndexView = IndexView { proposals :: ![AgentProposal] , widgets :: ![Widget] , mTypeFilter :: !(Maybe Text) , mStatusFilter :: !(Maybe Text) } allProposalTypes :: [Text] allProposalTypes = ["summary", "requirement_draft", "duplicate_flag", "policy_flag", "impl_proposal"] allStatuses :: [Text] allStatuses = ["pending", "accepted", "rejected", "superseded"] instance View IndexView where html IndexView { .. } = [hsx|

Agent Proposals

Type: All {forEach allProposalTypes (\t -> [hsx| {t} |])}
Status: All {forEach allStatuses (\s -> [hsx| {s} |])}
{if null proposals then [hsx|

No proposals found.

|] else renderTable proposals widgets} |] agentProposalsUrl :: Maybe Text -> Maybe Text -> Text agentProposalsUrl mt ms = let parts = catMaybes [ fmap ("proposal_type=" <>) mt , fmap ("status=" <>) ms ] in "/AgentProposals" <> if null parts then "" else "?" <> intercalate "&" parts renderTable :: [AgentProposal] -> [Widget] -> Html renderTable proposals widgets = [hsx|
{forEach proposals (renderRow widgets)}
Type Source Widget Confidence Status Created
|] renderRow :: [Widget] -> AgentProposal -> Html renderRow widgets p = [hsx| " text-xs px-2 py-0.5 rounded font-medium"}> {p.proposalType} {widgetName widgets p.sourceWidgetId} {renderConfidenceBar p.confidence} " text-xs px-2 py-0.5 rounded font-medium"}> {p.status} {show p.createdAt} |] widgetName :: [Widget] -> Maybe (Id Widget) -> Text widgetName _ Nothing = "—" widgetName widgets (Just wid) = maybe "(unknown)" (.name) (find (\w -> w.id == wid) widgets) renderConfidenceBar :: Maybe Double -> Html renderConfidenceBar Nothing = [hsx||] renderConfidenceBar (Just c) = let pct = show (round (c * 100) :: Int) <> "%" barWidth = "width: " <> pct in [hsx|
{pct}
|] proposalTypeBadge :: Text -> Text proposalTypeBadge "summary" = "bg-blue-100 text-blue-800" proposalTypeBadge "requirement_draft" = "bg-indigo-100 text-indigo-800" proposalTypeBadge "duplicate_flag" = "bg-orange-100 text-orange-800" proposalTypeBadge "policy_flag" = "bg-red-100 text-red-800" proposalTypeBadge "impl_proposal" = "bg-green-100 text-green-800" proposalTypeBadge _ = "bg-gray-100 text-gray-600" statusBadge :: Text -> Text statusBadge "pending" = "bg-yellow-100 text-yellow-800" statusBadge "accepted" = "bg-green-100 text-green-800" statusBadge "rejected" = "bg-red-100 text-red-800" statusBadge "superseded" = "bg-gray-100 text-gray-500" statusBadge _ = "bg-gray-100 text-gray-600" typeTabClass :: Maybe Text -> Maybe Text -> Text typeTabClass a b | a == b = "px-3 py-1 rounded bg-indigo-100 text-indigo-700 font-medium text-xs" | otherwise = "px-3 py-1 rounded text-gray-600 hover:bg-gray-100 text-xs"