Skip to content

Commit

Permalink
refactor(build): restart build and almost cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
KellyMerrick committed Feb 13, 2024
1 parent dbd91ae commit d7b8f34
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 105 deletions.
71 changes: 69 additions & 2 deletions src/elm/Components/Build.elm
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ SPDX-License-Identifier: Apache-2.0
--}


module Components.Build exposing (view, viewActionsMenu)
module Components.Build exposing (view, viewActionsMenu, viewCancelBuildButton, viewRestartBuildButton)

import Components.Svgs
import DateFormat.Relative
import FeatherIcons
import Html exposing (Html, a, details, div, label, li, span, strong, summary, text, ul)
import Html exposing (Html, a, button, details, div, label, li, span, strong, summary, text, ul)
import Html.Attributes exposing (attribute, class, classList, href, id, title)
import Html.Events exposing (onClick)
import List.Extra
import Maybe.Extra
import RemoteData exposing (WebData)
Expand Down Expand Up @@ -382,6 +383,72 @@ viewActionsMenu props =
]



-- BUILD


{-| viewCancelBuildButton : takes org repo and build number and renders button to cancel a build
-}
viewCancelBuildButton : Vela.Org -> Vela.Repo -> Vela.BuildNumber -> ({ org : Vela.Org, repo : Vela.Repo, buildNumber : Vela.BuildNumber } -> msg) -> Html msg
viewCancelBuildButton org repo buildNumber cancelBuild =
button
[ classList
[ ( "button", True )
, ( "-outline", True )
]
, onClick <| cancelBuild { org = org, repo = repo, buildNumber = buildNumber }
, Util.testAttribute "cancel-build"
]
[ text "Cancel Build"
]


{-| viewRestartBuildButton : takes org repo and build number and renders button to restart a build
-}
viewRestartBuildButton : Vela.Org -> Vela.Repo -> Vela.BuildNumber -> ({ org : Vela.Org, repo : Vela.Repo, buildNumber : Vela.BuildNumber } -> msg) -> Html msg
viewRestartBuildButton org repo buildNumber restartBuild =
button
[ classList
[ ( "button", True )
, ( "-outline", True )
]
, onClick <| restartBuild { org = org, repo = repo, buildNumber = buildNumber }
, Util.testAttribute "restart-build"
]
[ text "Restart Build"
]


{-| viewApproveBuildButton: takes org repo and build number and renders button to approve a build run
-}
viewApproveBuildButton : Vela.Org -> Vela.Repo -> WebData Vela.Build -> (Vela.Org -> Vela.Repo -> Vela.BuildNumber -> msg) -> Html msg
viewApproveBuildButton org repo build approveBuild =
case build of
RemoteData.Success b ->
let
approveButton =
button
[ classList
[ ( "button", True )
, ( "-outline", True )
]
, onClick <| approveBuild org repo <| String.fromInt b.number
, Util.testAttribute "approve-build"
]
[ text "Approve Build"
]
in
case b.status of
Vela.PendingApproval ->
approveButton

_ ->
text ""

_ ->
text ""


{-| viewError : checks for build error and renders message
-}
viewError : Vela.Build -> Html msg
Expand Down
100 changes: 0 additions & 100 deletions src/elm/Components/Nav.elm
Original file line number Diff line number Diff line change
Expand Up @@ -46,103 +46,3 @@ view shared route props =
(props.crumbs
:: props.buttons
)



-- BUILD


{-| cancelBuildButton : takes org repo and build number and renders button to cancel a build
-}
cancelBuildButton : Vela.Org -> Vela.Repo -> WebData Vela.Build -> (Vela.Org -> Vela.Repo -> Vela.BuildNumber -> msg) -> Html msg
cancelBuildButton org repo build cancelBuild =
case build of
RemoteData.Success b ->
let
cancelButton =
button
[ classList
[ ( "button", True )
, ( "-outline", True )
]
, onClick <| cancelBuild org repo <| String.fromInt b.number
, Util.testAttribute "cancel-build"
]
[ text "Cancel Build"
]
in
case b.status of
Vela.Running ->
cancelButton

Vela.Pending ->
cancelButton

Vela.PendingApproval ->
cancelButton

_ ->
text ""

_ ->
text ""


{-| restartBuildButton : takes org repo and build number and renders button to restart a build
-}
restartBuildButton : Vela.Org -> Vela.Repo -> WebData Vela.Build -> (Vela.Org -> Vela.Repo -> Vela.BuildNumber -> msg) -> Html msg
restartBuildButton org repo build restartBuild =
case build of
RemoteData.Success b ->
let
restartButton =
button
[ classList
[ ( "button", True )
, ( "-outline", True )
]
, onClick <| restartBuild org repo <| String.fromInt b.number
, Util.testAttribute "restart-build"
]
[ text "Restart Build"
]
in
case b.status of
Vela.PendingApproval ->
text ""

_ ->
restartButton

_ ->
text ""


{-| approveBuildButton: takes org repo and build number and renders button to approve a build run
-}
approveBuildButton : Vela.Org -> Vela.Repo -> WebData Vela.Build -> (Vela.Org -> Vela.Repo -> Vela.BuildNumber -> msg) -> Html msg
approveBuildButton org repo build approveBuild =
case build of
RemoteData.Success b ->
let
approveButton =
button
[ classList
[ ( "button", True )
, ( "-outline", True )
]
, onClick <| approveBuild org repo <| String.fromInt b.number
, Util.testAttribute "approve-build"
]
[ text "Approve Build"
]
in
case b.status of
Vela.PendingApproval ->
approveButton

_ ->
text ""

_ ->
text ""
33 changes: 30 additions & 3 deletions src/elm/Pages/Org_/Repo_/Build_.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ SPDX-License-Identifier: Apache-2.0

module Pages.Org_.Repo_.Build_ exposing (..)

import Api.Operations exposing (cancelBuild, restartBuild)
import Auth
import Browser.Dom exposing (focus)
import Components.Build
import Components.Loading
import Components.Logs
import Components.Svgs
Expand Down Expand Up @@ -56,7 +58,10 @@ page user shared route =
toLayout : Auth.User -> Route { org : String, repo : String, buildNumber : String } -> Model -> Layouts.Layout Msg
toLayout user route model =
Layouts.Default_Build
{ navButtons = []
{ navButtons =
[ Components.Build.viewRestartBuildButton route.params.org route.params.repo route.params.buildNumber RestartBuild
, Components.Build.viewCancelBuildButton route.params.org route.params.repo route.params.buildNumber CancelBuild
]
, utilButtons = []
, helpCommands = []
, crumbs =
Expand Down Expand Up @@ -128,10 +133,13 @@ init shared route () =

type Msg
= NoOp
| -- BROWSER
OnHashChanged { from : Maybe String, to : Maybe String }
-- BROWSER
| OnHashChanged { from : Maybe String, to : Maybe String }
| PushUrlHash { hash : String }
| FocusOn { target : String }
-- BUILD
| RestartBuild { org : Vela.Org, repo : Vela.Repo, buildNumber : Vela.BuildNumber }
| CancelBuild { org : Vela.Org, repo : Vela.Repo, buildNumber : Vela.BuildNumber }
-- STEPS
| GetBuildStepsResponse { applyDomFocus : Bool } (Result (Http.Detailed.Error String) ( Http.Metadata, List Vela.Step ))
| GetBuildStepsRefreshResponse (Result (Http.Detailed.Error String) ( Http.Metadata, List Vela.Step ))
Expand Down Expand Up @@ -190,6 +198,25 @@ update shared route msg model =
, Effect.focusOn options
)

-- BUILD
RestartBuild options ->
( model
, Effect.restartBuild
{ org = options.org
, repo = options.repo
, buildNumber = options.buildNumber
}
)

CancelBuild options ->
( model
, Effect.restartBuild
{ org = options.org
, repo = options.repo
, buildNumber = options.buildNumber
}
)

-- STEPS
GetBuildStepsResponse options response ->
case response of
Expand Down

0 comments on commit d7b8f34

Please sign in to comment.