Skip to content

Commit

Permalink
pkp/pkp-lib#10771 Persist also selected menu in workflow page (pkp#475)
Browse files Browse the repository at this point in the history
* pkp/pkp-lib#10771 Persist also selected menu in workflow page

* pkp/pkp-lib#10771 remove correct query param when redirecting to decision page
  • Loading branch information
jardakotesovec authored Jan 5, 2025
1 parent 420ea58 commit 8d6954b
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 31 deletions.
6 changes: 5 additions & 1 deletion src/composables/useSideMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,16 @@ export function useSideMenu(_items, opts = {}) {
}

function setActiveItemKey(key = '') {
activeItemKey.value = key;
if (!findItemByKey(items.value, key)) {
return false;
}

activeItemKey.value = key;
const parentKeys = findParentKeys(items.value, key);
if (parentKeys) {
setExpandedKeys([...parentKeys, ...Object.keys(expandedKeys.value)]);
}
return true;
}

function compareUrlPaths(url1, url2) {
Expand Down
4 changes: 4 additions & 0 deletions src/pages/dashboard/dashboardPageStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ export const useDashboardPageStore = defineComponentStore(
});
});

// Teoretically initFiltersFormFromQueryParams could be called only on the page load.
// Motivation to use watch here is to keep using the url as source of the truth, to
// catch bugs early, without testing all possible filters being loaded just from the url.
watch(
queryParamsUrl,
(newQueryParamsUrl) => {
Expand Down Expand Up @@ -369,6 +372,7 @@ export const useDashboardPageStore = defineComponentStore(
{
onClose: async () => {
queryParamsUrl.workflowSubmissionId = null;
queryParamsUrl.workflowMenuKey = null;
await fetchSubmissions();
},
},
Expand Down
10 changes: 9 additions & 1 deletion src/pages/workflow/composables/useWorkflowDecisions.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,15 @@ export const Actions = {
function openDecisionPage(submission, decisionId, actionArgs = {}) {
const queryParamsUrl = useUrlSearchParams();

const currentPageUrl = `dashboard/editorial?${new URLSearchParams({...queryParamsUrl, workflowSubmissionId: submission.id}).toString()}`;
const urlSearchParams = new URLSearchParams({
...queryParamsUrl,
workflowSubmissionId: submission.id,
});

// Given that decision often change the stage - its better to let workflow page to calculate current stage
urlSearchParams.delete('workflowMenuKey');

const currentPageUrl = `dashboard/editorial?${urlSearchParams.toString()}`;

const queryParams = {decision: decisionId, ret: currentPageUrl};

Expand Down
54 changes: 37 additions & 17 deletions src/pages/workflow/composables/useWorkflowMenu.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
import {useSideMenu} from '@/composables/useSideMenu';
import {computed} from 'vue';
import {useSubmission} from '@/composables/useSubmission';
import {computed, watch} from 'vue';
import {useQueryParams} from '@/composables/useQueryParams';

const {getReviewRound} = useSubmission();

export function useWorkflowMenu({menuItems, submission}) {
export function useWorkflowMenu({
menuItems,
submission,
getInitialSelectionItemKey,
}) {
const {
sideMenuProps,
setExpandedKeys,
setActiveItemKey,
selectedItem: selectedMenuItem,
} = useSideMenu(menuItems);

/**
* Url query params
*/
// Reactive query params parsed from the url
const queryParamsUrl = useQueryParams();

/**
* primaryMenuItem: workflow/publication/marketing
* secondaryMenuItem: name of publication/marketing submenu
Expand All @@ -26,30 +34,42 @@ export function useWorkflowMenu({menuItems, submission}) {
};
});

const selectedMenuKey = computed(() => {
return selectedMenuItem.value?.key || null;
});

const menuTitle = computed(() => {
return selectedMenuState.value?.title || '';
});

const selectedReviewRound = computed(() => {
if (!selectedMenuState.value.reviewRoundId) {
return null;
function navigateToMenu(key) {
return setActiveItemKey(key);
}

watch(submission, (newSubmission, oldSubmission) => {
// Once the submission is fetched, select relevant stage in navigation
if (!oldSubmission && newSubmission) {
// use the menu selection from the url, if it does exist, otherwise fallback
if (queryParamsUrl?.workflowMenuKey?.length) {
const doesKeyExist = navigateToMenu(queryParamsUrl?.workflowMenuKey);
if (doesKeyExist) {
return;
}
}
navigateToMenu(getInitialSelectionItemKey(newSubmission));
}
const reviewRound = getReviewRound(
submission.value,
selectedMenuState.value.reviewRoundId,
);
return reviewRound;
});

function navigateToMenu(key) {
setActiveItemKey(key);
}
// Update selectedMenuKey in url when menu selection changes
watch(selectedMenuKey, (newSelectedMenuKey) => {
queryParamsUrl.workflowMenuKey = newSelectedMenuKey;
});

return {
menuTitle,
navigateToMenu,
selectedMenuKey,
selectedMenuState,
selectedReviewRound,
setExpandedKeys,
sideMenuProps,
};
Expand Down
27 changes: 15 additions & 12 deletions src/pages/workflow/workflowStore.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {computed, watch, inject} from 'vue';
import {computed, inject} from 'vue';

import {defineComponentStore} from '@/utils/defineComponentStore';
import {
Expand Down Expand Up @@ -45,7 +45,19 @@ export const useWorkflowStore = defineComponentStore(
submissionId: props.submissionId,
});

const {getExtendedStage, getExtendedStageLabel} = useSubmission();
const selectedReviewRound = computed(() => {
if (!selectedMenuState.value.reviewRoundId) {
return null;
}
const reviewRound = getReviewRound(
submission.value,
selectedMenuState.value.reviewRoundId,
);
return reviewRound;
});

const {getExtendedStage, getExtendedStageLabel, getReviewRound} =
useSubmission();

/**
* Current Stage Indication
Expand Down Expand Up @@ -90,18 +102,9 @@ export const useWorkflowStore = defineComponentStore(
menuTitle,
navigateToMenu,
selectedMenuState,
selectedReviewRound,
setExpandedKeys,
sideMenuProps,
} = useWorkflowMenu({menuItems, submission});

/** When submission is loaded initially - select relevant menu */
watch(submission, (newSubmission, oldSubmission) => {
// Once the submission is fetched, select relevant stage in navigaton
if (!oldSubmission && newSubmission) {
navigateToMenu(getInitialSelectionItemKey(newSubmission));
}
});
} = useWorkflowMenu({menuItems, submission, getInitialSelectionItemKey});

/**
* Expose workflow actions
Expand Down

0 comments on commit 8d6954b

Please sign in to comment.