Skip to content

Commit

Permalink
refactor: query parameters and pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
plyr4 committed Jan 18, 2024
1 parent c16b802 commit c1d6791
Show file tree
Hide file tree
Showing 9 changed files with 298 additions and 88 deletions.
12 changes: 6 additions & 6 deletions src/elm/Api/Operations_.elm
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,15 @@ getOrgRepos baseUrl session { org } =

{-| getRepoBuilds : retrieves builds for a repo
-}
getRepoBuilds : String -> Session -> { a | org : String, repo : String } -> Request (List Vela.Build)
getRepoBuilds baseUrl session { org, repo } =
get baseUrl (Endpoint.Builds Nothing Nothing Nothing org repo) Vela.decodeBuilds
getRepoBuilds : String -> Session -> { a | org : String, repo : String, pageNumber : Maybe Int, perPage : Maybe Int, maybeEvent : Maybe String } -> Request (List Vela.Build)
getRepoBuilds baseUrl session options =
get baseUrl (Endpoint.Builds options.pageNumber options.perPage options.maybeEvent options.org options.repo) Vela.decodeBuilds
|> withAuth session


{-| getRepoDeployments : retrieves deployments for a repo
-}
getRepoDeployments : String -> Session -> { a | org : String, repo : String } -> Request (List Vela.Deployment)
getRepoDeployments baseUrl session { org, repo } =
get baseUrl (Endpoint.Deployments Nothing Nothing org repo) Vela.decodeDeployments
getRepoDeployments : String -> Session -> { a | org : String, repo : String, pageNumber : Maybe Int, perPage : Maybe Int } -> Request (List Vela.Deployment)
getRepoDeployments baseUrl session options =
get baseUrl (Endpoint.Deployments options.pageNumber options.perPage options.org options.repo) Vela.decodeDeployments
|> withAuth session
4 changes: 2 additions & 2 deletions src/elm/Auth.elm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Auth.Session exposing (Session(..))
import Dict
import Route exposing (Route)
import Route.Path
import Route.Query
import Shared
import View exposing (View)

Expand All @@ -34,8 +35,7 @@ onPageLoad shared route =
{ path = Route.Path.Login_
, query =
Dict.fromList
[ ( "from", route.url.path )
]
[ ( "from", Route.toString route ) ]
, hash = Nothing
}

Expand Down
102 changes: 100 additions & 2 deletions src/elm/Components/Builds.elm
Original file line number Diff line number Diff line change
@@ -1,21 +1,49 @@
module Components.Builds exposing (view, viewPreview)
module Components.Builds exposing (view, viewHeader)

import Ansi
import Ansi.Log
import Components.Svgs as SvgBuilder exposing (buildStatusToIcon)
import DateFormat.Relative exposing (relativeTime)
import FeatherIcons
import Html exposing (Html, a, br, code, details, div, em, h1, li, ol, p, span, strong, summary, table, td, text, tr, ul)
import Html
exposing
( Html
, a
, br
, code
, details
, div
, em
, h1
, input
, label
, li
, ol
, p
, span
, strong
, summary
, table
, td
, text
, tr
, ul
)
import Html.Attributes
exposing
( attribute
, checked
, class
, classList
, for
, href
, id
, name
, style
, title
, type_
)
import Html.Events exposing (onClick)
import List.Extra
import Pages.Build.Model
exposing
Expand Down Expand Up @@ -714,3 +742,73 @@ colorClassesAnsi suffix bold mc =

Just Ansi.BrightWhite ->
[ brightPrefix ++ "white" ++ suffix ]


viewHeader :
{ maybeEvent : Maybe String
, showFullTimestamps : Bool
, filterByEvent : Maybe String -> msg
, showHideFullTimestamps : msg
}
-> Html msg
viewHeader props =
div [ class "build-bar" ]
[ viewFilter props.maybeEvent props.filterByEvent
, viewTimeToggle props.showFullTimestamps props.showHideFullTimestamps
]


viewFilter : Maybe String -> (Maybe String -> msg) -> Html msg
viewFilter maybeEvent filterByEventMsg =
let
eventToMaybe event =
case event of
"all" ->
Nothing

_ ->
Just event

eventEnum =
[ "all"
, "push"
, "pull_request"
, "tag"
, "deployment"
, "schedule"
, "comment"
]
in
div [ class "form-controls", class "build-filters", Util.testAttribute "build-filter" ] <|
div [] [ text "Filter by Event:" ]
:: List.map
(\e ->
div [ class "form-control" ]
[ input
[ type_ "radio"
, id <| "filter-" ++ e
, name "build-filter"
, Util.testAttribute <| "build-filter-" ++ e
, checked <| maybeEvent == eventToMaybe e
, onClick <| filterByEventMsg (eventToMaybe e)
, attribute "aria-label" <| "filter to show " ++ e ++ " events"
]
[]
, label
[ class "form-label"
, for <| "filter-" ++ e
]
[ text <| String.replace "_" " " e ]
]
)
eventEnum


viewTimeToggle : Bool -> msg -> Html msg
viewTimeToggle showTimestamp showHideFullTimestampMsg =
div [ class "form-controls", class "-stack", class "time-toggle" ]
[ div [ class "form-control" ]
[ input [ type_ "checkbox", checked showTimestamp, onClick showHideFullTimestampMsg, id "checkbox-time-toggle", Util.testAttribute "time-toggle" ] []
, label [ class "form-label", for "checkbox-time-toggle" ] [ text "show full timestamps" ]
]
]
13 changes: 9 additions & 4 deletions src/elm/Effect.elm
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ toCmd options effect =
-- CUSTOM EFFECTS


setTheme : Vela.Theme -> Effect msg
setTheme theme =
SendSharedMsg <| Shared.Msg.SetTheme theme
setTheme : { theme : Vela.Theme } -> Effect msg
setTheme options =
SendSharedMsg <| Shared.Msg.SetTheme options


logout : {} -> Effect msg
Expand Down Expand Up @@ -264,6 +264,9 @@ getRepoBuilds :
{ baseUrl : String
, session : Session
, onResponse : Result (Http.Detailed.Error String) ( Http.Metadata, List Vela.Build ) -> msg
, pageNumber : Maybe Int
, perPage : Maybe Int
, maybeEvent : Maybe String
, org : String
, repo : String
}
Expand Down Expand Up @@ -293,6 +296,8 @@ getRepoDeployments :
{ baseUrl : String
, session : Session
, onResponse : Result (Http.Detailed.Error String) ( Http.Metadata, List Vela.Deployment ) -> msg
, pageNumber : Maybe Int
, perPage : Maybe Int
, org : String
, repo : String
}
Expand Down Expand Up @@ -331,4 +336,4 @@ alertsUpdate options =

focusOn : { target : String } -> Effect msg
focusOn options =
SendSharedMsg <| Shared.Msg.FocusOn options.target
SendSharedMsg <| Shared.Msg.FocusOn options
32 changes: 16 additions & 16 deletions src/elm/Layouts/Default.elm
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ init shared _ =

type Msg
= NoOp
| CopyAlert String
| AlertsUpdate (Alerting.Msg Alert)
| SetTheme Theme
| ShowHideIdentity (Maybe Bool)
| ShowHideHelp (Maybe Bool)
| SetTheme Theme
| AlertsUpdate (Alerting.Msg Alert)
| CopyAlert String


update : Msg -> Model -> ( Model, Effect Msg )
Expand All @@ -94,19 +94,6 @@ update msg model =
, Effect.none
)

CopyAlert contentCopied ->
( model
, Effect.addAlertSuccess { content = contentCopied, addToastIfUnique = False }
)

AlertsUpdate alert ->
( model
, Effect.alertsUpdate { alert = alert }
)

SetTheme theme ->
( model, Effect.setTheme theme )

ShowHideIdentity show ->
( { model
| showIdentity =
Expand All @@ -133,6 +120,19 @@ update msg model =
, Effect.none
)

SetTheme theme ->
( model, Effect.setTheme { theme = theme } )

AlertsUpdate alert ->
( model
, Effect.alertsUpdate { alert = alert }
)

CopyAlert contentCopied ->
( model
, Effect.addAlertSuccess { content = contentCopied, addToastIfUnique = False }
)


subscriptions : Model -> Sub Msg
subscriptions model =
Expand Down
Loading

0 comments on commit c1d6791

Please sign in to comment.