From ccd51cd09e20e412c4d91bda70127d749417e743 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jarda=20Kot=C4=9B=C5=A1ovec?= Date: Thu, 19 Dec 2024 14:26:28 +0100 Subject: [PATCH] pkp/pkp-lib#10598 Remove the workflow store duplications across different apps for now as they are common enough --- src/pages/workflow/WorkflowPageOJS.vue | 63 +++++- src/pages/workflow/WorkflowPageOMP.vue | 69 ++++++- src/pages/workflow/WorkflowPageOPS.vue | 52 ++++- src/pages/workflow/workflowStore.js | 225 +++++++++++++++++++- src/pages/workflow/workflowStoreOJS.js | 267 ------------------------ src/pages/workflow/workflowStoreOMP.js | 273 ------------------------- src/pages/workflow/workflowStoreOPS.js | 257 ----------------------- 7 files changed, 399 insertions(+), 807 deletions(-) delete mode 100644 src/pages/workflow/workflowStoreOJS.js delete mode 100644 src/pages/workflow/workflowStoreOMP.js delete mode 100644 src/pages/workflow/workflowStoreOPS.js diff --git a/src/pages/workflow/WorkflowPageOJS.vue b/src/pages/workflow/WorkflowPageOJS.vue index 35ff57089..2f707ed34 100644 --- a/src/pages/workflow/WorkflowPageOJS.vue +++ b/src/pages/workflow/WorkflowPageOJS.vue @@ -3,13 +3,72 @@ diff --git a/src/pages/workflow/WorkflowPageOMP.vue b/src/pages/workflow/WorkflowPageOMP.vue index cf73002de..4dfbc8a86 100644 --- a/src/pages/workflow/WorkflowPageOMP.vue +++ b/src/pages/workflow/WorkflowPageOMP.vue @@ -3,13 +3,78 @@ diff --git a/src/pages/workflow/WorkflowPageOPS.vue b/src/pages/workflow/WorkflowPageOPS.vue index ba304552d..0fe501f4e 100644 --- a/src/pages/workflow/WorkflowPageOPS.vue +++ b/src/pages/workflow/WorkflowPageOPS.vue @@ -3,13 +3,61 @@ diff --git a/src/pages/workflow/workflowStore.js b/src/pages/workflow/workflowStore.js index 84516b55d..2d4a68f03 100644 --- a/src/pages/workflow/workflowStore.js +++ b/src/pages/workflow/workflowStore.js @@ -1,4 +1,221 @@ -import {getComponentStoreByName} from '@/utils/defineComponentStore'; -export function useWorkflowStore() { - return getComponentStoreByName('workflow'); -} +import {computed, watch, inject} from 'vue'; + +import {defineComponentStore} from '@/utils/defineComponentStore'; +import { + useWorkflowActions, + Actions as WorkflowActions, +} from './composables/useWorkflowActions'; + +import { + useWorkflowDecisions, + Actions as DecisionActions, +} from './composables/useWorkflowDecisions'; + +import {useDataChangedProvider} from '@/composables/useDataChangedProvider'; + +import {wrapActionFns} from '@/utils/wrapActionFns'; + +import {useWorkflowDataSubmissionPublication} from './composables/useWorkflowDataSubmissionPublication'; +import {useWorkflowPermissions} from './composables/useWorkflowPermissions'; +import {useWorkflowMenu} from './composables/useWorkflowMenu'; +import {useWorkflowItems} from './composables/useWorkflowItems'; +import {useSubmission} from '@/composables/useSubmission'; + +export const useWorkflowStore = defineComponentStore( + 'workflow', + ({props, Components, useWorkflowConfig, useWorkflowNavigationConfig}) => { + const dashboardPage = props.pageInitConfig.dashboardPage; + + /** + * Action to close the workflow from inside + * */ + const closeWorkflowModal = inject('closeModal'); + + /** + * Submission & Publication + */ + const { + submission, + submissionId, + selectPublicationId, + selectedPublication, + selectedPublicationId, + refetchSubmissionPublication, + } = useWorkflowDataSubmissionPublication({ + submissionId: props.submissionId, + }); + + const {getExtendedStage, getExtendedStageLabel} = useSubmission(); + + /** + * Current Stage Indication + */ + const extendedStage = computed( + () => submission.value && getExtendedStage(submission.value), + ); + const stageLabel = computed( + () => submission.value && getExtendedStageLabel(submission.value), + ); + + /** + * Data changes tracking + */ + const {triggerDataChange} = useDataChangedProvider(() => { + return refetchSubmissionPublication(); + }); + + /** + * UI Permissions + */ + const {permissions} = useWorkflowPermissions({ + submission, + selectedPublication, + }); + + /** + * Navigation + */ + + const {getMenuItems, getInitialSelectionItemKey} = + useWorkflowNavigationConfig(props.pageInitConfig); + + const menuItems = computed(() => + getMenuItems({ + submission: submission.value, + permissions: permissions.value, + }), + ); + + const { + 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)); + } + }); + + /** + * Expose workflow actions + * + */ + const _workflowActionsFns = useWorkflowActions(props.pageInitConfig); + const workflowActions = wrapActionFns( + WorkflowActions, + _workflowActionsFns, + (actionFn, actionArgs, finishedCallback = null) => + actionFn( + { + ...actionArgs, + submission: submission.value, + selectedPublication: selectedPublication.value, + reviewRoundId: selectedReviewRound.value?.id, + store, + }, + (finishedData) => { + triggerDataChange(); + if (finishedCallback) { + finishedCallback(finishedData); + } + }, + ), + ); + + /** + * Expose decision functions + * + * */ + const _workflowDecisionsFns = useWorkflowDecisions(); + const decisionActions = wrapActionFns( + DecisionActions, + _workflowDecisionsFns, + (actionFn, actionArgs) => + actionFn({ + ...actionArgs, + submission: submission.value, + selectedPublication: selectedPublication.value, + reviewRoundId: selectedReviewRound.value?.id, + }), + ); + + /** + * Items + * + * */ + + const _workflowConfigFns = useWorkflowConfig({dashboardPage}); + + const { + headerItems, + primaryItems, + secondaryItems, + actionItems, + publicationControlsLeft, + publicationControlsRight, + } = useWorkflowItems(_workflowConfigFns, () => ({ + selectedMenuState: selectedMenuState.value, + submission: submission.value, + pageInitConfig: props.pageInitConfig, + selectedPublication: selectedPublication.value, + selectedPublicationId: selectedPublicationId.value, + selectedReviewRound: selectedReviewRound.value, + permissions: permissions.value, + publicationSettings: props.pageInitConfig.publicationSettings, + })); + + const store = { + dashboardPage, + closeWorkflowModal, + + submission, + submissionId, + selectedPublication, + selectPublicationId, + extendedStage, + stageLabel, + + /** + * Navigation + * */ + sideMenuProps, + selectedMenuState, + navigateToMenu, + setExpandedKeys, + + /** Actions + * + */ + ...workflowActions, + ...decisionActions, + + /** + * Summary + */ + menuTitle, + headerItems, + primaryItems, + secondaryItems, + actionItems, + publicationControlsLeft, + publicationControlsRight, + + /** + * Expose for extensions + */ + + _workflowActionsFns, + _workflowDecisionsFns, + + Components, + }; + return store; + }, +); diff --git a/src/pages/workflow/workflowStoreOJS.js b/src/pages/workflow/workflowStoreOJS.js deleted file mode 100644 index bd34773f9..000000000 --- a/src/pages/workflow/workflowStoreOJS.js +++ /dev/null @@ -1,267 +0,0 @@ -import {computed, watch, markRaw, inject} from 'vue'; - -import {defineComponentStore} from '@/utils/defineComponentStore'; -import { - useWorkflowActions, - Actions as WorkflowActions, -} from './composables/useWorkflowActions'; - -import { - useWorkflowDecisions, - Actions as DecisionActions, -} from './composables/useWorkflowDecisions'; - -import {useDataChangedProvider} from '@/composables/useDataChangedProvider'; - -import {wrapActionFns} from '@/utils/wrapActionFns'; - -import {useWorkflowConfigOJS as useWorkflowConfig} from './composables/useWorkflowConfig/useWorkflowConfigOJS'; -import {useWorkflowNavigationConfigOJS as useWorkflowNavigationConfig} from './composables/useWorkflowNavigationConfig/useWorkflowNavigationConfigOJS'; - -import {useWorkflowDataSubmissionPublication} from './composables/useWorkflowDataSubmissionPublication'; -import {useWorkflowPermissions} from './composables/useWorkflowPermissions'; -import {useWorkflowMenu} from './composables/useWorkflowMenu'; -import {useWorkflowItems} from './composables/useWorkflowItems'; -import {useSubmission} from '@/composables/useSubmission'; - -import FileManager from '@/managers/FileManager/FileManager.vue'; -import ReviewerManager from '@/managers/ReviewerManager/ReviewerManager.vue'; -import DiscussionManager from '@/managers/DiscussionManager/DiscussionManager.vue'; -import ContributorManager from '@/managers/ContributorManager/ContributorManager.vue'; -import ParticipantManager from '@/managers/ParticipantManager/ParticipantManager.vue'; -import GalleyManager from '@/managers/GalleyManager/GalleyManager.vue'; -import WorkflowActionButton from './components/action/WorkflowActionButton.vue'; -import WorkflowRecommendOnlyControls from './components/action/WorkflowRecommendOnlyControls.vue'; -import WorkflowRecommendOnlyListingRecommendations from './components/secondary/WorkflowRecommendOnlyListingRecommendations.vue'; -import WorkflowNotificationDisplay from './components/primary/WorkflowNotificationDisplay.vue'; -import WorkflowListingEmails from './components/primary/WorkflowListingEmails.vue'; -import WorkflowPaymentDropdown from './components/header/WorkflowPaymentDropdown.vue'; -import WorkflowPublicationForm from './components/publication/WorkflowPublicationForm.vue'; -import WorkflowPublicationJats from './components/publication/WorkflowPublicationJats.vue'; -import WorkflowPublicationVersionControl from './components/publication/WorkflowPublicationVersionControl.vue'; -import WorkflowChangeSubmissionLanguage from './components/publication/WorkflowChangeSubmissionLanguage.vue'; -import WorkflowPrimaryBasicMetadata from './components/primary/WorkflowPrimaryBasicMetadata.vue'; -import WorkflowSubmissionStatus from './components/primary/WorkflowSubmissionStatus.vue'; -import WorkflowPublicationEditDisabled from './components/publication/WorkflowPublicationEditDisabled.vue'; - -export const useWorkflowStore = defineComponentStore('workflow', (props) => { - const dashboardPage = props.pageInitConfig.dashboardPage; - - /** - * Action to close the workflow from inside - * */ - const closeWorkflowModal = inject('closeModal'); - - /** - * Submission & Publication - */ - const { - submission, - submissionId, - selectPublicationId, - selectedPublication, - selectedPublicationId, - refetchSubmissionPublication, - } = useWorkflowDataSubmissionPublication({submissionId: props.submissionId}); - - const {getExtendedStage, getExtendedStageLabel} = useSubmission(); - - /** - * Current Stage Indication - */ - const extendedStage = computed( - () => submission.value && getExtendedStage(submission.value), - ); - const stageLabel = computed( - () => submission.value && getExtendedStageLabel(submission.value), - ); - - /** - * Data changes tracking - */ - const {triggerDataChange} = useDataChangedProvider(() => { - return refetchSubmissionPublication(); - }); - - /** - * UI Permissions - */ - const {permissions} = useWorkflowPermissions({ - submission, - selectedPublication, - }); - - /** - * Navigation - */ - - const {getMenuItems, getInitialSelectionItemKey} = - useWorkflowNavigationConfig(props.pageInitConfig); - - const menuItems = computed(() => - getMenuItems({ - submission: submission.value, - permissions: permissions.value, - }), - ); - - const { - menuTitle, - navigateToMenu, - selectedMenuState, - selectedReviewRound, - setExpandedKeys, - sideMenuProps, - } = useWorkflowMenu({menuItems, submission}); - - setExpandedKeys([ - 'workflow', - 'publication', - 'marketing', - `workflow_${pkp.const.WORKFLOW_STAGE_ID_EXTERNAL_REVIEW}`, - ]); - - /** 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)); - } - }); - - /** - * Expose workflow actions - * - */ - const _workflowActionsFns = useWorkflowActions(props.pageInitConfig); - const workflowActions = wrapActionFns( - WorkflowActions, - _workflowActionsFns, - (actionFn, actionArgs, finishedCallback = null) => - actionFn( - { - ...actionArgs, - submission: submission.value, - selectedPublication: selectedPublication.value, - reviewRoundId: selectedReviewRound.value?.id, - store, - }, - (finishedData) => { - triggerDataChange(); - if (finishedCallback) { - finishedCallback(finishedData); - } - }, - ), - ); - - /** - * Expose decision functions - * - * */ - const _workflowDecisionsFns = useWorkflowDecisions(); - const decisionActions = wrapActionFns( - DecisionActions, - _workflowDecisionsFns, - (actionFn, actionArgs) => - actionFn({ - ...actionArgs, - submission: submission.value, - selectedPublication: selectedPublication.value, - reviewRoundId: selectedReviewRound.value?.id, - }), - ); - - /** - * Items - * - * */ - - const _workflowConfigFns = useWorkflowConfig({dashboardPage}); - - const { - headerItems, - primaryItems, - secondaryItems, - actionItems, - publicationControlsLeft, - publicationControlsRight, - } = useWorkflowItems(_workflowConfigFns, () => ({ - selectedMenuState: selectedMenuState.value, - submission: submission.value, - pageInitConfig: props.pageInitConfig, - selectedPublication: selectedPublication.value, - selectedPublicationId: selectedPublicationId.value, - selectedReviewRound: selectedReviewRound.value, - permissions: permissions.value, - publicationSettings: props.pageInitConfig.publicationSettings, - })); - - const Components = markRaw({ - FileManager, - ReviewerManager, - DiscussionManager, - ContributorManager, - ParticipantManager, - GalleyManager, - WorkflowActionButton, - WorkflowRecommendOnlyControls, - WorkflowRecommendOnlyListingRecommendations, - WorkflowNotificationDisplay, - WorkflowListingEmails, - WorkflowPaymentDropdown, - WorkflowPrimaryBasicMetadata, - WorkflowPublicationForm, - WorkflowPublicationJats, - WorkflowPublicationVersionControl, - WorkflowChangeSubmissionLanguage, - WorkflowSubmissionStatus, - WorkflowPublicationEditDisabled, - }); - - const store = { - dashboardPage, - closeWorkflowModal, - - submission, - submissionId, - selectedPublication, - selectPublicationId, - extendedStage, - stageLabel, - - /** - * Navigation - * */ - sideMenuProps, - selectedMenuState, - navigateToMenu, - - /** Actions - * - */ - ...workflowActions, - ...decisionActions, - - /** - * Summary - */ - menuTitle, - headerItems, - primaryItems, - secondaryItems, - actionItems, - publicationControlsLeft, - publicationControlsRight, - - /** - * Expose for extensions - */ - - _workflowActionsFns, - _workflowDecisionsFns, - - Components, - }; - return store; -}); diff --git a/src/pages/workflow/workflowStoreOMP.js b/src/pages/workflow/workflowStoreOMP.js deleted file mode 100644 index b09ac3ff3..000000000 --- a/src/pages/workflow/workflowStoreOMP.js +++ /dev/null @@ -1,273 +0,0 @@ -import {computed, watch, markRaw, inject} from 'vue'; - -import {defineComponentStore} from '@/utils/defineComponentStore'; -import { - useWorkflowActions, - Actions as WorkflowActions, -} from './composables/useWorkflowActions'; - -import { - useWorkflowDecisions, - Actions as DecisionActions, -} from './composables/useWorkflowDecisions'; - -import {useDataChangedProvider} from '@/composables/useDataChangedProvider'; - -import {wrapActionFns} from '@/utils/wrapActionFns'; - -import {useWorkflowConfigOMP as useWorkflowConfig} from './composables/useWorkflowConfig/useWorkflowConfigOMP'; -import {useWorkflowNavigationConfigOMP as useWorkflowNavigationConfig} from './composables/useWorkflowNavigationConfig/useWorkflowNavigationConfigOMP'; - -import {useWorkflowDataSubmissionPublication} from './composables/useWorkflowDataSubmissionPublication'; -import {useWorkflowPermissions} from './composables/useWorkflowPermissions'; -import {useWorkflowMenu} from './composables/useWorkflowMenu'; -import {useWorkflowItems} from './composables/useWorkflowItems'; -import {useSubmission} from '@/composables/useSubmission'; - -import FileManager from '@/managers/FileManager/FileManager.vue'; -import ReviewerManager from '@/managers/ReviewerManager/ReviewerManager.vue'; -import DiscussionManager from '@/managers/DiscussionManager/DiscussionManager.vue'; -import ContributorManager from '@/managers/ContributorManager/ContributorManager.vue'; -import ParticipantManager from '@/managers/ParticipantManager/ParticipantManager.vue'; -import GalleyManager from '@/managers/GalleyManager/GalleyManager.vue'; -import ChapterManager from '@/managers/ChapterManager/ChapterManager.vue'; -import PublicationFormatManager from '@/managers/PublicationFormatManager/PublicationFormatManager.vue'; -import RepresentativeManager from '@/managers/RepresentativeManager/RepresentativeManager.vue'; -import WorkflowMarketingForm from './components/publication/WorkflowMarketingForm.vue'; -import WorkflowWorkTypeOMP from './components/header/WorkflowWorkTypeOMP.vue'; -import WorkflowActionButton from './components/action/WorkflowActionButton.vue'; -import WorkflowRecommendOnlyControls from './components/action/WorkflowRecommendOnlyControls.vue'; -import WorkflowRecommendOnlyListingRecommendations from './components/secondary/WorkflowRecommendOnlyListingRecommendations.vue'; -import WorkflowNotificationDisplay from './components/primary/WorkflowNotificationDisplay.vue'; -import WorkflowListingEmails from './components/primary/WorkflowListingEmails.vue'; -import WorkflowPublicationForm from './components/publication/WorkflowPublicationForm.vue'; -import WorkflowPublicationVersionControl from './components/publication/WorkflowPublicationVersionControl.vue'; -import WorkflowChangeSubmissionLanguage from './components/publication/WorkflowChangeSubmissionLanguage.vue'; -import WorkflowPrimaryBasicMetadata from './components/primary/WorkflowPrimaryBasicMetadata.vue'; -import WorkflowSubmissionStatus from './components/primary/WorkflowSubmissionStatus.vue'; -import WorkflowPublicationEditDisabled from './components/publication/WorkflowPublicationEditDisabled.vue'; - -export const useWorkflowStore = defineComponentStore('workflow', (props) => { - const dashboardPage = props.pageInitConfig.dashboardPage; - - /** - * Action to close the workflow from inside - * */ - const closeWorkflowModal = inject('closeModal'); - - /** - * Submission & Publication - */ - const { - submission, - submissionId, - selectPublicationId, - selectedPublication, - selectedPublicationId, - refetchSubmissionPublication, - } = useWorkflowDataSubmissionPublication({submissionId: props.submissionId}); - - const {getExtendedStage, getExtendedStageLabel} = useSubmission(); - - /** - * Current Stage Indication - */ - const extendedStage = computed( - () => submission.value && getExtendedStage(submission.value), - ); - const stageLabel = computed( - () => submission.value && getExtendedStageLabel(submission.value), - ); - - /** - * Data changes tracking - */ - const {triggerDataChange} = useDataChangedProvider(() => { - return refetchSubmissionPublication(); - }); - - /** - * UI Permissions - */ - const {permissions} = useWorkflowPermissions({ - submission, - selectedPublication, - }); - - /** - * Navigation - */ - - const {getMenuItems, getInitialSelectionItemKey} = - useWorkflowNavigationConfig(props.pageInitConfig); - - const menuItems = computed(() => - getMenuItems({ - submission: submission.value, - permissions: permissions.value, - }), - ); - - const { - menuTitle, - navigateToMenu, - selectedMenuState, - selectedReviewRound, - setExpandedKeys, - sideMenuProps, - } = useWorkflowMenu({menuItems, submission}); - - setExpandedKeys([ - 'workflow', - 'publication', - 'marketing', - `workflow_${pkp.const.WORKFLOW_STAGE_ID_EXTERNAL_REVIEW}`, - `workflow_${pkp.const.WORKFLOW_STAGE_ID_INTERNAL_REVIEW}`, - ]); - - /** 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)); - } - }); - - /** - * Expose workflow actions - * - */ - const _workflowActionsFns = useWorkflowActions(props.pageInitConfig); - const workflowActions = wrapActionFns( - WorkflowActions, - _workflowActionsFns, - (actionFn, actionArgs, finishedCallback = null) => - actionFn( - { - ...actionArgs, - submission: submission.value, - selectedPublication: selectedPublication.value, - reviewRoundId: selectedReviewRound.value?.id, - store, - }, - (finishedData) => { - triggerDataChange(); - if (finishedCallback) { - finishedCallback(finishedData); - } - }, - ), - ); - - /** - * Expose decision functions - * - * */ - const _workflowDecisionsFns = useWorkflowDecisions(); - const decisionActions = wrapActionFns( - DecisionActions, - _workflowDecisionsFns, - (actionFn, actionArgs) => - actionFn({ - ...actionArgs, - submission: submission.value, - selectedPublication: selectedPublication.value, - reviewRoundId: selectedReviewRound.value?.id, - }), - ); - - /** - * Items - * - * */ - - const _workflowConfigFns = useWorkflowConfig({dashboardPage}); - - const { - headerItems, - primaryItems, - secondaryItems, - actionItems, - publicationControlsLeft, - publicationControlsRight, - } = useWorkflowItems(_workflowConfigFns, () => ({ - selectedMenuState: selectedMenuState.value, - submission: submission.value, - pageInitConfig: props.pageInitConfig, - selectedPublication: selectedPublication.value, - selectedPublicationId: selectedPublicationId.value, - selectedReviewRound: selectedReviewRound.value, - permissions: permissions.value, - })); - - const Components = markRaw({ - FileManager, - ReviewerManager, - DiscussionManager, - ContributorManager, - ParticipantManager, - GalleyManager, - ChapterManager, - RepresentativeManager, - PublicationFormatManager, - WorkflowActionButton, - WorkflowRecommendOnlyControls, - WorkflowRecommendOnlyListingRecommendations, - WorkflowNotificationDisplay, - WorkflowListingEmails, - WorkflowPrimaryBasicMetadata, - WorkflowPublicationForm, - WorkflowPublicationVersionControl, - WorkflowChangeSubmissionLanguage, - WorkflowSubmissionStatus, - WorkflowPublicationEditDisabled, - WorkflowMarketingForm, - WorkflowWorkTypeOMP, - }); - - const store = { - dashboardPage, - closeWorkflowModal, - - submission, - submissionId, - selectedPublication, - selectPublicationId, - extendedStage, - stageLabel, - - /** - * Navigation - * */ - sideMenuProps, - selectedMenuState, - navigateToMenu, - - /** Actions - * - */ - ...workflowActions, - ...decisionActions, - - /** - * Summary - */ - menuTitle, - headerItems, - primaryItems, - secondaryItems, - actionItems, - publicationControlsLeft, - publicationControlsRight, - - /** - * Expose for extensions - */ - - _workflowActionsFns, - _workflowDecisionsFns, - - Components, - }; - return store; -}); diff --git a/src/pages/workflow/workflowStoreOPS.js b/src/pages/workflow/workflowStoreOPS.js deleted file mode 100644 index 89b845e78..000000000 --- a/src/pages/workflow/workflowStoreOPS.js +++ /dev/null @@ -1,257 +0,0 @@ -import {computed, watch, markRaw, inject} from 'vue'; - -import {defineComponentStore} from '@/utils/defineComponentStore'; -import { - useWorkflowActions, - Actions as WorkflowActions, -} from './composables/useWorkflowActions'; - -import { - useWorkflowDecisions, - Actions as DecisionActions, -} from './composables/useWorkflowDecisions'; - -import {useDataChangedProvider} from '@/composables/useDataChangedProvider'; - -import {wrapActionFns} from '@/utils/wrapActionFns'; - -import {useWorkflowConfigOPS as useWorkflowConfig} from './composables/useWorkflowConfig/useWorkflowConfigOPS'; -import {useWorkflowNavigationConfigOPS as useWorkflowNavigationConfig} from './composables/useWorkflowNavigationConfig/useWorkflowNavigationConfigOPS'; - -import {useWorkflowDataSubmissionPublication} from './composables/useWorkflowDataSubmissionPublication'; -import {useWorkflowPermissions} from './composables/useWorkflowPermissions'; -import {useWorkflowMenu} from './composables/useWorkflowMenu'; -import {useWorkflowItems} from './composables/useWorkflowItems'; -import {useSubmission} from '@/composables/useSubmission'; - -import FileManager from '@/managers/FileManager/FileManager.vue'; -import ReviewerManager from '@/managers/ReviewerManager/ReviewerManager.vue'; -import DiscussionManager from '@/managers/DiscussionManager/DiscussionManager.vue'; -import ContributorManager from '@/managers/ContributorManager/ContributorManager.vue'; -import ParticipantManager from '@/managers/ParticipantManager/ParticipantManager.vue'; -import GalleyManager from '@/managers/GalleyManager/GalleyManager.vue'; -import WorkflowActionButton from './components/action/WorkflowActionButton.vue'; -import WorkflowActionChangeDecision from './components/action/WorkflowActionChangeDecision.vue'; -import WorkflowNotificationDisplay from './components/primary/WorkflowNotificationDisplay.vue'; -import WorkflowPublicationForm from './components/publication/WorkflowPublicationForm.vue'; -import WorkflowPublicationVersionControl from './components/publication/WorkflowPublicationVersionControl.vue'; -import WorkflowChangeSubmissionLanguage from './components/publication/WorkflowChangeSubmissionLanguage.vue'; -import WorkflowPrimaryBasicMetadata from './components/primary/WorkflowPrimaryBasicMetadata.vue'; -import WorkflowPublicationRelationDropdownOPS from './components/publication/WorkflowPublicationRelationDropdownOPS.vue'; -import WorkflowSubmissionStatus from './components/primary/WorkflowSubmissionStatus.vue'; -import WorkflowPublicationEditDisabled from './components/publication/WorkflowPublicationEditDisabled.vue'; - -export const useWorkflowStore = defineComponentStore('workflow', (props) => { - const dashboardPage = props.pageInitConfig.dashboardPage; - - /** - * Action to close the workflow from inside - * */ - const closeWorkflowModal = inject('closeModal'); - - /** - * Submission & Publication - */ - const { - submission, - submissionId, - selectPublicationId, - selectedPublication, - selectedPublicationId, - refetchSubmissionPublication, - } = useWorkflowDataSubmissionPublication({submissionId: props.submissionId}); - - const {getExtendedStage, getExtendedStageLabel} = useSubmission(); - - /** - * Current Stage Indication - */ - const extendedStage = computed( - () => submission.value && getExtendedStage(submission.value), - ); - const stageLabel = computed( - () => submission.value && getExtendedStageLabel(submission.value), - ); - - /** - * Data changes tracking - */ - const {triggerDataChange} = useDataChangedProvider(() => { - return refetchSubmissionPublication(); - }); - - /** - * UI Permissions - */ - const {permissions} = useWorkflowPermissions({ - submission, - selectedPublication, - }); - - /** - * Navigation - */ - - const {getMenuItems, getInitialSelectionItemKey} = - useWorkflowNavigationConfig(props.pageInitConfig); - - const menuItems = computed(() => - getMenuItems({ - submission: submission.value, - permissions: permissions.value, - }), - ); - - const { - menuTitle, - navigateToMenu, - selectedMenuState, - selectedReviewRound, - setExpandedKeys, - sideMenuProps, - } = useWorkflowMenu({menuItems, submission}); - - setExpandedKeys(['workflow', 'publication']); - - /** 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)); - } - }); - - /** - * Expose workflow actions - * - */ - const _workflowActionsFns = useWorkflowActions(props.pageInitConfig); - const workflowActions = wrapActionFns( - WorkflowActions, - _workflowActionsFns, - (actionFn, actionArgs, finishedCallback = null) => - actionFn( - { - ...actionArgs, - submission: submission.value, - selectedPublication: selectedPublication.value, - reviewRoundId: selectedReviewRound.value?.id, - store, - }, - (finishedData) => { - triggerDataChange(); - if (finishedCallback) { - finishedCallback(finishedData); - } - }, - ), - ); - - /** - * Expose decision functions - * - * */ - const _workflowDecisionsFns = useWorkflowDecisions(); - const decisionActions = wrapActionFns( - DecisionActions, - _workflowDecisionsFns, - (actionFn, actionArgs) => - actionFn({ - ...actionArgs, - submission: submission.value, - selectedPublication: selectedPublication.value, - reviewRoundId: selectedReviewRound.value?.id, - }), - ); - - /** - * Items - * - * */ - - const _workflowConfigFns = useWorkflowConfig({dashboardPage}); - - const { - headerItems, - primaryItems, - secondaryItems, - actionItems, - publicationControlsLeft, - publicationControlsRight, - } = useWorkflowItems(_workflowConfigFns, () => ({ - selectedMenuState: selectedMenuState.value, - submission: submission.value, - pageInitConfig: props.pageInitConfig, - selectedPublication: selectedPublication.value, - selectedPublicationId: selectedPublicationId.value, - selectedReviewRound: selectedReviewRound.value, - permissions: permissions.value, - publicationSettings: props.pageInitConfig.publicationSettings, - })); - - const Components = markRaw({ - FileManager, - ReviewerManager, - DiscussionManager, - ContributorManager, - ParticipantManager, - GalleyManager, - WorkflowActionButton, - WorkflowActionChangeDecision, - WorkflowNotificationDisplay, - WorkflowPrimaryBasicMetadata, - WorkflowPublicationForm, - WorkflowPublicationRelationDropdownOPS, - WorkflowPublicationVersionControl, - WorkflowChangeSubmissionLanguage, - WorkflowSubmissionStatus, - WorkflowPublicationEditDisabled, - }); - - const store = { - dashboardPage, - closeWorkflowModal, - - submission, - submissionId, - selectedPublication, - selectPublicationId, - extendedStage, - stageLabel, - - /** - * Navigation - * */ - sideMenuProps, - selectedMenuState, - navigateToMenu, - - /** Actions - * - */ - ...workflowActions, - ...decisionActions, - - /** - * Summary - */ - menuTitle, - headerItems, - primaryItems, - secondaryItems, - actionItems, - publicationControlsLeft, - publicationControlsRight, - - permissions, - /** - * Expose for extensions - */ - - _workflowActionsFns, - _workflowDecisionsFns, - - Components, - }; - return store; -});