From 1a4996dfc9e279c1aad2f766a75d12b27c133a24 Mon Sep 17 00:00:00 2001 From: davidvader Date: Sat, 27 Jan 2024 14:56:04 -0600 Subject: [PATCH] refactor: cleaned up msgs and added grouping comments --- src/elm/Layouts/Default.elm | 6 ++ src/elm/Layouts/Default/Build.elm | 8 +- src/elm/Pages/Account/Login.elm | 2 + src/elm/Pages/Account/Settings.elm | 2 + src/elm/Pages/Account/SourceRepos.elm | 16 +-- src/elm/Pages/Home.elm | 12 ++- src/elm/Pages/Org_.elm | 6 +- src/elm/Pages/Org_/Builds.elm | 36 ++++--- src/elm/Pages/Org_/Repo_.elm | 21 +++- src/elm/Pages/Org_/Repo_/Audit.elm | 4 +- src/elm/Pages/Org_/Repo_/Build_/Graph.elm | 24 ++--- src/elm/Pages/Org_/Repo_/Deployments.elm | 4 +- src/elm/Pages/Org_/Repo_/Deployments/Add.elm | 16 +-- src/elm/Pages/Org_/Repo_/Schedules.elm | 4 +- src/elm/Pages/Org_/Repo_/Schedules/Add.elm | 4 +- src/elm/Pages/Org_/Repo_/Schedules/Edit_.elm | 2 + src/elm/Pages/Org_/Repo_/Secrets.elm | 6 +- src/elm/Pages/Org_/Repo_/Secrets/Add.elm | 10 +- src/elm/Pages/Org_/Repo_/Secrets/Edit_.elm | 8 +- src/elm/Pages/Org_/Repo_/Settings.elm | 6 +- src/elm/Pages/Org_/Secrets.elm | 6 +- src/elm/Pages/Org_/Secrets/Add.elm | 10 +- src/elm/Pages/Org_/Secrets/Edit_.elm | 6 -- src/elm/Shared.elm | 108 +++++++++---------- src/elm/Shared/Msg.elm | 19 ++-- 25 files changed, 200 insertions(+), 146 deletions(-) diff --git a/src/elm/Layouts/Default.elm b/src/elm/Layouts/Default.elm index 382c42f2f..0647f0743 100644 --- a/src/elm/Layouts/Default.elm +++ b/src/elm/Layouts/Default.elm @@ -78,9 +78,12 @@ init shared _ = type Msg = NoOp + -- HEADER | ShowHideIdentity (Maybe Bool) | ShowHideHelp (Maybe Bool) + -- THEME | SetTheme Theme.Theme + -- ALERTS | AlertsUpdate (Alerting.Msg Alert) | CopyAlert String @@ -93,6 +96,7 @@ update msg model = , Effect.none ) + -- HEADER ShowHideIdentity show -> ( { model | showIdentity = @@ -119,9 +123,11 @@ update msg model = , Effect.none ) + -- THEME SetTheme theme -> ( model, Effect.setTheme { theme = theme } ) + -- ALERTS AlertsUpdate alert -> ( model , Effect.alertsUpdate { alert = alert } diff --git a/src/elm/Layouts/Default/Build.elm b/src/elm/Layouts/Default/Build.elm index b7990b4dc..fd427def4 100644 --- a/src/elm/Layouts/Default/Build.elm +++ b/src/elm/Layouts/Default/Build.elm @@ -99,14 +99,18 @@ init props shared _ = type Msg - = OnUrlChanged { from : Route (), to : Route () } + = --BROWSER + OnUrlChanged { from : Route (), to : Route () } + -- BUILD | GetBuildResponse (Result (Http.Detailed.Error String) ( Http.Metadata, Vela.Build )) + -- REFRESH | Tick { time : Time.Posix, interval : Interval.Interval } update : Props contentMsg -> Shared.Model -> Msg -> Model -> ( Model, Effect Msg ) update props shared msg model = case msg of + -- BROWSER OnUrlChanged _ -> ( model , Effect.batch @@ -128,6 +132,7 @@ update props shared msg model = ] ) + -- BUILD GetBuildResponse response -> case response of Ok ( _, build ) -> @@ -142,6 +147,7 @@ update props shared msg model = , Effect.handleHttpError { httpError = error } ) + -- REFRESH Tick options -> ( model , Effect.batch diff --git a/src/elm/Pages/Account/Login.elm b/src/elm/Pages/Account/Login.elm index 66bf0d05f..9874af410 100644 --- a/src/elm/Pages/Account/Login.elm +++ b/src/elm/Pages/Account/Login.elm @@ -76,6 +76,7 @@ init () = type Msg = NoOp + -- AUTH | SignInRequested @@ -87,6 +88,7 @@ update shared msg model = , Effect.none ) + -- AUTH SignInRequested -> ( model , (Browser.Navigation.load <| Api.Endpoint.toUrl shared.velaAPI Api.Endpoint.Login) |> Effect.sendCmd diff --git a/src/elm/Pages/Account/Settings.elm b/src/elm/Pages/Account/Settings.elm index 072f096d4..2139de120 100644 --- a/src/elm/Pages/Account/Settings.elm +++ b/src/elm/Pages/Account/Settings.elm @@ -88,6 +88,7 @@ init () = type Msg = NoOp + -- ALERTS | AddAlertCopiedToClipboard String @@ -99,6 +100,7 @@ update msg model = , Effect.none ) + -- ALERTS AddAlertCopiedToClipboard contentCopied -> ( model , Effect.addAlertSuccess { content = contentCopied, addToastIfUnique = False } diff --git a/src/elm/Pages/Account/SourceRepos.elm b/src/elm/Pages/Account/SourceRepos.elm index 34aaf1f4f..6709029f5 100644 --- a/src/elm/Pages/Account/SourceRepos.elm +++ b/src/elm/Pages/Account/SourceRepos.elm @@ -124,13 +124,15 @@ init () = type Msg = NoOp + -- SOURCE REPOS | GetUserSourceRepos Bool | GetUserSourceReposResponse (Result (Http.Detailed.Error String) ( Http.Metadata, Vela.SourceRepositories )) - | ToggleFavorite Vela.Org (Maybe String) | EnableRepos (List Vela.Repository) | EnableRepo Vela.Repository | EnableRepoResponse Vela.Repository (Result (Http.Detailed.Error String) ( Http.Metadata, Vela.Repository )) | UpdateSearchFilter Vela.Org String + -- FAVORITES + | ToggleFavorite Vela.Org (Maybe String) update : Shared.Model -> Msg -> Model -> ( Model, Effect Msg ) @@ -141,6 +143,7 @@ update shared msg model = , Effect.none ) + -- SOURCE REPOS GetUserSourceRepos isReload -> ( { model | sourceRepos = @@ -172,11 +175,6 @@ update shared msg model = , Effect.handleHttpError { httpError = error } ) - ToggleFavorite org maybeRepo -> - ( model - , Effect.updateFavorites { org = org, maybeRepo = maybeRepo, updateType = Favorites.Toggle } - ) - EnableRepos repos -> ( model , repos @@ -240,6 +238,12 @@ update shared msg model = , Effect.none ) + -- FAVORITES + ToggleFavorite org maybeRepo -> + ( model + , Effect.updateFavorites { org = org, maybeRepo = maybeRepo, updateType = Favorites.Toggle } + ) + -- SUBSCRIPTIONS diff --git a/src/elm/Pages/Home.elm b/src/elm/Pages/Home.elm index a5aa12b6b..e7e9cb85c 100644 --- a/src/elm/Pages/Home.elm +++ b/src/elm/Pages/Home.elm @@ -99,6 +99,7 @@ init shared () = type Msg = NoOp + -- FAVORITES | ToggleFavorite Vela.Org (Maybe Vela.Repo) | SearchFavorites String @@ -111,16 +112,17 @@ update msg model = , Effect.none ) - SearchFavorites searchBy -> - ( { model | favoritesFilter = searchBy } - , Effect.none - ) - + -- FAVORITES ToggleFavorite org maybeRepo -> ( model , Effect.updateFavorites { org = org, maybeRepo = maybeRepo, updateType = Favorites.Toggle } ) + SearchFavorites searchBy -> + ( { model | favoritesFilter = searchBy } + , Effect.none + ) + -- SUBSCRIPTIONS diff --git a/src/elm/Pages/Org_.elm b/src/elm/Pages/Org_.elm index 10064bbb9..fdca4d2a5 100644 --- a/src/elm/Pages/Org_.elm +++ b/src/elm/Pages/Org_.elm @@ -76,13 +76,16 @@ init shared route () = type Msg - = GetOrgReposResponse (Result (Http.Detailed.Error String) ( Http.Metadata, List Vela.Repository )) + = -- REPOS + GetOrgReposResponse (Result (Http.Detailed.Error String) ( Http.Metadata, List Vela.Repository )) + -- REFRESH | Tick { time : Time.Posix, interval : Interval.Interval } update : Shared.Model -> Route { org : String } -> Msg -> Model -> ( Model, Effect Msg ) update shared route msg model = case msg of + -- REPOS GetOrgReposResponse response -> case response of Ok ( _, repos ) -> @@ -95,6 +98,7 @@ update shared route msg model = , Effect.handleHttpError { httpError = error } ) + -- REFRESH Tick options -> ( model , Effect.getOrgRepos diff --git a/src/elm/Pages/Org_/Builds.elm b/src/elm/Pages/Org_/Builds.elm index 2be4287a7..daeef100b 100644 --- a/src/elm/Pages/Org_/Builds.elm +++ b/src/elm/Pages/Org_/Builds.elm @@ -91,21 +91,39 @@ init shared route () = type Msg - = GetOrgBuildsResponse (Result (Http.Detailed.Error String) ( Http.Metadata, List Vela.Build )) + = --BROWSER + OnEventQueryParameterChanged { from : Maybe String, to : Maybe String } + -- BUILDS + | 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 | CancelBuild Vela.Org Vela.Repo Vela.BuildNumber | ShowHideActionsMenus (Maybe Int) (Maybe Bool) - | OnEventQueryParameterChanged { from : Maybe String, to : Maybe String } | FilterByEvent (Maybe String) | ShowHideFullTimestamps + -- REFRESH | Tick { time : Time.Posix, interval : Interval.Interval } update : Shared.Model -> Route { org : String } -> Msg -> Model -> ( Model, Effect Msg ) update shared route msg model = case msg of + -- BROWSER + OnEventQueryParameterChanged options -> + ( model + , Effect.getOrgBuilds + { baseUrl = shared.velaAPI + , session = shared.session + , onResponse = GetOrgBuildsResponse + , pageNumber = Dict.get "page" route.query |> Maybe.andThen String.toInt + , perPage = Dict.get "perPage" route.query |> Maybe.andThen String.toInt + , maybeEvent = options.to + , org = route.params.org + } + ) + + -- BUILDS GetOrgBuildsResponse response -> case response of Ok ( meta, builds ) -> @@ -181,19 +199,6 @@ update shared route msg model = , Effect.none ) - OnEventQueryParameterChanged options -> - ( model - , Effect.getOrgBuilds - { baseUrl = shared.velaAPI - , session = shared.session - , onResponse = GetOrgBuildsResponse - , pageNumber = Dict.get "page" route.query |> Maybe.andThen String.toInt - , perPage = Dict.get "perPage" route.query |> Maybe.andThen String.toInt - , maybeEvent = options.to - , org = route.params.org - } - ) - FilterByEvent maybeEvent -> ( { model | builds = RemoteData.Loading @@ -221,6 +226,7 @@ update shared route msg model = ShowHideFullTimestamps -> ( { model | showFullTimestamps = not model.showFullTimestamps }, Effect.none ) + -- REFRESH Tick options -> ( model , Effect.getOrgBuilds diff --git a/src/elm/Pages/Org_/Repo_.elm b/src/elm/Pages/Org_/Repo_.elm index e66cbbfcc..3011d1ca2 100644 --- a/src/elm/Pages/Org_/Repo_.elm +++ b/src/elm/Pages/Org_/Repo_.elm @@ -86,7 +86,10 @@ init shared route () = type Msg - = GetRepoBuildsResponse (Result (Http.Detailed.Error String) ( Http.Metadata, List Vela.Build )) + = --BROWSER + OnEventQueryParameterChanged { from : Maybe String, to : Maybe String } + -- BUILDS + | 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 @@ -99,6 +102,22 @@ type Msg update : Shared.Model -> Route { org : String, repo : String } -> Msg -> Model -> ( Model, Effect Msg ) update shared route msg model = case msg of + -- BROWSER + OnEventQueryParameterChanged options -> + ( model + , Effect.getRepoBuilds + { baseUrl = shared.velaAPI + , session = shared.session + , onResponse = GetRepoBuildsResponse + , pageNumber = Dict.get "page" route.query |> Maybe.andThen String.toInt + , perPage = Dict.get "perPage" route.query |> Maybe.andThen String.toInt + , maybeEvent = options.to + , org = route.params.org + , repo = route.params.repo + } + ) + + -- BUILDS GetRepoBuildsResponse response -> Tuple.mapSecond (\_ -> Effect.sendSharedRepoBuildsResponse { response = response }) <| case response of diff --git a/src/elm/Pages/Org_/Repo_/Audit.elm b/src/elm/Pages/Org_/Repo_/Audit.elm index 09553be5f..d50d0bb4f 100644 --- a/src/elm/Pages/Org_/Repo_/Audit.elm +++ b/src/elm/Pages/Org_/Repo_/Audit.elm @@ -104,7 +104,8 @@ init shared route () = type Msg - = GetRepoHooksResponse (Result (Http.Detailed.Error String) ( Http.Metadata, List Vela.Hook )) + = -- HOOKS + GetRepoHooksResponse (Result (Http.Detailed.Error String) ( Http.Metadata, List Vela.Hook )) | RedeliverRepoHook { hook : Vela.Hook } | RedeliverRepoHookResponse (Result (Http.Detailed.Error String) ( Http.Metadata, String )) | GotoPage Int @@ -113,6 +114,7 @@ type Msg update : Shared.Model -> Route { org : String, repo : String } -> Msg -> Model -> ( Model, Effect Msg ) update shared route msg model = case msg of + -- HOOKS GetRepoHooksResponse response -> Tuple.mapSecond (\_ -> Effect.sendSharedRepoHooksResponse { response = response }) <| case response of diff --git a/src/elm/Pages/Org_/Repo_/Build_/Graph.elm b/src/elm/Pages/Org_/Repo_/Build_/Graph.elm index e658800e9..61a35dd43 100644 --- a/src/elm/Pages/Org_/Repo_/Build_/Graph.elm +++ b/src/elm/Pages/Org_/Repo_/Build_/Graph.elm @@ -111,6 +111,8 @@ init shared route () = type Msg = NoOp + -- BROWSER + | VisibilityChanged { visibility : Browser.Events.Visibility } -- GRAPH | RenderBuildGraph { freshDraw : Bool } | GetBuildGraphResponse { freshDraw : Bool } (Result (Http.Detailed.Error String) ( Http.Metadata, Vela.BuildGraph )) @@ -122,8 +124,6 @@ type Msg | OnBuildGraphInteraction Vela.BuildGraphInteraction -- REFRESH | Tick { interval : Interval.Interval, time : Time.Posix } - -- BROWSER - | VisibilityChanged { visibility : Browser.Events.Visibility } update : Shared.Model -> Route { org : String, repo : String, buildNumber : String } -> Msg -> Model -> ( Model, Effect Msg ) @@ -134,6 +134,16 @@ update shared route msg model = , Effect.none ) + -- BROWSER + VisibilityChanged options -> + ( model + , if options.visibility == Browser.Events.Visible then + Effect.sendMsg <| RenderBuildGraph { freshDraw = False } + + else + Effect.none + ) + -- GRAPH RenderBuildGraph options -> ( model @@ -261,16 +271,6 @@ update shared route msg model = , Effect.sendMsg <| Refresh { freshDraw = False, setToLoading = False, clear = False } ) - -- BROWSER - VisibilityChanged options -> - ( model - , if options.visibility == Browser.Events.Visible then - Effect.sendMsg <| RenderBuildGraph { freshDraw = False } - - else - Effect.none - ) - -- SUBSCRIPTIONS diff --git a/src/elm/Pages/Org_/Repo_/Deployments.elm b/src/elm/Pages/Org_/Repo_/Deployments.elm index b86663525..ed2e54a18 100644 --- a/src/elm/Pages/Org_/Repo_/Deployments.elm +++ b/src/elm/Pages/Org_/Repo_/Deployments.elm @@ -107,13 +107,15 @@ init shared route () = type Msg - = GetRepoDeploymentsResponse (Result (Http.Detailed.Error String) ( Http.Metadata, List Vela.Deployment )) + = -- DEPLOYMENTS + GetRepoDeploymentsResponse (Result (Http.Detailed.Error String) ( Http.Metadata, List Vela.Deployment )) | GotoPage Int update : Shared.Model -> Route { org : String, repo : String } -> Msg -> Model -> ( Model, Effect Msg ) update shared route msg model = case msg of + -- DEPLOYMENTS GetRepoDeploymentsResponse response -> case response of Ok ( meta, deployments ) -> diff --git a/src/elm/Pages/Org_/Repo_/Deployments/Add.elm b/src/elm/Pages/Org_/Repo_/Deployments/Add.elm index 9f47a6f0e..a98b2aede 100644 --- a/src/elm/Pages/Org_/Repo_/Deployments/Add.elm +++ b/src/elm/Pages/Org_/Repo_/Deployments/Add.elm @@ -108,7 +108,11 @@ init shared route () = type Msg - = GetRepoResponse (Result (Http.Detailed.Error String) ( Http.Metadata, Vela.Repository )) + = --BROWSER + OnQueryParamChanged { from : Maybe String, to : Maybe String } + -- REPO + | GetRepoResponse (Result (Http.Detailed.Error String) ( Http.Metadata, Vela.Repository )) + -- DEPLOYMENTS | AddDeploymentResponse (Result (Http.Detailed.Error String) ( Http.Metadata, Vela.Deployment )) | TargetOnInput String | RefOnInput String @@ -119,16 +123,16 @@ type Msg | AddParameter | RemoveParameter Vela.KeyValuePair | SubmitForm - | AddAlertCopiedToClipboard String - | OnQueryParamChanged { from : Maybe String, to : Maybe String } update : Shared.Model -> Route { org : String, repo : String } -> Msg -> Model -> ( Model, Effect Msg ) update shared route msg model = case msg of + -- BROWSER OnQueryParamChanged _ -> ( model, Effect.none ) + -- REPO GetRepoResponse response -> case response of Ok ( _, repo ) -> @@ -141,6 +145,7 @@ update shared route msg model = , Effect.handleHttpError { httpError = error } ) + -- DEPLOYMENTS AddDeploymentResponse response -> case response of Ok ( _, deployment ) -> @@ -242,11 +247,6 @@ update shared route msg model = } ) - AddAlertCopiedToClipboard contentCopied -> - ( model - , Effect.addAlertSuccess { content = contentCopied, addToastIfUnique = False } - ) - -- SUBSCRIPTIONS diff --git a/src/elm/Pages/Org_/Repo_/Schedules.elm b/src/elm/Pages/Org_/Repo_/Schedules.elm index 0007fe080..c3dba1b48 100644 --- a/src/elm/Pages/Org_/Repo_/Schedules.elm +++ b/src/elm/Pages/Org_/Repo_/Schedules.elm @@ -88,13 +88,15 @@ init shared route () = type Msg - = GetRepoSchedulesResponse (Result (Http.Detailed.Error String) ( Http.Metadata, List Vela.Schedule )) + = -- SCHEDULES + GetRepoSchedulesResponse (Result (Http.Detailed.Error String) ( Http.Metadata, List Vela.Schedule )) | GotoPage Int update : Shared.Model -> Route { org : String, repo : String } -> Msg -> Model -> ( Model, Effect Msg ) update shared route msg model = case msg of + -- SCHEDULES GetRepoSchedulesResponse response -> case response of Ok ( meta, schedules ) -> diff --git a/src/elm/Pages/Org_/Repo_/Schedules/Add.elm b/src/elm/Pages/Org_/Repo_/Schedules/Add.elm index 014c86d28..006586fe2 100644 --- a/src/elm/Pages/Org_/Repo_/Schedules/Add.elm +++ b/src/elm/Pages/Org_/Repo_/Schedules/Add.elm @@ -75,7 +75,8 @@ init shared () = type Msg - = AddRepoScheduleResponse (Result (Http.Detailed.Error String) ( Http.Metadata, Vela.Schedule )) + = -- SCHEDULES + AddRepoScheduleResponse (Result (Http.Detailed.Error String) ( Http.Metadata, Vela.Schedule )) | NameOnInput String | EntryOnInput String | BranchOnInput String @@ -86,6 +87,7 @@ type Msg update : Shared.Model -> Route { org : String, repo : String } -> Msg -> Model -> ( Model, Effect Msg ) update shared route msg model = case msg of + -- SCHEDULES AddRepoScheduleResponse response -> case response of Ok ( _, schedule ) -> diff --git a/src/elm/Pages/Org_/Repo_/Schedules/Edit_.elm b/src/elm/Pages/Org_/Repo_/Schedules/Edit_.elm index 1948bb066..7aa35f957 100644 --- a/src/elm/Pages/Org_/Repo_/Schedules/Edit_.elm +++ b/src/elm/Pages/Org_/Repo_/Schedules/Edit_.elm @@ -85,6 +85,7 @@ init shared route () = type Msg = NoOp + -- SCHEDULES | GetRepoScheduleResponse (Result (Http.Detailed.Error String) ( Http.Metadata, Vela.Schedule )) | UpdateRepoScheduleResponse (Result (Http.Detailed.Error String) ( Http.Metadata, Vela.Schedule )) | EntryOnInput String @@ -101,6 +102,7 @@ update shared route msg model = , Effect.none ) + -- SCHEDULES GetRepoScheduleResponse response -> case response of Ok ( _, schedule ) -> diff --git a/src/elm/Pages/Org_/Repo_/Secrets.elm b/src/elm/Pages/Org_/Repo_/Secrets.elm index 4437b141f..c4a3dd8e9 100644 --- a/src/elm/Pages/Org_/Repo_/Secrets.elm +++ b/src/elm/Pages/Org_/Repo_/Secrets.elm @@ -87,14 +87,17 @@ init shared route () = type Msg - = GetRepoSecretsResponse (Result (Http.Detailed.Error String) ( Http.Metadata, List Vela.Secret )) + = -- SECRETS + GetRepoSecretsResponse (Result (Http.Detailed.Error String) ( Http.Metadata, List Vela.Secret )) | GotoPage Int + -- ALERTS | AddAlertCopiedToClipboard String update : Shared.Model -> Route { org : String, repo : String } -> Msg -> Model -> ( Model, Effect Msg ) update shared route msg model = case msg of + -- SECRETS GetRepoSecretsResponse response -> case response of Ok ( meta, secrets ) -> @@ -131,6 +134,7 @@ update shared route msg model = ] ) + -- ALERTS AddAlertCopiedToClipboard contentCopied -> ( model , Effect.addAlertSuccess { content = contentCopied, addToastIfUnique = False } diff --git a/src/elm/Pages/Org_/Repo_/Secrets/Add.elm b/src/elm/Pages/Org_/Repo_/Secrets/Add.elm index 956884998..02cf2cad8 100644 --- a/src/elm/Pages/Org_/Repo_/Secrets/Add.elm +++ b/src/elm/Pages/Org_/Repo_/Secrets/Add.elm @@ -79,7 +79,8 @@ init shared () = type Msg - = AddSecretResponse (Result (Http.Detailed.Error String) ( Http.Metadata, Vela.Secret )) + = -- SECRETS + AddSecretResponse (Result (Http.Detailed.Error String) ( Http.Metadata, Vela.Secret )) | NameOnInput String | ValueOnInput String | ImageOnInput String @@ -88,12 +89,12 @@ type Msg | RemoveImage String | AllowCommandsOnClick String | SubmitForm - | AddAlertCopiedToClipboard String update : Shared.Model -> Route { org : String, repo : String } -> Msg -> Model -> ( Model, Effect Msg ) update shared route msg model = case msg of + -- SECRETS AddSecretResponse response -> case response of Ok ( _, secret ) -> @@ -195,11 +196,6 @@ update shared route msg model = } ) - AddAlertCopiedToClipboard contentCopied -> - ( model - , Effect.addAlertSuccess { content = contentCopied, addToastIfUnique = False } - ) - -- SUBSCRIPTIONS diff --git a/src/elm/Pages/Org_/Repo_/Secrets/Edit_.elm b/src/elm/Pages/Org_/Repo_/Secrets/Edit_.elm index ba5c43511..964c28bca 100644 --- a/src/elm/Pages/Org_/Repo_/Secrets/Edit_.elm +++ b/src/elm/Pages/Org_/Repo_/Secrets/Edit_.elm @@ -90,6 +90,7 @@ init shared route () = type Msg = NoOp + -- SECRETS | GetSecretResponse (Result (Http.Detailed.Error String) ( Http.Metadata, Vela.Secret )) | UpdateSecretResponse (Result (Http.Detailed.Error String) ( Http.Metadata, Vela.Secret )) | ValueOnInput String @@ -99,7 +100,6 @@ type Msg | RemoveImage String | AllowCommandsOnClick String | SubmitForm - | AddAlertCopiedToClipboard String update : Shared.Model -> Route { org : String, repo : String, name : String } -> Msg -> Model -> ( Model, Effect Msg ) @@ -108,6 +108,7 @@ update shared route msg model = NoOp -> ( model, Effect.none ) + -- SECRETS GetSecretResponse response -> case response of Ok ( _, secret ) -> @@ -223,11 +224,6 @@ update shared route msg model = } ) - AddAlertCopiedToClipboard contentCopied -> - ( model - , Effect.addAlertSuccess { content = contentCopied, addToastIfUnique = False } - ) - -- SUBSCRIPTIONS diff --git a/src/elm/Pages/Org_/Repo_/Settings.elm b/src/elm/Pages/Org_/Repo_/Settings.elm index 4a3828d2e..6c94f6c24 100644 --- a/src/elm/Pages/Org_/Repo_/Settings.elm +++ b/src/elm/Pages/Org_/Repo_/Settings.elm @@ -83,7 +83,8 @@ init shared route () = type Msg - = GetRepoResponse (Result (Http.Detailed.Error String) ( Http.Metadata, Vela.Repository )) + = --REPO + GetRepoResponse (Result (Http.Detailed.Error String) ( Http.Metadata, Vela.Repository )) | AllowEventsUpdate String Bool | AccessUpdate String | ForkPolicyUpdate String @@ -98,12 +99,14 @@ type Msg | Chown | Repair | PipelineTypeUpdate String + -- ALERTS | AddAlertCopiedToClipboard String update : Shared.Model -> Route { org : String, repo : String } -> Msg -> Model -> ( Model, Effect Msg ) update shared route msg model = case msg of + -- REPO GetRepoResponse response -> case response of Ok ( _, repo ) -> @@ -204,6 +207,7 @@ update shared route msg model = , Effect.none ) + -- ALERTS AddAlertCopiedToClipboard contentCopied -> ( model , Effect.addAlertSuccess { content = contentCopied, addToastIfUnique = False } diff --git a/src/elm/Pages/Org_/Secrets.elm b/src/elm/Pages/Org_/Secrets.elm index 2a3b6f465..e0c446e56 100644 --- a/src/elm/Pages/Org_/Secrets.elm +++ b/src/elm/Pages/Org_/Secrets.elm @@ -85,14 +85,17 @@ init shared route () = type Msg - = GetOrgSecretsResponse (Result (Http.Detailed.Error String) ( Http.Metadata, List Vela.Secret )) + = -- SECRETS + GetOrgSecretsResponse (Result (Http.Detailed.Error String) ( Http.Metadata, List Vela.Secret )) | GotoPage Int + -- ALERTS | AddAlertCopiedToClipboard String update : Shared.Model -> Route { org : String } -> Msg -> Model -> ( Model, Effect Msg ) update shared route msg model = case msg of + -- SECRETS GetOrgSecretsResponse response -> case response of Ok ( meta, secrets ) -> @@ -128,6 +131,7 @@ update shared route msg model = ] ) + -- ALERTS AddAlertCopiedToClipboard contentCopied -> ( model , Effect.addAlertSuccess { content = contentCopied, addToastIfUnique = False } diff --git a/src/elm/Pages/Org_/Secrets/Add.elm b/src/elm/Pages/Org_/Secrets/Add.elm index c49981a0c..bf30cb512 100644 --- a/src/elm/Pages/Org_/Secrets/Add.elm +++ b/src/elm/Pages/Org_/Secrets/Add.elm @@ -79,7 +79,8 @@ init shared () = type Msg - = AddSecretResponse (Result (Http.Detailed.Error String) ( Http.Metadata, Vela.Secret )) + = -- SECRETS + AddSecretResponse (Result (Http.Detailed.Error String) ( Http.Metadata, Vela.Secret )) | NameOnInput String | ValueOnInput String | ImageOnInput String @@ -88,12 +89,12 @@ type Msg | RemoveImage String | AllowCommandsOnClick String | SubmitForm - | AddAlertCopiedToClipboard String update : Shared.Model -> Route { org : String } -> Msg -> Model -> ( Model, Effect Msg ) update shared route msg model = case msg of + -- SECRETS AddSecretResponse response -> case response of Ok ( _, secret ) -> @@ -194,11 +195,6 @@ update shared route msg model = } ) - AddAlertCopiedToClipboard contentCopied -> - ( model - , Effect.addAlertSuccess { content = contentCopied, addToastIfUnique = False } - ) - -- SUBSCRIPTIONS diff --git a/src/elm/Pages/Org_/Secrets/Edit_.elm b/src/elm/Pages/Org_/Secrets/Edit_.elm index a1d4f01c8..62f00484c 100644 --- a/src/elm/Pages/Org_/Secrets/Edit_.elm +++ b/src/elm/Pages/Org_/Secrets/Edit_.elm @@ -98,7 +98,6 @@ type Msg | RemoveImage String | AllowCommandsOnClick String | SubmitForm - | AddAlertCopiedToClipboard String update : Shared.Model -> Route { org : String, name : String } -> Msg -> Model -> ( Model, Effect Msg ) @@ -223,11 +222,6 @@ update shared route msg model = } ) - AddAlertCopiedToClipboard contentCopied -> - ( model - , Effect.addAlertSuccess { content = contentCopied, addToastIfUnique = False } - ) - -- SUBSCRIPTIONS diff --git a/src/elm/Shared.elm b/src/elm/Shared.elm index 94d7ffde9..fdf8e3d61 100644 --- a/src/elm/Shared.elm +++ b/src/elm/Shared.elm @@ -189,6 +189,54 @@ update route msg model = , Effect.none ) + -- BROWSER + Shared.Msg.FocusOn options -> + ( model + , Browser.Dom.focus options.target |> Task.attempt Shared.Msg.FocusResult |> Effect.sendCmd + ) + + Shared.Msg.FocusResult result -> + case result of + Err (Browser.Dom.NotFound _) -> + ( model, Effect.none ) + + Ok _ -> + ( model, Effect.none ) + + Shared.Msg.DownloadFile options -> + ( model + , File.Download.string + options.filename + "text" + (options.map options.content) + |> Effect.sendCmd + ) + + Shared.Msg.OnKeyDown options -> + ( case options.key of + "Shift" -> + { model | shift = True } + + _ -> + model + , Effect.none + ) + + Shared.Msg.OnKeyUp options -> + ( case options.key of + "Shift" -> + { model | shift = False } + + _ -> + model + , Effect.none + ) + + Shared.Msg.VisibilityChanged options -> + ( { model | visibility = options.visibility, shift = False } + , Effect.none + ) + -- TIME Shared.Msg.AdjustTimeZone options -> ( { model | zone = options.zone } @@ -200,15 +248,6 @@ update route msg model = , Effect.none ) - -- REFRESH - Shared.Msg.Tick options -> - case options.interval of - Interval.OneSecond -> - ( { model | time = options.time }, Effect.none ) - - Interval.FiveSeconds -> - ( model, Effect.none ) - -- AUTH Shared.Msg.FinishAuthentication options -> ( model @@ -553,54 +592,15 @@ update route msg model = ] ) - -- DOM - Shared.Msg.FocusOn options -> - ( model - , Browser.Dom.focus options.target |> Task.attempt Shared.Msg.FocusResult |> Effect.sendCmd - ) - - Shared.Msg.FocusResult result -> - case result of - Err (Browser.Dom.NotFound _) -> - ( model, Effect.none ) + -- REFRESH + Shared.Msg.Tick options -> + case options.interval of + Interval.OneSecond -> + ( { model | time = options.time }, Effect.none ) - Ok _ -> + Interval.FiveSeconds -> ( model, Effect.none ) - Shared.Msg.DownloadFile options -> - ( model - , File.Download.string - options.filename - "text" - (options.map options.content) - |> Effect.sendCmd - ) - - Shared.Msg.OnKeyDown options -> - ( case options.key of - "Shift" -> - { model | shift = True } - - _ -> - model - , Effect.none - ) - - Shared.Msg.OnKeyUp options -> - ( case options.key of - "Shift" -> - { model | shift = False } - - _ -> - model - , Effect.none - ) - - Shared.Msg.VisibilityChanged options -> - ( { model | visibility = options.visibility, shift = False } - , Effect.none - ) - subscriptions : Route () -> Model -> Sub Msg subscriptions _ model = diff --git a/src/elm/Shared/Msg.elm b/src/elm/Shared/Msg.elm index eec266be5..ea79b296d 100644 --- a/src/elm/Shared/Msg.elm +++ b/src/elm/Shared/Msg.elm @@ -21,11 +21,16 @@ import Vela type Msg = NoOp + -- BROWSER + | FocusOn { target : String } + | FocusResult (Result Browser.Dom.Error ()) + | DownloadFile { filename : String, content : String, map : String -> String } + | OnKeyDown { key : String } + | OnKeyUp { key : String } + | VisibilityChanged { visibility : Browser.Events.Visibility } -- TIME | AdjustTimeZone { zone : Time.Zone } | AdjustTime { time : Time.Posix } - --REFRESH - | Tick { interval : Interval.Interval, time : Time.Posix } -- AUTH | FinishAuthentication { code : Maybe String, state : Maybe String } | TokenResponse (Result (Http.Detailed.Error String) ( Http.Metadata, Auth.Jwt.JwtAccessToken )) @@ -54,11 +59,5 @@ type Msg | AlertsUpdate (Alerting.Msg Alert) -- ERRORS | HandleHttpError (Http.Detailed.Error String) - -- DOM - | FocusOn { target : String } - | FocusResult (Result Browser.Dom.Error ()) - -- BROWSER - | DownloadFile { filename : String, content : String, map : String -> String } - | OnKeyDown { key : String } - | OnKeyUp { key : String } - | VisibilityChanged { visibility : Browser.Events.Visibility } + --REFRESH + | Tick { interval : Interval.Interval, time : Time.Posix }