From d928431ef16a021597b44048eb11cea940d052dc Mon Sep 17 00:00:00 2001 From: Daniel Asaboro Date: Fri, 6 Sep 2024 09:50:13 +0100 Subject: [PATCH 01/15] fix: update server setup --- .env.example | 34 ++++++++++++++++++++++++++++++++++ Makefile | 4 ++-- apitoolkit-server.cabal | 2 ++ package-lock.json | 2 +- stack.yaml | 5 +++++ 5 files changed, 44 insertions(+), 3 deletions(-) diff --git a/.env.example b/.env.example index b6fe9b6cf..49fa43015 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 8bdce092e..9b47cce9d 100644 --- a/apitoolkit-server.cabal +++ b/apitoolkit-server.cabal @@ -134,7 +134,9 @@ library Pages.Specification.Server Pages.Survey Pages.SurveySpec + Pages.Traces.Routes Pages.Traces.Spans + Pages.Traces.Trace Pkg.Components Pkg.Components.ExternalHeadScripts Pkg.Components.ItemsList diff --git a/package-lock.json b/package-lock.json index c2c5cdc36..55d53b572 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/stack.yaml b/stack.yaml index 18f3830b7..77dd24c10 100644 --- a/stack.yaml +++ b/stack.yaml @@ -5,6 +5,11 @@ packages: ghc-options: "grpc-haskell-core": -Wno-x-partial +extra-include-dirs: + - /opt/homebrew/Cellar/grpc/1.62.2_4/include +extra-lib-dirs: + - /opt/homebrew/Cellar/grpc/1.62.2_4/lib + extra-deps: - ./rust-interop - ./otlp From 5244953c3e296f245862bb9f97312853facdcf87 Mon Sep 17 00:00:00 2001 From: Daniel Asaboro Date: Mon, 9 Sep 2024 12:21:30 +0100 Subject: [PATCH 02/15] fix: filter out daily reports from the report list --- src/Pages/Reports.hs | 95 ++++++++++++++++++++++++++++++-------------- 1 file changed, 65 insertions(+), 30 deletions(-) diff --git a/src/Pages/Reports.hs b/src/Pages/Reports.hs index ee99b33e4..2117da4f5 100644 --- a/src/Pages/Reports.hs +++ b/src/Pages/Reports.hs @@ -37,6 +37,35 @@ import Data.Vector (Vector) import Data.Vector qualified as V import Effectful.PostgreSQL.Transact.Effect (dbtToEff) 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) @@ -49,6 +78,8 @@ import Pages.BodyWrapper (BWConfig, PageCtx (..), currProject, pageTitle, sessM) import Relude import System.Types (ATAuthCtx, RespHeaders, addRespHeaders, addSuccessToast) import Text.Printf (printf) +-- import Debug.Trace (traceShow) + data PerformanceReport = PerformanceReport @@ -259,30 +290,30 @@ 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_ "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,16 +322,20 @@ 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 + -- Renders Conditionally... + -- Only if reportType matches a condition + -- putStrLn report.reportType + + 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" - renderEndpointRow :: PerformanceReport -> Html () renderEndpointRow endpoint = tr_ do let (pcls, prc) = From 36d317627fa675891127350329acf7afb371c57f Mon Sep 17 00:00:00 2001 From: Daniel Asaboro Date: Wed, 11 Sep 2024 22:32:28 +0100 Subject: [PATCH 03/15] fix: filter logs based on time elapsed --- src/Pages/Anomalies/AnomalyList.hs | 1 + src/Pages/Endpoints/ApiCatalog.hs | 87 ++++++---- src/Pages/Endpoints/EndpointList.hs | 1 + src/Pages/Endpoints/Routes.hs | 2 +- src/Pages/Monitors/Testing.hs | 1 + src/Pkg/Components/ItemsList.hs | 235 +++++++++++++++------------- 6 files changed, 189 insertions(+), 138 deletions(-) diff --git a/src/Pages/Anomalies/AnomalyList.hs b/src/Pages/Anomalies/AnomalyList.hs index 40a0a63dc..33b5ca5f8 100644 --- a/src/Pages/Anomalies/AnomalyList.hs +++ b/src/Pages/Anomalies/AnomalyList.hs @@ -183,6 +183,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 = diff --git a/src/Pages/Endpoints/ApiCatalog.hs b/src/Pages/Endpoints/ApiCatalog.hs index 65b9155ac..f860cb28f 100644 --- a/src/Pages/Endpoints/ApiCatalog.hs +++ b/src/Pages/Endpoints/ApiCatalog.hs @@ -6,40 +6,55 @@ import Data.Vector qualified as V import Effectful.PostgreSQL.Transact.Effect (dbtToEff) import Effectful.Time qualified as Time import Lucid -import Lucid.Htmx (hxGet_, hxSwap_, hxTrigger_) +import Lucid.Htmx (hxGet_, hxSwap_, hxTrigger_) -- HTMX integration for frontend interactivity. import Models.Apis.Endpoints qualified as Endpoints import Models.Projects.Projects qualified as Projects import Models.Users.Sessions qualified as Sessions import Pages.Anomalies.AnomalyList qualified as AnomalyList import Pages.BodyWrapper (BWConfig (currProject, pageTitle, sessM), PageCtx (..), navTabs) -import Pkg.Components.ItemsList qualified as ItemsList -import PyF qualified -import Relude hiding (ask, asks) -import System.Types (ATAuthCtx, RespHeaders, addRespHeaders) +import Pkg.Components.ItemsList qualified as ItemsList -- Package for the reusable list component. +import PyF qualified -- PyF for formatted strings. +import Relude hiding (ask, asks) -- Standard library extensions with certain functions hidden. +import System.Types (ATAuthCtx, RespHeaders, addRespHeaders) -- Importing custom types for handling responses. - -apiCatalogH :: Projects.ProjectId -> Maybe Text -> Maybe Text -> ATAuthCtx (RespHeaders (PageCtx (ItemsList.ItemsPage HostEventsVM))) -apiCatalogH pid sortM requestTypeM = do +-- Function to handle the API catalog page. +apiCatalogH :: Projects.ProjectId -> Maybe Text -> Maybe Text -> Maybe Text -> ATAuthCtx (RespHeaders (PageCtx (ItemsList.ItemsPage HostEventsVM))) +apiCatalogH pid sortM timeFilter requestTypeM = do + -- Fetch user session and project details based on the project ID. (sess, project) <- Sessions.sessionAndProject pid + + -- Default the request type to "Incoming" if not provided. let requestType = fromMaybe "Incoming" requestTypeM + + -- Fetch hosts and events from the database with sorting and request type filtering. hostsAndEvents <- dbtToEff $ Endpoints.dependenciesAndEventsCount pid requestType (fromMaybe "events" sortM) + currTime <- Time.currentTime + + -- Extract or default the sort and filter values. let sortV = fromMaybe "events" sortM + let filterV = fromMaybe "24h" timeFilter + + -- Build the current URL with appropriate query parameters. let currentURL = "/p/" <> pid.toText <> "/api_catalog?sort=" <> sortV <> "&request_type=" <> requestType + + -- Configure the items list for rendering events related to hosts. 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"} + [ -- Define bulk actions like "acknowledge" and "archive" for anomalies. + 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 = + , zeroState = -- Define the empty state when no requests are being monitored. Just $ ItemsList.ZeroState { icon = "empty-set" @@ -50,43 +65,61 @@ apiCatalogH pid sortM requestTypeM = do } , elemID = "anomalyListForm" } + + -- Define the page's body wrapper configuration (metadata for rendering). let bwconf = def - { sessM = Just sess.persistentSession - , currProject = Just project - , pageTitle = "API Catalog" - , navTabs = Just $ div_ [class_ "tabs tabs-boxed border"] do + { sessM = Just sess.persistentSession -- User session management. + , currProject = Just project -- Current project information. + , pageTitle = "API Catalog" -- Page title for the API catalog. + , navTabs = Just $ div_ [class_ "tabs tabs-boxed border"] do -- Navigation tabs for "Incoming" and "Outgoing" requests. 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) + + -- Add response headers and render the page context (items list). + addRespHeaders $ PageCtx bwconf (ItemsList.ItemsPage listCfg $ V.map (\host -> HostEventsVM pid host filterV requestType) hostsAndEvents) -data HostEventsVM = HostEventsVM Projects.ProjectId Endpoints.HostEvents Text +-- Data type for representing host events in the ViewModel. +data HostEventsVM = HostEventsVM Projects.ProjectId Endpoints.HostEvents Text Text +-- ToHtml instance to define how HostEventsVM should be converted to HTML. instance ToHtml HostEventsVM where - toHtml (HostEventsVM pid he requestType) = toHtmlRaw $ renderapiCatalog pid he requestType - toHtmlRaw = toHtml + toHtml :: Monad m => HostEventsVM -> HtmlT m () + toHtml (HostEventsVM pid he timeFilter requestType) = toHtmlRaw $ renderapiCatalog pid he timeFilter requestType -- Convert HostEventsVM to HTML using renderapiCatalog function. + toHtmlRaw :: Monad m => HostEventsVM -> HtmlT m () + toHtmlRaw = toHtml -- Raw HTML rendering. - -renderapiCatalog :: Projects.ProjectId -> Endpoints.HostEvents -> Text -> Html () -renderapiCatalog pid host requestType = div_ [class_ "flex py-4 gap-8 items-center itemsListItem"] do +-- Function to render the API catalog for a specific project, host, and request type. +renderapiCatalog :: Projects.ProjectId -> Endpoints.HostEvents -> Text -> Text -> Html () +renderapiCatalog pid host timeFilter requestType = div_ [class_ "flex py-4 gap-8 items-center itemsListItem"] do + -- Checkbox for selecting an issue in the list. 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] + -- Main content section displaying the host and actions (view logs, etc.). div_ [class_ "space-y-3 grow"] do div_ [class_ "space-x-3"] do a_ [class_ "inline-block font-bold space-x-2"] $ do + -- Display host and link to endpoint details. 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) + -- Link to view logs for this 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_ + + -- Section for fetching and displaying a time chart via HTMX. + div_ [class_ "flex items-center justify-center "] $ do + -- Conditionally use the filter for the chart. + div_ [ class_ "w-56 h-12 px-3" - , hxGet_ $ "/charts_html?pid=" <> pid.toText <> "&since=14D&query_raw=" <> AnomalyList.escapedQueryPartial [PyF.fmt|host=="{host.host}" | timechart [1d]|] - , hxTrigger_ "intersect once" - , hxSwap_ "innerHTML" + , hxGet_ $ "/charts_html?pid=" <> pid.toText <> "&since=" <> (if timeFilter == "14d" then "14D" else "24h") <> "&query_raw=" <> AnomalyList.escapedQueryPartial [PyF.fmt|host=="{host.host}" | timechart [1d]|] -- Fetch the chart for this host. + , hxTrigger_ "intersect once" -- Load the chart when the element is in view. + , hxSwap_ "innerHTML" -- Replace the content with the fetched chart. ] "" - 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 (show host.eventCount) + + -- Display the number of events for this anomaly in the last 14 days. + 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 (show host.eventCount) diff --git a/src/Pages/Endpoints/EndpointList.hs b/src/Pages/Endpoints/EndpointList.hs index 02ac486bc..178bc36d6 100644 --- a/src/Pages/Endpoints/EndpointList.hs +++ b/src/Pages/Endpoints/EndpointList.hs @@ -85,6 +85,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"} 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/Monitors/Testing.hs b/src/Pages/Monitors/Testing.hs index 525a7ad8f..18e5dd134 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/Pkg/Components/ItemsList.hs b/src/Pkg/Components/ItemsList.hs index d1eebf156..63d2110fb 100644 --- a/src/Pkg/Components/ItemsList.hs +++ b/src/Pkg/Components/ItemsList.hs @@ -1,3 +1,4 @@ +-- This module defines components for rendering and managing lists of items module Pkg.Components.ItemsList ( itemsList_, itemsPage_, @@ -12,6 +13,7 @@ module Pkg.Components.ItemsList ( ) where +-- Import necessary modules and libraries import Data.Time (UTCTime) import Data.Tuple.Extra (fst3) import Data.Vector qualified as V @@ -22,64 +24,66 @@ import Models.Projects.Projects qualified as Projects import Relude import Utils (deleteParam, faSprite_) - +-- Configuration for the items list data ItemsListCfg = ItemsListCfg - { currentURL :: Text - , sort :: Maybe SortCfg - , projectId :: Projects.ProjectId - , currTime :: UTCTime - , elemID :: Text - , nextFetchUrl :: Maybe Text - , zeroState :: Maybe ZeroState - , bulkActions :: [BulkAction] - , search :: Maybe SearchCfg - , heading :: Maybe (Html ()) + { currentURL :: Text -- Current URL of the page + , sort :: Maybe SortCfg -- Sorting configuration + , filter :: Maybe Text -- Filter Configuration (for now) + , projectId :: Projects.ProjectId -- ID of the current project + , currTime :: UTCTime -- Current time + , elemID :: Text -- ID of the main element + , nextFetchUrl :: Maybe Text -- URL for fetching next set of items + , zeroState :: Maybe ZeroState -- Configuration for empty state + , bulkActions :: [BulkAction] -- List of bulk actions + , search :: Maybe SearchCfg -- Search configuration + , heading :: Maybe (Html ()) -- Optional heading HTML } - +-- Configuration for search functionality data SearchCfg = SearchCfg - {viaQueryParam :: Maybe Text} - + {viaQueryParam :: Maybe Text} -- Query parameter for search +-- Representation of a bulk action data BulkAction = BulkAction - { icon :: Maybe Text - , title :: Text - , uri :: Text + { icon :: Maybe Text -- Icon for the action + , title :: Text -- Title of the action + , uri :: Text -- URI to trigger the action } - +-- Configuration for sorting data SortCfg = SortCfg - { current :: Text + { current :: Text -- Current sort option } +-- Configuration for filtering +-- data FilterCfg = FilterCfg{ +-- current:: Text +-- } +-- Configuration for zero state (empty list) data ZeroState = ZeroState { icon :: Text , title :: Text , description :: Text , actionText :: Text - , destination :: Either Text Text -- Either LabelID URL + , destination :: Either Text Text -- Either LabelID or URL } - +-- Represents a page of items type role ItemsPage representational - - data ItemsPage a = ItemsPage ItemsListCfg (V.Vector a) - +-- Implementation of ToHtml for ItemsPage 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 - +-- Function to render a page of items itemsPage_ :: ToHtml a => ItemsListCfg -> V.Vector a -> Html () itemsPage_ listCfg items = div_ [class_ "w-full mx-auto px-8 pt-10 pb-24 overflow-y-scroll h-full space-y-6", id_ "itemsListPage"] $ do itemsList_ listCfg items - +-- Main function to render the items list itemsList_ :: ToHtml a => ItemsListCfg -> V.Vector a -> Html () itemsList_ listCfg items = div_ [class_ "grid card-round overflow-hidden group/grid", id_ "anomalyListBelowTab", hxGet_ listCfg.currentURL, hxSwap_ "outerHTML", hxTrigger_ "refreshMain"] do @@ -91,75 +95,90 @@ 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" - ] - 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" + -- Render the header with bulk actions, search, and sort options + div_ [class_ "flex py-3 gap-8 items-center bg-gray-50"] do + -- Checkbox for selecting all items + 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 |] + ] - 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_ - [ class_ $ "block flex flex-row px-3 py-2 hover:bg-blue-50 rounded-md cursor-pointer " <> (if isActive then " text-blue-800 " else "") - , href_ $ currentURL' <> "&sort=" <> identifier - , hxIndicator_ "#sortLoader" - ] - do - div_ [class_ "flex flex-col items-center justify-center px-3"] - $ if isActive then faSprite_ "icon-checkmark4" "solid" "w-4 h-5" else div_ [class_ "w-4 h-5"] "" - div_ [class_ "grow space-y-1"] do - span_ [class_ "block text-lg"] $ toHtml title - span_ [class_ "block "] $ toHtml desc + -- Bulk actions + 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) - 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"] "" + -- Search input + 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" + -- Sort options + 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_ [ class_ $ "block flex flex-row px-3 py-2 hover:bg-blue-50 rounded-md cursor-pointer " <> (if isActive then " text-blue-800 " else "") + , href_ $ currentURL' <> "&sort=" <> identifier + , hxIndicator_ "#sortLoader" + ] do + div_ [class_ "flex flex-col items-center justify-center px-3"] + $ if isActive then faSprite_ "icon-checkmark4" "solid" "w-4 h-5" else div_ [class_ "w-4 h-5"] "" + div_ [class_ "grow space-y-1"] do + span_ [class_ "block text-lg"] $ toHtml title + span_ [class_ "block "] $ toHtml desc + + -- Graph and events display + 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 text-blue-800" else "") , href_ $ currentURL' <> "&since=24h"] "24h" + a_ [ class_ $ "cursor-pointer " <> (if selectedFilter == "14d" then "text-base font-bold text-blue-800" 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" + ] "" + + -- Render zero state if the list is empty 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" div_ [class_ "flex flex-col gap-2"] do @@ -168,36 +187,32 @@ 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 + + -- Render the list of items 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 - +-- Represents rows of items type role ItemsRows representational - - data ItemsRows a = ItemsRows (Maybe Text) (V.Vector a) -- Text represents nextFetchUrl - +-- Implementation of ToHtml for ItemsRows 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 - +-- Function to render rows of items itemRows_ :: (Monad m, ToHtml a) => Maybe Text -> V.Vector a -> HtmlT m () itemRows_ nextFetchUrl items = do mapM_ toHtml items whenJust nextFetchUrl \url -> when (length items > 9) - $ a_ - [ class_ "cursor-pointer flex justify-center items-center block p-1 blue-800 bg-blue-100 hover:bg-blue-200 text-center" - , hxTrigger_ "click, intersect once" - , hxSwap_ "outerHTML" - , hxGet_ url - , hxIndicator_ "#rowsIndicator" - ] - do - "Load more" - span_ [id_ "rowsIndicator", class_ "ml-2 htmx-indicator loading loading-dots loading-md"] "" + $ a_ [ class_ "cursor-pointer flex justify-center items-center block p-1 blue-800 bg-blue-100 hover:bg-blue-200 text-center" + , hxTrigger_ "click, intersect once" + , hxSwap_ "outerHTML" + , hxGet_ url + , hxIndicator_ "#rowsIndicator" + ] do + "Load more" + span_ [id_ "rowsIndicator", class_ "ml-2 htmx-indicator loading loading-dots loading-md"] "" \ No newline at end of file From 67216ea14632c97f67844cc43cc38738a27236fc Mon Sep 17 00:00:00 2001 From: Daniel Asaboro Date: Thu, 12 Sep 2024 13:22:26 +0100 Subject: [PATCH 04/15] fix: implemented the required fix to initial pr of color and default time range --- src/Opentelemetry/OtlpServer.hs | 46 ++--- src/Pages/Endpoints/ApiCatalog.hs | 66 +++---- src/Pages/Endpoints/EndpointDetailsSpec.hs | 4 +- src/Pages/Endpoints/EndpointListSpec.hs | 4 +- src/Pages/Fields/FieldDetailsSpec.hs | 4 +- src/Pages/Log.hs | 53 +++--- src/Pages/Reports.hs | 132 +++++++------- src/Pages/Traces/Trace.hs | 8 +- src/Pkg/Components/ItemsList.hs | 195 ++++++++++----------- src/RequestMessages.hs | 4 +- 10 files changed, 251 insertions(+), 265 deletions(-) diff --git a/src/Opentelemetry/OtlpServer.hs b/src/Opentelemetry/OtlpServer.hs index 5fd6fdc7d..f1d19bf40 100644 --- a/src/Opentelemetry/OtlpServer.hs +++ b/src/Opentelemetry/OtlpServer.hs @@ -126,8 +126,8 @@ byteStringToHexText bs = decodeUtf8 (B16.encode bs) -- Convert a list of KeyValue to a JSONB object keyValueToJSONB :: V.Vector KeyValue -> AE.Value keyValueToJSONB kvs = - AE.object $ - V.foldr (\kv acc -> (AEK.fromText $ LT.toStrict kv.keyValueKey, convertAnyValue kv.keyValueValue) : acc) [] kvs + AE.object + $ V.foldr (\kv acc -> (AEK.fromText $ LT.toStrict kv.keyValueKey, convertAnyValue kv.keyValueValue) : acc) [] kvs convertAnyValue :: Maybe AnyValue -> AE.Value @@ -304,31 +304,31 @@ parseSpanStatus st = case st of eventsToJSONB :: [Span_Event] -> AE.Value eventsToJSONB spans = - AE.toJSON $ - ( \sp -> - object - [ "event_name" .= toText sp.span_EventName - , "event_time" .= nanosecondsToUTC sp.span_EventTimeUnixNano - , "event_attributes" .= keyValueToJSONB sp.span_EventAttributes - , "event_dropped_attributes_count" .= fromIntegral sp.span_EventDroppedAttributesCount - ] - ) - <$> spans + AE.toJSON + $ ( \sp -> + object + [ "event_name" .= toText sp.span_EventName + , "event_time" .= nanosecondsToUTC sp.span_EventTimeUnixNano + , "event_attributes" .= keyValueToJSONB sp.span_EventAttributes + , "event_dropped_attributes_count" .= fromIntegral sp.span_EventDroppedAttributesCount + ] + ) + <$> spans linksToJSONB :: [Span_Link] -> AE.Value linksToJSONB lnks = - AE.toJSON $ - ( \lnk -> - object - [ "link_span_id" .= (decodeUtf8 lnk.span_LinkSpanId :: Text) - , "link_trace_id" .= (decodeUtf8 lnk.span_LinkTraceId :: Text) - , "link_attributes" .= keyValueToJSONB lnk.span_LinkAttributes - , "link_dropped_attributes_count" .= fromIntegral lnk.span_LinkDroppedAttributesCount - , "link_flags" .= fromIntegral lnk.span_LinkFlags - ] - ) - <$> lnks + AE.toJSON + $ ( \lnk -> + object + [ "link_span_id" .= (decodeUtf8 lnk.span_LinkSpanId :: Text) + , "link_trace_id" .= (decodeUtf8 lnk.span_LinkTraceId :: Text) + , "link_attributes" .= keyValueToJSONB lnk.span_LinkAttributes + , "link_dropped_attributes_count" .= fromIntegral lnk.span_LinkDroppedAttributesCount + , "link_flags" .= fromIntegral lnk.span_LinkFlags + ] + ) + <$> lnks --------------------------------------------------------------------------------------- diff --git a/src/Pages/Endpoints/ApiCatalog.hs b/src/Pages/Endpoints/ApiCatalog.hs index f860cb28f..5d97ebd74 100644 --- a/src/Pages/Endpoints/ApiCatalog.hs +++ b/src/Pages/Endpoints/ApiCatalog.hs @@ -6,39 +6,33 @@ import Data.Vector qualified as V import Effectful.PostgreSQL.Transact.Effect (dbtToEff) import Effectful.Time qualified as Time import Lucid -import Lucid.Htmx (hxGet_, hxSwap_, hxTrigger_) -- HTMX integration for frontend interactivity. +import Lucid.Htmx (hxGet_, hxSwap_, hxTrigger_) import Models.Apis.Endpoints qualified as Endpoints import Models.Projects.Projects qualified as Projects import Models.Users.Sessions qualified as Sessions import Pages.Anomalies.AnomalyList qualified as AnomalyList import Pages.BodyWrapper (BWConfig (currProject, pageTitle, sessM), PageCtx (..), navTabs) -import Pkg.Components.ItemsList qualified as ItemsList -- Package for the reusable list component. -import PyF qualified -- PyF for formatted strings. -import Relude hiding (ask, asks) -- Standard library extensions with certain functions hidden. -import System.Types (ATAuthCtx, RespHeaders, addRespHeaders) -- Importing custom types for handling responses. +import Pkg.Components.ItemsList qualified as ItemsList +import PyF qualified +import Relude hiding (ask, asks) +import System.Types (ATAuthCtx, RespHeaders, addRespHeaders) + --- Function to handle the API catalog page. apiCatalogH :: Projects.ProjectId -> Maybe Text -> Maybe Text -> Maybe Text -> ATAuthCtx (RespHeaders (PageCtx (ItemsList.ItemsPage HostEventsVM))) apiCatalogH pid sortM timeFilter requestTypeM = do - -- Fetch user session and project details based on the project ID. (sess, project) <- Sessions.sessionAndProject pid - -- Default the request type to "Incoming" if not provided. let requestType = fromMaybe "Incoming" requestTypeM - -- Fetch hosts and events from the database with sorting and request type filtering. hostsAndEvents <- dbtToEff $ Endpoints.dependenciesAndEventsCount pid requestType (fromMaybe "events" sortM) currTime <- Time.currentTime - -- Extract or default the sort and filter values. let sortV = fromMaybe "events" sortM - let filterV = fromMaybe "24h" timeFilter + let filterV = fromMaybe "14d" timeFilter - -- Build the current URL with appropriate query parameters. let currentURL = "/p/" <> pid.toText <> "/api_catalog?sort=" <> sortV <> "&request_type=" <> requestType - -- Configure the items list for rendering events related to hosts. let listCfg = ItemsList.ItemsListCfg { projectId = pid @@ -47,14 +41,15 @@ apiCatalogH pid sortM timeFilter requestTypeM = do , currentURL = currentURL , currTime , bulkActions = - [ -- Define bulk actions like "acknowledge" and "archive" for anomalies. + [ 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 = -- Define the empty state when no requests are being monitored. + , zeroState + = Just $ ItemsList.ZeroState { icon = "empty-set" @@ -66,60 +61,51 @@ apiCatalogH pid sortM timeFilter requestTypeM = do , elemID = "anomalyListForm" } - -- Define the page's body wrapper configuration (metadata for rendering). let bwconf = def - { sessM = Just sess.persistentSession -- User session management. - , currProject = Just project -- Current project information. - , pageTitle = "API Catalog" -- Page title for the API catalog. - , navTabs = Just $ div_ [class_ "tabs tabs-boxed border"] do -- Navigation tabs for "Incoming" and "Outgoing" requests. + { sessM = Just sess.persistentSession + , currProject = Just project + , pageTitle = "API Catalog" + , navTabs = Just $ div_ [class_ "tabs tabs-boxed border"] 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" } - - -- Add response headers and render the page context (items list). + addRespHeaders $ PageCtx bwconf (ItemsList.ItemsPage listCfg $ V.map (\host -> HostEventsVM pid host filterV requestType) hostsAndEvents) --- Data type for representing host events in the ViewModel. data HostEventsVM = HostEventsVM Projects.ProjectId Endpoints.HostEvents Text Text --- ToHtml instance to define how HostEventsVM should be converted to HTML. instance ToHtml HostEventsVM where toHtml :: Monad m => HostEventsVM -> HtmlT m () - toHtml (HostEventsVM pid he timeFilter requestType) = toHtmlRaw $ renderapiCatalog pid he timeFilter requestType -- Convert HostEventsVM to HTML using renderapiCatalog function. + toHtml (HostEventsVM pid he timeFilter requestType) = toHtmlRaw $ renderapiCatalog pid he timeFilter requestType toHtmlRaw :: Monad m => HostEventsVM -> HtmlT m () - toHtmlRaw = toHtml -- Raw HTML rendering. + toHtmlRaw = toHtml + --- Function to render the API catalog for a specific project, host, and request type. renderapiCatalog :: Projects.ProjectId -> Endpoints.HostEvents -> Text -> Text -> Html () renderapiCatalog pid host timeFilter requestType = div_ [class_ "flex py-4 gap-8 items-center itemsListItem"] do - -- Checkbox for selecting an issue in the list. 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] - -- Main content section displaying the host and actions (view logs, etc.). div_ [class_ "space-y-3 grow"] do div_ [class_ "space-x-3"] do a_ [class_ "inline-block font-bold space-x-2"] $ do - -- Display host and link to endpoint details. 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) - -- Link to view logs for this 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" - -- Section for fetching and displaying a time chart via HTMX. div_ [class_ "flex items-center justify-center "] $ do - -- Conditionally use the filter for the chart. - div_ + div_ [ class_ "w-56 h-12 px-3" - , hxGet_ $ "/charts_html?pid=" <> pid.toText <> "&since=" <> (if timeFilter == "14d" then "14D" else "24h") <> "&query_raw=" <> AnomalyList.escapedQueryPartial [PyF.fmt|host=="{host.host}" | timechart [1d]|] -- Fetch the chart for this host. - , hxTrigger_ "intersect once" -- Load the chart when the element is in view. - , hxSwap_ "innerHTML" -- Replace the content with the fetched chart. + , hxGet_ $ "/charts_html?pid=" <> pid.toText <> "&since=" <> (if timeFilter == "14d" then "14D" else "24h") <> "&query_raw=" <> AnomalyList.escapedQueryPartial [PyF.fmt|host=="{host.host}" | timechart [1d]|] + , + hxTrigger_ "intersect once" + , hxSwap_ "innerHTML" ] "" - -- Display the number of events for this anomaly in the last 14 days. - 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 (show 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 (show host.eventCount) diff --git a/src/Pages/Endpoints/EndpointDetailsSpec.hs b/src/Pages/Endpoints/EndpointDetailsSpec.hs index 4a5c5a316..facdc005c 100644 --- a/src/Pages/Endpoints/EndpointDetailsSpec.hs +++ b/src/Pages/Endpoints/EndpointDetailsSpec.hs @@ -38,8 +38,8 @@ spec = aroundAll withTestResources do let reqMsg1 = Unsafe.fromJust $ convert $ testRequestMsgs.reqMsg1 nowTxt let reqMsg2 = Unsafe.fromJust $ convert $ testRequestMsgs.reqMsg2 nowTxt let msgs = - concat $ - replicate + concat + $ replicate 100 [ ("m1", reqMsg1) , ("m2", reqMsg2) diff --git a/src/Pages/Endpoints/EndpointListSpec.hs b/src/Pages/Endpoints/EndpointListSpec.hs index 74d6f9b65..00bf94973 100644 --- a/src/Pages/Endpoints/EndpointListSpec.hs +++ b/src/Pages/Endpoints/EndpointListSpec.hs @@ -43,8 +43,8 @@ spec = aroundAll withTestResources do let reqMsg1 = Unsafe.fromJust $ convert $ testRequestMsgs.reqMsg1 nowTxt let reqMsg2 = Unsafe.fromJust $ convert $ testRequestMsgs.reqMsg2 nowTxt let msgs = - concat $ - replicate + concat + $ replicate 100 [ ("m1", reqMsg1) , ("m2", reqMsg2) diff --git a/src/Pages/Fields/FieldDetailsSpec.hs b/src/Pages/Fields/FieldDetailsSpec.hs index 20e8b4566..ca326da60 100644 --- a/src/Pages/Fields/FieldDetailsSpec.hs +++ b/src/Pages/Fields/FieldDetailsSpec.hs @@ -31,8 +31,8 @@ spec = aroundAll withTestResources do let reqMsg1 = Unsafe.fromJust $ convert $ testRequestMsgs.reqMsg1 nowTxt let reqMsg2 = Unsafe.fromJust $ convert $ testRequestMsgs.reqMsg2 nowTxt let msgs = - concat $ - replicate + concat + $ replicate 2 [ ("m1", reqMsg1) , ("m2", reqMsg2) diff --git a/src/Pages/Log.hs b/src/Pages/Log.hs index 21d83f65a..e766d037b 100644 --- a/src/Pages/Log.hs +++ b/src/Pages/Log.hs @@ -89,8 +89,8 @@ apiLogH pid queryM cols' cursorM' sinceM fromM toM layoutM sourceM hxRequestM hx let tableAsVecM = hush tableAsVecE freeTierExceeded <- - dbtToEff $ - if project.paymentPlan == "Free" + dbtToEff + $ if project.paymentPlan == "Free" then do totalRequest <- RequestDumps.getLastSevenDaysTotalRequest pid return $ totalRequest > 5000 @@ -190,9 +190,9 @@ logQueryBox_ pid currentRange = div_ [class_ "flex-1"] do div_ [id_ "queryEditor", class_ "h-14 hidden overflow-hidden bg-gray-200"] pass div_ [id_ "queryBuilder"] $ termRaw "filter-element" [id_ "filterElement"] ("" :: Text) - div_ [class_ "form-control"] $ - label_ [class_ "label cursor-pointer space-x-2"] $ - input_ [type_ "checkbox", class_ "toggle tooltip tooltip-left", id_ "toggleQueryEditor", onclick_ "toggleQueryBuilder()", term "data-tip" "toggle query editor"] + div_ [class_ "form-control"] + $ label_ [class_ "label cursor-pointer space-x-2"] + $ input_ [type_ "checkbox", class_ "toggle tooltip tooltip-left", id_ "toggleQueryEditor", onclick_ "toggleQueryBuilder()", term "data-tip" "toggle query editor"] button_ [type_ "submit", class_ "btn btn-sm btn-success"] do @@ -231,9 +231,9 @@ apiLogsPage page = do ] do div_ [class_ "relative ml-auto w-full", style_ ""] do - div_ [class_ "flex justify-end w-full p-4 "] $ - button_ [[__|on click add .hidden to #expand-log-modal|]] $ - faSprite_ "xmark" "regular" "h-8" + div_ [class_ "flex justify-end w-full p-4 "] + $ button_ [[__|on click add .hidden to #expand-log-modal|]] + $ faSprite_ "xmark" "regular" "h-8" form_ [ hxPost_ $ "/p/" <> page.pid.toText <> "/share/" , hxSwap_ "innerHTML" @@ -381,23 +381,23 @@ logItemRows_ pid requests curatedCols colIdxMap nextLogsURL source = do forM_ requests \reqVec -> do let (logItemPath, _reqId) = fromMaybe ("", "") $ requestDumpLogItemUrlPath pid reqVec colIdxMap let (_, errCount, errClass) = errorClass True reqVec colIdxMap - tr_ [class_ "cursor-pointer divide-x b--b2", [__|on click toggle .hidden on next then toggle .expanded-log on me|]] $ - forM_ curatedCols (td_ . logItemCol_ source pid reqVec colIdxMap) + tr_ [class_ "cursor-pointer divide-x b--b2", [__|on click toggle .hidden on next then toggle .expanded-log on me|]] + $ forM_ curatedCols (td_ . logItemCol_ source pid reqVec colIdxMap) tr_ [class_ "hidden"] $ do -- used for when a row is expanded. td_ $ a_ [class_ $ "inline-block h-full " <> errClass, term "data-tippy-content" $ show errCount <> " errors attached to this request"] "" td_ [colspan_ $ show $ length curatedCols - 1] $ div_ [hxGet_ $ logItemPath <> "?source=" <> source, hxTrigger_ "intersect once", hxSwap_ "outerHTML"] $ span_ [class_ "loading loading-dots loading-md"] "" - when (Vector.length requests > 199) $ - tr_ $ - td_ [colspan_ $ show $ length curatedCols] $ - a_ - [ class_ "cursor-pointer inline-flex justify-center py-1 px-56 ml-36 blue-800 bg-blue-100 hover:bg-blue-200 gap-3 items-center" - , hxTrigger_ "click, intersect once" - , hxSwap_ "outerHTML" - , hxGet_ nextLogsURL - , hxTarget_ "closest tr" - ] - (span_ [class_ "inline-block"] "LOAD MORE " >> span_ [class_ "loading loading-dots loading-sm inline-block pl-3"] "") + when (Vector.length requests > 199) + $ tr_ + $ td_ [colspan_ $ show $ length curatedCols] + $ a_ + [ class_ "cursor-pointer inline-flex justify-center py-1 px-56 ml-36 blue-800 bg-blue-100 hover:bg-blue-200 gap-3 items-center" + , hxTrigger_ "click, intersect once" + , hxSwap_ "outerHTML" + , hxGet_ nextLogsURL + , hxTarget_ "closest tr" + ] + (span_ [class_ "inline-block"] "LOAD MORE " >> span_ [class_ "loading loading-dots loading-sm inline-block pl-3"] "") errorClass :: Bool -> V.Vector Value -> HM.HashMap Text Int -> (Int, Int, Text) @@ -447,8 +447,8 @@ logTableHeadingWrapper_ pid title child = td_ div_ [tabindex_ "0", role_ "button", class_ "py-1 px-3 block"] child ul_ [tabindex_ "0", class_ "dropdown-content z-[1] menu p-2 shadow bg-base-100 rounded-box min-w-[15rem]"] do li_ [class_ "underline underline-offset-2"] $ toHtml title - li_ $ - a_ + li_ + $ a_ [ hxGet_ $ "/p/" <> pid.toText <> "/log_explorer" , hxPushUrl_ "true" , hxVals_ $ "js:{query:params().query,cols:removeNamedColumnToSummary('" <> title <> "'),layout:'resultTable'}" @@ -483,7 +483,6 @@ logItemCol_ _ _ reqVec colIdxMap "severity_text" = span_ [class_ $ "badge badge- logItemCol_ _ _ reqVec colIdxMap "duration" = span_ [class_ "badge badge-sm badge-ghost whitespace-nowrap", term "data-tippy-content" "duration"] $ toHtml $ show (lookupVecIntByKey reqVec colIdxMap "duration") <> " ms" logItemCol_ _ _ reqVec colIdxMap "span_name" = span_ [class_ "badge badge-sm badge-ghost whitespace-nowrap", term "data-tippy-content" "span name"] $ toHtml $ fromMaybe "" $ lookupVecTextByKey reqVec colIdxMap "span_name" logItemCol_ _ _ reqVec colIdxMap "body" = span_ [class_ "space-x-2 whitespace-nowrap"] $ toHtml $ fromMaybe "" $ lookupVecTextByKey reqVec colIdxMap "body" - logItemCol_ _ _ reqVec colIdxMap "kind" = do let kind = fromMaybe "" $ lookupVecTextByKey reqVec colIdxMap "kind" span_ [class_ $ "badge badge-sm min-w-[4.5rem] " <> getKindColor kind, term "data-tippy-content" "span kind"] $ toHtml kind @@ -515,9 +514,9 @@ logItemCol_ source pid reqVec colIdxMap key@"rest" = div_ [class_ "space-x-2 whi span_ [class_ "badge badge-sm badge-ghost ", term "data-tippy-content" "Host"] $ toHtml $ fromMaybe "" $ lookupVecTextByKey reqVec colIdxMap "host" span_ [] $ toHtml $ maybe "" unwrapJsonPrimValue (lookupVecByKey reqVec colIdxMap key) logItemCol_ _ _ reqVec colIdxMap key = - div_ [class_ "xwhitespace-nowrap overflow-x-hidden max-w-lg ", term "data-tippy-content" key] $ - toHtml $ - maybe "" unwrapJsonPrimValue (lookupVecByKey reqVec colIdxMap key) + div_ [class_ "xwhitespace-nowrap overflow-x-hidden max-w-lg ", term "data-tippy-content" key] + $ toHtml + $ maybe "" unwrapJsonPrimValue (lookupVecByKey reqVec colIdxMap key) requestDumpLogItemUrlPath :: Projects.ProjectId -> V.Vector Value -> HM.HashMap Text Int -> Maybe (Text, Text) diff --git a/src/Pages/Reports.hs b/src/Pages/Reports.hs index 2117da4f5..5426599e4 100644 --- a/src/Pages/Reports.hs +++ b/src/Pages/Reports.hs @@ -36,36 +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 - ( 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 ( + 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) @@ -78,10 +79,10 @@ import Pages.BodyWrapper (BWConfig, PageCtx (..), currProject, pageTitle, sessM) import Relude import System.Types (ATAuthCtx, RespHeaders, addRespHeaders, addSuccessToast) import Text.Printf (printf) + + -- import Debug.Trace (traceShow) - - data PerformanceReport = PerformanceReport { urlPath :: Text , method :: Text @@ -290,30 +291,30 @@ 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_ "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 @@ -322,20 +323,21 @@ reportListItems :: Projects.ProjectId -> Vector Reports.ReportListItem -> Text - reportListItems pid reports nextUrl = div_ [class_ "space-y-4"] do forM_ reports $ \report -> do - -- Renders Conditionally... - -- Only if reportType matches a condition - -- putStrLn report.reportType + -- Renders Conditionally... + -- Only if reportType matches a condition + -- putStrLn report.reportType - 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 + 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" + renderEndpointRow :: PerformanceReport -> Html () renderEndpointRow endpoint = tr_ do let (pcls, prc) = diff --git a/src/Pages/Traces/Trace.hs b/src/Pages/Traces/Trace.hs index ac3be5738..dfbd1b035 100644 --- a/src/Pages/Traces/Trace.hs +++ b/src/Pages/Traces/Trace.hs @@ -143,8 +143,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", style_ $ "width:" <> percent <> "%; background-color:" <> color] pass + div_ [class_ "w-[100px] h-3 bg-gray-200 rounded overflow-hidden"] + $ div_ [class_ "h-full pl-2 text-xs font-medium", style_ $ "width:" <> percent <> "%; background-color:" <> color] 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 @@ -255,8 +255,8 @@ renderSpanTable 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 getRequestDetails :: Telemetry.SpanRecord -> Maybe (Text, Text, Text, Int) diff --git a/src/Pkg/Components/ItemsList.hs b/src/Pkg/Components/ItemsList.hs index 63d2110fb..3cae85832 100644 --- a/src/Pkg/Components/ItemsList.hs +++ b/src/Pkg/Components/ItemsList.hs @@ -1,4 +1,3 @@ --- This module defines components for rendering and managing lists of items module Pkg.Components.ItemsList ( itemsList_, itemsPage_, @@ -13,7 +12,6 @@ module Pkg.Components.ItemsList ( ) where --- Import necessary modules and libraries import Data.Time (UTCTime) import Data.Tuple.Extra (fst3) import Data.Vector qualified as V @@ -24,66 +22,63 @@ import Models.Projects.Projects qualified as Projects import Relude import Utils (deleteParam, faSprite_) --- Configuration for the items list + data ItemsListCfg = ItemsListCfg - { currentURL :: Text -- Current URL of the page - , sort :: Maybe SortCfg -- Sorting configuration - , filter :: Maybe Text -- Filter Configuration (for now) - , projectId :: Projects.ProjectId -- ID of the current project - , currTime :: UTCTime -- Current time - , elemID :: Text -- ID of the main element - , nextFetchUrl :: Maybe Text -- URL for fetching next set of items - , zeroState :: Maybe ZeroState -- Configuration for empty state - , bulkActions :: [BulkAction] -- List of bulk actions - , search :: Maybe SearchCfg -- Search configuration - , heading :: Maybe (Html ()) -- Optional heading HTML + { currentURL :: Text + , sort :: Maybe SortCfg + , filter :: Maybe Text + , projectId :: Projects.ProjectId + , currTime :: UTCTime + , elemID :: Text + , nextFetchUrl :: Maybe Text + , zeroState :: Maybe ZeroState + , bulkActions :: [BulkAction] + , search :: Maybe SearchCfg + , heading :: Maybe (Html ()) } --- Configuration for search functionality + + data SearchCfg = SearchCfg - {viaQueryParam :: Maybe Text} -- Query parameter for search + {viaQueryParam :: Maybe Text} + --- Representation of a bulk action data BulkAction = BulkAction - { icon :: Maybe Text -- Icon for the action - , title :: Text -- Title of the action - , uri :: Text -- URI to trigger the action + { icon :: Maybe Text + , title :: Text + , uri :: Text } --- Configuration for sorting + data SortCfg = SortCfg - { current :: Text -- Current sort option + { current :: Text } --- Configuration for filtering --- data FilterCfg = FilterCfg{ --- current:: Text --- } --- Configuration for zero state (empty list) + data ZeroState = ZeroState { icon :: Text , title :: Text , description :: Text , actionText :: Text - , destination :: Either Text Text -- Either LabelID or URL + , destination :: Either Text Text } --- Represents a page of items + type role ItemsPage representational data ItemsPage a = ItemsPage ItemsListCfg (V.Vector a) --- Implementation of ToHtml for ItemsPage + instance ToHtml a => ToHtml (ItemsPage a) where toHtml (ItemsPage cfg items) = toHtmlRaw $ itemsPage_ cfg items toHtmlRaw (ItemsPage cfg items) = toHtmlRaw $ itemsPage_ cfg items --- Function to render a page of items + itemsPage_ :: ToHtml a => ItemsListCfg -> V.Vector a -> Html () itemsPage_ listCfg items = div_ [class_ "w-full mx-auto px-8 pt-10 pb-24 overflow-y-scroll h-full space-y-6", id_ "itemsListPage"] $ do itemsList_ listCfg items --- Main function to render the items list + itemsList_ :: ToHtml a => ItemsListCfg -> V.Vector a -> Html () itemsList_ listCfg items = div_ [class_ "grid card-round overflow-hidden group/grid", id_ "anomalyListBelowTab", hxGet_ listCfg.currentURL, hxSwap_ "outerHTML", hxTrigger_ "refreshMain"] do @@ -96,89 +91,92 @@ itemsList_ listCfg items = ] :: [(Text, Text, Text)] - -- Render the header with bulk actions, search, and sort options div_ [class_ "flex py-3 gap-8 items-center bg-gray-50"] do - -- Checkbox for selecting all items 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 |] - ] + input_ + [ term "aria-label" "Select Issue" + , type_ "checkbox" + , class_ "checkbox checkbox-md checked:checkbox-primary" + , [__| on click set .bulkactionItemCheckbox.checked to my.checked |] + ] - -- Bulk actions 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 + ] + do whenJust blkA.icon \icon -> faSprite_ icon "solid" "h-4 w-4 inline-block" span_ (toHtml blkA.title) - -- Search input 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" - ] + 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() |] - ] + 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" - -- Sort options 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_ [ class_ $ "block flex flex-row px-3 py-2 hover:bg-blue-50 rounded-md cursor-pointer " <> (if isActive then " text-blue-800 " else "") - , href_ $ currentURL' <> "&sort=" <> identifier - , hxIndicator_ "#sortLoader" - ] do - div_ [class_ "flex flex-col items-center justify-center px-3"] - $ if isActive then faSprite_ "icon-checkmark4" "solid" "w-4 h-5" else div_ [class_ "w-4 h-5"] "" - div_ [class_ "grow space-y-1"] do - span_ [class_ "block text-lg"] $ toHtml title - span_ [class_ "block "] $ toHtml desc + 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_ + [ class_ $ "block flex flex-row px-3 py-2 hover:bg-blue-50 rounded-md cursor-pointer " <> (if isActive then " text-blue-800 " else "") + , href_ $ currentURL' <> "&sort=" <> identifier + , hxIndicator_ "#sortLoader" + ] + do + div_ [class_ "flex flex-col items-center justify-center px-3"] + $ if isActive then faSprite_ "icon-checkmark4" "solid" "w-4 h-5" else div_ [class_ "w-4 h-5"] "" + div_ [class_ "grow space-y-1"] do + span_ [class_ "block text-lg"] $ toHtml title + span_ [class_ "block "] $ toHtml desc - -- Graph and events display 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 text-blue-800" else "") , href_ $ currentURL' <> "&since=24h"] "24h" - a_ [ class_ $ "cursor-pointer " <> (if selectedFilter == "14d" then "text-base font-bold text-blue-800" else ""), href_ $ currentURL' <> "&since=14d"] "14d" + 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" - ] "" + 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" + ] + "" - -- Render zero state if the list is empty 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" div_ [class_ "flex flex-col gap-2"] do @@ -188,31 +186,32 @@ itemsList_ listCfg items = 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 - -- Render the list of items 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 --- Represents rows of items -type role ItemsRows representational -data ItemsRows a = ItemsRows (Maybe Text) (V.Vector a) -- Text represents nextFetchUrl --- Implementation of ToHtml for ItemsRows +type role ItemsRows representational +data ItemsRows a = ItemsRows (Maybe Text) (V.Vector a) + + instance ToHtml a => ToHtml (ItemsRows a) where toHtml (ItemsRows nextFetchUrl items) = toHtmlRaw $ itemRows_ nextFetchUrl items toHtmlRaw (ItemsRows nextFetchUrl items) = toHtmlRaw $ itemRows_ nextFetchUrl items --- Function to render rows of items + itemRows_ :: (Monad m, ToHtml a) => Maybe Text -> V.Vector a -> HtmlT m () itemRows_ nextFetchUrl items = do mapM_ toHtml items whenJust nextFetchUrl \url -> when (length items > 9) - $ a_ [ class_ "cursor-pointer flex justify-center items-center block p-1 blue-800 bg-blue-100 hover:bg-blue-200 text-center" - , hxTrigger_ "click, intersect once" - , hxSwap_ "outerHTML" - , hxGet_ url - , hxIndicator_ "#rowsIndicator" - ] do - "Load more" - span_ [id_ "rowsIndicator", class_ "ml-2 htmx-indicator loading loading-dots loading-md"] "" \ No newline at end of file + $ a_ + [ class_ "cursor-pointer flex justify-center items-center block p-1 blue-800 bg-blue-100 hover:bg-blue-200 text-center" + , hxTrigger_ "click, intersect once" + , hxSwap_ "outerHTML" + , hxGet_ url + , hxIndicator_ "#rowsIndicator" + ] + do + "Load more" + span_ [id_ "rowsIndicator", class_ "ml-2 htmx-indicator loading loading-dots loading-md"] "" diff --git a/src/RequestMessages.hs b/src/RequestMessages.hs index ba8924493..1d3b2bdd3 100644 --- a/src/RequestMessages.hs +++ b/src/RequestMessages.hs @@ -237,8 +237,8 @@ requestMsgToDumpAndEndpoint pjc rM now dumpIDOriginal = do -- A shape is a deterministic representation of a request-response combination for a given endpoint. -- We usually expect multiple shapes per endpoint. Eg a shape for a success request-response and another for an error response. -- Shapes are dependent on the endpoint, statusCode and the unique fields in that shape. - Just $ - Shapes.Shape + Just + $ Shapes.Shape { id = Shapes.ShapeId dumpID , createdAt = timestampUTC , updatedAt = now From 99563616e9ee20fb59adc5ec38e8afc84bc8c4d0 Mon Sep 17 00:00:00 2001 From: Daniel Asaboro Date: Thu, 12 Sep 2024 13:30:51 +0100 Subject: [PATCH 05/15] fix: resolve overloading the local stack.yaml file and removed unnecessary comments and uncommented code without reason --- src/Pages/Endpoints/ApiCatalog.hs | 25 +++++++++++-------------- src/Pages/Reports.hs | 30 ------------------------------ src/Pkg/Components/ItemsList.hs | 14 ++++++-------- stack.yaml | 5 ----- 4 files changed, 17 insertions(+), 57 deletions(-) diff --git a/src/Pages/Endpoints/ApiCatalog.hs b/src/Pages/Endpoints/ApiCatalog.hs index 5d97ebd74..31d9d3cfe 100644 --- a/src/Pages/Endpoints/ApiCatalog.hs +++ b/src/Pages/Endpoints/ApiCatalog.hs @@ -6,16 +6,16 @@ import Data.Vector qualified as V import Effectful.PostgreSQL.Transact.Effect (dbtToEff) import Effectful.Time qualified as Time import Lucid -import Lucid.Htmx (hxGet_, hxSwap_, hxTrigger_) +import Lucid.Htmx (hxGet_, hxSwap_, hxTrigger_) import Models.Apis.Endpoints qualified as Endpoints import Models.Projects.Projects qualified as Projects import Models.Users.Sessions qualified as Sessions import Pages.Anomalies.AnomalyList qualified as AnomalyList import Pages.BodyWrapper (BWConfig (currProject, pageTitle, sessM), PageCtx (..), navTabs) -import Pkg.Components.ItemsList qualified as ItemsList -import PyF qualified -import Relude hiding (ask, asks) -import System.Types (ATAuthCtx, RespHeaders, addRespHeaders) +import Pkg.Components.ItemsList qualified as ItemsList +import PyF qualified +import Relude hiding (ask, asks) +import System.Types (ATAuthCtx, RespHeaders, addRespHeaders) apiCatalogH :: Projects.ProjectId -> Maybe Text -> Maybe Text -> Maybe Text -> ATAuthCtx (RespHeaders (PageCtx (ItemsList.ItemsPage HostEventsVM))) @@ -41,15 +41,13 @@ apiCatalogH pid sortM timeFilter requestTypeM = do , currentURL = currentURL , currTime , bulkActions = - [ - ItemsList.BulkAction{icon = Just "check", title = "acknowledge", uri = "/p/" <> pid.toText <> "/anomalies/bulk_actions/acknowledge"} + [ 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 - = + , zeroState = Just $ ItemsList.ZeroState { icon = "empty-set" @@ -63,7 +61,7 @@ apiCatalogH pid sortM timeFilter requestTypeM = do let bwconf = def - { sessM = Just sess.persistentSession + { sessM = Just sess.persistentSession , currProject = Just project , pageTitle = "API Catalog" , navTabs = Just $ div_ [class_ "tabs tabs-boxed border"] do @@ -79,9 +77,9 @@ data HostEventsVM = HostEventsVM Projects.ProjectId Endpoints.HostEvents Text Te instance ToHtml HostEventsVM where toHtml :: Monad m => HostEventsVM -> HtmlT m () - toHtml (HostEventsVM pid he timeFilter requestType) = toHtmlRaw $ renderapiCatalog pid he timeFilter requestType + toHtml (HostEventsVM pid he timeFilter requestType) = toHtmlRaw $ renderapiCatalog pid he timeFilter requestType toHtmlRaw :: Monad m => HostEventsVM -> HtmlT m () - toHtmlRaw = toHtml + toHtmlRaw = toHtml renderapiCatalog :: Projects.ProjectId -> Endpoints.HostEvents -> Text -> Text -> Html () @@ -100,8 +98,7 @@ renderapiCatalog pid host timeFilter requestType = div_ [class_ "flex py-4 gap-8 div_ [ class_ "w-56 h-12 px-3" , hxGet_ $ "/charts_html?pid=" <> pid.toText <> "&since=" <> (if timeFilter == "14d" then "14D" else "24h") <> "&query_raw=" <> AnomalyList.escapedQueryPartial [PyF.fmt|host=="{host.host}" | timechart [1d]|] - , - hxTrigger_ "intersect once" + , hxTrigger_ "intersect once" , hxSwap_ "innerHTML" ] "" diff --git a/src/Pages/Reports.hs b/src/Pages/Reports.hs index 5426599e4..17811e129 100644 --- a/src/Pages/Reports.hs +++ b/src/Pages/Reports.hs @@ -81,8 +81,6 @@ import System.Types (ATAuthCtx, RespHeaders, addRespHeaders, addSuccessToast) import Text.Printf (printf) --- import Debug.Trace (traceShow) - data PerformanceReport = PerformanceReport { urlPath :: Text , method :: Text @@ -291,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 @@ -323,10 +297,6 @@ reportListItems :: Projects.ProjectId -> Vector Reports.ReportListItem -> Text - reportListItems pid reports nextUrl = div_ [class_ "space-y-4"] do forM_ reports $ \report -> do - -- Renders Conditionally... - -- Only if reportType matches a condition - -- putStrLn report.reportType - 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 diff --git a/src/Pkg/Components/ItemsList.hs b/src/Pkg/Components/ItemsList.hs index 3cae85832..e6080f9e8 100644 --- a/src/Pkg/Components/ItemsList.hs +++ b/src/Pkg/Components/ItemsList.hs @@ -38,30 +38,28 @@ data ItemsListCfg = ItemsListCfg } - data SearchCfg = SearchCfg - {viaQueryParam :: Maybe Text} + {viaQueryParam :: Maybe Text} data BulkAction = BulkAction - { icon :: Maybe Text - , title :: Text - , uri :: Text + { icon :: Maybe Text + , title :: Text + , uri :: Text } data SortCfg = SortCfg - { current :: Text + { current :: Text } - data ZeroState = ZeroState { icon :: Text , title :: Text , description :: Text , actionText :: Text - , destination :: Either Text Text + , destination :: Either Text Text } diff --git a/stack.yaml b/stack.yaml index 77dd24c10..18f3830b7 100644 --- a/stack.yaml +++ b/stack.yaml @@ -5,11 +5,6 @@ packages: ghc-options: "grpc-haskell-core": -Wno-x-partial -extra-include-dirs: - - /opt/homebrew/Cellar/grpc/1.62.2_4/include -extra-lib-dirs: - - /opt/homebrew/Cellar/grpc/1.62.2_4/lib - extra-deps: - ./rust-interop - ./otlp From ef75905e33f9cfa9feafe3e77851278ba6f04be7 Mon Sep 17 00:00:00 2001 From: Daniel Asaboro Date: Thu, 12 Sep 2024 15:58:46 +0100 Subject: [PATCH 06/15] fix: removed all comments --- src/Pages/Reports.hs | 31 ----------------- src/Pkg/Components/ItemsList.hs | 60 ++++++++++----------------------- 2 files changed, 17 insertions(+), 74 deletions(-) diff --git a/src/Pages/Reports.hs b/src/Pages/Reports.hs index 85df67746..3a9077db5 100644 --- a/src/Pages/Reports.hs +++ b/src/Pages/Reports.hs @@ -78,9 +78,6 @@ import Pages.BodyWrapper (BWConfig, PageCtx (..), currProject, pageTitle, sessM) import Relude import System.Types (ATAuthCtx, RespHeaders, addRespHeaders, addSuccessToast) import Text.Printf (printf) --- import Debug.Trace (traceShow) - - data PerformanceReport = PerformanceReport { urlPath :: Text @@ -290,30 +287,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 @@ -322,10 +295,6 @@ reportListItems :: Projects.ProjectId -> Vector Reports.ReportListItem -> Text - reportListItems pid reports nextUrl = div_ [class_ "space-y-4"] do forM_ reports $ \report -> do - -- Renders Conditionally... - -- Only if reportType matches a condition - -- putStrLn report.reportType - 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 diff --git a/src/Pkg/Components/ItemsList.hs b/src/Pkg/Components/ItemsList.hs index b8f2aab88..c6ade91fb 100644 --- a/src/Pkg/Components/ItemsList.hs +++ b/src/Pkg/Components/ItemsList.hs @@ -1,4 +1,3 @@ --- This module defines components for rendering and managing lists of items module Pkg.Components.ItemsList ( itemsList_, itemsPage_, @@ -13,7 +12,6 @@ module Pkg.Components.ItemsList ( ) where --- Import necessary modules and libraries import Data.Time (UTCTime) import Data.Tuple.Extra (fst3) import Data.Vector qualified as V @@ -24,66 +22,53 @@ import Models.Projects.Projects qualified as Projects import Relude import Utils (deleteParam, faSprite_) --- Configuration for the items list data ItemsListCfg = ItemsListCfg - { currentURL :: Text -- Current URL of the page - , sort :: Maybe SortCfg -- Sorting configuration - , filter :: Maybe Text -- Filter Configuration (for now) - , projectId :: Projects.ProjectId -- ID of the current project - , currTime :: UTCTime -- Current time - , elemID :: Text -- ID of the main element - , nextFetchUrl :: Maybe Text -- URL for fetching next set of items - , zeroState :: Maybe ZeroState -- Configuration for empty state - , bulkActions :: [BulkAction] -- List of bulk actions - , search :: Maybe SearchCfg -- Search configuration - , heading :: Maybe (Html ()) -- Optional heading HTML + { currentURL :: Text + , sort :: Maybe SortCfg + , filter :: Maybe Text + , projectId :: Projects.ProjectId + , currTime :: UTCTime + , elemID :: Text + , nextFetchUrl :: Maybe Text + , zeroState :: Maybe ZeroState + , bulkActions :: [BulkAction] + , search :: Maybe SearchCfg + , heading :: Maybe (Html ()) } --- Configuration for search functionality data SearchCfg = SearchCfg - {viaQueryParam :: Maybe Text} -- Query parameter for search + {viaQueryParam :: Maybe Text} --- Representation of a bulk action data BulkAction = BulkAction - { icon :: Maybe Text -- Icon for the action - , title :: Text -- Title of the action - , uri :: Text -- URI to trigger the action + { icon :: Maybe Text + , title :: Text + , uri :: Text } --- Configuration for sorting data SortCfg = SortCfg - { current :: Text -- Current sort option + { current :: Text } --- Configuration for filtering --- data FilterCfg = FilterCfg{ --- current:: Text --- } --- Configuration for zero state (empty list) data ZeroState = ZeroState { icon :: Text , title :: Text , description :: Text , actionText :: Text - , destination :: Either Text Text -- Either LabelID or URL + , destination :: Either Text Text } --- Represents a page of items type role ItemsPage representational data ItemsPage a = ItemsPage ItemsListCfg (V.Vector a) --- Implementation of ToHtml for ItemsPage instance ToHtml a => ToHtml (ItemsPage a) where toHtml (ItemsPage cfg items) = toHtmlRaw $ itemsPage_ cfg items toHtmlRaw (ItemsPage cfg items) = toHtmlRaw $ itemsPage_ cfg items --- Function to render a page of items itemsPage_ :: ToHtml a => ItemsListCfg -> V.Vector a -> Html () itemsPage_ listCfg items = div_ [class_ "w-full mx-auto px-6 pt-2 pb-16 overflow-y-scroll h-full space-y-6", id_ "itemsListPage"] $ do itemsList_ listCfg items --- Main function to render the items list itemsList_ :: ToHtml a => ItemsListCfg -> V.Vector a -> Html () itemsList_ listCfg items = div_ [class_ "grid card-round overflow-hidden group/grid", id_ "anomalyListBelowTab", hxGet_ listCfg.currentURL, hxSwap_ "outerHTML", hxTrigger_ "refreshMain"] do @@ -96,9 +81,7 @@ itemsList_ listCfg items = ] :: [(Text, Text, Text)] - -- Render the header with bulk actions, search, and sort options div_ [class_ "flex py-3 gap-8 items-center bg-gray-50"] do - -- Checkbox for selecting all items 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" @@ -107,7 +90,6 @@ itemsList_ listCfg items = , [__| on click set .bulkactionItemCheckbox.checked to my.checked |] ] - -- Bulk actions 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 " @@ -117,7 +99,6 @@ itemsList_ listCfg items = whenJust blkA.icon \icon -> faSprite_ icon "solid" "h-4 w-4 inline-block" span_ (toHtml blkA.title) - -- Search input whenJust listCfg.search \search -> do label_ [class_ "input input-sm input-bordered flex overflow-hidden items-center gap-2"] do case search.viaQueryParam of @@ -142,7 +123,6 @@ itemsList_ listCfg items = ] faSprite_ "magnifying-glass" "regular" "w-4 h-4 opacity-70" - -- Sort options 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 @@ -166,7 +146,6 @@ itemsList_ listCfg items = span_ [class_ "block text-lg"] $ toHtml title span_ [class_ "block "] $ toHtml desc - -- Graph and events display 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 @@ -178,7 +157,6 @@ itemsList_ listCfg items = , id_ "sortLoader" ] "" - -- Render zero state if the list is empty 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" div_ [class_ "flex flex-col gap-2"] do @@ -188,21 +166,17 @@ itemsList_ listCfg items = 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 - -- Render the list of items 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 --- Represents rows of items type role ItemsRows representational data ItemsRows a = ItemsRows (Maybe Text) (V.Vector a) -- Text represents nextFetchUrl --- Implementation of ToHtml for ItemsRows instance ToHtml a => ToHtml (ItemsRows a) where toHtml (ItemsRows nextFetchUrl items) = toHtmlRaw $ itemRows_ nextFetchUrl items toHtmlRaw (ItemsRows nextFetchUrl items) = toHtmlRaw $ itemRows_ nextFetchUrl items --- Function to render rows of items itemRows_ :: (Monad m, ToHtml a) => Maybe Text -> V.Vector a -> HtmlT m () itemRows_ nextFetchUrl items = do mapM_ toHtml items From 61b4b2321d2c9178d7248b367c2d3a72a74d5eb5 Mon Sep 17 00:00:00 2001 From: Daniel Asaboro Date: Thu, 12 Sep 2024 16:00:54 +0100 Subject: [PATCH 07/15] fix: removed spaces --- src/Pkg/Components/ItemsList.hs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Pkg/Components/ItemsList.hs b/src/Pkg/Components/ItemsList.hs index c6ade91fb..160ecda43 100644 --- a/src/Pkg/Components/ItemsList.hs +++ b/src/Pkg/Components/ItemsList.hs @@ -23,30 +23,30 @@ import Relude import Utils (deleteParam, faSprite_) data ItemsListCfg = ItemsListCfg - { currentURL :: Text - , sort :: Maybe SortCfg - , filter :: Maybe Text - , projectId :: Projects.ProjectId - , currTime :: UTCTime - , elemID :: Text - , nextFetchUrl :: Maybe Text - , zeroState :: Maybe ZeroState - , bulkActions :: [BulkAction] - , search :: Maybe SearchCfg - , heading :: Maybe (Html ()) + { currentURL :: Text + , sort :: Maybe SortCfg + , filter :: Maybe Text + , projectId :: Projects.ProjectId + , currTime :: UTCTime + , elemID :: Text + , nextFetchUrl :: Maybe Text + , zeroState :: Maybe ZeroState + , bulkActions :: [BulkAction] + , search :: Maybe SearchCfg + , heading :: Maybe (Html ()) } data SearchCfg = SearchCfg {viaQueryParam :: Maybe Text} data BulkAction = BulkAction - { icon :: Maybe Text - , title :: Text - , uri :: Text + { icon :: Maybe Text + , title :: Text + , uri :: Text } data SortCfg = SortCfg - { current :: Text + { current :: Text } From 0abe9f0457e88f57fa29d40de49b85120a7d28a7 Mon Sep 17 00:00:00 2001 From: Daniel Asaboro Date: Thu, 12 Sep 2024 16:04:20 +0100 Subject: [PATCH 08/15] fix: removed extra unnecessary comments --- src/Pages/Endpoints/ApiCatalog.hs | 48 ++++++++++--------------------- 1 file changed, 15 insertions(+), 33 deletions(-) diff --git a/src/Pages/Endpoints/ApiCatalog.hs b/src/Pages/Endpoints/ApiCatalog.hs index fda285d88..7ca13e5e1 100644 --- a/src/Pages/Endpoints/ApiCatalog.hs +++ b/src/Pages/Endpoints/ApiCatalog.hs @@ -7,39 +7,32 @@ import Effectful.PostgreSQL.Transact.Effect (dbtToEff) import Effectful.Time qualified as Time import Fmt (commaizeF, fmt) import Lucid -import Lucid.Htmx (hxGet_, hxSwap_, hxTrigger_) -- HTMX integration for frontend interactivity. +import Lucid.Htmx (hxGet_, hxSwap_, hxTrigger_) import Models.Apis.Endpoints qualified as Endpoints import Models.Projects.Projects qualified as Projects import Models.Users.Sessions qualified as Sessions import Pages.Anomalies.AnomalyList qualified as AnomalyList import Pages.BodyWrapper (BWConfig (currProject, pageTitle, sessM), PageCtx (..), navTabs) -import Pkg.Components.ItemsList qualified as ItemsList -- Package for the reusable list component. -import PyF qualified -- PyF for formatted strings. -import Relude hiding (ask, asks) -- Standard library extensions with certain functions hidden. -import System.Types (ATAuthCtx, RespHeaders, addRespHeaders) -- Importing custom types for handling responses. +import Pkg.Components.ItemsList qualified as ItemsList +import PyF qualified +import Relude hiding (ask, asks) +import System.Types (ATAuthCtx, RespHeaders, addRespHeaders) --- Function to handle the API catalog page. apiCatalogH :: Projects.ProjectId -> Maybe Text -> Maybe Text -> Maybe Text -> ATAuthCtx (RespHeaders (PageCtx (ItemsList.ItemsPage HostEventsVM))) apiCatalogH pid sortM timeFilter requestTypeM = do - -- Fetch user session and project details based on the project ID. (sess, project) <- Sessions.sessionAndProject pid - -- Default the request type to "Incoming" if not provided. let requestType = fromMaybe "Incoming" requestTypeM - -- Fetch hosts and events from the database with sorting and request type filtering. hostsAndEvents <- dbtToEff $ Endpoints.dependenciesAndEventsCount pid requestType (fromMaybe "events" sortM) currTime <- Time.currentTime - -- Extract or default the sort and filter values. let sortV = fromMaybe "events" sortM - let filterV = fromMaybe "24h" timeFilter + let filterV = fromMaybe "14d" timeFilter - -- Build the current URL with appropriate query parameters. let currentURL = "/p/" <> pid.toText <> "/api_catalog?sort=" <> sortV <> "&request_type=" <> requestType - -- Configure the items list for rendering events related to hosts. let listCfg = ItemsList.ItemsListCfg { projectId = pid @@ -48,14 +41,14 @@ apiCatalogH pid sortM timeFilter requestTypeM = do , currentURL = currentURL , currTime , bulkActions = - [ -- Define bulk actions like "acknowledge" and "archive" for anomalies. + [ 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 = -- Define the empty state when no requests are being monitored. + , zeroState = Just $ ItemsList.ZeroState { icon = "empty-set" @@ -67,57 +60,46 @@ apiCatalogH pid sortM timeFilter requestTypeM = do , elemID = "anomalyListForm" } - -- Define the page's body wrapper configuration (metadata for rendering). let bwconf = def - { sessM = Just sess.persistentSession -- User session management. - , currProject = Just project -- Current project information. - , pageTitle = "API Catalog" -- Page title for the API catalog. - , navTabs = Just $ div_ [class_ "tabs tabs-boxed border"] do -- Navigation tabs for "Incoming" and "Outgoing" requests. + { sessM = Just sess.persistentSession + , currProject = Just project + , pageTitle = "API Catalog" + , navTabs = Just $ div_ [class_ "tabs tabs-boxed border"] 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" } - -- Add response headers and render the page context (items list). addRespHeaders $ PageCtx bwconf (ItemsList.ItemsPage listCfg $ V.map (\host -> HostEventsVM pid host filterV requestType) hostsAndEvents) --- Data type for representing host events in the ViewModel. data HostEventsVM = HostEventsVM Projects.ProjectId Endpoints.HostEvents Text Text --- ToHtml instance to define how HostEventsVM should be converted to HTML. instance ToHtml HostEventsVM where toHtml :: Monad m => HostEventsVM -> HtmlT m () toHtml (HostEventsVM pid he timeFilter requestType) = toHtmlRaw $ renderapiCatalog pid he timeFilter requestType -- Convert HostEventsVM to HTML using renderapiCatalog function. toHtmlRaw :: Monad m => HostEventsVM -> HtmlT m () - toHtmlRaw = toHtml -- Raw HTML rendering. + toHtmlRaw = toHtml --- Function to render the API catalog for a specific project, host, and request type. renderapiCatalog :: Projects.ProjectId -> Endpoints.HostEvents -> Text -> Text -> Html () renderapiCatalog pid host timeFilter requestType = div_ [class_ "flex py-4 gap-8 items-center itemsListItem"] do - -- Checkbox for selecting an issue in the list. 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] - -- Main content section displaying the host and actions (view logs, etc.). div_ [class_ "space-y-3 grow"] do div_ [class_ "space-x-3"] do a_ [class_ "inline-block font-bold space-x-2"] $ do - -- Display host and link to endpoint details. 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) - -- Link to view logs for this 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" - -- Section for fetching and displaying a time chart via HTMX. div_ [class_ "flex items-center justify-center "] $ do - -- Conditionally use the filter for the chart. div_ [ class_ "w-56 h-12 px-3" , hxGet_ $ "/charts_html?pid=" <> pid.toText <> "&since=" <> (if timeFilter == "14d" then "14D" else "24h") <> "&query_raw=" <> AnomalyList.escapedQueryPartial [PyF.fmt|host=="{host.host}" | timechart [1d]|] -- Fetch the chart for this host. - , hxTrigger_ "intersect once" -- Load the chart when the element is in view. - , hxSwap_ "innerHTML" -- Replace the content with the fetched chart. + , 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 From 75bafd7bdffe0df5a3023a10552e6df091f76f04 Mon Sep 17 00:00:00 2001 From: Daniel Asaboro Date: Thu, 12 Sep 2024 16:13:25 +0100 Subject: [PATCH 09/15] fix: reverted selected time range color to black --- src/Pages/Endpoints/ApiCatalog.hs | 8 ++++---- src/Pkg/Components/ItemsList.hs | 4 ++-- stack.yaml | 5 ----- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/Pages/Endpoints/ApiCatalog.hs b/src/Pages/Endpoints/ApiCatalog.hs index 7ca13e5e1..d8b49bba2 100644 --- a/src/Pages/Endpoints/ApiCatalog.hs +++ b/src/Pages/Endpoints/ApiCatalog.hs @@ -69,7 +69,7 @@ apiCatalogH pid sortM timeFilter 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 filterV requestType) hostsAndEvents) @@ -78,9 +78,9 @@ data HostEventsVM = HostEventsVM Projects.ProjectId Endpoints.HostEvents Text Te instance ToHtml HostEventsVM where toHtml :: Monad m => HostEventsVM -> HtmlT m () - toHtml (HostEventsVM pid he timeFilter requestType) = toHtmlRaw $ renderapiCatalog pid he timeFilter requestType -- Convert HostEventsVM to HTML using renderapiCatalog function. + toHtml (HostEventsVM pid he timeFilter requestType) = toHtmlRaw $ renderapiCatalog pid he timeFilter requestType toHtmlRaw :: Monad m => HostEventsVM -> HtmlT m () - toHtmlRaw = toHtml + toHtmlRaw = toHtml renderapiCatalog :: Projects.ProjectId -> Endpoints.HostEvents -> Text -> Text -> Html () renderapiCatalog pid host timeFilter requestType = div_ [class_ "flex py-4 gap-8 items-center itemsListItem"] do @@ -97,7 +97,7 @@ renderapiCatalog pid host timeFilter requestType = div_ [class_ "flex py-4 gap-8 div_ [class_ "flex items-center justify-center "] $ do div_ [ class_ "w-56 h-12 px-3" - , hxGet_ $ "/charts_html?pid=" <> pid.toText <> "&since=" <> (if timeFilter == "14d" then "14D" else "24h") <> "&query_raw=" <> AnomalyList.escapedQueryPartial [PyF.fmt|host=="{host.host}" | timechart [1d]|] -- Fetch the chart for this host. + , hxGet_ $ "/charts_html?pid=" <> pid.toText <> "&since=" <> (if timeFilter == "14d" then "14D" else "24h") <> "&query_raw=" <> AnomalyList.escapedQueryPartial [PyF.fmt|host=="{host.host}" | timechart [1d]|] , hxTrigger_ "intersect once" , hxSwap_ "innerHTML" ] diff --git a/src/Pkg/Components/ItemsList.hs b/src/Pkg/Components/ItemsList.hs index 160ecda43..78a4c119a 100644 --- a/src/Pkg/Components/ItemsList.hs +++ b/src/Pkg/Components/ItemsList.hs @@ -150,8 +150,8 @@ itemsList_ listCfg items = 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 text-blue-800" else "") , href_ $ currentURL' <> "&since=24h"] "24h" - a_ [ class_ $ "cursor-pointer " <> (if selectedFilter == "14d" then "text-base font-bold text-blue-800" else ""), href_ $ currentURL' <> "&since=14d"] "14d" + 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" diff --git a/stack.yaml b/stack.yaml index 77dd24c10..18f3830b7 100644 --- a/stack.yaml +++ b/stack.yaml @@ -5,11 +5,6 @@ packages: ghc-options: "grpc-haskell-core": -Wno-x-partial -extra-include-dirs: - - /opt/homebrew/Cellar/grpc/1.62.2_4/include -extra-lib-dirs: - - /opt/homebrew/Cellar/grpc/1.62.2_4/lib - extra-deps: - ./rust-interop - ./otlp From a846c25007c33859d370e59aea3464b73901fe8b Mon Sep 17 00:00:00 2001 From: Daniel Asaboro Date: Thu, 12 Sep 2024 16:25:39 +0100 Subject: [PATCH 10/15] fix: fixed formatting issues --- src/Pages/Endpoints/ApiCatalog.hs | 12 ++++--- src/Pages/Log.hs | 50 +++++++++++++------------- src/Pages/LogExplorer/LogItem.hs | 60 +++++++++++++++---------------- src/Pages/Reports.hs | 1 + src/Pages/Traces/Trace.hs | 8 ++--- src/Pkg/Components/ItemsList.hs | 19 +++++++--- 6 files changed, 83 insertions(+), 67 deletions(-) diff --git a/src/Pages/Endpoints/ApiCatalog.hs b/src/Pages/Endpoints/ApiCatalog.hs index 652472a54..ea36bbd1a 100644 --- a/src/Pages/Endpoints/ApiCatalog.hs +++ b/src/Pages/Endpoints/ApiCatalog.hs @@ -18,6 +18,7 @@ import PyF qualified import Relude hiding (ask, asks) import System.Types (ATAuthCtx, RespHeaders, addRespHeaders) + 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 @@ -41,8 +42,7 @@ apiCatalogH pid sortM timeFilter requestTypeM = do , currentURL = currentURL , currTime , bulkActions = - [ - ItemsList.BulkAction{icon = Just "check", title = "acknowledge", uri = "/p/" <> pid.toText <> "/anomalies/bulk_actions/acknowledge"} + [ 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} @@ -82,6 +82,7 @@ instance ToHtml HostEventsVM where toHtmlRaw :: Monad m => HostEventsVM -> HtmlT m () toHtmlRaw = toHtml + 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 @@ -103,5 +104,8 @@ renderapiCatalog pid host timeFilter requestType = div_ [class_ "flex py-4 gap-8 ] "" - 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 + 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/Log.hs b/src/Pages/Log.hs index cbadb045a..68fac0528 100644 --- a/src/Pages/Log.hs +++ b/src/Pages/Log.hs @@ -86,8 +86,8 @@ apiLogH pid queryM cols' cursorM' sinceM fromM toM layoutM sourceM hxRequestM hx let tableAsVecM = hush tableAsVecE freeTierExceeded <- - dbtToEff $ - if project.paymentPlan == "Free" + dbtToEff + $ if project.paymentPlan == "Free" then do totalRequest <- RequestDumps.getLastSevenDaysTotalRequest pid return $ totalRequest > 5000 @@ -228,9 +228,9 @@ apiLogsPage page = do ] do div_ [class_ "relative ml-auto w-full", style_ ""] do - div_ [class_ "flex justify-end w-full p-4 "] $ - button_ [[__|on click add .hidden to #expand-log-modal|]] $ - faSprite_ "xmark" "regular" "h-8" + div_ [class_ "flex justify-end w-full p-4 "] + $ button_ [[__|on click add .hidden to #expand-log-modal|]] + $ faSprite_ "xmark" "regular" "h-8" form_ [ hxPost_ $ "/p/" <> page.pid.toText <> "/share/" , hxSwap_ "innerHTML" @@ -372,23 +372,23 @@ logItemRows_ pid requests curatedCols colIdxMap nextLogsURL source = do forM_ requests \reqVec -> do let (logItemPath, _reqId) = fromMaybe ("", "") $ requestDumpLogItemUrlPath pid reqVec colIdxMap let (_, errCount, errClass) = errorClass True reqVec colIdxMap - tr_ [class_ "cursor-pointer divide-x b--b2", [__|on click toggle .hidden on next then toggle .expanded-log on me|]] $ - forM_ curatedCols (td_ . logItemCol_ source pid reqVec colIdxMap) + tr_ [class_ "cursor-pointer divide-x b--b2", [__|on click toggle .hidden on next then toggle .expanded-log on me|]] + $ forM_ curatedCols (td_ . logItemCol_ source pid reqVec colIdxMap) tr_ [class_ "hidden"] $ do -- used for when a row is expanded. td_ $ a_ [class_ $ "inline-block h-full " <> errClass, term "data-tippy-content" $ show errCount <> " errors attached to this request"] "" td_ [colspan_ $ show $ length curatedCols - 1] $ div_ [hxGet_ $ logItemPath <> "?source=" <> source, hxTrigger_ "intersect once", hxSwap_ "outerHTML"] $ span_ [class_ "loading loading-dots loading-md"] "" - when (Vector.length requests > 199) $ - tr_ $ - td_ [colspan_ $ show $ length curatedCols] $ - a_ - [ class_ "cursor-pointer inline-flex justify-center py-1 px-56 ml-36 blue-800 bg-blue-100 hover:bg-blue-200 gap-3 items-center" - , hxTrigger_ "click, intersect once" - , hxSwap_ "outerHTML" - , hxGet_ nextLogsURL - , hxTarget_ "closest tr" - ] - (span_ [class_ "inline-block"] "LOAD MORE " >> span_ [class_ "loading loading-dots loading-sm inline-block pl-3"] "") + when (Vector.length requests > 199) + $ tr_ + $ td_ [colspan_ $ show $ length curatedCols] + $ a_ + [ class_ "cursor-pointer inline-flex justify-center py-1 px-56 ml-36 blue-800 bg-blue-100 hover:bg-blue-200 gap-3 items-center" + , hxTrigger_ "click, intersect once" + , hxSwap_ "outerHTML" + , hxGet_ nextLogsURL + , hxTarget_ "closest tr" + ] + (span_ [class_ "inline-block"] "LOAD MORE " >> span_ [class_ "loading loading-dots loading-sm inline-block pl-3"] "") errorClass :: Bool -> V.Vector Value -> HM.HashMap Text Int -> (Int, Int, Text) @@ -438,8 +438,8 @@ logTableHeadingWrapper_ pid title child = td_ div_ [tabindex_ "0", role_ "button", class_ "py-1 px-3 block"] child ul_ [tabindex_ "0", class_ "dropdown-content z-[1] menu p-2 shadow bg-base-100 rounded-box min-w-[15rem]"] do li_ [class_ "underline underline-offset-2"] $ toHtml title - li_ $ - a_ + li_ + $ a_ [ hxGet_ $ "/p/" <> pid.toText <> "/log_explorer" , hxPushUrl_ "true" , hxVals_ $ "js:{query:params().query,cols:removeNamedColumnToSummary('" <> title <> "'),layout:'resultTable'}" @@ -464,8 +464,8 @@ logItemCol_ source pid reqVec colIdxMap "id" = do label_ [ class_ "col-span-2 cursor-pointer" , Lucid.for_ "global-data-drawer" - , term "_" $ - [text|on mousedown or click fetch $logItemPathDetailed + , term "_" + $ [text|on mousedown or click fetch $logItemPathDetailed then set #global-data-drawer-content.innerHTML to #loader-tmp.innerHTML 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)|] @@ -516,9 +516,9 @@ logItemCol_ source pid reqVec colIdxMap key@"rest" = div_ [class_ "space-x-2 whi span_ [class_ "badge badge-sm badge-ghost ", term "data-tippy-content" "Host"] $ toHtml $ fromMaybe "" $ lookupVecTextByKey reqVec colIdxMap "host" span_ [] $ toHtml $ maybe "" unwrapJsonPrimValue (lookupVecByKey reqVec colIdxMap key) logItemCol_ _ _ reqVec colIdxMap key = - div_ [class_ "xwhitespace-nowrap overflow-x-hidden max-w-lg ", term "data-tippy-content" key] $ - toHtml $ - maybe "" unwrapJsonPrimValue (lookupVecByKey reqVec colIdxMap key) + div_ [class_ "xwhitespace-nowrap overflow-x-hidden max-w-lg ", term "data-tippy-content" key] + $ toHtml + $ maybe "" unwrapJsonPrimValue (lookupVecByKey reqVec colIdxMap key) requestDumpLogItemUrlPath :: Projects.ProjectId -> V.Vector Value -> HM.HashMap Text Int -> Maybe (Text, Text) diff --git a/src/Pages/LogExplorer/LogItem.hs b/src/Pages/LogExplorer/LogItem.hs index d7082f165..1281586f2 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) @@ -232,12 +232,12 @@ apiLogItemView :: Projects.ProjectId -> UUID.UUID -> AE.Value -> Text -> Text -> apiLogItemView pid logId req expandItemPath source = do let logItemPathDetailed = expandItemPath <> "/detailed?source=" <> source div_ [class_ "flex items-center gap-2"] do - when (source == "requests") $ - label_ + when (source == "requests") + $ label_ [ class_ "btn btn-sm btn-outline" , Lucid.for_ "global-data-drawer" - , term "_" $ - [text|on mousedown or click fetch $logItemPathDetailed + , 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 @@ -254,8 +254,8 @@ apiLogItemView pid logId req expandItemPath source = do label_ [ class_ "btn btn-sm btn-outline" , Lucid.for_ "global-data-drawer" - , term "_" $ - [text|on mousedown or click fetch $tracePathDetailed + , term "_" + $ [text|on mousedown or click fetch $tracePathDetailed then set #global-data-drawer-content.innerHTML to #loader-tmp.innerHTML 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)|] @@ -263,8 +263,8 @@ apiLogItemView pid logId req expandItemPath source = do "Expand" let reqJson = decodeUtf8 $ AE.encode req - when (source == "requests") $ - button_ + when (source == "requests") + $ button_ [ class_ "btn btn-sm btn-outline" , term "data-reqJson" reqJson , onclick_ "window.buildCurlRequest(event)" @@ -283,8 +283,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] @@ -310,8 +310,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/Reports.hs b/src/Pages/Reports.hs index 106e1c89e..c447994bb 100644 --- a/src/Pages/Reports.hs +++ b/src/Pages/Reports.hs @@ -80,6 +80,7 @@ import Relude import System.Types (ATAuthCtx, RespHeaders, addRespHeaders, addSuccessToast) import Text.Printf (printf) + data PerformanceReport = PerformanceReport { urlPath :: Text , method :: Text diff --git a/src/Pages/Traces/Trace.hs b/src/Pages/Traces/Trace.hs index 861bb65aa..afe917e55 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", style_ $ "width:" <> percent <> "%; background-color:" <> color] pass + div_ [class_ "w-[100px] h-3 bg-gray-200 rounded overflow-hidden"] + $ div_ [class_ "h-full pl-2 text-xs font-medium", style_ $ "width:" <> percent <> "%; background-color:" <> color] 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 0f3625d85..5737161ec 100644 --- a/src/Pkg/Components/ItemsList.hs +++ b/src/Pkg/Components/ItemsList.hs @@ -22,6 +22,7 @@ import Models.Projects.Projects qualified as Projects import Relude import Utils (deleteParam, faSprite_) + data ItemsListCfg = ItemsListCfg { currentURL :: Text , sort :: Maybe SortCfg @@ -36,15 +37,18 @@ data ItemsListCfg = ItemsListCfg , heading :: Maybe (Html ()) } + data SearchCfg = SearchCfg {viaQueryParam :: Maybe Text} + data BulkAction = BulkAction { icon :: Maybe Text , title :: Text , uri :: Text } + data SortCfg = SortCfg { current :: Text } @@ -55,20 +59,24 @@ data ZeroState = ZeroState , title :: Text , description :: Text , actionText :: Text - , destination :: Either Text Text + , destination :: Either Text Text } + type role ItemsPage representational data ItemsPage a = ItemsPage ItemsListCfg (V.Vector a) + instance ToHtml a => ToHtml (ItemsPage a) where toHtml (ItemsPage cfg items) = toHtmlRaw $ itemsPage_ cfg items toHtmlRaw (ItemsPage cfg items) = toHtmlRaw $ itemsPage_ cfg items + itemsPage_ :: ToHtml a => ItemsListCfg -> V.Vector a -> Html () itemsPage_ listCfg items = div_ [class_ "w-full mx-auto px-6 pt-2 pb-16 overflow-y-scroll h-full space-y-6", id_ "itemsListPage"] $ do itemsList_ listCfg items + itemsList_ :: ToHtml a => ItemsListCfg -> V.Vector a -> Html () itemsList_ listCfg items = div_ [class_ "grid card-round overflow-hidden group/grid", id_ "anomalyListBelowTab", hxGet_ listCfg.currentURL, hxSwap_ "outerHTML", hxTrigger_ "refreshMain"] do @@ -157,9 +165,9 @@ itemsList_ listCfg items = 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" + 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" @@ -180,13 +188,16 @@ itemsList_ listCfg items = 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 toHtml (ItemsRows nextFetchUrl items) = toHtmlRaw $ itemRows_ nextFetchUrl items toHtmlRaw (ItemsRows nextFetchUrl items) = toHtmlRaw $ itemRows_ nextFetchUrl items + itemRows_ :: (Monad m, ToHtml a) => Maybe Text -> V.Vector a -> HtmlT m () itemRows_ nextFetchUrl items = do mapM_ toHtml items From 1c41f9e22d4053b7d81655e3532afb8ccedd62d8 Mon Sep 17 00:00:00 2001 From: Daniel Asaboro Date: Fri, 13 Sep 2024 18:17:42 +0100 Subject: [PATCH 11/15] fix: swapped the function of the error box to open a modal popup instead of a new route --- src/Pages/Anomalies/AnomalyList.hs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Pages/Anomalies/AnomalyList.hs b/src/Pages/Anomalies/AnomalyList.hs index eb9f36767..8cb387b64 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_, hxTrigger_, hxTarget_) import Lucid.Hyperscript (__) import Models.Apis.Anomalies qualified as Anomalies import Models.Apis.Endpoints qualified as Endpoints @@ -315,8 +315,10 @@ 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 From f0f046df635e58a89daa2c8d36f80ceb293c5194 Mon Sep 17 00:00:00 2001 From: Daniel Asaboro Date: Fri, 13 Sep 2024 18:19:40 +0100 Subject: [PATCH 12/15] fix: fixed formatting issues --- src/Pages/Anomalies/AnomalyList.hs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Pages/Anomalies/AnomalyList.hs b/src/Pages/Anomalies/AnomalyList.hs index 8cb387b64..b855840fd 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_, hxTarget_) +import Lucid.Htmx (hxGet_, hxSwap_, hxTarget_, hxTrigger_) import Lucid.Hyperscript (__) import Models.Apis.Anomalies qualified as Anomalies import Models.Apis.Endpoints qualified as Endpoints @@ -316,8 +316,9 @@ issueItem hideByDefault currTime issue icon title subTitle content = do div_ [class_ "space-y-3 grow"] do div_ [class_ "space-x-3"] do 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"] + 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 From 68cccea1308ae38cb33aa2cb1a19df4285d375b6 Mon Sep 17 00:00:00 2001 From: Daniel Asaboro Date: Tue, 17 Sep 2024 12:06:56 +0100 Subject: [PATCH 13/15] Revert "fix: fixed formatting issues" This reverts commit f0f046df635e58a89daa2c8d36f80ceb293c5194. --- src/Pages/Anomalies/AnomalyList.hs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Pages/Anomalies/AnomalyList.hs b/src/Pages/Anomalies/AnomalyList.hs index 80b66ad3e..1c5632042 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_, hxTarget_, hxTrigger_) +import Lucid.Htmx (hxGet_, hxSwap_, hxTrigger_, hxTarget_) import Lucid.Hyperscript (__) import Models.Apis.Anomalies qualified as Anomalies import Models.Apis.Endpoints qualified as Endpoints @@ -316,9 +316,8 @@ issueItem hideByDefault currTime issue icon title subTitle content = do div_ [class_ "space-y-3 grow"] do div_ [class_ "space-x-3"] do 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"] + 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 From 8ef8315a3a848f015687224649333bfb9b2bd1ab Mon Sep 17 00:00:00 2001 From: Daniel Asaboro Date: Tue, 17 Sep 2024 12:27:29 +0100 Subject: [PATCH 14/15] fixed conflicts with master --- src/Pages/Anomalies/AnomalyList.hs | 91 +++++++++++++------------- src/Pages/Endpoints/ApiCatalog.hs | 6 +- src/Pages/Endpoints/EndpointDetails.hs | 76 ++++++++++----------- src/Pages/Endpoints/EndpointList.hs | 34 +++++----- src/Pages/LogExplorer/LogItem.hs | 36 +++++----- src/Pages/Traces/Trace.hs | 2 +- 6 files changed, 123 insertions(+), 122 deletions(-) diff --git a/src/Pages/Anomalies/AnomalyList.hs b/src/Pages/Anomalies/AnomalyList.hs index 1c5632042..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_, hxTarget_) +import Lucid.Htmx (hxGet_, hxSwap_, hxTarget_, hxTrigger_) import Lucid.Hyperscript (__) import Models.Apis.Anomalies qualified as Anomalies import Models.Apis.Endpoints qualified as Endpoints @@ -194,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." @@ -212,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 @@ -316,8 +316,9 @@ issueItem hideByDefault currTime issue icon title subTitle content = do div_ [class_ "space-y-3 grow"] do div_ [class_ "space-x-3"] do 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"] + 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 @@ -342,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 @@ -389,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) @@ -660,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" @@ -674,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" @@ -689,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 6caa4ef17..bf49b5c78 100644 --- a/src/Pages/Endpoints/ApiCatalog.hs +++ b/src/Pages/Endpoints/ApiCatalog.hs @@ -49,8 +49,8 @@ apiCatalogH pid sortM timeFilter requestTypeM = do , 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." @@ -98,7 +98,7 @@ renderapiCatalog pid host timeFilter requestType = div_ [class_ "flex py-4 gap-8 div_ [class_ "flex items-center justify-center "] $ do div_ [ class_ "w-56 h-12 px-3" - , hxGet_ $ "/charts_html?pid=" <> pid.toText <> "&since=" <> (if timeFilter == "14d" then "14D" else "24h") <> "&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" ] 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 b2091b28f..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" @@ -99,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." @@ -160,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/LogExplorer/LogItem.hs b/src/Pages/LogExplorer/LogItem.hs index bd5e0ae23..10c6cd662 100644 --- a/src/Pages/LogExplorer/LogItem.hs +++ b/src/Pages/LogExplorer/LogItem.hs @@ -250,26 +250,26 @@ apiLogItemView pid logId req expandItemPath source = do 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") - let trId = case req of - AE.Object o -> case KEM.lookup "trace_id" o of - Just (AE.String trid) -> Just trid - _ -> Nothing - _ -> Nothing - when (source == "spans" && isJust trId) do - let tracePathDetailed = "/p/" <> pid.toText <> "/traces/" <> fromMaybe "" trId - label_ - [ class_ "btn btn-sm btn-outline" - , Lucid.for_ "global-data-drawer" - , term "_" - $ [text|on mousedown or click fetch $tracePathDetailed - then set #global-data-drawer-content.innerHTML to #loader-tmp.innerHTML - 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" + -- let trId = case req of + -- AE.Object o -> case KEM.lookup "trace_id" o of + -- Just (AE.String trid) -> Just trid + -- _ -> Nothing + -- _ -> Nothing + -- when (source == "spans" && isJust trId) do + -- let tracePathDetailed = "/p/" <> pid.toText <> "/traces/" <> fromMaybe "" trId + -- label_ + -- [ class_ "btn btn-sm btn-outline" + -- , Lucid.for_ "global-data-drawer" + -- , term "_" + -- $ [text|on mousedown or click fetch $tracePathDetailed + -- then set #global-data-drawer-content.innerHTML to #loader-tmp.innerHTML + -- 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" let reqJson = decodeUtf8 $ AE.encode req - when (source == "requests") + when (source /= "logs" && source /= "spans") $ button_ [ class_ "btn btn-sm btn-outline" , term "data-reqJson" reqJson diff --git a/src/Pages/Traces/Trace.hs b/src/Pages/Traces/Trace.hs index 4011f6b13..099bcc158 100644 --- a/src/Pages/Traces/Trace.hs +++ b/src/Pages/Traces/Trace.hs @@ -137,7 +137,7 @@ tracePage p = do 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", style_ $ "width:" <> percent <> "%; background-color:" <> color] pass + $ div_ [class_ "h-full pl-2 text-xs font-medium", 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 From 1bfe5373e6aba647e75ba5cf45dcf6a2deb3683d Mon Sep 17 00:00:00 2001 From: Daniel Asaboro Date: Tue, 17 Sep 2024 12:32:08 +0100 Subject: [PATCH 15/15] fix: removed unnecessary commits --- src/Pages/LogExplorer/LogItem.hs | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/Pages/LogExplorer/LogItem.hs b/src/Pages/LogExplorer/LogItem.hs index 10c6cd662..101446516 100644 --- a/src/Pages/LogExplorer/LogItem.hs +++ b/src/Pages/LogExplorer/LogItem.hs @@ -250,23 +250,6 @@ apiLogItemView pid logId req expandItemPath source = do 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") - -- let trId = case req of - -- AE.Object o -> case KEM.lookup "trace_id" o of - -- Just (AE.String trid) -> Just trid - -- _ -> Nothing - -- _ -> Nothing - -- when (source == "spans" && isJust trId) do - -- let tracePathDetailed = "/p/" <> pid.toText <> "/traces/" <> fromMaybe "" trId - -- label_ - -- [ class_ "btn btn-sm btn-outline" - -- , Lucid.for_ "global-data-drawer" - -- , term "_" - -- $ [text|on mousedown or click fetch $tracePathDetailed - -- then set #global-data-drawer-content.innerHTML to #loader-tmp.innerHTML - -- 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" let reqJson = decodeUtf8 $ AE.encode req when (source /= "logs" && source /= "spans")