diff --git a/.env.example b/.env.example index 4cb6ec530..3f7abba4c 100644 --- a/.env.example +++ b/.env.example @@ -26,3 +26,37 @@ SLACK_CLIENT_SECRET= SLACK_REDIRECT_URI=https://app.apitoolkit.io/slack/oauth/callback/ ENABLE_PUBSUB_SERVICE=True + + +# Extra parameters needed +# to run the project from start +# Note: we no longer use paddle; +# Code will be removed later; + +ENABLE_PUBSUB_SERVICE=True +OTLP_STREAM_TOPICS= +SMTP_HOST= +SMTP_PORT=25 +SMTP_USERNAME= +SMTP_PASSWORD= +SMTP_SENDER= +PADDLE_SANDBOX=True +PADDLE_SANDBOX_VENDOR_ID=1 +PADDLE_SANDBOX_API_KEY= +PADDLE_VENDOR_ID= +PADDLE_API_KEY= +PADDLE_SANDBOX_STARTUP= +PADDLE_STARTUP= +PADDLE_SANDBOX_GROWTH= +PADDLE_GROWTH= +PADDLE_SANDBOX_HOBBY= +PADDLE_HOBBY= +ORTTO_API_KEY= +GOOGLE_SERVICE_ACCOUNT_B64= +ENABLE_BACKGROUND_JOBS=True +COURIER_CLIENT_KEY= +COURIER_API_KEY= +LEMON_SQUEEZY_API_KEY= +LEMON_SQUEEZY_URL= +POSTMARK_TOKEN= +LEMON_SQUEEZY_WEBHOOK_SECRET= diff --git a/Makefile b/Makefile index aac90485c..621d451e7 100644 --- a/Makefile +++ b/Makefile @@ -52,11 +52,11 @@ gen-proto: timescaledb-docker: docker run -it --rm --name=apitoolkit -p 5432:5432/tcp -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=apitoolkit -v $$HOME/pg-data:/home/postgres/pgdata \ - docker.io/timescale/timescaledb-ha:pg15-latest -c shared_preload_libraries='pg_stat_statements,timescaledb' + docker.io/timescale/timescaledb-ha:pg16-all -c shared_preload_libraries='pg_stat_statements,timescaledb' timescaledb-docker-tmp: docker run -it --rm --name=apitoolkit -p 5432:5432/tcp -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=apitoolkit \ - docker.io/timescale/timescaledb-ha:pg15-latest -c shared_preload_libraries='pg_stat_statements,timescaledb' + docker.io/timescale/timescaledb-ha:pg16-all -c shared_preload_libraries='pg_stat_statements,timescaledb' update-service-worker: npx workbox generateSW workbox-config.js diff --git a/apitoolkit-server.cabal b/apitoolkit-server.cabal index 44b393718..8658a4510 100644 --- a/apitoolkit-server.cabal +++ b/apitoolkit-server.cabal @@ -1,6 +1,6 @@ cabal-version: 2.0 --- This file has been generated from package.yaml by hpack version 0.36.0. +-- This file has been generated from package.yaml by hpack version 0.37.0. -- -- see: https://github.com/sol/hpack diff --git a/package-lock.json b/package-lock.json index 06946ab31..485ed56f2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "apitoolkit-server", + "name": "api_tool_kit_server", "lockfileVersion": 3, "requires": true, "packages": { diff --git a/src/Pages/Anomalies/AnomalyList.hs b/src/Pages/Anomalies/AnomalyList.hs index 8690e7e24..e4bbd64ca 100644 --- a/src/Pages/Anomalies/AnomalyList.hs +++ b/src/Pages/Anomalies/AnomalyList.hs @@ -35,7 +35,7 @@ import Effectful.Reader.Static (ask) import Lucid import Lucid.Aria qualified as Aria import Lucid.Base (termRaw) -import Lucid.Htmx (hxGet_, hxSwap_, hxTrigger_) +import Lucid.Htmx (hxGet_, hxSwap_, hxTarget_, hxTrigger_) import Lucid.Hyperscript (__) import Models.Apis.Anomalies qualified as Anomalies import Models.Apis.Endpoints qualified as Endpoints @@ -186,6 +186,7 @@ anomalyListGetH pid layoutM filterTM sortM pageM loadM endpointM hxRequestM hxBo { projectId = pid , nextFetchUrl , sort = Just $ ItemsList.SortCfg{current = fromMaybe "events" sortM} + , filter = Nothing , search = Just $ ItemsList.SearchCfg{viaQueryParam = Nothing} -- FIXME: search actual db , heading = Nothing , bulkActions = @@ -193,8 +194,8 @@ anomalyListGetH pid layoutM filterTM sortM pageM loadM endpointM hxRequestM hxBo , ItemsList.BulkAction{icon = Just "inbox-full", title = "archive", uri = "/p/" <> pid.toText <> "/anomalies/bulk_actions/archive"} ] , zeroState = - Just $ - ItemsList.ZeroState + Just + $ ItemsList.ZeroState { icon = "empty-set" , title = "No Issues Or Errors." , description = "Start monitoring errors that happened during a request." @@ -211,17 +212,17 @@ anomalyListGetH pid layoutM filterTM sortM pageM loadM endpointM hxRequestM hxBo , pageTitle = "Issues: Changes, Alerts & Errors" , menuItem = Just "Changes & Errors" , navTabs = - Just $ - toHtml $ - Components.TabFilter - { current = currentFilterTab - , currentURL - , options = - [ Components.TabFilterOpt{name = "Inbox", count = Nothing} - , Components.TabFilterOpt{name = "Acknowleged", count = Nothing} - , Components.TabFilterOpt{name = "Archived", count = Nothing} - ] - } + Just + $ toHtml + $ Components.TabFilter + { current = currentFilterTab + , currentURL + , options = + [ Components.TabFilterOpt{name = "Inbox", count = Nothing} + , Components.TabFilterOpt{name = "Acknowleged", count = Nothing} + , Components.TabFilterOpt{name = "Archived", count = Nothing} + ] + } } issuesVM = V.map (IssueVM False currTime) issues addRespHeaders $ case (layoutM, hxRequestM, hxBoostedM, loadM) of @@ -314,8 +315,11 @@ issueItem hideByDefault currTime issue icon title subTitle content = do input_ [term "aria-label" "Select Issue", class_ "bulkactionItemCheckbox checkbox checkbox-md checked:checkbox-primary", type_ "checkbox", name_ "issueId", value_ issueId] div_ [class_ "space-y-3 grow"] do div_ [class_ "space-x-3"] do - a_ [href_ $ "/p/" <> issue.projectId.toText <> "/anomalies/by_hash/" <> issue.targetHash, class_ "inline-block font-bold text-blue-700 space-x-2", termRaw "preload" "mouseover"] do - img_ [src_ icon, class_ "inline w-4 h-4"] >> span_ (toHtml title) + let modalEndpoint = "/p/" <> issue.projectId.toText <> "/anomalies/by_hash/" <> issue.targetHash <> "?modal=True" + a_ [hxGet_ modalEndpoint, hxTarget_ ("#expand-log-drawer-" <> issue.targetHash), hxTrigger_ "click", class_ "inline-block font-bold text-blue-700 space-x-2 cursor-pointer", termRaw "preload" "mouseover"] + $ do + img_ [src_ icon, class_ "inline w-4 h-4"] + >> span_ (toHtml title) small_ [class_ "inline-block text-gray-800"] $ fromMaybe (toHtml @String "") subTitle div_ [class_ "flex flex-row gap-8"] do div_ do @@ -339,17 +343,17 @@ issueItem hideByDefault currTime issue icon title subTitle content = do Components.drawerWithURLContent_ ("expand-log-drawer-" <> issue.targetHash) (Just modalEndpoint) $ span_ [class_ "flex items-center justify-center cursor-pointer py-2 px-3 rounded border border-gray-200 text-xs hover:shadow shadow-blue-100"] (faSprite_ "expand" "regular" "w-3 h-3") fromMaybe (toHtml @String "") content let issueQueryPartial = buildQueryForAnomaly issue.anomalyType issue.targetHash - div_ [class_ "flex items-center justify-center "] $ - div_ + div_ [class_ "flex items-center justify-center "] + $ div_ [ class_ "w-60 h-16 px-3" , hxGet_ $ "/charts_html?pid=" <> issue.projectId.toText <> "&since=14D&show_axes=false&query_raw=" <> escapedQueryPartial [fmt|{issueQueryPartial} | timechart [1d]|] , hxTrigger_ "intersect once" , hxSwap_ "innerHTML" ] "" - div_ [class_ "w-36 flex items-center justify-center"] $ - span_ [class_ "tabular-nums text-xl", term "data-tippy-content" "Events for this Anomaly in the last 14days"] $ - show issue.eventsAgg.count + div_ [class_ "w-36 flex items-center justify-center"] + $ span_ [class_ "tabular-nums text-xl", term "data-tippy-content" "Events for this Anomaly in the last 14days"] + $ show issue.eventsAgg.count -- anomalyDetailsGetH: either in modal or as a standalone page @@ -386,8 +390,8 @@ anomalyDetailsGetH pid targetHash hxBoostedM = do Nothing -> addRespHeaders $ AnomalyDetailsMain $ PageCtx bwconf (issue, Nothing, Just anFields, Nothing, currTime, False) Anomalies.IDNewFormatIssue issueD -> do anFormats <- - dbtToEff $ - Fields.getFieldsByEndpointKeyPathAndCategory pid issueD.endpointId.toText issueD.fieldKeyPath issueD.fieldCategory + dbtToEff + $ Fields.getFieldsByEndpointKeyPathAndCategory pid issueD.endpointId.toText issueD.fieldKeyPath issueD.fieldCategory case hxBoostedM of Just _ -> addRespHeaders $ AnomalyDetailsBoosted (issue, Nothing, Nothing, Just anFormats, currTime, True) Nothing -> addRespHeaders $ AnomalyDetailsMain $ PageCtx bwconf (issue, Nothing, Nothing, Just anFormats, currTime, False) @@ -657,9 +661,9 @@ anomalyAcknowlegeButton :: Projects.ProjectId -> Anomalies.AnomalyId -> Bool -> anomalyAcknowlegeButton pid aid acked host = do let acknowlegeAnomalyEndpoint = "/p/" <> pid.toText <> "/anomalies/" <> Anomalies.anomalyIdText aid <> if acked then "/unacknowlege" else "/acknowlege?host=" <> host a_ - [ class_ $ - "inline-block child-hover cursor-pointer py-2 px-3 rounded border border-gray-200 text-xs hover:shadow shadow-blue-100 " - <> (if acked then "bg-green-100 text-green-900" else "") + [ class_ + $ "inline-block child-hover cursor-pointer py-2 px-3 rounded border border-gray-200 text-xs hover:shadow shadow-blue-100 " + <> (if acked then "bg-green-100 text-green-900" else "") , term "data-tippy-content" "acknowlege anomaly" , hxGet_ acknowlegeAnomalyEndpoint , hxSwap_ "outerHTML" @@ -671,9 +675,9 @@ anomalyArchiveButton :: Projects.ProjectId -> Anomalies.AnomalyId -> Bool -> Htm anomalyArchiveButton pid aid archived = do let archiveAnomalyEndpoint = "/p/" <> pid.toText <> "/anomalies/" <> Anomalies.anomalyIdText aid <> if archived then "/unarchive" else "/archive" a_ - [ class_ $ - "inline-block xchild-hover cursor-pointer py-2 px-3 rounded border border-gray-200 text-xs hover:shadow shadow-blue-100 " - <> (if archived then " bg-green-100 text-green-900" else "") + [ class_ + $ "inline-block xchild-hover cursor-pointer py-2 px-3 rounded border border-gray-200 text-xs hover:shadow shadow-blue-100 " + <> (if archived then " bg-green-100 text-green-900" else "") , term "data-tippy-content" $ if archived then "unarchive" else "archive" , hxGet_ archiveAnomalyEndpoint , hxSwap_ "outerHTML" @@ -686,24 +690,24 @@ reqResSection title isRequest shapesWithFieldsMap = section_ [class_ "space-y-3"] do div_ [class_ "flex justify-between mt-5"] do div_ [class_ "flex flex-row"] do - a_ [class_ "cursor-pointer", [__|on click toggle .neg-rotate-90 on me then toggle .hidden on (next .reqResSubSection)|]] $ - faSprite_ "chevron-down" "light" "h-4 mr-3 mt-1 w-4" + a_ [class_ "cursor-pointer", [__|on click toggle .neg-rotate-90 on me then toggle .hidden on (next .reqResSubSection)|]] + $ faSprite_ "chevron-down" "light" "h-4 mr-3 mt-1 w-4" span_ [class_ "text-lg text-slate-800"] $ toHtml title - div_ [class_ "bg-base-100 border border-gray-100 rounded-xl py-5 px-5 space-y-6 reqResSubSection"] $ - forM_ (zip [(1 :: Int) ..] shapesWithFieldsMap) $ - \(index, s) -> do - let sh = if index == 1 then title <> "_fields" else title <> "_fields hidden" - div_ [class_ sh, id_ $ title <> "_" <> show index] do - if isRequest - then do - subSubSection (title <> " Path Params") (Map.lookup Fields.FCPathParam s.fieldsMap) - subSubSection (title <> " Query Params") (Map.lookup Fields.FCQueryParam s.fieldsMap) - subSubSection (title <> " Headers") (Map.lookup Fields.FCRequestHeader s.fieldsMap) - subSubSection (title <> " Body") (Map.lookup Fields.FCRequestBody s.fieldsMap) - else do - subSubSection (title <> " Headers") (Map.lookup Fields.FCResponseHeader s.fieldsMap) - subSubSection (title <> " Body") (Map.lookup Fields.FCResponseBody s.fieldsMap) + div_ [class_ "bg-base-100 border border-gray-100 rounded-xl py-5 px-5 space-y-6 reqResSubSection"] + $ forM_ (zip [(1 :: Int) ..] shapesWithFieldsMap) + $ \(index, s) -> do + let sh = if index == 1 then title <> "_fields" else title <> "_fields hidden" + div_ [class_ sh, id_ $ title <> "_" <> show index] do + if isRequest + then do + subSubSection (title <> " Path Params") (Map.lookup Fields.FCPathParam s.fieldsMap) + subSubSection (title <> " Query Params") (Map.lookup Fields.FCQueryParam s.fieldsMap) + subSubSection (title <> " Headers") (Map.lookup Fields.FCRequestHeader s.fieldsMap) + subSubSection (title <> " Body") (Map.lookup Fields.FCRequestBody s.fieldsMap) + else do + subSubSection (title <> " Headers") (Map.lookup Fields.FCResponseHeader s.fieldsMap) + subSubSection (title <> " Body") (Map.lookup Fields.FCResponseBody s.fieldsMap) -- | subSubSection .. diff --git a/src/Pages/Endpoints/ApiCatalog.hs b/src/Pages/Endpoints/ApiCatalog.hs index 6f118400f..bf49b5c78 100644 --- a/src/Pages/Endpoints/ApiCatalog.hs +++ b/src/Pages/Endpoints/ApiCatalog.hs @@ -19,30 +19,38 @@ import Relude hiding (ask, asks) import System.Types (ATAuthCtx, RespHeaders, addRespHeaders) -apiCatalogH :: Projects.ProjectId -> Maybe Text -> Maybe Text -> ATAuthCtx (RespHeaders (PageCtx (ItemsList.ItemsPage HostEventsVM))) -apiCatalogH pid sortM requestTypeM = do +apiCatalogH :: Projects.ProjectId -> Maybe Text -> Maybe Text -> Maybe Text -> ATAuthCtx (RespHeaders (PageCtx (ItemsList.ItemsPage HostEventsVM))) +apiCatalogH pid sortM timeFilter requestTypeM = do (sess, project) <- Sessions.sessionAndProject pid + let requestType = fromMaybe "Incoming" requestTypeM + hostsAndEvents <- dbtToEff $ Endpoints.dependenciesAndEventsCount pid requestType (fromMaybe "events" sortM) + currTime <- Time.currentTime + let sortV = fromMaybe "events" sortM + let filterV = fromMaybe "14d" timeFilter + let currentURL = "/p/" <> pid.toText <> "/api_catalog?sort=" <> sortV <> "&request_type=" <> requestType + let listCfg = ItemsList.ItemsListCfg { projectId = pid , sort = Just $ ItemsList.SortCfg{current = sortV} + , filter = Just filterV , currentURL = currentURL , currTime , bulkActions = - [ ItemsList.BulkAction{icon = Just "check", title = "acknowlege", uri = "/p/" <> pid.toText <> "/anomalies/bulk_actions/acknowlege"} + [ ItemsList.BulkAction{icon = Just "check", title = "acknowledge", uri = "/p/" <> pid.toText <> "/anomalies/bulk_actions/acknowledge"} , ItemsList.BulkAction{icon = Just "inbox-full", title = "archive", uri = "/p/" <> pid.toText <> "/anomalies/bulk_actions/archive"} ] , search = Just $ ItemsList.SearchCfg{viaQueryParam = Nothing} , nextFetchUrl = Nothing , heading = Nothing , zeroState = - Just $ - ItemsList.ZeroState + Just + $ ItemsList.ZeroState { icon = "empty-set" , title = "No " <> requestType <> " Requests Monitored." , description = "You're currently not monitoring your " <> T.toLower requestType <> " integrations." @@ -51,6 +59,7 @@ apiCatalogH pid sortM requestTypeM = do } , elemID = "anomalyListForm" } + let bwconf = def { sessM = Just sess.persistentSession @@ -60,19 +69,22 @@ apiCatalogH pid sortM requestTypeM = do a_ [href_ $ "/p/" <> pid.toText <> "/api_catalog?sort=" <> sortV <> "&request_type=Incoming", role_ "tab", class_ $ "tab " <> if requestType == "Incoming" then "tab-active" else ""] "Incoming" a_ [href_ $ "/p/" <> pid.toText <> "/api_catalog?sort=" <> sortV <> "&request_type=Outgoing", role_ "tab", class_ $ "tab " <> if requestType == "Outgoing" then "tab-active" else ""] "Outgoing" } - addRespHeaders $ PageCtx bwconf (ItemsList.ItemsPage listCfg $ V.map (\host -> HostEventsVM pid host requestType) hostsAndEvents) + + addRespHeaders $ PageCtx bwconf (ItemsList.ItemsPage listCfg $ V.map (\host -> HostEventsVM pid host filterV requestType) hostsAndEvents) -data HostEventsVM = HostEventsVM Projects.ProjectId Endpoints.HostEvents Text +data HostEventsVM = HostEventsVM Projects.ProjectId Endpoints.HostEvents Text Text instance ToHtml HostEventsVM where - toHtml (HostEventsVM pid he requestType) = toHtmlRaw $ renderapiCatalog pid he requestType + toHtml :: Monad m => HostEventsVM -> HtmlT m () + toHtml (HostEventsVM pid he timeFilter requestType) = toHtmlRaw $ renderapiCatalog pid he timeFilter requestType + toHtmlRaw :: Monad m => HostEventsVM -> HtmlT m () toHtmlRaw = toHtml -renderapiCatalog :: Projects.ProjectId -> Endpoints.HostEvents -> Text -> Html () -renderapiCatalog pid host requestType = div_ [class_ "flex py-4 gap-8 items-center itemsListItem"] do +renderapiCatalog :: Projects.ProjectId -> Endpoints.HostEvents -> Text -> Text -> Html () +renderapiCatalog pid host timeFilter requestType = div_ [class_ "flex py-4 gap-8 items-center itemsListItem"] do div_ [class_ "h-4 flex space-x-3 w-8 "] do a_ [class_ "w-2 h-full"] "" input_ [term "aria-label" "Select Issue", class_ "endpoint_anomaly_input bulkactionItemCheckbox checkbox checkbox-md checked:checkbox-primary", type_ "checkbox", name_ "hostId", value_ host.host] @@ -82,12 +94,18 @@ renderapiCatalog pid host requestType = div_ [class_ "flex py-4 gap-8 items-cent a_ [class_ "inline-block font-bold space-x-2"] $ do a_ [href_ $ "/p/" <> pid.toText <> "/endpoints?host=" <> host.host <> "&request_type=" <> requestType, class_ " hover:text-slate-600"] $ toHtml (T.replace "http://" "" $ T.replace "https://" "" host.host) a_ [href_ $ "/p/" <> pid.toText <> "/log_explorer?query=host%3D%3D" <> "\"" <> host.host <> "\"", class_ "text-blue-500 hover:text-slate-600 text-xs"] "View logs" - div_ [class_ "flex items-center justify-center "] $ + + div_ [class_ "flex items-center justify-center "] $ do div_ [ class_ "w-56 h-12 px-3" - , hxGet_ $ "/charts_html?pid=" <> pid.toText <> "&since=14D&show_axes=false&query_raw=" <> AnomalyList.escapedQueryPartial [PyF.fmt|host=="{host.host}" | timechart [1d]|] + , hxGet_ $ "/charts_html?pid=" <> pid.toText <> "&since=" <> (if timeFilter == "14d" then "14D" else "24h") <> "&show_axes=false&query_raw=" <> AnomalyList.escapedQueryPartial [PyF.fmt|host=="{host.host}" | timechart [1d]|] , hxTrigger_ "intersect once" , hxSwap_ "innerHTML" ] "" - div_ [class_ "w-36 flex items-center justify-center"] $ span_ [class_ "tabular-nums text-xl", term "data-tippy-content" "Events for this Anomaly in the last 14days"] $ toHtml @String $ fmt $ commaizeF host.eventCount + + div_ [class_ "w-36 flex items-center justify-center"] + $ span_ [class_ "tabular-nums text-xl", term "data-tippy-content" "Events for this Anomaly in the last 14 days"] + $ toHtml @String + $ fmt + $ commaizeF host.eventCount diff --git a/src/Pages/Endpoints/ApiCatalogSpec.hs b/src/Pages/Endpoints/ApiCatalogSpec.hs index c835afcdd..ef1b86ef3 100644 --- a/src/Pages/Endpoints/ApiCatalogSpec.hs +++ b/src/Pages/Endpoints/ApiCatalogSpec.hs @@ -22,7 +22,7 @@ spec :: Spec spec = aroundAll withTestResources do describe "Check Api Catalog List" do it "should return an empty list" \TestResources{..} -> do - PageCtx _ (ItemsList.ItemsPage _ hostsAndEvents) <- toServantResponse trATCtx trSessAndHeader trLogger $ ApiCatalog.apiCatalogH testPid Nothing Nothing + PageCtx _ (ItemsList.ItemsPage _ hostsAndEvents) <- toServantResponse trATCtx trSessAndHeader trLogger $ ApiCatalog.apiCatalogH testPid Nothing Nothing Nothing length hostsAndEvents `shouldBe` 0 it "should return incoming hosts list and outgoing host list" \TestResources{..} -> do @@ -41,5 +41,5 @@ spec = aroundAll withTestResources do _ <- runAllBackgroundJobs trATCtx _ <- withPool trPool $ refreshMaterializedView "apis.endpoint_request_stats" - PageCtx _ (ItemsList.ItemsPage _ hostsAndEvents) <- toServantResponse trATCtx trSessAndHeader trLogger $ ApiCatalog.apiCatalogH testPid Nothing (Just "Incoming") + PageCtx _ (ItemsList.ItemsPage _ hostsAndEvents) <- toServantResponse trATCtx trSessAndHeader trLogger $ ApiCatalog.apiCatalogH testPid Nothing Nothing (Just "Incoming") length hostsAndEvents `shouldBe` 1 diff --git a/src/Pages/Endpoints/EndpointDetails.hs b/src/Pages/Endpoints/EndpointDetails.hs index d6201695c..890ef9a65 100644 --- a/src/Pages/Endpoints/EndpointDetails.hs +++ b/src/Pages/Endpoints/EndpointDetails.hs @@ -179,21 +179,21 @@ fieldDetailsView field formats = do div_ do h5_ [class_ "text-sm text-slate-800"] "DETECTED FIELD FORMATS AND TYPES" - div_ [class_ "space-y-2"] $ - formats - & mapM_ \formatV -> do - div_ [class_ "border-l-slate-200 border-l-2 pl-2 py-2"] do - div_ [class_ "flex flex-row gap-9"] do - div_ [class_ "space-y-2"] do - h6_ [class_ "text-slate-800 text-xs"] "TYPE" - h4_ [class_ "text-base text-slate-800"] $ EndpointComponents.fieldTypeToDisplay formatV.fieldType - div_ [class_ "mx-5 space-y-2"] do - h6_ [class_ "text-slate-800 text-xs"] "FORMAT" - h4_ [class_ "text-base text-slate-800"] $ toHtml formatV.fieldFormat - h6_ [class_ "text-slate-600 mt-4 text-xs"] $ if field.isEnum then "ENUM VALUES" else "EXAMPLE VALUES" - ul_ [class_ "list-disc"] do - formatV.examples & mapM_ \ex -> do - li_ [class_ "ml-10 text-slate-800 text-sm"] $ toHtml $ aesonValueToText ex + div_ [class_ "space-y-2"] + $ formats + & mapM_ \formatV -> do + div_ [class_ "border-l-slate-200 border-l-2 pl-2 py-2"] do + div_ [class_ "flex flex-row gap-9"] do + div_ [class_ "space-y-2"] do + h6_ [class_ "text-slate-800 text-xs"] "TYPE" + h4_ [class_ "text-base text-slate-800"] $ EndpointComponents.fieldTypeToDisplay formatV.fieldType + div_ [class_ "mx-5 space-y-2"] do + h6_ [class_ "text-slate-800 text-xs"] "FORMAT" + h4_ [class_ "text-base text-slate-800"] $ toHtml formatV.fieldFormat + h6_ [class_ "text-slate-600 mt-4 text-xs"] $ if field.isEnum then "ENUM VALUES" else "EXAMPLE VALUES" + ul_ [class_ "list-disc"] do + formatV.examples & mapM_ \ex -> do + li_ [class_ "ml-10 text-slate-800 text-sm"] $ toHtml $ aesonValueToText ex div_ [class_ "flex flex-row justify-between mt-10 "] do div_ [class_ " "] do h4_ [class_ "text-sm text-slate-800 mb-2"] "CREATION DATE" @@ -348,9 +348,9 @@ endpointDetails pid paramInput currTime endpoint endpointStats shapesWithFieldsM & mapM_ \(title, slug) -> a_ [ href_ $ currentURLSubPage <> "&subpage=" <> slug - , class_ $ - "cursor-pointer px-3 py-2 font-medium text-sm rounded-md " - <> if slug == paramInput.subPage then " bg-indigo-100 text-indigo-700 " else " text-slate-500 hover:text-gray-700" + , class_ + $ "cursor-pointer px-3 py-2 font-medium text-sm rounded-md " + <> if slug == paramInput.subPage then " bg-indigo-100 text-indigo-700 " else " text-slate-500 hover:text-gray-700" ] $ toHtml title @@ -555,8 +555,8 @@ apiOverviewSubPage pid paramInput currTime endpoint fieldsM reqLatenciesRolledBy endpointStats :: Endpoints.EndpointRequestStats -> Text -> (Maybe UTCTime, Maybe UTCTime) -> Html () endpointStats enpStats@Endpoints.EndpointRequestStats{min, p50, p75, p90, p95, p99, max} reqLatenciesRolledByStepsJ dateRange@(fromD, toD) = section_ [class_ "space-y-3"] do - div_ [class_ "flex justify-between mt-5"] $ - div_ + div_ [class_ "flex justify-between mt-5"] + $ div_ [class_ "flex flex-row"] do a_ [href_ "#", [__|on click toggle .neg-rotate-90 on me then toggle .hidden on (next .endpointStatsSubSection)|]] $ faSprite_ "chevron-down" "regular" "h-4 mr-3 mt-1 w-4 cursor-pointer" @@ -598,8 +598,8 @@ endpointStats enpStats@Endpoints.EndpointRequestStats{min, p50, p75, p90, p95, p Charts.lazy [C.QByE $ [C.QBPId enpStats.projectId, C.QBEndpointHash enpStats.endpointHash] ++ catMaybes [C.QBFrom <$> fromD, C.QBTo <$> toD], C.GByE C.GBEndpoint, C.SlotsE 120, C.ShowLegendE] div_ [class_ "col-span-3 bg-base-100 border border-gray-100 rounded-xl py-3 px-6"] do - div_ [class_ "p-4"] $ - select_ + div_ [class_ "p-4"] + $ select_ [] do option_ "Request Latency Distribution" @@ -643,24 +643,24 @@ reqResSection title isRequest shapesWithFieldsMap targetIndex = section_ [class_ "space-y-3"] do div_ [class_ "flex justify-between mt-5"] do div_ [class_ "flex flex-row"] do - a_ [class_ "cursor-pointer", [__|on click toggle .neg-rotate-90 on me then toggle .hidden on (next .reqResSubSection)|]] $ - faSprite_ "chevron-down" "light" "h-4 mr-3 mt-1 w-4" + a_ [class_ "cursor-pointer", [__|on click toggle .neg-rotate-90 on me then toggle .hidden on (next .reqResSubSection)|]] + $ faSprite_ "chevron-down" "light" "h-4 mr-3 mt-1 w-4" span_ [class_ "text-lg text-slate-800"] $ toHtml title - div_ [class_ "bg-base-100 border border-gray-100 rounded-xl py-5 px-5 space-y-6 reqResSubSection"] $ - forM_ (zip [(1 :: Int) ..] shapesWithFieldsMap) $ - \(index, s) -> do - let sh = if index == targetIndex then title <> "_fields" else title <> "_fields hidden" - div_ [class_ sh, id_ $ title <> "_" <> show index] do - if isRequest - then do - subSubSection (title <> " Path Params") (Map.lookup Fields.FCPathParam s.fieldsMap) Nothing - subSubSection (title <> " Query Params") (Map.lookup Fields.FCQueryParam s.fieldsMap) Nothing - subSubSection (title <> " Headers") (Map.lookup Fields.FCRequestHeader s.fieldsMap) Nothing - subSubSection (title <> " Body") (Map.lookup Fields.FCRequestBody s.fieldsMap) (Just s.reqDescription) - else do - subSubSection (title <> " Headers") (Map.lookup Fields.FCResponseHeader s.fieldsMap) Nothing - subSubSection (title <> " Body") (Map.lookup Fields.FCResponseBody s.fieldsMap) (Just s.resDescription) + div_ [class_ "bg-base-100 border border-gray-100 rounded-xl py-5 px-5 space-y-6 reqResSubSection"] + $ forM_ (zip [(1 :: Int) ..] shapesWithFieldsMap) + $ \(index, s) -> do + let sh = if index == targetIndex then title <> "_fields" else title <> "_fields hidden" + div_ [class_ sh, id_ $ title <> "_" <> show index] do + if isRequest + then do + subSubSection (title <> " Path Params") (Map.lookup Fields.FCPathParam s.fieldsMap) Nothing + subSubSection (title <> " Query Params") (Map.lookup Fields.FCQueryParam s.fieldsMap) Nothing + subSubSection (title <> " Headers") (Map.lookup Fields.FCRequestHeader s.fieldsMap) Nothing + subSubSection (title <> " Body") (Map.lookup Fields.FCRequestBody s.fieldsMap) (Just s.reqDescription) + else do + subSubSection (title <> " Headers") (Map.lookup Fields.FCResponseHeader s.fieldsMap) Nothing + subSubSection (title <> " Body") (Map.lookup Fields.FCResponseBody s.fieldsMap) (Just s.resDescription) -- | subSubSection .. diff --git a/src/Pages/Endpoints/EndpointList.hs b/src/Pages/Endpoints/EndpointList.hs index 051699367..35f0cec44 100644 --- a/src/Pages/Endpoints/EndpointList.hs +++ b/src/Pages/Endpoints/EndpointList.hs @@ -59,21 +59,21 @@ endpointListGetH pid pageM layoutM filterTM hostM requestTypeM sortM hxRequestM , currProject = Just project , pageTitle = "Endpoints for " <> host , pageActions = - Just $ - a_ [class_ "btn btn-sm btn-primary space-x-2", href_ $ "/p/" <> pid.toText <> "/documentation?host=" <> host] do + Just + $ a_ [class_ "btn btn-sm btn-primary space-x-2", href_ $ "/p/" <> pid.toText <> "/documentation?host=" <> host] do Utils.faSprite_ "plus" "regular" "h-4" >> "OpenAPI/Swagger" , navTabs = - Just $ - toHtml $ - Components.TabFilter - { current = currentFilterTab - , currentURL - , options = - [ Components.TabFilterOpt{name = "Active", count = Nothing} - , Components.TabFilterOpt{name = "Inbox", count = Just inboxCount} - , Components.TabFilterOpt{name = "Archived", count = Nothing} - ] - } + Just + $ toHtml + $ Components.TabFilter + { current = currentFilterTab + , currentURL + , options = + [ Components.TabFilterOpt{name = "Active", count = Nothing} + , Components.TabFilterOpt{name = "Inbox", count = Just inboxCount} + , Components.TabFilterOpt{name = "Archived", count = Nothing} + ] + } } let nextFetchUrl = currentURL <> "&page=" <> show (page + 1) <> "&load_more=true" @@ -88,6 +88,7 @@ endpointListGetH pid pageM layoutM filterTM hostM requestTypeM sortM hxRequestM { projectId = pid , nextFetchUrl = Just nextFetchUrl , sort = Just $ ItemsList.SortCfg{current = fromMaybe "events" sortM} + , filter = Nothing , bulkActions = [ ItemsList.BulkAction{icon = Just "check", title = "acknowlege", uri = "/p/" <> pid.toText <> "/anomalies/bulk_actions/acknowlege"} , ItemsList.BulkAction{icon = Just "inbox-full", title = "archive", uri = "/p/" <> pid.toText <> "/anomalies/bulk_actions/archive"} @@ -98,8 +99,8 @@ endpointListGetH pid pageM layoutM filterTM hostM requestTypeM sortM hxRequestM Nothing -> "Endpoints" , search = Just $ ItemsList.SearchCfg{viaQueryParam = Just (fromMaybe "" searchM)} , zeroState = - Just $ - ItemsList.ZeroState + Just + $ ItemsList.ZeroState { icon = "empty-set" , title = "Waiting for events" , description = "You're currently not sending any data to APItoolkit from your backends yet." @@ -159,8 +160,8 @@ renderEndpoint activePage currTime enp = do let host = enp.host AnomalyList.anomalyArchiveButton enp.projectId (Anomalies.AnomalyId enp.anomalyId) (isJust enp.archivedAt) AnomalyList.anomalyAcknowlegeButton enp.projectId (Anomalies.AnomalyId enp.anomalyId) (isJust enp.acknowlegedAt) host - div_ [class_ "flex items-center justify-center "] $ - div_ + div_ [class_ "flex items-center justify-center "] + $ div_ [ class_ "w-56 h-12 px-3" , hxGet_ $ "/charts_html?pid=" <> enp.projectId.toText <> "&since=14D&show_axes=false&query_raw=" <> Utils.escapedQueryPartial [PyF.fmt|endpoint_hash=="{enp.endpointHash}" | timechart [1d]|] , hxTrigger_ "intersect once" diff --git a/src/Pages/Endpoints/Routes.hs b/src/Pages/Endpoints/Routes.hs index 97f388116..8575ab934 100644 --- a/src/Pages/Endpoints/Routes.hs +++ b/src/Pages/Endpoints/Routes.hs @@ -29,6 +29,6 @@ data Routes' mode = Routes' , fieldDetailsPartial :: mode :- "fields" :> Capture "field_id" Fields.FieldId :> Get '[HTML] (RespHeaders EndpointDetails.FieldDetails) , endpointDetailsWithHash :: mode :- "log_explorer" :> "endpoint" :> Capture "endpoint_hash" Text :> Get '[HTML] (RespHeaders (Html ())) , endpointDetails :: mode :- "endpoints" :> Capture "endpoints_id" Endpoints.EndpointId :> QPT "from" :> QPT "to" :> QPT "since" :> QPT "subpage" :> QPT "shape" :> Get '[HTML] (RespHeaders EndpointDetails.EndpointDetailsGet) - , apiCatalogGet :: mode :- "api_catalog" :> QPT "sort" :> QPT "request_type" :> Get '[HTML] (RespHeaders (PageCtx (ItemsList.ItemsPage ApiCatalog.HostEventsVM))) + , apiCatalogGet :: mode :- "api_catalog" :> QPT "sort" :> QPT "since" :> QPT "request_type" :> Get '[HTML] (RespHeaders (PageCtx (ItemsList.ItemsPage ApiCatalog.HostEventsVM))) } deriving stock (Generic) diff --git a/src/Pages/LogExplorer/LogItem.hs b/src/Pages/LogExplorer/LogItem.hs index 3d188f19e..a583f1e6e 100644 --- a/src/Pages/LogExplorer/LogItem.hs +++ b/src/Pages/LogExplorer/LogItem.hs @@ -145,24 +145,24 @@ expandAPIlogItem' pid req modal = do div_ [class_ "tabs tabs-bordered place-content-start ", role_ "tablist"] do input_ [type_ "radio", name_ $ "req-details-tabx-" <> show req.id, role_ "tab", Aria.label_ "Body", class_ "tab w-max", checked_] - div_ [class_ "tab-content grow w-full", role_ "tabpanel"] $ - div_ [class_ "bg-gray-50 m-4 p-2 rounded-lg border break-all", id_ "req_body_json"] $ - jsonValueToHtmlTree req.requestBody + div_ [class_ "tab-content grow w-full", role_ "tabpanel"] + $ div_ [class_ "bg-gray-50 m-4 p-2 rounded-lg border break-all", id_ "req_body_json"] + $ jsonValueToHtmlTree req.requestBody input_ [type_ "radio", name_ $ "req-details-tabx-" <> show req.id, role_ "tab", Aria.label_ "Headers", class_ "tab"] - div_ [class_ "tab-content grow w-full", role_ "tabpanel"] $ - div_ [class_ "bg-gray-50 m-4 p-2 rounded-lg border break-all", id_ "req_headers_json"] $ - jsonValueToHtmlTree req.requestHeaders + div_ [class_ "tab-content grow w-full", role_ "tabpanel"] + $ div_ [class_ "bg-gray-50 m-4 p-2 rounded-lg border break-all", id_ "req_headers_json"] + $ jsonValueToHtmlTree req.requestHeaders input_ [type_ "radio", name_ $ "req-details-tabx-" <> show req.id, role_ "tab", Aria.label_ "Query Params", class_ "tab break-keep"] - div_ [class_ "tab-content grow w-full", role_ "tabpanel"] $ - div_ [class_ "bg-gray-50 m-4 p-2 rounded-lg border", id_ "query_params_json"] $ - jsonValueToHtmlTree req.queryParams + div_ [class_ "tab-content grow w-full", role_ "tabpanel"] + $ div_ [class_ "bg-gray-50 m-4 p-2 rounded-lg border", id_ "query_params_json"] + $ jsonValueToHtmlTree req.queryParams input_ [type_ "radio", name_ $ "req-details-tabx-" <> show req.id, role_ "tab", Aria.label_ "Path Params", class_ "tab break-keep"] - div_ [class_ "tab-content grow w-full", role_ "tabpanel"] $ - div_ [class_ "bg-gray-50 m-4 p-2 rounded-lg border", id_ "path_params_json"] $ - jsonValueToHtmlTree req.pathParams + div_ [class_ "tab-content grow w-full", role_ "tabpanel"] + $ div_ [class_ "bg-gray-50 m-4 p-2 rounded-lg border", id_ "path_params_json"] + $ jsonValueToHtmlTree req.pathParams -- response details div_ [class_ "border rounded-lg mt-8", id_ "reponse_detail_container"] do @@ -171,14 +171,14 @@ expandAPIlogItem' pid req modal = do div_ [class_ "tabs tabs-bordered place-content-start grid grid-flow-col", role_ "tablist"] do input_ [type_ "radio", name_ "resp-details-tab", role_ "tab", Aria.label_ "Body", class_ "tab", checked_] - div_ [class_ "tab-content", role_ "tabpanel"] $ - div_ [class_ "bg-gray-50 m-4 p-2 rounded-lg border", id_ "res_body_json"] $ - jsonValueToHtmlTree req.responseBody + div_ [class_ "tab-content", role_ "tabpanel"] + $ div_ [class_ "bg-gray-50 m-4 p-2 rounded-lg border", id_ "res_body_json"] + $ jsonValueToHtmlTree req.responseBody input_ [type_ "radio", name_ "resp-details-tab", role_ "tab", Aria.label_ "Headers", class_ "tab"] - div_ [class_ "tab-content", role_ "tabpanel"] $ - div_ [class_ "bg-gray-50 m-4 p-2 rounded-lg border", id_ "res_headers_json"] $ - jsonValueToHtmlTree req.responseHeaders + div_ [class_ "tab-content", role_ "tabpanel"] + $ div_ [class_ "bg-gray-50 m-4 p-2 rounded-lg border", id_ "res_headers_json"] + $ jsonValueToHtmlTree req.responseHeaders apiLogItemH :: Projects.ProjectId -> UUID.UUID -> UTCTime -> Maybe Text -> ATAuthCtx (RespHeaders ApiLogItem) @@ -237,21 +237,22 @@ apiLogItemView pid logId req expandItemPath source = do _ -> Nothing let logItemPathDetailed = if source == "spans" then "/p/" <> pid.toText <> "/traces/" <> fromMaybe "" trId else expandItemPath <> "/detailed?source=" <> source div_ [class_ "flex items-center gap-2"] do - label_ - [ class_ "btn btn-sm btn-outline" - , Lucid.for_ "global-data-drawer" - , term "_" $ - [text|on mousedown or click fetch $logItemPathDetailed + when (source == "requests") + $ label_ + [ class_ "btn btn-sm btn-outline" + , Lucid.for_ "global-data-drawer" + , term "_" + $ [text|on mousedown or click fetch $logItemPathDetailed then set #global-data-drawer-content.innerHTML to #loader-tmp.innerHTML then set #global-data-drawer.checked to true then set #global-data-drawer-content.innerHTML to it then htmx.process(#global-data-drawer-content) then _hyperscript.processNode(#global-data-drawer-content) then window.evalScriptsFromContent(#global-data-drawer-content)|] - ] - ("Expand" >> faSprite_ "expand" "regular" "h-3 w-3") + ] + ("Expand" >> faSprite_ "expand" "regular" "h-3 w-3") let reqJson = decodeUtf8 $ AE.encode req - when (source /= "logs" && source /= "spans") $ - button_ + when (source /= "logs" && source /= "spans") + $ button_ [ class_ "btn btn-sm btn-outline" , term "data-reqJson" reqJson , onclick_ "window.buildCurlRequest(event)" @@ -270,8 +271,8 @@ apiLogItemView pid logId req expandItemPath source = do -- Function to selectively convert RequestDumpLogItem to JSON selectiveReqToJson :: RequestDumps.RequestDumpLogItem -> AE.Value selectiveReqToJson req = - AE.object $ - concat @[] + AE.object + $ concat @[] [ ["created_at" .= req.createdAt] , ["duration_ns" .= req.durationNs] , ["errors" .= req.errors] @@ -297,8 +298,8 @@ selectiveReqToJson req = selectiveSpanToJson :: Telemetry.SpanRecord -> AE.Value selectiveSpanToJson sp = - AE.object $ - concat @[] + AE.object + $ concat @[] [ ["timestamp" .= sp.timestamp] , ["span_id" .= sp.spanId] , ["span_name" .= sp.spanName] diff --git a/src/Pages/Monitors/Testing.hs b/src/Pages/Monitors/Testing.hs index 7bd3f1c9d..1fa59dbcb 100644 --- a/src/Pages/Monitors/Testing.hs +++ b/src/Pages/Monitors/Testing.hs @@ -89,6 +89,7 @@ testingGetH pid filterTM = do , sort = Nothing , currentURL , currTime + , filter = Nothing , nextFetchUrl = Nothing , search = Just $ ItemsList.SearchCfg{viaQueryParam = Nothing} , heading = Nothing diff --git a/src/Pages/Reports.hs b/src/Pages/Reports.hs index 45b3f23ba..c447994bb 100644 --- a/src/Pages/Reports.hs +++ b/src/Pages/Reports.hs @@ -36,7 +36,37 @@ import Data.Time.LocalTime (LocalTime (localDay), ZonedTime (zonedTimeToLocalTim import Data.Vector (Vector) import Data.Vector qualified as V import Effectful.PostgreSQL.Transact.Effect (dbtToEff) -import Lucid +import Lucid ( + Html, + ToHtml (..), + a_, + checked_, + class_, + div_, + for_, + h3_, + h4_, + h5_, + href_, + id_, + img_, + input_, + label_, + name_, + p_, + small_, + span_, + src_, + style_, + table_, + tbody_, + td_, + th_, + thead_, + tr_, + type_, + value_, + ) import Lucid.Htmx (hxGet_, hxPost_, hxSwap_, hxTrigger_) import Models.Apis.Anomalies qualified as Anomalies import Models.Apis.Fields.Types (textFieldTypeToText) @@ -259,30 +289,6 @@ reportsPage pid reports nextUrl daily weekly = div_ [class_ "mx-auto w-full flex flex-col px-16 pt-10 pb-24 overflow-y-scroll h-full"] do h3_ [class_ "text-xl text-slate-700 flex place-items-center font-bold pb-4 border-b"] "Reports History" div_ [class_ "mt-4 grid grid-cols-12 gap-4"] do - div_ [class_ "flex flex-col col-span-2 border h-max rounded-lg overflow-hidden mt-16"] do - h5_ [class_ "text-lg font-semibold text-slate-700 pb-1 bg-gray-200 p-2"] "Email notifications" - div_ [class_ "p-2 flex items-center justify-between w-full hover:bg-gray-100"] do - label_ [class_ "inline-flex items-center w-full", Lucid.for_ "e-daily"] "Daily reports" - input_ - [ type_ "checkbox" - , id_ "e-daily" - , name_ "daily-reports" - , if daily then checked_ else value_ "off" - , hxPost_ $ "/p/" <> show pid.unProjectId <> "/reports_notif/daily" - , hxTrigger_ "change" - , class_ "checkbox checkbox-success checkbox-sm" - ] - div_ [class_ "p-2 flex items-center justify-between w-full hover:bg-gray-100"] do - label_ [class_ "inline-flex items-center w-full", Lucid.for_ "e-weekly"] "Weekly reports" - input_ - [ type_ "checkbox" - , id_ "e-weekly" - , name_ "weekly-reports" - , if weekly then checked_ else value_ "off" - , hxPost_ $ "/p/" <> show pid.unProjectId <> "/reports_notif/weekly" - , hxTrigger_ "change" - , class_ "checkbox checkbox-success checkbox-sm" - ] div_ [class_ "col-span-8"] do reportListItems pid reports nextUrl @@ -291,11 +297,12 @@ reportListItems :: Projects.ProjectId -> Vector Reports.ReportListItem -> Text - reportListItems pid reports nextUrl = div_ [class_ "space-y-4"] do forM_ reports $ \report -> do - div_ [class_ "mx-auto rounded-lg border max-w-[1000px]"] do - a_ [class_ "bg-gray-100 px-4 py-3 flex justify-between", href_ $ "/p/" <> show pid.unProjectId <> "/reports/" <> show report.id.reportId] do - h4_ [class_ "text-xl font-medium capitalize"] $ toHtml report.reportType <> " report" - span_ [] $ show $ localDay (zonedTimeToLocalTime report.createdAt) - div_ [class_ "px-4 py-3 space-y-8"] pass + when (report.reportType == "weekly") $ do + div_ [class_ "mx-auto rounded-lg border max-w-[1000px]"] do + a_ [class_ "bg-gray-100 px-4 py-3 flex justify-between", href_ $ "/p/" <> show pid.unProjectId <> "/reports/" <> show report.id.reportId] do + h4_ [class_ "text-xl font-medium capitalize"] $ toHtml report.reportType <> " report" + span_ [] $ show $ localDay (zonedTimeToLocalTime report.createdAt) + div_ [class_ "px-4 py-3 space-y-8"] pass if length reports < 20 then pass else a_ [class_ "max-w-[800px] mx-auto cursor-pointer block p-1 blue-800 bg-blue-100 hover:bg-blue-200 text-center", hxTrigger_ "click", hxSwap_ "outerHTML", hxGet_ nextUrl] "LOAD MORE" diff --git a/src/Pages/Traces/Trace.hs b/src/Pages/Traces/Trace.hs index 04bec4115..fe3fb1df6 100644 --- a/src/Pages/Traces/Trace.hs +++ b/src/Pages/Traces/Trace.hs @@ -136,8 +136,8 @@ tracePage p = do span_ [class_ ""] $ toHtml s div_ [class_ "flex gap-1 items-center"] $ do span_ [class_ "text-xs max-w-52 truncate"] $ toHtml $ T.take 4 percent <> "%" - div_ [class_ "w-[100px] h-3 bg-gray-200 rounded overflow-hidden"] $ - div_ [class_ $ "h-full pl-2 text-xs font-medium " <> color, style_ $ "width:" <> percent <> "%"] pass + div_ [class_ "w-[100px] h-3 bg-gray-200 rounded overflow-hidden"] + $ div_ [class_ $ "h-full pl-2 text-xs font-medium " <> color, style_ $ "width:" <> percent <> "%"] pass input_ [type_ "radio", name_ "my_tabs_2", role_ "tab", class_ "tab after:pb-2", term "aria-label" "Span List"] div_ [role_ "tabpanel", class_ "tab-content pt-2"] do @@ -200,8 +200,8 @@ renderSpanListTable services colors records = th_ "Avg. Duration" th_ "Exec. Time" th_ "%Exec. Time" - tbody_ [class_ "space-y-0"] $ - mapM_ (renderSpanRecordRow records colors) services + tbody_ [class_ "space-y-0"] + $ mapM_ (renderSpanRecordRow records colors) services spanTable :: V.Vector Telemetry.SpanRecord -> Html () diff --git a/src/Pkg/Components/ItemsList.hs b/src/Pkg/Components/ItemsList.hs index 11bd51ce4..5737161ec 100644 --- a/src/Pkg/Components/ItemsList.hs +++ b/src/Pkg/Components/ItemsList.hs @@ -26,6 +26,7 @@ import Utils (deleteParam, faSprite_) data ItemsListCfg = ItemsListCfg { currentURL :: Text , sort :: Maybe SortCfg + , filter :: Maybe Text , projectId :: Projects.ProjectId , currTime :: UTCTime , elemID :: Text @@ -58,20 +59,16 @@ data ZeroState = ZeroState , title :: Text , description :: Text , actionText :: Text - , destination :: Either Text Text -- Either LabelID URL + , destination :: Either Text Text } type role ItemsPage representational - - data ItemsPage a = ItemsPage ItemsListCfg (V.Vector a) instance ToHtml a => ToHtml (ItemsPage a) where - {-# INLINE toHtml #-} toHtml (ItemsPage cfg items) = toHtmlRaw $ itemsPage_ cfg items - {-# INLINE toHtmlRaw #-} toHtmlRaw (ItemsPage cfg items) = toHtmlRaw $ itemsPage_ cfg items @@ -91,55 +88,66 @@ itemsList_ listCfg items = , ("Events", "Number of events", "events") ] :: [(Text, Text, Text)] - div_ - [class_ "flex py-3 gap-8 items-center bg-gray-50"] - do - div_ [class_ "h-4 flex space-x-3 w-8 items-center"] do - span_ [class_ " w-2 h-full"] "" - input_ - [ term "aria-label" "Select Issue" - , type_ "checkbox" - , class_ "checkbox checkbox-md checked:checkbox-primary" - , [__| on click set .bulkactionItemCheckbox.checked to my.checked |] - ] - div_ [class_ " grow flex flex-row gap-2"] do - forM_ listCfg.bulkActions \blkA -> button_ - [ class_ "btn btn-sm border-black hover:shadow-2xl btn-disabled group-has-[.bulkactionItemCheckbox:checked]/grid:!btn-outline group-has-[.bulkactionItemCheckbox:checked]/grid:!pointer-events-auto " - , hxPost_ blkA.uri - , hxSwap_ "none" + + div_ [class_ "flex py-3 gap-8 items-center bg-gray-50"] do + div_ [class_ "h-4 flex space-x-3 w-8 items-center"] do + span_ [class_ " w-2 h-full"] "" + input_ + [ term "aria-label" "Select Issue" + , type_ "checkbox" + , class_ "checkbox checkbox-md checked:checkbox-primary" + , [__| on click set .bulkactionItemCheckbox.checked to my.checked |] + ] + + div_ [class_ " grow flex flex-row gap-2"] do + forM_ listCfg.bulkActions \blkA -> button_ + [ class_ "btn btn-sm border-black hover:shadow-2xl btn-disabled group-has-[.bulkactionItemCheckbox:checked]/grid:!btn-outline group-has-[.bulkactionItemCheckbox:checked]/grid:!pointer-events-auto " + , hxPost_ blkA.uri + , hxSwap_ "none" + ] + do + whenJust blkA.icon \icon -> faSprite_ icon "solid" "h-4 w-4 inline-block" + span_ (toHtml blkA.title) + + whenJust listCfg.search \search -> do + label_ [class_ "input input-sm input-bordered flex overflow-hidden items-center gap-2"] do + case search.viaQueryParam of + Just param -> + input_ + [ type_ "text" + , class_ "grow" + , name_ "search" + , id_ "search_box" + , placeholder_ "Search" + , hxTrigger_ "keyup changed delay:500ms" + , hxGet_ currentURL' + , hxTarget_ "#rowsContainer" + , hxSwap_ "innerHTML" + , id_ "searchThing" + , hxIndicator_ "#searchIndicator" + ] + Nothing -> do + input_ + [ type_ "text" + , class_ "grow" + , placeholder_ "Search" + , [__| on input show .itemsListItem in #itemsListPage when its textContent.toLowerCase() contains my value.toLowerCase() |] + ] + faSprite_ "magnifying-glass" "regular" "w-4 h-4 opacity-70" + + whenJust listCfg.sort \sortCfg -> do + let currentSortTitle = maybe "First Seen" fst3 $ find (\(_, _, identifier) -> identifier == sortCfg.current) sortMenu + div_ [class_ "dropdown dropdown-end inline-block"] do + a_ [class_ "btn btn-sm btn-outline border-black hover:shadow-2xl", tabindex_ "0"] do + faSprite_ "sort" "solid" "h-4 w-4" + span_ $ toHtml currentSortTitle + div_ + [ id_ "sortMenuDiv" + , hxBoost_ "true" + , class_ "dropdown-content bg-base-100 p-1 text-sm border border-black-30 z-50 mt-2 w-72 origin-top-right rounded-md shadow-lg " + , tabindex_ "0" ] do - whenJust blkA.icon \icon -> faSprite_ icon "solid" "h-4 w-4 inline-block" - span_ (toHtml blkA.title) - - whenJust listCfg.search \search -> do - label_ [class_ "input input-sm input-bordered flex overflow-hidden items-center gap-2"] do - case search.viaQueryParam of - Just param -> - input_ - [ type_ "text" - , class_ "grow" - , name_ "search" - , id_ "search_box" - , placeholder_ "Search" - , hxTrigger_ "keyup changed delay:500ms" - , hxGet_ currentURL' - , hxTarget_ "#rowsContainer" - , hxSwap_ "innerHTML" - , id_ "searchThing" - , hxIndicator_ "#searchIndicator" - ] - Nothing -> do - input_ [type_ "text", class_ "grow", placeholder_ "Search", [__| on input show .itemsListItem in #itemsListPage when its textContent.toLowerCase() contains my value.toLowerCase() |]] - faSprite_ "magnifying-glass" "regular" "w-4 h-4 opacity-70" - - whenJust listCfg.sort \sortCfg -> do - let currentSortTitle = maybe "First Seen" fst3 $ find (\(_, _, identifier) -> identifier == sortCfg.current) sortMenu - div_ [class_ "dropdown dropdown-end inline-block"] do - a_ [class_ "btn btn-sm btn-outline border-black hover:shadow-2xl", tabindex_ "0"] do - faSprite_ "sort" "solid" "h-4 w-4" - span_ $ toHtml currentSortTitle - div_ [id_ "sortMenuDiv", hxBoost_ "true", class_ "dropdown-content bg-base-100 p-1 text-sm border border-black-30 z-50 mt-2 w-72 origin-top-right rounded-md shadow-lg ", tabindex_ "0"] do sortMenu & mapM_ \(title, desc, identifier) -> do let isActive = sortCfg.current == identifier || (sortCfg.current == "" && identifier == "first_seen") a_ @@ -154,11 +162,18 @@ itemsList_ listCfg items = span_ [class_ "block text-lg"] $ toHtml title span_ [class_ "block "] $ toHtml desc - div_ [class_ "flex justify-center font-base w-60 content-between gap-14"] do - span_ "GRAPH" - div_ [class_ " space-x-2 font-base text-sm"] (a_ [class_ "cursor-pointer"] "24h" >> a_ [class_ "cursor-pointer font-bold text-base"] "14d") - div_ [class_ "w-36 flex items-center justify-center"] $ span_ [class_ "font-base"] "EVENTS" - div_ [class_ "p-12 fixed rounded-lg shadow bg-base-100 top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 htmx-indicator loading loading-dots loading-md", id_ "sortLoader"] "" + div_ [class_ "flex justify-center font-base w-60 content-between gap-14"] do + span_ "GRAPH" + div_ [class_ "space-x-2 font-base text-sm"] do + let selectedFilter = fromMaybe "14d" listCfg.filter -- Default to "14d" if Nothing + a_ [class_ $ "cursor-pointer " <> (if selectedFilter == "24h" then "text-base font-bold" else ""), href_ $ currentURL' <> "&since=24h"] "24h" + a_ [class_ $ "cursor-pointer " <> (if selectedFilter == "14d" then "text-base font-bold" else ""), href_ $ currentURL' <> "&since=14d"] "14d" + div_ [class_ "w-36 flex items-center justify-center"] $ span_ [class_ "font-base"] "EVENTS" + div_ + [ class_ "p-12 fixed rounded-lg shadow bg-base-100 top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 htmx-indicator loading loading-dots loading-md" + , id_ "sortLoader" + ] + "" when (null items) $ whenJust listCfg.zeroState \zeroState -> section_ [class_ "mx-auto w-max p-5 sm:py-10 sm:px-16 items-center flex my-10 gap-16"] do div_ [] $ faSprite_ zeroState.icon "solid" "h-24 w-24" @@ -168,21 +183,18 @@ itemsList_ listCfg items = case zeroState.destination of Right destination -> a_ [href_ destination, class_ "w-max btn btn-indigo -ml-1 text-md"] $ toHtml zeroState.actionText Left labelId -> label_ [Lucid.for_ labelId, class_ "w-max btn btn-indigo -ml-1 text-md"] $ toHtml zeroState.actionText + div_ [class_ "w-full flex flex-col"] do span_ [id_ "searchIndicator", class_ "htmx-indicator loading loading-sm loading-dots mx-auto"] "" div_ [id_ "rowsContainer", class_ "divide-y"] $ itemRows_ listCfg.nextFetchUrl items type role ItemsRows representational - - data ItemsRows a = ItemsRows (Maybe Text) (V.Vector a) -- Text represents nextFetchUrl instance ToHtml a => ToHtml (ItemsRows a) where - {-# INLINE toHtml #-} toHtml (ItemsRows nextFetchUrl items) = toHtmlRaw $ itemRows_ nextFetchUrl items - {-# INLINE toHtmlRaw #-} toHtmlRaw (ItemsRows nextFetchUrl items) = toHtmlRaw $ itemRows_ nextFetchUrl items