Skip to content

Commit

Permalink
refactor: merge in code from original branch
Browse files Browse the repository at this point in the history
  • Loading branch information
plyr4 committed Feb 13, 2024
1 parent ede6b95 commit 4a8f491
Show file tree
Hide file tree
Showing 10 changed files with 340 additions and 254 deletions.
126 changes: 92 additions & 34 deletions src/elm/Components/Build.elm
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@ SPDX-License-Identifier: Apache-2.0
--}


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

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)
import Route
import Route.Path
import Shared
import Svg exposing (path)
import Time
import Url
import Utils.Helpers as Util
import Vela

Expand All @@ -27,7 +24,6 @@ type alias Props msg =
{ build : WebData Vela.Build
, showFullTimestamps : Bool
, actionsMenu : Html msg
, showActionsMenuBool : Bool
}


Expand Down Expand Up @@ -250,17 +246,13 @@ viewActionsMenu :
}
, build : Vela.Build
, showActionsMenus : List Int
, showActionsMenuBool : Bool
}
-> Html msg
viewActionsMenu props =
let
( org, repo ) =
Util.orgRepoFromBuildLink props.build.link

isMenuOpen =
List.member props.build.id props.showActionsMenus

buildMenuBaseClassList =
classList
[ ( "details", True )
Expand All @@ -272,25 +264,7 @@ viewActionsMenu props =
buildMenuAttributeList =
Util.open (List.member props.build.id props.showActionsMenus) ++ [ id "build-actions" ]

approveBuild =
case props.build.status of
Vela.PendingApproval ->
li [ class "build-menu-item" ]
[ a
[ href "#"
, class "menu-item"

-- , Util.onClickPreventDefault <| props.msgs.approveBuild org repo <| String.fromInt build.number
, Util.testAttribute "approve-build"
]
[ text "Approve Build"
]
]

_ ->
text ""

restartBuild =
viewRestartLink =
case props.build.status of
Vela.PendingApproval ->
text ""
Expand All @@ -312,7 +286,7 @@ viewActionsMenu props =
]
]

cancelBuild =
viewCancelLink =
case props.build.status of
Vela.Running ->
li [ class "build-menu-item" ]
Expand Down Expand Up @@ -355,6 +329,24 @@ viewActionsMenu props =

_ ->
text ""

viewApproveLink =
case props.build.status of
Vela.PendingApproval ->
li [ class "build-menu-item" ]
[ a
[ href "#"
, class "menu-item"

-- , Util.onClickPreventDefault <| props.msgs.approveBuild org repo <| String.fromInt build.number
, Util.testAttribute "approve-build"
]
[ text "Approve Build"
]
]

_ ->
text ""
in
details (buildMenuBaseClassList :: buildMenuAttributeList)
[ summary
Expand All @@ -370,9 +362,9 @@ viewActionsMenu props =
, attribute "aria-hidden" "true"
, attribute "role" "menu"
]
[ approveBuild
, restartBuild
, cancelBuild
[ viewApproveLink
, viewRestartLink
, viewCancelLink
]
]

Expand Down Expand Up @@ -561,3 +553,69 @@ bottomBuildNumberDashes buildNumber =

_ ->
"-animation-dashes-2"



-- BUILD


{-| viewCancelButton : takes org repo and build number and renders button to cancel a build
-}
viewCancelButton : Vela.Org -> Vela.Repo -> Vela.BuildNumber -> ({ org : Vela.Org, repo : Vela.Repo, buildNumber : Vela.BuildNumber } -> msg) -> Html msg
viewCancelButton 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"
]


{-| viewRestartButton : takes org repo and build number and renders button to restart a build
-}
viewRestartButton : Vela.Org -> Vela.Repo -> Vela.BuildNumber -> ({ org : Vela.Org, repo : Vela.Repo, buildNumber : Vela.BuildNumber } -> msg) -> Html msg
viewRestartButton 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"
]


{-| viewApproveButton: takes org repo and build number and renders button to approve a build run
-}
viewApproveButton : Vela.Org -> Vela.Repo -> WebData Vela.Build -> (Vela.Org -> Vela.Repo -> Vela.BuildNumber -> msg) -> Html msg
viewApproveButton 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 ""
5 changes: 2 additions & 3 deletions src/elm/Components/Builds.elm
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ import Vela


type alias Msgs msg =
{ approveBuild : Vela.Org -> Vela.Repo -> Vela.BuildNumber -> msg
{ approveBuild : { org : Vela.Org, repo : Vela.Repo, buildNumber : Vela.BuildNumber } -> msg
, restartBuild : { org : Vela.Org, repo : Vela.Repo, buildNumber : Vela.BuildNumber } -> msg
, cancelBuild : Vela.Org -> Vela.Repo -> Vela.BuildNumber -> msg
, cancelBuild : { org : Vela.Org, repo : Vela.Repo, buildNumber : Vela.BuildNumber } -> msg
, showHideActionsMenus : Maybe Int -> Maybe Bool -> msg
}

Expand Down Expand Up @@ -123,7 +123,6 @@ view shared props =
{ build = RemoteData.succeed build
, showFullTimestamps = props.showFullTimestamps
, actionsMenu = props.viewActionsMenu { build = build }
, showActionsMenuBool = True
}
)
builds
Expand Down
109 changes: 1 addition & 108 deletions src/elm/Components/Nav.elm
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,21 @@ SPDX-License-Identifier: Apache-2.0
--}


module Components.Nav exposing (restartBuildButton, view)
module Components.Nav exposing (view)

import Html
exposing
( Html
, button
, div
, nav
, text
)
import Html.Attributes
exposing
( attribute
, class
, classList
)
import Html.Events exposing (onClick)
import RemoteData exposing (WebData)
import Route exposing (Route)
import Shared
import Utils.Helpers as Util
import Vela



Expand All @@ -47,103 +40,3 @@ view shared route props =
[ props.crumbs
, div [ class "buttons" ] 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 ""
Loading

0 comments on commit 4a8f491

Please sign in to comment.