Skip to content

Commit

Permalink
refactor(builds): get actions menu to display and begin restart build
Browse files Browse the repository at this point in the history
  • Loading branch information
KellyMerrick committed Feb 6, 2024
1 parent 1e6eeba commit da75e14
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 27 deletions.
23 changes: 23 additions & 0 deletions src/elm/Api/Operations.elm
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ module Api.Operations exposing
, logout
, redeliverHook
, repairRepo
, restartBuild
, updateCurrentUser
, updateOrgSecret
, updateRepo
Expand Down Expand Up @@ -284,6 +285,28 @@ getRepoBuilds baseUrl session options =
|> withAuth session


restartBuild :
String
-> Session
->
{ a
| org : String
, repo : String
, buildNumber : String
}
-> Request Vela.Build
restartBuild baseUrl session options =
post baseUrl
(Api.Endpoint.Build
options.org
options.repo
options.buildNumber
)
Http.emptyBody
Vela.decodeBuild
|> withAuth session


{-| getRepoDeployments : retrieves deployments for a repo
-}
getRepoDeployments :
Expand Down
15 changes: 12 additions & 3 deletions src/elm/Components/Build.elm
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import Vela
type alias Props msg =
{ build : WebData Vela.Build
, showFullTimestamps : Bool
, actionsMenu : Maybe (Html msg)
, actionsMenu : Html msg
, showActionsMenuBool : Bool
}


Expand Down Expand Up @@ -180,6 +181,7 @@ view shared props =
, infoRow = [ viewError build ]
, buildAnimation = [ buildAnimation build.status build.number ]
, hoverTitle = title hoverTime
, viewActionsMenu = props.actionsMenu
}

_ ->
Expand All @@ -194,6 +196,7 @@ view shared props =
, infoRow = []
, buildAnimation = [ buildAnimation Vela.Pending 1 ]
, hoverTitle = Html.Attributes.class ""
, viewActionsMenu = Html.div [] []
}


Expand All @@ -208,6 +211,7 @@ viewBuildPreview :
, infoRow : List (Html msg)
, buildAnimation : List (Html msg)
, hoverTitle : Html.Attribute msg
, viewActionsMenu : Html msg
}
-> Html msg
viewBuildPreview props =
Expand Down Expand Up @@ -240,6 +244,7 @@ viewBuildPreview props =
, span [ class "delimiter" ] [ text " /" ]
, div [ class "duration" ] props.duration
]
, props.viewActionsMenu
]
]
, div [ class "row" ] props.infoRow
Expand All @@ -253,13 +258,18 @@ viewBuildPreview props =
viewActionsMenu :
{ msgs :
{ showHideActionsMenus : Maybe Int -> Maybe Bool -> msg
, restartBuild : { org : String, repo : String, buildNumber : String } -> msg
}
, build : Vela.Build
, showActionsMenus : List Int
, showActionsMenuBool : Bool
}
-> Html msg
viewActionsMenu props =
let
isMenuOpen =
List.member props.build.id props.showActionsMenus

buildMenuBaseClassList =
classList
[ ( "details", True )
Expand Down Expand Up @@ -299,8 +309,7 @@ viewActionsMenu props =
[ a
[ href "#"
, class "menu-item"

-- , Util.onClickPreventDefault <| props.msgs.restartBuild org repo <| String.fromInt build.number
, Util.onClickPreventDefault <| props.msgs.restartBuild { org = "", repo = "", buildNumber = String.fromInt props.build.number }
, Util.testAttribute "restart-build"
]
[ text "Restart Build"
Expand Down
5 changes: 3 additions & 2 deletions src/elm/Components/Builds.elm
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import Vela

type alias Msgs msg =
{ approveBuild : Vela.Org -> Vela.Repo -> Vela.BuildNumber -> msg
, restartBuild : Vela.Org -> Vela.Repo -> Vela.BuildNumber -> msg
, restartBuild : { org : Vela.Org, repo : Vela.Repo, buildNumber : Vela.BuildNumber } -> msg
, cancelBuild : Vela.Org -> Vela.Repo -> Vela.BuildNumber -> msg
, showHideActionsMenus : Maybe Int -> Maybe Bool -> msg
}
Expand All @@ -59,7 +59,7 @@ type alias Props msg =
, builds : WebData (List Vela.Build)
, maybeEvent : Maybe String
, showFullTimestamps : Bool
, viewActionsMenu : Vela.Build -> Maybe (Html msg)
, viewActionsMenu : Vela.Build -> Html msg
}


Expand Down Expand Up @@ -123,6 +123,7 @@ view shared props =
{ build = RemoteData.succeed build
, showFullTimestamps = props.showFullTimestamps
, actionsMenu = props.viewActionsMenu build
, showActionsMenuBool = True
}
)
builds
Expand Down
12 changes: 11 additions & 1 deletion 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, addDeployment, addOrgSecret, addRepoSchedule, addRepoSecret, addSharedSecret, alertsUpdate, chownRepo, clearRedirect, deleteOrgSecret, deleteRepoSchedule, deleteRepoSecret, deleteSharedSecret, disableRepo, downloadFile, enableRepo, expandPipelineConfig, finishAuthentication, focusOn, getBuild, getBuildGraph, getBuildServiceLog, getBuildServices, getBuildStepLog, getBuildSteps, getCurrentUser, getOrgBuilds, getOrgRepos, getOrgSecret, getOrgSecrets, getPipelineConfig, getPipelineTemplates, getRepo, getRepoBuilds, getRepoBuildsShared, getRepoDeployments, getRepoHooks, getRepoHooksShared, getRepoSchedule, getRepoSchedules, getRepoSecret, getRepoSecrets, getSharedSecret, getSharedSecrets, handleHttpError, logout, pushPath, redeliverHook, repairRepo, replacePath, replaceRouteRemoveTabHistorySkipDomFocus, setRedirect, setTheme, updateFavicon, updateFavorites, updateOrgSecret, updateRepo, updateRepoSchedule, updateRepoSecret, updateSharedSecret
, addAlertError, addAlertSuccess, addDeployment, addOrgSecret, addRepoSecret, alertsUpdate, clearRedirect, downloadFile, enableRepo, expandPipelineConfig, finishAuthentication, focusOn, getBuild, getBuildServiceLog, getBuildServices, getBuildStepLog, getBuildSteps, getCurrentUser, getOrgBuilds, getOrgRepos, getOrgSecret, getOrgSecrets, getPipelineConfig, getPipelineTemplates, getRepo, getRepoBuilds, getRepoBuildsShared, getRepoDeployments, getRepoHooks, getRepoHooksShared, getRepoSchedules, getRepoSecret, getRepoSecrets, getSharedSecrets, handleHttpError, logout, pushPath, redeliverHook, restartBuild, setRedirect, setTheme, updateFavorites, updateOrgSecret, updateRepoSecret
)

{-|
Expand Down Expand Up @@ -444,6 +444,16 @@ getRepoDeployments options =
|> sendCmd


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


addDeployment :
{ baseUrl : String
, session : Auth.Session.Session
Expand Down
3 changes: 2 additions & 1 deletion src/elm/Layouts/Default/Build.elm
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ view props shared route { toContentMsg, model, content } =
, Components.Build.view shared
{ build = model.build
, showFullTimestamps = False
, actionsMenu = Nothing
, actionsMenu = Html.div [] []
, showActionsMenuBool = True
}
, Components.Tabs.viewBuildTabs shared
{ org = props.org
Expand Down
19 changes: 10 additions & 9 deletions src/elm/Pages/Org_/Builds.elm
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ type Msg
| GetOrgBuildsResponse (Result (Http.Detailed.Error String) ( Http.Metadata, List Vela.Build ))
| GotoPage Int
| ApproveBuild Vela.Org Vela.Repo Vela.BuildNumber
| RestartBuild Vela.Org Vela.Repo Vela.BuildNumber
| RestartBuild { org : Vela.Org, repo : Vela.Repo, buildNumber : Vela.BuildNumber }
| CancelBuild Vela.Org Vela.Repo Vela.BuildNumber
| ShowHideActionsMenus (Maybe Int) (Maybe Bool)
| FilterByEvent (Maybe String)
Expand Down Expand Up @@ -171,7 +171,7 @@ update shared route msg model =
ApproveBuild _ _ _ ->
( model, Effect.none )

RestartBuild _ _ _ ->
RestartBuild _ ->
( model, Effect.none )

CancelBuild _ _ _ ->
Expand Down Expand Up @@ -296,14 +296,15 @@ view shared route model =
, showFullTimestamps = model.showFullTimestamps
, viewActionsMenu =
\b ->
Just <|
Components.Build.viewActionsMenu
{ msgs =
{ showHideActionsMenus = ShowHideActionsMenus
}
, build = b
, showActionsMenus = model.showActionsMenus
Components.Build.viewActionsMenu
{ msgs =
{ showHideActionsMenus = ShowHideActionsMenus
, restartBuild = RestartBuild
}
, build = b
, showActionsMenus = model.showActionsMenus
, showActionsMenuBool = True
}
}
, Components.Pager.viewIfNeeded model.pager Components.Pager.defaultLabels GotoPage model.builds
]
Expand Down
39 changes: 28 additions & 11 deletions src/elm/Pages/Org_/Repo_.elm
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ type Msg
| GetRepoBuildsResponse (Result (Http.Detailed.Error String) ( Http.Metadata, List Vela.Build ))
| GotoPage Int
| ApproveBuild Vela.Org Vela.Repo Vela.BuildNumber
| RestartBuild Vela.Org Vela.Repo Vela.BuildNumber
| RestartBuild { org : Vela.Org, repo : Vela.Repo, buildNumber : Vela.BuildNumber }
| CancelBuild Vela.Org Vela.Repo Vela.BuildNumber
| ShowHideActionsMenus (Maybe Int) (Maybe Bool)
| FilterByEvent (Maybe String)
Expand Down Expand Up @@ -188,13 +188,29 @@ update shared route msg model =
in
( model, Effect.none )

RestartBuild _ _ _ ->
RestartBuild options ->
let
_ =
Debug.log "restart build clicked" ""
Debug.log "restart build clicked"
""

_ =
Debug.log "options" options
in
( model, Effect.none )
( model
, Effect.restartBuild
{ org = options.org
, repo = options.repo
, buildNumber = options.buildNumber
}
)

-- RestartBuild _ ->
-- let
-- _ =
-- Debug.log "restart build clicked" ""
-- in
-- ( model, Effect.none )
CancelBuild _ _ _ ->
let
_ =
Expand Down Expand Up @@ -323,14 +339,15 @@ view shared route model =
, showFullTimestamps = model.showFullTimestamps
, viewActionsMenu =
\b ->
Just <|
Components.Build.viewActionsMenu
{ msgs =
{ showHideActionsMenus = ShowHideActionsMenus
}
, build = b
, showActionsMenus = model.showActionsMenus
Components.Build.viewActionsMenu
{ msgs =
{ showHideActionsMenus = ShowHideActionsMenus
, restartBuild = RestartBuild
}
, build = b
, showActionsMenus = model.showActionsMenus
, showActionsMenuBool = True
}
}
, Components.Pager.viewIfNeeded model.pager Components.Pager.defaultLabels GotoPage model.builds
]
Expand Down
37 changes: 37 additions & 0 deletions src/elm/Shared.elm
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,43 @@ update route msg model =
, Effect.handleHttpError { httpError = error }
)

-- BUILD
Shared.Msg.RestartBuild options ->
let
_ =
Debug.log "restart a build" options
in
( model
, Api.try
(Shared.Msg.RestartBuildResponse options)
(Api.Operations.restartBuild model.velaAPI model.session options)
|> Effect.sendCmd
)

Shared.Msg.RestartBuildResponse options response ->
case response of
Ok ( _, build ) ->
let
restartedBuild =
"Build " ++ String.join "/" [ options.org, options.repo, options.buildNumber ]

newBuildNumber =
String.fromInt <| build.number

newBuild =
String.join "/" [ "", options.org, options.repo, newBuildNumber ]

-- todo: create new build link, add to toastie, refresh builds
in
( model
, Effect.addAlertSuccess { content = restartedBuild ++ " restarted.", addToastIfUnique = True }
)

Err error ->
( model
, Effect.handleHttpError { httpError = error }
)

-- BUILDS
Shared.Msg.GetRepoHooks options ->
( model
Expand Down
3 changes: 3 additions & 0 deletions src/elm/Shared/Msg.elm
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ type Msg
-- BUILDS
| GetRepoBuilds { org : String, repo : String, pageNumber : Maybe Int, perPage : Maybe Int, maybeEvent : Maybe String }
| GetRepoBuildsResponse (Result (Http.Detailed.Error String) ( Http.Metadata, List Vela.Build ))
-- BUILD
| RestartBuild { org : String, repo : String, buildNumber : String }
| RestartBuildResponse { org : String, repo : String, buildNumber : String } (Result (Http.Detailed.Error String) ( Http.Metadata, Vela.Build ))
-- HOOKS
| GetRepoHooks { org : String, repo : String, pageNumber : Maybe Int, perPage : Maybe Int, maybeEvent : Maybe String }
| GetRepoHooksResponse (Result (Http.Detailed.Error String) ( Http.Metadata, List Vela.Hook ))
Expand Down

0 comments on commit da75e14

Please sign in to comment.