Skip to content

Commit b96e13e

Browse files
committed
add locale picker
1 parent 311b6f9 commit b96e13e

7 files changed

Lines changed: 92 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Changelog
22

3+
## UNRELEASED
4+
5+
### Adds
6+
7+
* Add locale picker in the page and piece manager modals.
8+
9+
### Fixes
10+
11+
### Changes
12+
313
## 4.22.0 (2025-10-01)
414

515
### Adds

modules/@apostrophecms/doc-type/ui/apos/components/AposDocLocalePicker.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
:forbidden="forbidden"
2121
:forbidden-tooltip="forbiddenTooltip"
2222
:is-open="isOpen"
23+
:hide-localized="hideLocalized"
2324
@switch-locale="switchLocale"
2425
/>
2526
</AposContextMenu>
@@ -51,6 +52,10 @@ const props = defineProps({
5152
isModified: {
5253
type: Boolean,
5354
required: true
55+
},
56+
hideLocalized: {
57+
type: Boolean,
58+
default: false
5459
}
5560
});
5661

modules/@apostrophecms/modal/ui/apos/mixins/AposDocsManagerMixin.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ export default {
8989
},
9090
manuallyPublished() {
9191
return this.moduleOptions.localized && !this.moduleOptions.autopublish;
92+
},
93+
showLocalePicker() {
94+
return Object.keys(window.apos.i18n.locales).length > 1 &&
95+
this.moduleOptions.localized !== false &&
96+
!this.modalData.hasContextLocale;
9297
}
9398
},
9499
mounted() {

modules/@apostrophecms/page/ui/apos/components/AposPagesManager.vue

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@
2121
@click="confirmAndCancel"
2222
/>
2323
</template>
24+
<template
25+
v-if="showLocalePicker"
26+
#localeDisplay
27+
>
28+
<AposDocLocalePicker
29+
:locale="modalData.locale"
30+
:module-options="moduleOptions"
31+
:is-modified="false"
32+
:hide-localized="true"
33+
@switch-locale="switchLocale"
34+
/>
35+
</template>
2436
<template #primaryControls>
2537
<AposUtilityOperations
2638
:module-options="moduleOptions"

modules/@apostrophecms/page/ui/apos/logic/AposPagesManager.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
// Pages manager (tree) modal business logic.
22

3+
import { mapActions } from 'pinia';
4+
import { klona } from 'klona';
35
import AposModifiedMixin from 'Modules/@apostrophecms/ui/mixins/AposModifiedMixin';
46
import AposArchiveMixin from 'Modules/@apostrophecms/ui/mixins/AposArchiveMixin';
57
import AposPublishMixin from 'Modules/@apostrophecms/ui/mixins/AposPublishMixin';
68
import AposDocsManagerMixin from 'Modules/@apostrophecms/modal/mixins/AposDocsManagerMixin';
7-
import { klona } from 'klona';
9+
import { useModalStore } from 'Modules/@apostrophecms/ui/stores/modal';
810
import { debounce, asyncTaskQueue } from 'Modules/@apostrophecms/ui/utils';
911

1012
export default {
@@ -67,7 +69,8 @@ export default {
6769
allPiecesSelection: {
6870
isSelected: false,
6971
total: 0
70-
}
72+
},
73+
localeSwitched: this.modalData.hasContextLocale
7174
};
7275
},
7376
computed: {
@@ -171,6 +174,7 @@ export default {
171174
apos.bus.$off('command-menu-manager-close', this.confirmAndCancel);
172175
},
173176
methods: {
177+
...mapActions(useModalStore, [ 'updateModalData' ]),
174178
async create() {
175179
const doc = await apos.modal.execute(this.moduleOptions.components.editorModal, {
176180
moduleName: this.moduleName,
@@ -573,15 +577,27 @@ export default {
573577
}
574578
if (
575579
docIds ||
576-
!doc.aposLocale ||
577-
doc.aposLocale.split(':')[0] === this.modalData.locale
580+
!doc.aposLocale || // TODO: check localeSwitched?
581+
doc.aposLocale.split(':')[0] === this.modalData.locale // TODO: check localeSwitched?
578582
) {
579583
await this.getPages();
580584
this.getAllPagesTotal();
581585
if (action === 'archive') {
582586
this.checked = this.checked.filter(checkedId => doc._id !== checkedId);
583587
}
584588
}
589+
},
590+
async switchLocale({ locale, localized }) {
591+
this.updateModalData(this.modalData.id, { locale });
592+
this.localeSwitched = locale !== apos.i18n.locale;
593+
594+
this.currentPage = 1;
595+
596+
await this.getPages();
597+
this.getAllPagesTotal();
598+
this.headers = this.computeHeaders();
599+
600+
this.setCheckedDocs([]);
585601
}
586602
}
587603
};

modules/@apostrophecms/piece-type/ui/apos/components/AposDocsManager.vue

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@
2222
@click="confirmAndCancel"
2323
/>
2424
</template>
25+
<template
26+
v-if="showLocalePicker"
27+
#localeDisplay
28+
>
29+
<AposDocLocalePicker
30+
:locale="modalData.locale"
31+
:module-options="moduleOptions"
32+
:is-modified="false"
33+
:hide-localized="true"
34+
@switch-locale="switchLocale"
35+
/>
36+
</template>
2537
<template #primaryControls>
2638
<AposUtilityOperations
2739
:module-options="moduleOptions"
@@ -132,7 +144,7 @@
132144
</template>
133145

134146
<script>
135-
import { mapState } from 'pinia';
147+
import { mapActions, mapState } from 'pinia';
136148
import AposDocsManagerMixin from 'Modules/@apostrophecms/modal/mixins/AposDocsManagerMixin';
137149
import AposModifiedMixin from 'Modules/@apostrophecms/ui/mixins/AposModifiedMixin';
138150
import AposPublishMixin from 'Modules/@apostrophecms/ui/mixins/AposPublishMixin';
@@ -177,11 +189,12 @@ export default {
177189
allPiecesSelection: {
178190
isSelected: false,
179191
total: 0
180-
}
192+
},
193+
localeSwitched: this.modalData.hasContextLocale
181194
};
182195
},
183196
computed: {
184-
...mapState(useModalStore, [ 'activeModal' ]),
197+
...mapState(useModalStore, [ 'activeModal', 'updateModalData' ]),
185198
moduleOptions() {
186199
return window.apos.modules[this.moduleName];
187200
},
@@ -281,6 +294,7 @@ export default {
281294
apos.bus.$off('command-menu-manager-close', this.confirmAndCancel);
282295
},
283296
methods: {
297+
...mapActions(useModalStore, [ 'updateModalData' ]),
284298
async create() {
285299
await this.edit(null);
286300
},
@@ -560,8 +574,8 @@ export default {
560574
}
561575
if (
562576
docIds ||
563-
!doc.aposLocale ||
564-
doc.aposLocale.split(':')[0] === this.modalData.locale
577+
!doc.aposLocale || // TODO: check localeSwitched?
578+
doc.aposLocale.split(':')[0] === this.modalData.locale // TODO: check localeSwitched?
565579
) {
566580
await this.managePieces();
567581
await this.manageAllPiecesTotal();
@@ -570,6 +584,18 @@ export default {
570584
this.checked = this.checked.filter(checkedId => !ids.includes(checkedId));
571585
}
572586
}
587+
},
588+
async switchLocale({ locale, localized }) {
589+
this.updateModalData(this.modalData.id, { locale });
590+
this.localeSwitched = locale !== apos.i18n.locale;
591+
592+
this.currentPage = 1;
593+
594+
await this.managePieces();
595+
await this.manageAllPiecesTotal();
596+
this.headers = this.computeHeaders();
597+
598+
this.setCheckedDocs([]);
573599
}
574600
}
575601
};

modules/@apostrophecms/ui/ui/apos/components/AposLocalePicker.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,17 @@
4646
({{ locale.name }})
4747
</span>
4848
<span
49+
v-if="hideLocalized"
4950
class="apos-locale-picker__localized"
5051
:class="{ 'apos-state-is-localized': isLocalized(locale) }"
5152
/>
5253
</button>
5354
</li>
5455
</ul>
55-
<div class="apos-locales-picker__available">
56+
<div
57+
v-if="hideLocalized"
58+
class="apos-locales-picker__available"
59+
>
5660
<p class="apos-locales-picker__available-desc">
5761
{{ $t('apostrophe:documentExistsInLocales') }}
5862
</p>
@@ -93,6 +97,10 @@ const props = defineProps({
9397
isOpen: {
9498
type: Boolean,
9599
default: false
100+
},
101+
hideLocalized: {
102+
type: Boolean,
103+
default: false
96104
}
97105
});
98106

0 commit comments

Comments
 (0)