Skip to content

Commit 74c46d7

Browse files
pkp/pkp-lib#9890 Improve SideMenu API for less confusion
1 parent 09e9bed commit 74c46d7

5 files changed

Lines changed: 16 additions & 16 deletions

File tree

src/components/SideMenu/SideMenu.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ const props = defineProps({
4848
* - `label` (string, required): The label of the menu item.
4949
* - `key` (string, required): A unique key for each item.
5050
* - `link` (string, optional): The URL to navigate to when the item is clicked.
51-
* - `action` (string, optional): A function to be executed when the item is clicked.
51+
* - `state` (object, optional): Place to store item specific state. Item gets selected on click.
52+
* - `action` (string, optional): A function to be executed when the item is clicked. Gets selected only if also `state` is provided
5253
* - `actionArgs` (object, optional): An object to be passed as function arguments when the `item.action` is emitted.
5354
* - `badge` (object, optional): Contains `slot` (string) and other props for `<Badge>` customization.
5455
* - `colorStripe` (string, optional): A border class to add a color stripe to the item.

src/composables/useSideMenu.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,15 @@ export function useSideMenu(_items, opts = {}) {
187187
}
188188
setActiveItemKey(item.key);
189189
};
190-
}
191-
192-
if (item.action) {
190+
} else if (item.action) {
193191
item.command = () => {
194192
onActionFn(item.action, {...item.actionArgs, key: item.key});
193+
if (item.state) {
194+
setActiveItemKey(item.key);
195+
}
196+
};
197+
} else if (item.state) {
198+
item.command = () => {
195199
setActiveItemKey(item.key);
196200
};
197201
}

src/pages/workflow/composables/useWorkflowMenu.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ export function useWorkflowMenu({
2828
* reviewRoundId: applicable when reviewRound is selected
2929
*/
3030
const selectedMenuState = computed(() => {
31-
const actionArgs = selectedMenuItem.value?.actionArgs || {};
31+
const state = selectedMenuItem.value?.state || {};
3232

3333
return {
34-
...actionArgs,
34+
...state,
3535
};
3636
});
3737

src/pages/workflow/composables/useWorkflowNavigationConfig/useWorkflowNavigationConfigOJS.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,20 @@ export function getPublicationItem({label, name}) {
1818
return {
1919
key: `publication_${name}`,
2020
label: label,
21-
action: 'selectMenu',
22-
actionArgs: {
21+
state: {
2322
primaryMenuItem: 'publication',
2423
secondaryMenuItem: name,
2524
title: getPublicationTitle(label),
2625
},
2726
};
2827
}
2928

30-
export function getWorkflowItem({stageId, label, isActive, isDisabled, items}) {
29+
export function getWorkflowItem({stageId, label, isActive, items}) {
3130
return {
3231
key: `workflow_${stageId}`,
3332
label: label,
3433
colorStripe: isActive ? StageColors[stageId] : null,
35-
action: isDisabled ? undefined : 'selectMenu',
36-
actionArgs: {
34+
state: {
3735
primaryMenuItem: 'workflow',
3836
stageId: stageId,
3937
title: getWorkflowTitle(label),
@@ -93,8 +91,7 @@ export function getReviewItem({stageId, reviewRound, isActive, title}) {
9391
key: `workflow_${stageId}_${reviewRound.id}`,
9492
label: t('workflow.reviewRoundN', {number: reviewRound.round}),
9593
colorStripe: isActive ? StageColors[stageId] : null,
96-
action: 'selectMenu',
97-
actionArgs: {
94+
state: {
9895
primaryMenuItem: 'workflow',
9996
stageId: stageId,
10097
reviewRoundId: reviewRound.id,
@@ -134,7 +131,6 @@ export function useWorkflowNavigationConfigOJS(pageInitConfig) {
134131
label: t('manager.publication.reviewStage'),
135132
isActive:
136133
activeStage.id === pkp.const.WORKFLOW_STAGE_ID_EXTERNAL_REVIEW,
137-
isDisabled: externalReviewItems.length,
138134
items: externalReviewItems,
139135
}),
140136
);

src/pages/workflow/composables/useWorkflowNavigationConfig/useWorkflowNavigationConfigOMP.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ function getMarketingItem({label, name}) {
2121
return {
2222
key: `marketing_${name}`,
2323
label: label,
24-
action: 'selectMenu',
25-
actionArgs: {
24+
state: {
2625
primaryMenuItem: 'marketing',
2726
secondaryMenuItem: name,
2827
title: getMarketingTitle(label),

0 commit comments

Comments
 (0)