Skip to content

Commit

Permalink
Merge branch 'refactor/elm-rebuild' into refactor/elm-rebuild-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
plyr4 authored Feb 14, 2024
2 parents b6b803e + 93176d5 commit c328e39
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 6 deletions.
1 change: 0 additions & 1 deletion src/elm/Api/Operations.elm
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,6 @@ approveBuild baseUrl session options =
Vela.decodeBuild
|> withAuth session


{-| getRepoDeployments : retrieves deployments for a repo
-}
getRepoDeployments :
Expand Down
76 changes: 74 additions & 2 deletions src/elm/Components/Build.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ SPDX-License-Identifier: Apache-2.0

module Components.Build exposing (view, viewActionsMenu, viewApproveButton, viewCancelButton, viewRestartButton)


import Components.Svgs
import DateFormat.Relative
import FeatherIcons
Expand Down Expand Up @@ -243,6 +244,7 @@ viewActionsMenu :
{ msgs :
{ showHideActionsMenus : Maybe Int -> Maybe Bool -> msg
, restartBuild : { org : String, repo : String, buildNumber : String } -> msg
, cancelBuild : { org : String, repo : String, buildNumber : String } -> msg
}
, build : Vela.Build
, showActionsMenus : List Int
Expand Down Expand Up @@ -293,8 +295,12 @@ viewActionsMenu props =
[ a
[ href "#"
, class "menu-item"

-- , Util.onClickPreventDefault <| props.msgs.cancelBuild org repo <| String.fromInt build.number
, Util.onClickPreventDefault <|
props.msgs.cancelBuild
{ org = org
, repo = repo
, buildNumber = String.fromInt props.build.number
}
, Util.testAttribute "cancel-build"
]
[ text "Cancel Build"
Expand Down Expand Up @@ -369,6 +375,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
10 changes: 10 additions & 0 deletions src/elm/Effect.elm
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,16 @@ approveBuild options =
|> sendCmd


cancelBuild :
{ org : String
, repo : String
, buildNumber : String
}
-> Effect msg
cancelBuild options =
SendSharedMsg <| Shared.Msg.CancelBuild options


addDeployment :
{ baseUrl : String
, session : Auth.Session.Session
Expand Down
1 change: 1 addition & 0 deletions src/elm/Pages/Org_/Builds.elm
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ view shared route model =
{ msgs =
{ showHideActionsMenus = ShowHideActionsMenus
, restartBuild = RestartBuild
, cancelBuild = CancelBuild
}
, build = options.build
, showActionsMenus = model.showActionsMenus
Expand Down
1 change: 1 addition & 0 deletions src/elm/Pages/Org_/Repo_.elm
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ view shared route model =
{ msgs =
{ showHideActionsMenus = ShowHideActionsMenus
, restartBuild = RestartBuild
, cancelBuild = CancelBuild
}
, build = options.build
, showActionsMenus = model.showActionsMenus
Expand Down
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.cancelBuild
{ org = options.org
, repo = options.repo
, buildNumber = options.buildNumber
}
)

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

0 comments on commit c328e39

Please sign in to comment.