Skip to content

Commit

Permalink
enhancement(settings): better UX/clarity on disabling events (#53)
Browse files Browse the repository at this point in the history
* events logic for disabling all

* cleanup, moving code to Settings.elm

* feedback updates
  • Loading branch information
plyr4 authored and Neal committed Dec 18, 2019
1 parent cdc7799 commit 6050609
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 27 deletions.
41 changes: 18 additions & 23 deletions src/elm/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -514,9 +514,16 @@ update msg model =
body : Http.Body
body =
Http.jsonBody <| encodeUpdateRepository payload

action =
if Pages.Settings.validEventsUpdate model.repo payload then
Api.try (RepoUpdatedResponse field) (Api.updateRepository model org repo body)

else
addErrorString "Could not disable webhook event. At least one event must be active."
in
( model
, Api.try (RepoUpdatedResponse field) (Api.updateRepository model org repo body)
, action
)

UpdateRepoAccess org repo field value ->
Expand All @@ -530,7 +537,7 @@ update msg model =
Http.jsonBody <| encodeUpdateRepository payload

action =
if accessChanged model.repo payload then
if Pages.Settings.validAccessUpdate model.repo payload then
Api.try (RepoUpdatedResponse field) (Api.updateRepository model org repo body)

else
Expand Down Expand Up @@ -1716,6 +1723,15 @@ addError error =
|> perform identity


{-| addErrorString : takes a string and produces a Cmd Msg that invokes an action in the Errors module
-}
addErrorString : String -> Cmd Msg
addErrorString error =
succeed
(Error <| error)
|> perform identity


{-| toFailure : maps a detailed error into a WebData Failure value
-}
toFailure : Http.Detailed.Error String -> WebData a
Expand Down Expand Up @@ -1936,27 +1952,6 @@ shouldSearch filter =
String.length filter > 2


{-| refreshPage : takes model webdata repo and repo visibility update and determines if an update is necessary
-}
accessChanged : WebData Repository -> UpdateRepositoryPayload -> Bool
accessChanged originalRepo repoUpdate =
case originalRepo of
RemoteData.Success repo ->
case repoUpdate.visibility of
Just visibility ->
if repo.visibility /= visibility then
True

else
False

Nothing ->
False

_ ->
False


{-| clickHook : takes model org repo and build number and fetches build information from the api
-}
clickHook : Model -> Org -> Repo -> BuildNumber -> ( HookBuilds, Cmd Msg )
Expand Down
48 changes: 44 additions & 4 deletions src/elm/Pages/Settings.elm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ module Pages.Settings exposing
, timeout
, timeoutInput
, timeoutWarning
, validAccessUpdate
, validEventsUpdate
, view
)

Expand All @@ -21,6 +23,7 @@ import Html
( Html
, button
, div
, em
, input
, label
, p
Expand All @@ -43,7 +46,7 @@ import Html.Events exposing (onCheck, onClick, onInput)
import RemoteData exposing (RemoteData(..), WebData)
import SvgBuilder
import Util
import Vela exposing (Field, Repository)
import Vela exposing (Field, Repository, UpdateRepositoryPayload)



Expand Down Expand Up @@ -110,7 +113,7 @@ access : Repository -> RadioUpdate msg -> Html msg
access repo msg =
div [ class "category", Util.testAttribute "repo-settings-access" ]
[ div [ class "header" ] [ span [ class "text" ] [ text "Access" ] ]
, div [ class "description" ] [ text "Change who can access build information" ]
, div [ class "description" ] [ text "Change who can access build information." ]
, div [ class "inputs", class "radios" ]
[ radio repo.visibility "private" "Private" <| msg repo.org repo.name "visibility" "private"
, radio repo.visibility "public" "Any" <| msg repo.org repo.name "visibility" "public"
Expand All @@ -124,7 +127,8 @@ events : Repository -> CheckboxUpdate msg -> Html msg
events repo msg =
div [ class "category", Util.testAttribute "repo-settings-events" ]
[ div [ class "header" ] [ span [ class "text" ] [ text "Webhook Events" ] ]
, div [ class "description" ] [ text "Control which events on Git will trigger Vela pipelines" ]
, div [ class "description" ] [ text "Control which events on Git will trigger Vela pipelines." ]
, div [ class "description" ] [ em [] [ text "Active repositories must have at least one event enabled." ] ]
, div [ class "inputs" ]
[ checkbox "Push"
"allow_push"
Expand Down Expand Up @@ -156,7 +160,7 @@ timeout : Maybe Int -> Repository -> NumberInputChange msg -> (String -> msg) ->
timeout inTimeout repo clickMsg inputMsg =
div [ class "category", Util.testAttribute "repo-settings-timeout" ]
[ div [ class "header" ] [ span [ class "text" ] [ text "Build Timeout" ] ]
, div [ class "description" ] [ text "Builds that reach this timeout setting will be stopped" ]
, div [ class "description" ] [ text "Builds that reach this timeout setting will be stopped." ]
, timeoutInput repo
inTimeout
inputMsg
Expand Down Expand Up @@ -300,6 +304,42 @@ validTimeout inTimeout repoTimeout =
True


{-| validAccessUpdate : takes model webdata repo and repo visibility update and determines if an update is necessary
-}
validAccessUpdate : WebData Repository -> UpdateRepositoryPayload -> Bool
validAccessUpdate originalRepo repoUpdate =
case originalRepo of
RemoteData.Success repo ->
case repoUpdate.visibility of
Just visibility ->
if repo.visibility /= visibility then
True

else
False

Nothing ->
False

_ ->
False


{-| validEventsUpdate : takes model webdata repo and repo events update and determines if an update is necessary
-}
validEventsUpdate : WebData Repository -> UpdateRepositoryPayload -> Bool
validEventsUpdate originalRepo repoUpdate =
case originalRepo of
RemoteData.Success repo ->
Maybe.withDefault repo.allow_push repoUpdate.allow_push
|| Maybe.withDefault repo.allow_pull repoUpdate.allow_pull
|| Maybe.withDefault repo.allow_deploy repoUpdate.allow_deploy
|| Maybe.withDefault repo.allow_tag repoUpdate.allow_tag

_ ->
False


{-| updateTip : takes field and returns the tip to display after the label.
-}
updateTip : Field -> Html msg
Expand Down

0 comments on commit 6050609

Please sign in to comment.