Skip to content

Commit d61e83f

Browse files
committed
pkp/pkp-lib#9295 remove redundant checks and fix issue with store at unmount
1 parent 7237121 commit d61e83f

File tree

6 files changed

+34
-45
lines changed

6 files changed

+34
-45
lines changed

src/components/Form/fields/FieldUpload.vue

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,12 @@ export default {
258258
* Add attributes to the hidden file input field so that labels and
259259
* descriptions can be accessed by those using assistive devices.
260260
*/
261-
if (this.$refs.dropzone) {
262-
this.$refs.dropzone.dropzone.hiddenFileInput.id =
263-
this.dropzoneHiddenFileId;
264-
this.$refs.dropzone.dropzone.hiddenFileInput.setAttribute(
265-
'aria-describedby',
266-
this.describedByIds,
267-
);
268-
}
261+
this.$refs.dropzone.dropzone.hiddenFileInput.id =
262+
this.dropzoneHiddenFileId;
263+
this.$refs.dropzone.dropzone.hiddenFileInput.setAttribute(
264+
'aria-describedby',
265+
this.describedByIds,
266+
);
269267
270268
/**
271269
* Set the initial data, which can't be set in the data() function because it relies on

src/components/Form/fields/FieldUploadImage.vue

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -250,14 +250,12 @@ export default {
250250
* Add attributes to the hidden file input field so that labels and
251251
* descriptions can be accessed by those using assistive devices.
252252
*/
253-
if (this.$refs.dropzone) {
254-
this.$refs.dropzone.dropzone.hiddenFileInput.id =
255-
this.dropzoneHiddenFileId;
256-
this.$refs.dropzone.dropzone.hiddenFileInput.setAttribute(
257-
'aria-describedby',
258-
this.describedByIds,
259-
);
260-
}
253+
this.$refs.dropzone.dropzone.hiddenFileInput.id =
254+
this.dropzoneHiddenFileId;
255+
this.$refs.dropzone.dropzone.hiddenFileInput.setAttribute(
256+
'aria-describedby',
257+
this.describedByIds,
258+
);
261259
262260
/**
263261
* Set the initial data, which can't be set in the data() function because it relies on

src/pages/workflow/components/publication/WorkflowPublicationForm.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ async function metadataDataChange() {
7373
await fetchForm();
7474
}
7575
76+
// This handle the case where the issue selection done vai `Schedule For Publication` modal while at issue page
77+
// but not finalise the publication status(publishing or scheduling) at final step but close the modal
78+
// so we need to fetch the form again to update the issue selection field to reflect the changes.
7679
async function issueDataChange() {
7780
await fetchForm();
7881
}
@@ -81,10 +84,13 @@ watch(
8184
form,
8285
async (newForm) => {
8386
if (newForm && props.formName === 'issue' && isOJS()) {
84-
const {initialize} = useWorkflowPublicationFormIssue(newForm);
87+
const {initialize} = useWorkflowPublicationFormIssue(
88+
newForm,
89+
props.publicationpublication,
90+
);
8591
await initialize();
8692
}
8793
},
88-
{immediate: true},
94+
{immediate: false},
8995
);
9096
</script>

src/pages/workflow/composables/useWorkflowPublicationFormIssue.js

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ import {useFetch} from '@/composables/useFetch';
22
import {useUrl} from '@/composables/useUrl';
33
import {computed, watch} from 'vue';
44
import {useLocalize} from '@/composables/useLocalize';
5-
import {useWorkflowStore} from '@/pages/workflow/workflowStore';
65
import {useForm} from '@/composables/useForm';
76

8-
export function useWorkflowPublicationFormIssue(form) {
7+
export function useWorkflowPublicationFormIssue(form, selectedPublication) {
98
const {t} = useLocalize();
10-
const store = useWorkflowStore();
119
const {
1210
setHiddenValue,
1311
getHiddenValue,
@@ -21,7 +19,7 @@ export function useWorkflowPublicationFormIssue(form) {
2119
const {fetch: fetchAssignments, data: assignments} = useFetch(assignmentsUrl);
2220

2321
const {apiUrl: assignmentStatusUrl} = useUrl(
24-
`submissions/${store.submission.id}/publications/${store.selectedPublication.id}/issueAssignmentStatus`,
22+
`submissions/${selectedPublication.submissionId}/publications/${selectedPublication.id}/issueAssignmentStatus`,
2523
);
2624
const {fetch: fetchAssignmentStatus, data: assignmentStatus} =
2725
useFetch(assignmentStatusUrl);
@@ -103,14 +101,8 @@ export function useWorkflowPublicationFormIssue(form) {
103101

104102
const issueIdField = getField('issueId');
105103
const assignmentField = getField('assignment');
106-
const statusValue = getHiddenValue('status');
107104

108-
return (
109-
issueIdField &&
110-
assignmentField &&
111-
statusValue !== null &&
112-
statusValue !== undefined
113-
);
105+
return issueIdField && assignmentField;
114106
}
115107

116108
/**
@@ -129,13 +121,13 @@ export function useWorkflowPublicationFormIssue(form) {
129121
description: t('publication.assignToIssue.issueDescription'),
130122
options: [],
131123
size: 'large',
132-
value: store.selectedPublication?.issueId,
124+
value: selectedPublication?.issueId,
133125
isRequired: true,
134126
showWhen: ['assignment', []],
135127
});
136128

137129
// Set initial status - will be updated by watchers when assignmentStatus data arrives
138-
setHiddenValue('status', store.selectedPublication?.status);
130+
setHiddenValue('status', selectedPublication?.status);
139131
}
140132

141133
/**
@@ -161,7 +153,7 @@ export function useWorkflowPublicationFormIssue(form) {
161153
![
162154
pkp.const.publication.STATUS_PUBLISHED,
163155
pkp.const.publication.STATUS_SCHEDULED,
164-
].includes(store.selectedPublication?.status)
156+
].includes(selectedPublication?.status)
165157
) {
166158
setHiddenValue('status', newStatus.status);
167159
}
@@ -191,7 +183,7 @@ export function useWorkflowPublicationFormIssue(form) {
191183
issueIdField.showWhen = ['assignment', newShowWhenIds];
192184
}
193185
},
194-
{immediate: true},
186+
{immediate: false},
195187
);
196188

197189
// Watch current assignment option changes and update status
@@ -209,10 +201,12 @@ export function useWorkflowPublicationFormIssue(form) {
209201
[
210202
pkp.const.publication.STATUS_PUBLISHED,
211203
pkp.const.publication.STATUS_SCHEDULED,
212-
].includes(store.selectedPublication?.status)
204+
].includes(selectedPublication?.status)
213205
) {
214206
setHiddenValue('status', null);
215207
}
208+
209+
isInitialDataLoad = false;
216210
}
217211

218212
if (newOption.isPublished !== null) {
@@ -232,12 +226,6 @@ export function useWorkflowPublicationFormIssue(form) {
232226
},
233227
{immediate: true},
234228
);
235-
236-
// Mark initial data load as complete after a short delay
237-
// which in return all initial watchers have had a chance to run
238-
setTimeout(() => {
239-
isInitialDataLoad = false;
240-
}, 100);
241229
}
242230

243231
/**

src/pages/workflow/composables/useWorkflowVersionForm.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,10 @@ export function useWorkflowVersionForm(
321321
// it's in publish mode
322322
// have issues
323323
if (modeState.isPublishMode && issueCount > 0 && isOJS()) {
324-
const {initialize} = useWorkflowPublicationFormIssue(form);
324+
const {initialize} = useWorkflowPublicationFormIssue(
325+
form,
326+
store.selectedPublication,
327+
);
325328
await initialize();
326329
}
327330

src/utils/defineComponentStore.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ export function defineComponentStore(
5656
storesMap[storeName].mountedCount = storesMap[storeName].mountedCount + 1;
5757
});
5858
onBeforeUnmount(() => {
59-
if (!storesMap[storeName]) {
60-
return;
61-
}
62-
6359
storesMap[storeName].mountedCount = storesMap[storeName].mountedCount - 1;
6460

6561
if (storesMap[storeName].mountedCount === 0) {

0 commit comments

Comments
 (0)