Skip to content

Commit

Permalink
refactor: cleaned up msgs and added grouping comments
Browse files Browse the repository at this point in the history
  • Loading branch information
plyr4 committed Jan 27, 2024
1 parent 3953b61 commit 1a4996d
Show file tree
Hide file tree
Showing 25 changed files with 200 additions and 146 deletions.
6 changes: 6 additions & 0 deletions src/elm/Layouts/Default.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -93,6 +96,7 @@ update msg model =
, Effect.none
)

-- HEADER
ShowHideIdentity show ->
( { model
| showIdentity =
Expand All @@ -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 }
Expand Down
8 changes: 7 additions & 1 deletion src/elm/Layouts/Default/Build.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -128,6 +132,7 @@ update props shared msg model =
]
)

-- BUILD
GetBuildResponse response ->
case response of
Ok ( _, build ) ->
Expand All @@ -142,6 +147,7 @@ update props shared msg model =
, Effect.handleHttpError { httpError = error }
)

-- REFRESH
Tick options ->
( model
, Effect.batch
Expand Down
2 changes: 2 additions & 0 deletions src/elm/Pages/Account/Login.elm
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ init () =

type Msg
= NoOp
-- AUTH
| SignInRequested


Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/elm/Pages/Account/Settings.elm
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ init () =

type Msg
= NoOp
-- ALERTS
| AddAlertCopiedToClipboard String


Expand All @@ -99,6 +100,7 @@ update msg model =
, Effect.none
)

-- ALERTS
AddAlertCopiedToClipboard contentCopied ->
( model
, Effect.addAlertSuccess { content = contentCopied, addToastIfUnique = False }
Expand Down
16 changes: 10 additions & 6 deletions src/elm/Pages/Account/SourceRepos.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -141,6 +143,7 @@ update shared msg model =
, Effect.none
)

-- SOURCE REPOS
GetUserSourceRepos isReload ->
( { model
| sourceRepos =
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions src/elm/Pages/Home.elm
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ init shared () =

type Msg
= NoOp
-- FAVORITES
| ToggleFavorite Vela.Org (Maybe Vela.Repo)
| SearchFavorites String

Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/elm/Pages/Org_.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ->
Expand All @@ -95,6 +98,7 @@ update shared route msg model =
, Effect.handleHttpError { httpError = error }
)

-- REFRESH
Tick options ->
( model
, Effect.getOrgRepos
Expand Down
36 changes: 21 additions & 15 deletions src/elm/Pages/Org_/Builds.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ->
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -221,6 +226,7 @@ update shared route msg model =
ShowHideFullTimestamps ->
( { model | showFullTimestamps = not model.showFullTimestamps }, Effect.none )

-- REFRESH
Tick options ->
( model
, Effect.getOrgBuilds
Expand Down
21 changes: 20 additions & 1 deletion src/elm/Pages/Org_/Repo_.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/elm/Pages/Org_/Repo_/Audit.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
24 changes: 12 additions & 12 deletions src/elm/Pages/Org_/Repo_/Build_/Graph.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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 ))
Expand All @@ -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 )
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/elm/Pages/Org_/Repo_/Deployments.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ->
Expand Down
Loading

0 comments on commit 1a4996d

Please sign in to comment.