Skip to content

Commit

Permalink
refactor: build layout and build_ page
Browse files Browse the repository at this point in the history
  • Loading branch information
plyr4 committed Jan 21, 2024
1 parent e649888 commit 1e30c6a
Show file tree
Hide file tree
Showing 16 changed files with 564 additions and 32 deletions.
20 changes: 20 additions & 0 deletions src/elm/Api/Operations.elm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Api.Operations exposing
( addOrgSecret
, enableRepo
, finishAuthentication
, getBuild
, getCurrentUser
, getOrgBuilds
, getOrgRepos
Expand Down Expand Up @@ -235,6 +236,25 @@ getRepoDeployments baseUrl session options =
|> withAuth session


{-| getBuild : retrieves a build
-}
getBuild :
String
-> Session
->
{ a
| org : String
, repo : String
, buildNumber : String
}
-> Request Vela.Build
getBuild baseUrl session options =
get baseUrl
(Api.Endpoint.Build options.org options.repo options.buildNumber)
Vela.decodeBuild
|> withAuth session


{-| addOrgSecret : adds an org secret
-}
addOrgSecret :
Expand Down
13 changes: 13 additions & 0 deletions src/elm/Components/Crumbs.elm
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,19 @@ toCrumbs path =
in
[ overviewCrumbLink, orgReposCrumbLink, repoCrumbStatic ]

Route.Path.Org_Repo_Build_ params ->
let
orgReposCrumbLink =
( params.org, Just <| Route.Path.Org_ { org = params.org } )

repoBuildsCrumbLink =
( params.repo, Just <| Route.Path.Org_Repo_ { org = params.org, repo = params.repo } )

buildNumberCrumbStatic =
( "#" ++ params.buildNumber, Nothing )
in
[ overviewCrumbLink, orgReposCrumbLink, repoBuildsCrumbLink, buildNumberCrumbStatic ]

Route.Path.NotFound_ ->
let
notFoundCrumbStatic =
Expand Down
54 changes: 35 additions & 19 deletions src/elm/Effect.elm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Effect exposing
, sendCmd, sendMsg
, pushRoute, replaceRoute, loadExternalUrl
, map, toCmd
, addAlertError, addAlertSuccess, addOrgSecret, alertsUpdate, clearRedirect, enableRepo, finishAuthentication, focusOn, getCurrentUser, getOrgBuilds, getOrgRepos, getOrgSecrets, getRepoBuilds, getRepoDeployments, getRepoSecrets, getSharedSecrets, handleHttpError, logout, pushPath, setRedirect, setTheme, updateFavorites
, addAlertError, addAlertSuccess, addOrgSecret, alertsUpdate, clearRedirect, enableRepo, finishAuthentication, focusOn, getBuild, getCurrentUser, getOrgBuilds, getOrgRepos, getOrgSecrets, getRepoBuilds, getRepoDeployments, getRepoSecrets, getSharedSecrets, handleHttpError, logout, pushPath, setRedirect, setTheme, updateFavorites
)

{-|
Expand Down Expand Up @@ -278,24 +278,6 @@ enableRepo options =
|> sendCmd


getRepoBuilds :
{ baseUrl : String
, session : Auth.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
}
-> Effect msg
getRepoBuilds options =
Api.try
options.onResponse
(Api.Operations.getRepoBuilds options.baseUrl options.session options)
|> sendCmd


getOrgRepos :
{ baseUrl : String
, session : Auth.Session.Session
Expand Down Expand Up @@ -343,6 +325,24 @@ getOrgSecrets options =
|> sendCmd


getRepoBuilds :
{ baseUrl : String
, session : Auth.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
}
-> Effect msg
getRepoBuilds options =
Api.try
options.onResponse
(Api.Operations.getRepoBuilds options.baseUrl options.session options)
|> sendCmd


getRepoSecrets :
{ baseUrl : String
, session : Auth.Session.Session
Expand Down Expand Up @@ -394,6 +394,22 @@ getRepoDeployments options =
|> sendCmd


getBuild :
{ baseUrl : String
, session : Auth.Session.Session
, onResponse : Result (Http.Detailed.Error String) ( Http.Metadata, Vela.Build ) -> msg
, org : String
, repo : String
, buildNumber : String
}
-> Effect msg
getBuild options =
Api.try
options.onResponse
(Api.Operations.getBuild options.baseUrl options.session options)
|> sendCmd


addOrgSecret :
{ baseUrl : String
, session : Auth.Session.Session
Expand Down
5 changes: 5 additions & 0 deletions src/elm/Layouts.elm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ SPDX-License-Identifier: Apache-2.0
module Layouts exposing (..)

import Layouts.Default
import Layouts.Default.Build
import Layouts.Default.Org
import Layouts.Default.Repo

Expand All @@ -14,6 +15,7 @@ type Layout msg
= Default (Layouts.Default.Props msg)
| Default_Org (Layouts.Default.Org.Props msg)
| Default_Repo (Layouts.Default.Repo.Props msg)
| Default_Build (Layouts.Default.Build.Props msg)


map : (msg1 -> msg2) -> Layout msg1 -> Layout msg2
Expand All @@ -27,3 +29,6 @@ map fn layout =

Default_Repo data ->
Default_Repo <| Layouts.Default.Repo.map fn data

Default_Build data ->
Default_Build <| Layouts.Default.Build.map fn data
107 changes: 107 additions & 0 deletions src/elm/Layouts/Default/Build.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
{--
SPDX-License-Identifier: Apache-2.0
--}


module Layouts.Default.Build exposing (Model, Msg, Props, layout, map)

import Components.Tabs
import Effect exposing (Effect)
import Html exposing (..)
import Layout exposing (Layout)
import Layouts.Default
import RemoteData exposing (WebData)
import Route exposing (Route)
import Shared
import Vela
import View exposing (View)


type alias Props contentMsg =
{ org : String
, repo : String
, buildNumber : String
, build : WebData Vela.Build
, nil : List contentMsg
}


map : (msg1 -> msg2) -> Props msg1 -> Props msg2
map fn props =
{ org = props.org
, repo = props.repo
, buildNumber = props.buildNumber
, build = props.build
, nil = List.map fn props.nil
}


layout : Props contentMsg -> Shared.Model -> Route () -> Layout (Layouts.Default.Props contentMsg) Model Msg contentMsg
layout props shared route =
Layout.new
{ init = init shared
, update = update
, view = view props shared route
, subscriptions = subscriptions
}
|> Layout.withParentProps
{ navButtons = []
, utilButtons = []
}



-- MODEL


type alias Model =
{}


init : Shared.Model -> () -> ( Model, Effect Msg )
init shared _ =
( {}
, Effect.none
)



-- UPDATE


type Msg
= NoOp


update : Msg -> Model -> ( Model, Effect Msg )
update msg model =
case msg of
NoOp ->
( model
, Effect.none
)


subscriptions : Model -> Sub Msg
subscriptions model =
Sub.none



-- VIEW


view : Props contentMsg -> Shared.Model -> Route () -> { toContentMsg : Msg -> contentMsg, content : View contentMsg, model : Model } -> View contentMsg
view props shared route { toContentMsg, model, content } =
{ title = props.org ++ "/" ++ props.repo ++ " #" ++ props.buildNumber
, body =
[ Html.text "build:layout->"
, case props.build of
RemoteData.Success build ->
Html.text (Vela.statusToString build.status)

_ ->
Html.text "Loading..."
, Html.div [] content.body
]
}
12 changes: 9 additions & 3 deletions src/elm/Layouts/Default/Org.elm
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@ import View exposing (View)


type alias Props contentMsg =
{ org : String, nil : List contentMsg }
{ org : String
, navButtons : List (Html contentMsg)
, utilButtons : List (Html contentMsg)
}


map : (msg1 -> msg2) -> Props msg1 -> Props msg2
map fn props =
{ org = props.org, nil = List.map fn props.nil }
{ org = props.org
, navButtons = List.map (Html.map fn) props.navButtons
, utilButtons = List.map (Html.map fn) props.navButtons
}


layout : Props contentMsg -> Shared.Model -> Route () -> Layout (Layouts.Default.Props contentMsg) Model Msg contentMsg
Expand All @@ -33,7 +39,7 @@ layout props shared route =
, subscriptions = subscriptions
}
|> Layout.withParentProps
{ navButtons = []
{ navButtons = props.navButtons
, utilButtons =
[ Components.Tabs.viewOrgTabs
{ org = props.org
Expand Down
Loading

0 comments on commit 1e30c6a

Please sign in to comment.