Skip to content

Commit 6050609

Browse files
plyr4Neal
authored and
Neal
committed
enhancement(settings): better UX/clarity on disabling events (#53)
* events logic for disabling all * cleanup, moving code to Settings.elm * feedback updates
1 parent cdc7799 commit 6050609

File tree

2 files changed

+62
-27
lines changed

2 files changed

+62
-27
lines changed

src/elm/Main.elm

+18-23
Original file line numberDiff line numberDiff line change
@@ -514,9 +514,16 @@ update msg model =
514514
body : Http.Body
515515
body =
516516
Http.jsonBody <| encodeUpdateRepository payload
517+
518+
action =
519+
if Pages.Settings.validEventsUpdate model.repo payload then
520+
Api.try (RepoUpdatedResponse field) (Api.updateRepository model org repo body)
521+
522+
else
523+
addErrorString "Could not disable webhook event. At least one event must be active."
517524
in
518525
( model
519-
, Api.try (RepoUpdatedResponse field) (Api.updateRepository model org repo body)
526+
, action
520527
)
521528

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

532539
action =
533-
if accessChanged model.repo payload then
540+
if Pages.Settings.validAccessUpdate model.repo payload then
534541
Api.try (RepoUpdatedResponse field) (Api.updateRepository model org repo body)
535542

536543
else
@@ -1716,6 +1723,15 @@ addError error =
17161723
|> perform identity
17171724

17181725

1726+
{-| addErrorString : takes a string and produces a Cmd Msg that invokes an action in the Errors module
1727+
-}
1728+
addErrorString : String -> Cmd Msg
1729+
addErrorString error =
1730+
succeed
1731+
(Error <| error)
1732+
|> perform identity
1733+
1734+
17191735
{-| toFailure : maps a detailed error into a WebData Failure value
17201736
-}
17211737
toFailure : Http.Detailed.Error String -> WebData a
@@ -1936,27 +1952,6 @@ shouldSearch filter =
19361952
String.length filter > 2
19371953

19381954

1939-
{-| refreshPage : takes model webdata repo and repo visibility update and determines if an update is necessary
1940-
-}
1941-
accessChanged : WebData Repository -> UpdateRepositoryPayload -> Bool
1942-
accessChanged originalRepo repoUpdate =
1943-
case originalRepo of
1944-
RemoteData.Success repo ->
1945-
case repoUpdate.visibility of
1946-
Just visibility ->
1947-
if repo.visibility /= visibility then
1948-
True
1949-
1950-
else
1951-
False
1952-
1953-
Nothing ->
1954-
False
1955-
1956-
_ ->
1957-
False
1958-
1959-
19601955
{-| clickHook : takes model org repo and build number and fetches build information from the api
19611956
-}
19621957
clickHook : Model -> Org -> Repo -> BuildNumber -> ( HookBuilds, Cmd Msg )

src/elm/Pages/Settings.elm

+44-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ module Pages.Settings exposing
1313
, timeout
1414
, timeoutInput
1515
, timeoutWarning
16+
, validAccessUpdate
17+
, validEventsUpdate
1618
, view
1719
)
1820

@@ -21,6 +23,7 @@ import Html
2123
( Html
2224
, button
2325
, div
26+
, em
2427
, input
2528
, label
2629
, p
@@ -43,7 +46,7 @@ import Html.Events exposing (onCheck, onClick, onInput)
4346
import RemoteData exposing (RemoteData(..), WebData)
4447
import SvgBuilder
4548
import Util
46-
import Vela exposing (Field, Repository)
49+
import Vela exposing (Field, Repository, UpdateRepositoryPayload)
4750

4851

4952

@@ -110,7 +113,7 @@ access : Repository -> RadioUpdate msg -> Html msg
110113
access repo msg =
111114
div [ class "category", Util.testAttribute "repo-settings-access" ]
112115
[ div [ class "header" ] [ span [ class "text" ] [ text "Access" ] ]
113-
, div [ class "description" ] [ text "Change who can access build information" ]
116+
, div [ class "description" ] [ text "Change who can access build information." ]
114117
, div [ class "inputs", class "radios" ]
115118
[ radio repo.visibility "private" "Private" <| msg repo.org repo.name "visibility" "private"
116119
, radio repo.visibility "public" "Any" <| msg repo.org repo.name "visibility" "public"
@@ -124,7 +127,8 @@ events : Repository -> CheckboxUpdate msg -> Html msg
124127
events repo msg =
125128
div [ class "category", Util.testAttribute "repo-settings-events" ]
126129
[ div [ class "header" ] [ span [ class "text" ] [ text "Webhook Events" ] ]
127-
, div [ class "description" ] [ text "Control which events on Git will trigger Vela pipelines" ]
130+
, div [ class "description" ] [ text "Control which events on Git will trigger Vela pipelines." ]
131+
, div [ class "description" ] [ em [] [ text "Active repositories must have at least one event enabled." ] ]
128132
, div [ class "inputs" ]
129133
[ checkbox "Push"
130134
"allow_push"
@@ -156,7 +160,7 @@ timeout : Maybe Int -> Repository -> NumberInputChange msg -> (String -> msg) ->
156160
timeout inTimeout repo clickMsg inputMsg =
157161
div [ class "category", Util.testAttribute "repo-settings-timeout" ]
158162
[ div [ class "header" ] [ span [ class "text" ] [ text "Build Timeout" ] ]
159-
, div [ class "description" ] [ text "Builds that reach this timeout setting will be stopped" ]
163+
, div [ class "description" ] [ text "Builds that reach this timeout setting will be stopped." ]
160164
, timeoutInput repo
161165
inTimeout
162166
inputMsg
@@ -300,6 +304,42 @@ validTimeout inTimeout repoTimeout =
300304
True
301305

302306

307+
{-| validAccessUpdate : takes model webdata repo and repo visibility update and determines if an update is necessary
308+
-}
309+
validAccessUpdate : WebData Repository -> UpdateRepositoryPayload -> Bool
310+
validAccessUpdate originalRepo repoUpdate =
311+
case originalRepo of
312+
RemoteData.Success repo ->
313+
case repoUpdate.visibility of
314+
Just visibility ->
315+
if repo.visibility /= visibility then
316+
True
317+
318+
else
319+
False
320+
321+
Nothing ->
322+
False
323+
324+
_ ->
325+
False
326+
327+
328+
{-| validEventsUpdate : takes model webdata repo and repo events update and determines if an update is necessary
329+
-}
330+
validEventsUpdate : WebData Repository -> UpdateRepositoryPayload -> Bool
331+
validEventsUpdate originalRepo repoUpdate =
332+
case originalRepo of
333+
RemoteData.Success repo ->
334+
Maybe.withDefault repo.allow_push repoUpdate.allow_push
335+
|| Maybe.withDefault repo.allow_pull repoUpdate.allow_pull
336+
|| Maybe.withDefault repo.allow_deploy repoUpdate.allow_deploy
337+
|| Maybe.withDefault repo.allow_tag repoUpdate.allow_tag
338+
339+
_ ->
340+
False
341+
342+
303343
{-| updateTip : takes field and returns the tip to display after the label.
304344
-}
305345
updateTip : Field -> Html msg

0 commit comments

Comments
 (0)