Skip to content

pkp/pkp-lib#9890 Improve SideMenu API for less confusion #622

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

Merged
merged 1 commit into from
May 21, 2025
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion src/components/SideMenu/SideMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ const props = defineProps({
* - `label` (string, required): The label of the menu item.
* - `key` (string, required): A unique key for each item.
* - `link` (string, optional): The URL to navigate to when the item is clicked.
* - `action` (string, optional): A function to be executed when the item is clicked.
* - `state` (object, optional): Place to store item specific state. Item gets selected on click.
* - `action` (string, optional): A function to be executed when the item is clicked. Gets selected only if also `state` is provided
* - `actionArgs` (object, optional): An object to be passed as function arguments when the `item.action` is emitted.
* - `badge` (object, optional): Contains `slot` (string) and other props for `<Badge>` customization.
* - `colorStripe` (string, optional): A border class to add a color stripe to the item.
Expand Down
10 changes: 7 additions & 3 deletions src/composables/useSideMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,15 @@ export function useSideMenu(_items, opts = {}) {
}
setActiveItemKey(item.key);
};
}

if (item.action) {
} else if (item.action) {
item.command = () => {
onActionFn(item.action, {...item.actionArgs, key: item.key});
if (item.state) {
setActiveItemKey(item.key);
}
};
} else if (item.state) {
item.command = () => {
setActiveItemKey(item.key);
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/workflow/composables/useWorkflowMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ export function useWorkflowMenu({
* reviewRoundId: applicable when reviewRound is selected
*/
const selectedMenuState = computed(() => {
const actionArgs = selectedMenuItem.value?.actionArgs || {};
const state = selectedMenuItem.value?.state || {};

return {
...actionArgs,
...state,
};
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,20 @@ export function getPublicationItem({label, name}) {
return {
key: `publication_${name}`,
label: label,
action: 'selectMenu',
actionArgs: {
state: {
primaryMenuItem: 'publication',
secondaryMenuItem: name,
title: getPublicationTitle(label),
},
};
}

export function getWorkflowItem({stageId, label, isActive, isDisabled, items}) {
export function getWorkflowItem({stageId, label, isActive, items}) {
return {
key: `workflow_${stageId}`,
label: label,
colorStripe: isActive ? StageColors[stageId] : null,
action: isDisabled ? undefined : 'selectMenu',
actionArgs: {
state: {
primaryMenuItem: 'workflow',
stageId: stageId,
title: getWorkflowTitle(label),
Expand Down Expand Up @@ -93,8 +91,7 @@ export function getReviewItem({stageId, reviewRound, isActive, title}) {
key: `workflow_${stageId}_${reviewRound.id}`,
label: t('workflow.reviewRoundN', {number: reviewRound.round}),
colorStripe: isActive ? StageColors[stageId] : null,
action: 'selectMenu',
actionArgs: {
state: {
primaryMenuItem: 'workflow',
stageId: stageId,
reviewRoundId: reviewRound.id,
Expand Down Expand Up @@ -134,7 +131,6 @@ export function useWorkflowNavigationConfigOJS(pageInitConfig) {
label: t('manager.publication.reviewStage'),
isActive:
activeStage.id === pkp.const.WORKFLOW_STAGE_ID_EXTERNAL_REVIEW,
isDisabled: externalReviewItems.length,
items: externalReviewItems,
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ function getMarketingItem({label, name}) {
return {
key: `marketing_${name}`,
label: label,
action: 'selectMenu',
actionArgs: {
state: {
primaryMenuItem: 'marketing',
secondaryMenuItem: name,
title: getMarketingTitle(label),
Expand Down