Skip to content

Commit

Permalink
Refs #131062 changed the following:
Browse files Browse the repository at this point in the history
- fetch workflow progress only if the base pathname is the url that is at the end of the content url
  this way we have only one request when we click on a parent breadcrumb link
- fetch workflow progress only on view of pathname + '/contents', this way we avoid loading the logic
  for control panels, this condition may change if this should load also for the edit form
  • Loading branch information
ichim-david committed Jun 2, 2021
1 parent fc07d79 commit b5d915e
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/ProgressWorkflow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ const ProgressWorkflow = (props) => {
const { content, pathname } = props;
const currentStateKey = content?.review_state;
const dispatch = useDispatch();
const contentId = content?.['@id'];
const basePathname = getBaseUrl(pathname);
const samePathname = contentId && contentId.endsWith(basePathname);
const fetchCondition = pathname.endsWith('/contents')
? pathname === basePathname + '/contents'
: pathname === basePathname;
const [visible, setVisible] = useState(false);
const [isToolbarOpen, setIsToolbarOpen] = useState(false);
const [workflowProgressSteps, setWorkflowProgressSteps] = useState([]);
Expand Down Expand Up @@ -88,12 +93,11 @@ const ProgressWorkflow = (props) => {
};

setIsToolbarOpen(!!hasToolbar);
const contentId = content?.['@id'];

// filter out paths that don't have workflow (home, login, dexterity even if the content obj stays the same etc)
if (
contentId &&
contentId.indexOf(basePathname) >= 0 &&
samePathname &&
basePathname !== '/' && // wihout this there will be a flicker for going back to home ('/' is included in all api paths)
workflowProgress?.result?.steps &&
workflowProgress.result.steps.length > 0 &&
Expand All @@ -111,14 +115,22 @@ const ProgressWorkflow = (props) => {
setCurrentState(null); // reset current state only if a path without workflow is
// chosen to avoid flicker for those that have workflow
}
}, [workflowProgress?.result, currentStateKey]); // eslint-disable-line
}, [workflowProgress?.result, currentStateKey, pathname]); // eslint-disable-line

// get progress again if path or content changes
useEffect(() => {
if (token) {
if (token && fetchCondition && samePathname) {
dispatch(getWorkflowProgress(basePathname));
} // the are paths that don't have workflow (home, login etc) only if logged in
}, [dispatch, pathname, basePathname, token, currentStateKey]);
}, [
dispatch,
pathname,
basePathname,
token,
currentStateKey,
samePathname,
fetchCondition,
]);

// on mount subscribe to mousedown to be able to close on click outside
useEffect(() => {
Expand Down

0 comments on commit b5d915e

Please sign in to comment.