-
Notifications
You must be signed in to change notification settings - Fork 653
Pro 8671 fix localize modal #5156
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
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| class="apos-wizard apos-i18n-localize" | ||
| :class="{ 'apos-wizard-busy': wizard.busy }" | ||
| :modal="modal" | ||
| :modal-data="modalData" | ||
| @esc="close" | ||
| @inactive="modal.active = false" | ||
| @show-modal="modal.showModal = true" | ||
|
|
@@ -325,6 +326,10 @@ export default { | |
| required: true, | ||
| type: String | ||
| }, | ||
| modalData: { | ||
| required: true, | ||
| type: Object | ||
| }, | ||
| shouldRedirect: { | ||
| type: Boolean, | ||
| default: true | ||
|
|
@@ -419,6 +424,7 @@ export default { | |
| allRelatedDocs: [], | ||
| allRelatedDocsKnown: false, | ||
| docTypesSeen: [], | ||
| relatedDocTypes: [], | ||
| searchField: { | ||
| label: this.$t('apostrophe:searchLocales'), | ||
| placeholder: `${this.$t('apostrophe:searchLocales')}...` | ||
|
|
@@ -488,13 +494,6 @@ export default { | |
| isBatchMode() { | ||
| return this.batchOptions.enabled; | ||
| }, | ||
| currentLocale() { | ||
| // We need to grab the locale from the modal data, because it can change | ||
| // while in modal (switch locale in editor modal). | ||
| // Exposing `modalData` property breaks the internally used AposModal | ||
| // component for some unknown reason, so we need to use the attrs. | ||
| return this.$attrs['modal-data']?.locale ?? this.moduleOptions.locale; | ||
| }, | ||
| action() { | ||
| return this.doc.slug.startsWith('/') | ||
| ? apos.page.action | ||
|
|
@@ -518,32 +517,6 @@ export default { | |
| .filter(locale => !this.isCurrentLocale(locale) && this.canEditLocale(locale)) | ||
| .length; | ||
| }, | ||
| relatedDocTypes() { | ||
| if (this.isBatchMode) { | ||
| return this.getRelatedSchemaTypes(this.batchOptions.checkedTypes); | ||
| } | ||
|
|
||
| const types = {}; | ||
| for (const doc of this.relatedDocs) { | ||
| if (!types[doc.type]) { | ||
| types[doc.type] = { | ||
| value: doc.type, | ||
| count: 0, | ||
| readOnly: false | ||
| }; | ||
| } | ||
| types[doc.type].count++; | ||
| } | ||
| for (const type of Object.values(types)) { | ||
| const baseLabel = this.plural(type.value); | ||
| type.label = { | ||
| key: 'apostrophe:typeWithCount', | ||
| type: this.$t(baseLabel), | ||
| count: type.count | ||
| }; | ||
| } | ||
| return Object.values(types); | ||
| }, | ||
| relatedDocTypesField() { | ||
| return { | ||
| name: 'related-doc-types-to-localize', | ||
|
|
@@ -611,17 +584,6 @@ export default { | |
| } | ||
| } | ||
| } | ||
| }, | ||
| relatedDocTypes(newVal) { | ||
| if (!this.isBatchMode) { | ||
| return; | ||
| } | ||
| for (const item of newVal) { | ||
| if (!this.docTypesSeen.includes(item.value)) { | ||
| this.docTypesSeen.push(item.value); | ||
| this.wizard.values.relatedDocTypesToLocalize.data.push(item.value); | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| async mounted() { | ||
|
|
@@ -631,6 +593,7 @@ export default { | |
| if (this.isBatchMode) { | ||
| this.wizard.step = this.visibleStepNames[0]; | ||
| this.wizard.busy = false; | ||
| this.setRelatedDocTypes(); | ||
| } else { | ||
| try { | ||
| this.fullDoc = await apos.http.get( | ||
|
|
@@ -659,6 +622,40 @@ export default { | |
| } | ||
| }, | ||
| methods: { | ||
| setRelatedDocTypes() { | ||
| if (this.isBatchMode) { | ||
| this.relatedDocTypes = this.getRelatedSchemaTypes(this.batchOptions.checkedTypes); | ||
| for (const item of this.relatedDocTypes) { | ||
| if (!this.docTypesSeen.includes(item.value)) { | ||
| this.docTypesSeen.push(item.value); | ||
| this.wizard.values.relatedDocTypesToLocalize.data.push(item.value); | ||
| } | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| const types = {}; | ||
| for (const doc of this.relatedDocs) { | ||
| if (!types[doc.type]) { | ||
| types[doc.type] = { | ||
| value: doc.type, | ||
| count: 0, | ||
| readOnly: false | ||
| }; | ||
| } | ||
| types[doc.type].count++; | ||
| } | ||
| for (const type of Object.values(types)) { | ||
| const baseLabel = this.plural(type.value); | ||
| type.label = { | ||
| key: 'apostrophe:typeWithCount', | ||
| type: this.$t(baseLabel), | ||
| count: type.count | ||
| }; | ||
| } | ||
| this.relatedDocTypes = Object.values(types); | ||
|
|
||
| }, | ||
| normalizeConfig() { | ||
| if (this.isBatchMode) { | ||
| this.toLocalizeChoices = this.toLocalizeChoicesBatch; | ||
|
|
@@ -710,7 +707,7 @@ export default { | |
| return this.wizard.step === name; | ||
| }, | ||
| isCurrentLocale(locale) { | ||
| return this.currentLocale === locale.name; | ||
| return this.modalData.locale === locale.name; | ||
| }, | ||
| canEditLocale(locale) { | ||
| return !!locale._edit; | ||
|
|
@@ -1158,6 +1155,17 @@ export default { | |
| } | ||
| this.relatedDocs = relatedDocs; | ||
| this.wizard.busy = status; | ||
|
|
||
| for (const doc of this.relatedDocs) { | ||
| if (!this.docTypesSeen.includes(doc.type)) { | ||
| this.docTypesSeen.push(doc.type); | ||
| if (apos.modules[doc.type].relatedDocument) { | ||
| this.wizard.values.relatedDocTypesToLocalize.data.push(doc.type); | ||
| } | ||
| } | ||
| } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What the watcher on |
||
|
|
||
| this.setRelatedDocTypes(); | ||
| }, | ||
| wait(time) { | ||
| return new Promise((resolve) => { | ||
|
|
@@ -1180,7 +1188,7 @@ export default { | |
| this.wizard.values.translateTargets.data = []; | ||
| return; | ||
| } | ||
| const sourceLocale = this.currentLocale; | ||
| const sourceLocale = this.modalData.locale; | ||
| const targets = this.wizard.values.toLocales.data; | ||
|
|
||
| let response; | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What the watcher on
relatedDocTypesused to do, no need for a watcher here since we want to set it when related doc types are set in batch mode only.