Skip to content

Commit

Permalink
removed 0% states unless is current
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Medesan committed Apr 15, 2021
1 parent f2cc442 commit 89ffcd6
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/ProgressWorkflow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,26 @@ const ProgressWorkflow = (props) => {
};
const hasToolbar = document.querySelector('#toolbar .toolbar-actions');

const filterOutZeroStatesNotCurrent = (states) => {
const firstFilter = states.filter(
(state) => state[1] > 0 || state[0].indexOf(currentStateKey) > -1,
);
const result = firstFilter.map((state) => {
const percent = state[1];
if (percent === 0) {
const indexOfCurrentSateKey = state[0].indexOf(currentStateKey);
const keys = [state[0][indexOfCurrentSateKey]];
const titles = [state[3][indexOfCurrentSateKey]];
const nextState = [state[2][indexOfCurrentSateKey]];
console.log({ indexOfCurrentSateKey });
console.log([keys, percent, nextState, titles]);
return [keys, percent, nextState, titles];
}
return state;
});
return result;
};

setIsToolbarOpen(!!hasToolbar);
// filter out paths that don't have workflow (home, login etc)
if (
Expand All @@ -60,7 +80,9 @@ const ProgressWorkflow = (props) => {
workflowProgress.result.steps,
workflowProgress.result.done,
);
setWorkflowProgressSteps(workflowProgress.result.steps);
setWorkflowProgressSteps(
filterOutZeroStatesNotCurrent(workflowProgress.result.steps),
);
} else {
setCurrentState(null); // reset current state only if a path without workflow is
// chosen to avoid flicker for those that have workflow
Expand Down

0 comments on commit 89ffcd6

Please sign in to comment.