Skip to content

Commit

Permalink
pkp/pkp-lib#10618 Remove some redundant logic from omp, which can be …
Browse files Browse the repository at this point in the history
…inherited from OJS
  • Loading branch information
jardakotesovec committed Nov 27, 2024
1 parent 0904eb8 commit 2f7832d
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 262 deletions.
10 changes: 8 additions & 2 deletions src/composables/useFetch.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {ref, unref} from 'vue';
import {ofetch, createFetch} from 'ofetch';
import {useModalStore} from '@/stores/modalStore';
import {useDebounceFn} from '@vueuse/core';

let ofetchInstance = ofetch;

Expand All @@ -26,7 +27,8 @@ export function getCSRFToken() {
* @param {Object} [options.body] - The request payload, typically used with 'POST', 'PUT', or 'DELETE' requests.
* @param {Object} [options.headers] - Additional HTTP headers to be sent with the request.
* @param {string} [options.method] - The HTTP method to be used for the request (e.g., 'GET', 'POST', etc.).
*
* @param {number} options.debouncedMs - When the fetch should be debounce, this defines the delay
* @returns {Object} An object containing several reactive properties and a method for performing the fetch operation:
* @returns {Ref<Object|null>} return.data - A ref object containing the response data from the fetch operation.
* @returns {Ref<Object|null>} return.validationError - A ref object containing validation error data, relevant when `expectValidationError` is true.
Expand Down Expand Up @@ -62,7 +64,7 @@ export function useFetch(url, options = {}) {

let lastRequestController = null;

async function fetch() {
async function _fetch() {
if (lastRequestController) {
// abort in-flight request
lastRequestController.abort();
Expand Down Expand Up @@ -123,6 +125,10 @@ export function useFetch(url, options = {}) {
}
}

let fetch = _fetch;
if (options.debouncedMs) {
fetch = useDebounceFn(_fetch);
}
return {
data,
isSuccess,
Expand Down
2 changes: 2 additions & 0 deletions src/pages/dashboard/dashboardPageStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ export const useDashboardPageStore = defineComponentStore(
currentPage,
pageSize: countPerPage,
query: submissionsQuery,
// to avoid multiple fetch calls while view changing watchers triggers query params recalculation
debouncedMs: 2,
});
watch(
[submissionsUrl, submissionsQuery, currentPage],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,16 @@
import {DashboardPageTypes} from '@/pages/dashboard/dashboardPageStore';

import * as ConfigAuthorShared from './workflowConfigAuthorOJS';
import * as ConfigEditorialShared from './workflowConfigEditorialOJS';

import * as ConfigAuthorOJS from './workflowConfigAuthorOJS';
import * as ConfigEditorialOJS from './workflowConfigEditorialOJS';
import {consolidateCommonAndSpecificItems} from './workflowConfigHelpers';

export function useWorkflowConfigOJS({dashboardPage}) {
let Configs = null;

if (dashboardPage === DashboardPageTypes.EDITORIAL_DASHBOARD) {
Configs = {
getHeaderItems: ConfigEditorialOJS.getHeaderItems,
WorkflowConfig: {
...ConfigEditorialShared.WorkflowConfig,
...ConfigEditorialOJS.WorkflowConfig,
},
PublicationConfig: {
...ConfigEditorialShared.PublicationConfig,
...ConfigEditorialOJS.PublicationConfig,
},
};
Configs = ConfigEditorialOJS;
} else {
Configs = {
getHeaderItems: ConfigEditorialOJS.getHeaderItems,
WorkflowConfig: {
...ConfigAuthorShared.WorkflowConfig,
...ConfigAuthorOJS.WorkflowConfig,
},
PublicationConfig: {
...ConfigAuthorShared.PublicationConfig,
...ConfigAuthorOJS.PublicationConfig,
},
};
Configs = ConfigAuthorOJS;
}

function _getItems(
Expand Down Expand Up @@ -60,20 +38,13 @@ export function useWorkflowConfigOJS({dashboardPage}) {
return [];
}

const commonItems =
Configs.WorkflowConfig?.common?.[getterFnName]?.(itemsArgs);

// early return, if common logic decides there is nothing more to show
if (commonItems?.shouldContinue === false) {
return commonItems?.items || [];
}

return [
...(commonItems?.items || []),
...(Configs.WorkflowConfig[selectedMenuState.stageId]?.[getterFnName]?.(
itemsArgs,
) || []),
];
return consolidateCommonAndSpecificItems(
Configs.WorkflowConfig,
// workflow config is using stageId as keys
selectedMenuState.stageId,
getterFnName,
itemsArgs,
);
} else if (selectedMenuState.primaryMenuItem === 'publication') {
const itemsArgs = {
submission,
Expand All @@ -86,19 +57,13 @@ export function useWorkflowConfigOJS({dashboardPage}) {
return [];
}

const commonItems =
Configs.PublicationConfig?.common?.[getterFnName]?.(itemsArgs);

if (commonItems?.shouldContinue === false) {
return commonItems?.items || [];
}

return [
...(commonItems?.items || []),
...(Configs.PublicationConfig[selectedMenuState.secondaryMenuItem]?.[
getterFnName
]?.(itemsArgs) || []),
];
return consolidateCommonAndSpecificItems(
Configs.PublicationConfig,
// publication config is using menu name as keys
selectedMenuState.secondaryMenuItem,
getterFnName,
itemsArgs,
);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,20 @@
import {useLocalize} from '@/composables/useLocalize';
import {DashboardPageTypes} from '@/pages/dashboard/dashboardPageStore';

import {deepMerge} from '@/utils/deepMerge';
import * as ConfigAuthorOJS from './workflowConfigAuthorOJS';
import * as ConfigEditorialOJS from './workflowConfigEditorialOJS';

import * as ConfigAuthorOMP from './workflowConfigAuthorOMP';
import * as ConfigEditorialOMP from './workflowConfigEditorialOMP';

export function useWorkflowConfigOMP({dashboardPage}) {
const {t} = useLocalize();
import {consolidateCommonAndSpecificItems} from './workflowConfigHelpers';

export function useWorkflowConfigOMP({dashboardPage}) {
let Configs = null;

if (dashboardPage === DashboardPageTypes.EDITORIAL_DASHBOARD) {
Configs = {
getHeaderItems: ConfigEditorialOMP.getHeaderItems,
WorkflowConfig: {
...ConfigEditorialOJS.WorkflowConfig,
...ConfigEditorialOMP.WorkflowConfig,
},
PublicationConfig: {
...ConfigEditorialOJS.PublicationConfig,
...ConfigEditorialOMP.PublicationConfig,
},
MarketingConfig: ConfigEditorialOMP.MarketingConfig,
};
Configs = deepMerge(deepMerge({}, ConfigEditorialOJS), ConfigEditorialOMP);
} else {
Configs = {
getHeaderItems: ConfigEditorialOMP.getHeaderItems,
WorkflowConfig: {
...ConfigAuthorOJS.WorkflowConfig,
...ConfigAuthorOMP.WorkflowConfig,
},
PublicationConfig: {
...ConfigAuthorOJS.PublicationConfig,
...ConfigAuthorOMP.PublicationConfig,
},
};
Configs = deepMerge(deepMerge({}, ConfigAuthorOJS), ConfigAuthorOMP);
}

function _getItems(
Expand Down Expand Up @@ -64,33 +42,12 @@ export function useWorkflowConfigOMP({dashboardPage}) {
return [];
}

if (!permissions.accessibleStages.includes(selectedMenuState.stageId)) {
if (getterFnName === 'getPrimaryItems') {
return [
{
component: 'PrimaryBasicMetadata',
props: {body: t('user.authorization.accessibleWorkflowStage')},
},
];
} else {
return [];
}
}

const commonItems =
Configs.WorkflowConfig?.common?.[getterFnName]?.(itemsArgs);

// early return, if common logic decides there is nothing more to show
if (commonItems?.shouldContinue === false) {
return commonItems?.items || [];
}

return [
...(commonItems?.items || []),
...(Configs.WorkflowConfig[selectedMenuState.stageId]?.[getterFnName]?.(
itemsArgs,
) || []),
];
return consolidateCommonAndSpecificItems(
Configs.WorkflowConfig,
selectedMenuState.stageId,
getterFnName,
itemsArgs,
);
} else if (selectedMenuState.primaryMenuItem === 'publication') {
const itemsArgs = {
submission,
Expand All @@ -103,18 +60,12 @@ export function useWorkflowConfigOMP({dashboardPage}) {
return [];
}

const commonItems =
Configs.PublicationConfig?.common?.[getterFnName]?.(itemsArgs);

if (commonItems?.shouldContinue === false) {
return commonItems?.items || [];
}
return [
...(commonItems?.items || []),
...(Configs.PublicationConfig[selectedMenuState.secondaryMenuItem]?.[
getterFnName
]?.(itemsArgs) || []),
];
return consolidateCommonAndSpecificItems(
Configs.PublicationConfig,
selectedMenuState.secondaryMenuItem,
getterFnName,
itemsArgs,
);
} else if (selectedMenuState.primaryMenuItem === 'marketing') {
const itemsArgs = {
submission,
Expand All @@ -126,19 +77,12 @@ export function useWorkflowConfigOMP({dashboardPage}) {
return [];
}

const commonItems =
Configs.MarketingConfig?.common?.[getterFnName]?.(itemsArgs);

if (commonItems?.shouldContinue === false) {
return commonItems?.items || [];
}

return [
...(commonItems?.items || []),
...(Configs.MarketingConfig[selectedMenuState.secondaryMenuItem]?.[
getterFnName
]?.(itemsArgs) || []),
];
return consolidateCommonAndSpecificItems(
Configs.MarketingConfig,
selectedMenuState.secondaryMenuItem,
getterFnName,
itemsArgs,
);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,17 @@
import {useLocalize} from '@/composables/useLocalize';
import {DashboardPageTypes} from '@/pages/dashboard/dashboardPageStore';

import * as ConfigAuthorOPS from './workflowConfigAuthorOPS';
import * as ConfigEditorialOPS from './workflowConfigEditorialOPS';

export function useWorkflowConfigOPS({dashboardPage}) {
const {t} = useLocalize();
import {consolidateCommonAndSpecificItems} from './workflowConfigHelpers';

export function useWorkflowConfigOPS({dashboardPage}) {
let Configs = null;

if (dashboardPage === DashboardPageTypes.EDITORIAL_DASHBOARD) {
Configs = {
getHeaderItems: ConfigEditorialOPS.getHeaderItems,
WorkflowConfig: {
...ConfigEditorialOPS.WorkflowConfig,
},
PublicationConfig: {
...ConfigEditorialOPS.PublicationConfig,
},
};
Configs = ConfigEditorialOPS;
} else {
Configs = {
getHeaderItems: ConfigEditorialOPS.getHeaderItems,
WorkflowConfig: {
...ConfigAuthorOPS.WorkflowConfig,
},
PublicationConfig: {
...ConfigAuthorOPS.PublicationConfig,
},
};
Configs = ConfigAuthorOPS;
}

function _getItems(
Expand Down Expand Up @@ -56,32 +39,12 @@ export function useWorkflowConfigOPS({dashboardPage}) {
return [];
}

if (!permissions.accessibleStages.includes(selectedMenuState.stageId)) {
if (getterFnName === 'getPrimaryItems') {
return [
{
component: 'PrimaryBasicMetadata',
props: {body: t('user.authorization.accessibleWorkflowStage')},
},
];
} else {
return [];
}
}
const commonItems =
Configs.WorkflowConfig?.common?.[getterFnName]?.(itemsArgs);

// early return, if common logic decides there is nothing more to show
if (commonItems?.shouldContinue === false) {
return commonItems?.items || [];
}

return [
...(commonItems?.items || []),
...(Configs.WorkflowConfig[selectedMenuState.stageId]?.[getterFnName]?.(
itemsArgs,
) || []),
];
return consolidateCommonAndSpecificItems(
Configs.WorkflowConfig,
selectedMenuState.stageId,
getterFnName,
itemsArgs,
);
} else if (selectedMenuState.primaryMenuItem === 'publication') {
const itemsArgs = {
submission,
Expand All @@ -94,19 +57,12 @@ export function useWorkflowConfigOPS({dashboardPage}) {
return [];
}

const commonItems =
Configs.PublicationConfig?.common?.[getterFnName]?.(itemsArgs);

if (commonItems?.shouldContinue === false) {
return commonItems?.items || [];
}

return [
...(commonItems?.items || []),
...(Configs.PublicationConfig[selectedMenuState.secondaryMenuItem]?.[
getterFnName
]?.(itemsArgs) || []),
];
return consolidateCommonAndSpecificItems(
Configs.PublicationConfig,
selectedMenuState.secondaryMenuItem,
getterFnName,
itemsArgs,
);
}
}

Expand Down
Loading

0 comments on commit 2f7832d

Please sign in to comment.