Skip to content

Commit

Permalink
refactor: auto refresh tweaks, organize secrets data
Browse files Browse the repository at this point in the history
  • Loading branch information
plyr4 committed Feb 2, 2024
1 parent 13c512b commit eb25600
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/elm/Pages/Org_/Repo_/Build_/Graph.elm
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,11 @@ subscriptions model =
Sub.batch
[ Interop.onGraphInteraction
(Vela.decodeOnGraphInteraction OnBuildGraphInteraction NoOp)
, Interval.tickEveryOneSecond Tick

-- on visiblity changed, same as shared
, Browser.Events.onVisibilityChange
(\visibility -> VisibilityChanged { visibility = visibility })
, Interval.tickEveryOneSecond Tick
]


Expand Down
5 changes: 2 additions & 3 deletions src/elm/Pages/Org_/Repo_/Schedules.elm
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import Components.Table
import Dict
import Effect exposing (Effect)
import FeatherIcons
import Html exposing (..)
import Html.Attributes exposing (..)
import Html exposing (Html, a, div, span, text, tr)
import Html.Attributes exposing (class)
import Http
import Http.Detailed
import Layouts
Expand All @@ -26,7 +26,6 @@ import Shared
import Svg.Attributes
import Time
import Utils.Errors
import Utils.Favorites as Favorites
import Utils.Helpers as Util
import Utils.Interval as Interval
import Vela
Expand Down
2 changes: 1 addition & 1 deletion src/elm/Pages/Secrets/Engine_/Org/Org_.elm
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ update shared route msg model =

Err error ->
( { model | sharedSecrets = Utils.Errors.toFailure error }
, Effect.handleHttpError { httpError = error }
, Effect.none
)

GotoPage pageNumber ->
Expand Down
70 changes: 35 additions & 35 deletions src/elm/Pages/Secrets/Engine_/Repo/Org_/Repo_.elm
Original file line number Diff line number Diff line change
Expand Up @@ -68,37 +68,37 @@ toLayout user route model =


type alias Model =
{ orgSecrets : WebData (List Vela.Secret)
, repoSecrets : WebData (List Vela.Secret)
{ repoSecrets : WebData (List Vela.Secret)
, orgSecrets : WebData (List Vela.Secret)
, pager : List WebLink
}


init : Shared.Model -> Route { engine : String, org : String, repo : String } -> () -> ( Model, Effect Msg )
init shared route () =
( { orgSecrets = RemoteData.Loading
, repoSecrets = RemoteData.Loading
( { repoSecrets = RemoteData.Loading
, orgSecrets = RemoteData.Loading
, pager = []
}
, Effect.batch
[ Effect.getOrgSecrets
[ Effect.getRepoSecrets
{ baseUrl = shared.velaAPIBaseURL
, session = shared.session
, onResponse = GetOrgSecretsResponse
, pageNumber = Nothing
, perPage = Nothing
, onResponse = GetRepoSecretsResponse
, pageNumber = Dict.get "page" route.query |> Maybe.andThen String.toInt
, perPage = Dict.get "perPage" route.query |> Maybe.andThen String.toInt
, engine = route.params.engine
, org = route.params.org
, repo = route.params.repo
}
, Effect.getRepoSecrets
, Effect.getOrgSecrets
{ baseUrl = shared.velaAPIBaseURL
, session = shared.session
, onResponse = GetRepoSecretsResponse
, pageNumber = Dict.get "page" route.query |> Maybe.andThen String.toInt
, perPage = Dict.get "perPage" route.query |> Maybe.andThen String.toInt
, onResponse = GetOrgSecretsResponse
, pageNumber = Nothing
, perPage = Nothing
, engine = route.params.engine
, org = route.params.org
, repo = route.params.repo
}
]
)
Expand All @@ -110,8 +110,8 @@ init shared route () =

type Msg
= -- SECRETS
GetOrgSecretsResponse (Result (Http.Detailed.Error String) ( Http.Metadata, List Vela.Secret ))
| GetRepoSecretsResponse (Result (Http.Detailed.Error String) ( Http.Metadata, List Vela.Secret ))
GetRepoSecretsResponse (Result (Http.Detailed.Error String) ( Http.Metadata, List Vela.Secret ))
| GetOrgSecretsResponse (Result (Http.Detailed.Error String) ( Http.Metadata, List Vela.Secret ))
| GotoPage Int
-- ALERTS
| AddAlertCopiedToClipboard String
Expand All @@ -123,33 +123,33 @@ update : Shared.Model -> Route { engine : String, org : String, repo : String }
update shared route msg model =
case msg of
-- SECRETS
GetOrgSecretsResponse response ->
GetRepoSecretsResponse response ->
case response of
Ok ( _, secrets ) ->
Ok ( meta, secrets ) ->
( { model
| orgSecrets = RemoteData.Success secrets
| repoSecrets = RemoteData.Success secrets
, pager = Api.Pagination.get meta.headers
}
, Effect.none
)

Err error ->
( { model | orgSecrets = Utils.Errors.toFailure error }
, Effect.none
( { model | repoSecrets = Utils.Errors.toFailure error }
, Effect.handleHttpError { httpError = error }
)

GetRepoSecretsResponse response ->
GetOrgSecretsResponse response ->
case response of
Ok ( meta, secrets ) ->
Ok ( _, secrets ) ->
( { model
| repoSecrets = RemoteData.Success secrets
, pager = Api.Pagination.get meta.headers
| orgSecrets = RemoteData.Success secrets
}
, Effect.none
)

Err error ->
( { model | repoSecrets = Utils.Errors.toFailure error }
, Effect.handleHttpError { httpError = error }
( { model | orgSecrets = Utils.Errors.toFailure error }
, Effect.none
)

GotoPage pageNumber ->
Expand Down Expand Up @@ -184,24 +184,24 @@ update shared route msg model =
Tick options ->
( model
, Effect.batch
[ Effect.getOrgSecrets
[ Effect.getRepoSecrets
{ baseUrl = shared.velaAPIBaseURL
, session = shared.session
, onResponse = GetOrgSecretsResponse
, pageNumber = Nothing
, perPage = Nothing
, onResponse = GetRepoSecretsResponse
, pageNumber = Dict.get "page" route.query |> Maybe.andThen String.toInt
, perPage = Dict.get "perPage" route.query |> Maybe.andThen String.toInt
, engine = route.params.engine
, org = route.params.org
, repo = route.params.repo
}
, Effect.getRepoSecrets
, Effect.getOrgSecrets
{ baseUrl = shared.velaAPIBaseURL
, session = shared.session
, onResponse = GetRepoSecretsResponse
, pageNumber = Dict.get "page" route.query |> Maybe.andThen String.toInt
, perPage = Dict.get "perPage" route.query |> Maybe.andThen String.toInt
, onResponse = GetOrgSecretsResponse
, pageNumber = Nothing
, perPage = Nothing
, engine = route.params.engine
, org = route.params.org
, repo = route.params.repo
}
]
)
Expand Down

0 comments on commit eb25600

Please sign in to comment.