Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve shouldRefresh logic for steps/services #711

Merged
merged 2 commits into from
Aug 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 35 additions & 27 deletions src/elm/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2373,7 +2373,7 @@ refreshData model =
-}
refreshBuild : Model -> Org -> Repo -> BuildNumber -> Cmd Msg
refreshBuild model org repo buildNumber =
if shouldRefresh model.repo.build then
if shouldRefresh model.page model.repo.build then
getBuild model org repo buildNumber

else
Expand All @@ -2384,7 +2384,7 @@ refreshBuild model org repo buildNumber =
-}
refreshBuildSteps : Model -> Org -> Repo -> BuildNumber -> FocusFragment -> Cmd Msg
refreshBuildSteps model org repo buildNumber focusFragment =
if shouldRefresh model.repo.build then
if shouldRefresh model.page model.repo.build then
getAllBuildSteps model org repo buildNumber focusFragment True

else
Expand All @@ -2395,7 +2395,7 @@ refreshBuildSteps model org repo buildNumber focusFragment =
-}
refreshBuildServices : Model -> Org -> Repo -> BuildNumber -> FocusFragment -> Cmd Msg
refreshBuildServices model org repo buildNumber focusFragment =
if shouldRefresh model.repo.build then
if shouldRefresh model.page model.repo.build then
getAllBuildServices model org repo buildNumber focusFragment True

else
Expand All @@ -2404,39 +2404,47 @@ refreshBuildServices model org repo buildNumber focusFragment =

{-| shouldRefresh : takes build and returns true if a refresh is required
-}
shouldRefresh : BuildModel -> Bool
shouldRefresh build =
shouldRefresh : Page -> BuildModel -> Bool
shouldRefresh page build =
case build.build of
Success bld ->
-- build is incomplete
(not <| isComplete bld.status)
-- any steps or services are incomplete
|| (case build.steps.steps of
Success steps ->
List.any (\s -> not <| isComplete s.status) steps
|| (case page of
-- check steps when viewing build tab
Pages.Build _ _ _ _ ->
case build.steps.steps of
Success steps ->
List.any (\s -> not <| isComplete s.status) steps

NotAsked ->
True
-- do not use unsuccessful states to dictate refresh
NotAsked ->
False

-- do not refresh Failed or Loading steps
Failure _ ->
False
Failure _ ->
False

Loading ->
False
)
|| (case build.services.services of
Success services ->
List.any (\s -> not <| isComplete s.status) services
Loading ->
False

NotAsked ->
True
-- check services when viewing services tab
Pages.BuildServices _ _ _ _ ->
case build.services.services of
Success services ->
List.any (\s -> not <| isComplete s.status) services

-- do not refresh Failed or Loading services
Failure _ ->
False
-- do not use unsuccessful states to dictate refresh
NotAsked ->
False

Failure _ ->
False

Loading ->
Loading ->
False

_ ->
False
)

Expand Down Expand Up @@ -2465,7 +2473,7 @@ refreshStepLogs model org repo buildNumber inSteps focusFragment =
_ ->
[]
in
if shouldRefresh model.repo.build then
if shouldRefresh model.page model.repo.build then
getBuildStepsLogs model org repo buildNumber stepsToRefresh focusFragment True

else
Expand All @@ -2486,7 +2494,7 @@ refreshServiceLogs model org repo buildNumber inServices focusFragment =
_ ->
[]
in
if shouldRefresh model.repo.build then
if shouldRefresh model.page model.repo.build then
getBuildServicesLogs model org repo buildNumber servicesToRefresh focusFragment True

else
Expand Down