Skip to content

Commit

Permalink
update isUpdatedPV function with comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ibolton336 committed Apr 28, 2020
1 parent aa39287 commit 6feb51e
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/app/plan/duck/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,23 +287,36 @@ function* checkUpdatedPVs(action) {

if (updatedPlan) {
const isUpdatedPVList = () => {
// TODO: refactor this function to improve logic.
// Possibly create a wizardStatus enum similar to planStatus. This will indicate which update function to run
// & write pure functions to encapsulate each behavior. Function names will become self documenting and will remove ambiguous functions like this one.

if (updatedPlan.status) {
// Initial plan add case(1): If no status, return false & keep polling.
if (isRerunPVDiscovery) {
const updatedGeneration = updatedPlan.status.observedDigest;
const oldGeneration = currentPlan.status.observedDigest;
if (updatedGeneration === oldGeneration) {
// Initial plan add case(1): isRerunPVDiscovery set to false on initial plan add from function instantiation on UI component.

// Rerun PV discovery on back nav case(2): isRerunPVDiscovery set to true from component.
// Check currentPlan observedDigest against getPlan polling response after patch request has succeeded.

const updatedObservedDigest = updatedPlan.status.observedDigest;
const oldObservedDigest = currentPlan.status.observedDigest;
if (updatedObservedDigest === oldObservedDigest) {
//Rerun PV discovery on back nav case(2): If the SHA is unchanged, return false and keep polling.
return false;
} else {
//Rerun PV discovery on back nav case(2): If the SHA is changed, return true and stop polling/hydrate redux store with updated info.
return true;
}
} else {
//Initial plan add case(1): Will return true here once status is available.
return true;
}
} else {
// Initial plan add case(1): Return false until status is ready.
return false;
}
};

if (isUpdatedPVList()) {
yield put(PlanActions.setCurrentPlan(updatedPlan));
yield put(PlanActions.pvUpdateSuccess());
Expand Down

0 comments on commit 6feb51e

Please sign in to comment.