feat: Adds dropdown to switch locales from articles list page (#8402)
This commit is contained in:
committed by
GitHub
parent
1ddb73ea97
commit
206433db32
@@ -3,6 +3,7 @@
|
|||||||
"HEADER": {
|
"HEADER": {
|
||||||
"FILTER": "Filter by",
|
"FILTER": "Filter by",
|
||||||
"SORT": "Sort by",
|
"SORT": "Sort by",
|
||||||
|
"LOCALE": "Locale",
|
||||||
"SETTINGS_BUTTON": "Settings",
|
"SETTINGS_BUTTON": "Settings",
|
||||||
"NEW_BUTTON": "New Article",
|
"NEW_BUTTON": "New Article",
|
||||||
"DROPDOWN_OPTIONS": {
|
"DROPDOWN_OPTIONS": {
|
||||||
@@ -15,6 +16,12 @@
|
|||||||
"MINE": "My Articles",
|
"MINE": "My Articles",
|
||||||
"DRAFT": "Draft Articles",
|
"DRAFT": "Draft Articles",
|
||||||
"ARCHIVED": "Archived Articles"
|
"ARCHIVED": "Archived Articles"
|
||||||
|
},
|
||||||
|
"LOCALE_SELECT": {
|
||||||
|
"TITLE": "Select locale",
|
||||||
|
"PLACEHOLDER": "Select locale",
|
||||||
|
"NO_RESULT": "No locale found",
|
||||||
|
"SEARCH_PLACEHOLDER": "Search locale"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"EDIT_HEADER": {
|
"EDIT_HEADER": {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div
|
<div
|
||||||
class="flex px-4 items-center justify-between w-full h-16 pt-2 sticky top-0 bg-white dark:bg-slate-900"
|
class="flex px-4 items-center justify-between w-full h-16 pt-2 sticky top-0 z-10 bg-white dark:bg-slate-900"
|
||||||
>
|
>
|
||||||
<div class="flex items-center">
|
<div class="flex items-center">
|
||||||
<woot-sidemenu-icon />
|
<woot-sidemenu-icon />
|
||||||
@@ -86,6 +86,45 @@
|
|||||||
size="small"
|
size="small"
|
||||||
color-scheme="secondary"
|
color-scheme="secondary"
|
||||||
/>
|
/>
|
||||||
|
<div class="relative">
|
||||||
|
<woot-button
|
||||||
|
v-if="shouldShowLocaleDropdown"
|
||||||
|
icon="globe"
|
||||||
|
color-scheme="secondary"
|
||||||
|
size="small"
|
||||||
|
variant="hollow"
|
||||||
|
@click="openLocaleDropdown"
|
||||||
|
>
|
||||||
|
<div class="flex justify-between w-full min-w-0 items-center">
|
||||||
|
<span
|
||||||
|
class="inline-flex ml-1 rtl:ml-0 rtl:mr-1 items-center text-slate-800 dark:text-slate-100"
|
||||||
|
>
|
||||||
|
{{ selectedLocale }}
|
||||||
|
<Fluent-icon
|
||||||
|
class="dropdown-arrow"
|
||||||
|
icon="chevron-down"
|
||||||
|
size="14"
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</woot-button>
|
||||||
|
<div
|
||||||
|
v-if="showLocaleDropdown"
|
||||||
|
v-on-clickaway="closeLocaleDropdown"
|
||||||
|
class="dropdown-pane dropdown-pane--open"
|
||||||
|
>
|
||||||
|
<multiselect-dropdown-items
|
||||||
|
:options="switchableLocales"
|
||||||
|
:has-thumbnail="false"
|
||||||
|
:selected-items="[selectedLocale]"
|
||||||
|
:input-placeholder="
|
||||||
|
$t('HELP_CENTER.HEADER.LOCALE_SELECT.SEARCH_PLACEHOLDER')
|
||||||
|
"
|
||||||
|
:no-search-result="$t('HELP_CENTER.HEADER.LOCALE_SELECT.NO_RESULT')"
|
||||||
|
@click="onClickSelectItem"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<woot-button
|
<woot-button
|
||||||
size="small"
|
size="small"
|
||||||
icon="add"
|
icon="add"
|
||||||
@@ -103,12 +142,15 @@ import { mixin as clickaway } from 'vue-clickaway';
|
|||||||
|
|
||||||
import WootDropdownItem from 'shared/components/ui/dropdown/DropdownItem.vue';
|
import WootDropdownItem from 'shared/components/ui/dropdown/DropdownItem.vue';
|
||||||
import WootDropdownMenu from 'shared/components/ui/dropdown/DropdownMenu.vue';
|
import WootDropdownMenu from 'shared/components/ui/dropdown/DropdownMenu.vue';
|
||||||
|
import MultiselectDropdownItems from 'shared/components/ui/MultiselectDropdownItems.vue';
|
||||||
|
|
||||||
import FluentIcon from 'shared/components/FluentIcon/DashboardIcon.vue';
|
import FluentIcon from 'shared/components/FluentIcon/DashboardIcon.vue';
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
FluentIcon,
|
FluentIcon,
|
||||||
WootDropdownItem,
|
WootDropdownItem,
|
||||||
WootDropdownMenu,
|
WootDropdownMenu,
|
||||||
|
MultiselectDropdownItems,
|
||||||
},
|
},
|
||||||
mixins: [clickaway],
|
mixins: [clickaway],
|
||||||
props: {
|
props: {
|
||||||
@@ -124,16 +166,35 @@ export default {
|
|||||||
type: String,
|
type: String,
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
|
selectedLocale: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
shouldShowSettings: {
|
shouldShowSettings: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
|
allLocales: {
|
||||||
|
type: Array,
|
||||||
|
default: () => [],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
showSortByDropdown: false,
|
showSortByDropdown: false,
|
||||||
|
showLocaleDropdown: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
computed: {
|
||||||
|
shouldShowLocaleDropdown() {
|
||||||
|
return this.allLocales.length > 1;
|
||||||
|
},
|
||||||
|
switchableLocales() {
|
||||||
|
return this.allLocales.filter(
|
||||||
|
locale => locale.name !== this.selectedLocale
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
openFilterModal() {
|
openFilterModal() {
|
||||||
this.$emit('openModal');
|
this.$emit('openModal');
|
||||||
@@ -146,8 +207,22 @@ export default {
|
|||||||
this.$emit('close');
|
this.$emit('close');
|
||||||
this.showSortByDropdown = false;
|
this.showSortByDropdown = false;
|
||||||
},
|
},
|
||||||
|
openLocaleDropdown() {
|
||||||
|
this.showLocaleDropdown = true;
|
||||||
|
},
|
||||||
|
closeLocaleDropdown() {
|
||||||
|
this.showLocaleDropdown = false;
|
||||||
|
},
|
||||||
onClickNewArticlePage() {
|
onClickNewArticlePage() {
|
||||||
this.$emit('newArticlePage');
|
this.$emit('new-article-page');
|
||||||
|
},
|
||||||
|
onClickSelectItem(value) {
|
||||||
|
const { name, code } = value;
|
||||||
|
this.closeLocaleDropdown();
|
||||||
|
if (!name || name === this.selectedLocale) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.$emit('change-locale', code);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -155,7 +230,7 @@ export default {
|
|||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
.dropdown-pane--open {
|
.dropdown-pane--open {
|
||||||
@apply top-12 right-[9.25rem];
|
@apply absolute top-10 right-0 z-50 min-w-[8rem];
|
||||||
}
|
}
|
||||||
.dropdown-arrow {
|
.dropdown-arrow {
|
||||||
@apply ml-1 rtl:ml-0 rtl:mr-1;
|
@apply ml-1 rtl:ml-0 rtl:mr-1;
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
v-if="isHelpCenterEnabled"
|
v-if="isHelpCenterEnabled"
|
||||||
class="flex h-full min-h-0 overflow-hidden flex-1 px-0 bg-white dark:bg-slate-900"
|
class="flex h-full min-h-0 overflow-hidden flex-1 px-0 bg-white dark:bg-slate-900"
|
||||||
>
|
>
|
||||||
<router-view />
|
<router-view @reload-locale="fetchPortalAndItsCategories" />
|
||||||
<command-bar />
|
<command-bar />
|
||||||
<account-selector
|
<account-selector
|
||||||
:show-account-modal="showAccountModal"
|
:show-account-modal="showAccountModal"
|
||||||
|
|||||||
@@ -5,8 +5,11 @@
|
|||||||
<article-header
|
<article-header
|
||||||
:header-title="headerTitle"
|
:header-title="headerTitle"
|
||||||
:count="meta.count"
|
:count="meta.count"
|
||||||
|
:selected-locale="activeLocaleName"
|
||||||
|
:all-locales="allowedLocales"
|
||||||
selected-value="Published"
|
selected-value="Published"
|
||||||
@newArticlePage="newArticlePage"
|
@new-article-page="newArticlePage"
|
||||||
|
@change-locale="onChangeLocale"
|
||||||
/>
|
/>
|
||||||
<article-table
|
<article-table
|
||||||
:articles="articles"
|
:articles="articles"
|
||||||
@@ -32,6 +35,7 @@
|
|||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import { mapGetters } from 'vuex';
|
import { mapGetters } from 'vuex';
|
||||||
|
import allLocales from 'shared/constants/locales.js';
|
||||||
|
|
||||||
import Spinner from 'shared/components/Spinner.vue';
|
import Spinner from 'shared/components/Spinner.vue';
|
||||||
import ArticleHeader from 'dashboard/routes/dashboard/helpcenter/components/Header/ArticleHeader.vue';
|
import ArticleHeader from 'dashboard/routes/dashboard/helpcenter/components/Header/ArticleHeader.vue';
|
||||||
@@ -58,6 +62,7 @@ export default {
|
|||||||
meta: 'articles/getMeta',
|
meta: 'articles/getMeta',
|
||||||
isFetching: 'articles/isFetching',
|
isFetching: 'articles/isFetching',
|
||||||
currentUserId: 'getCurrentUserID',
|
currentUserId: 'getCurrentUserID',
|
||||||
|
getPortalBySlug: 'portals/portalBySlug',
|
||||||
}),
|
}),
|
||||||
selectedCategory() {
|
selectedCategory() {
|
||||||
return this.categories.find(
|
return this.categories.find(
|
||||||
@@ -118,6 +123,28 @@ export default {
|
|||||||
? this.selectedCategory.name
|
? this.selectedCategory.name
|
||||||
: '';
|
: '';
|
||||||
},
|
},
|
||||||
|
activeLocale() {
|
||||||
|
return this.$route.params.locale;
|
||||||
|
},
|
||||||
|
activeLocaleName() {
|
||||||
|
return allLocales[this.activeLocale];
|
||||||
|
},
|
||||||
|
portal() {
|
||||||
|
return this.getPortalBySlug(this.selectedPortalSlug);
|
||||||
|
},
|
||||||
|
allowedLocales() {
|
||||||
|
if (!this.portal) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
const { allowed_locales: allowedLocales } = this.portal.config;
|
||||||
|
return allowedLocales.map(locale => {
|
||||||
|
return {
|
||||||
|
id: locale.code,
|
||||||
|
name: allLocales[locale.code],
|
||||||
|
code: locale.code,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
},
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
$route() {
|
$route() {
|
||||||
@@ -137,7 +164,7 @@ export default {
|
|||||||
this.$store.dispatch('articles/index', {
|
this.$store.dispatch('articles/index', {
|
||||||
pageNumber: pageNumber || this.pageNumber,
|
pageNumber: pageNumber || this.pageNumber,
|
||||||
portalSlug: this.$route.params.portalSlug,
|
portalSlug: this.$route.params.portalSlug,
|
||||||
locale: this.$route.params.locale,
|
locale: this.activeLocale,
|
||||||
status: this.status,
|
status: this.status,
|
||||||
authorId: this.author,
|
authorId: this.author,
|
||||||
categorySlug: this.selectedCategorySlug,
|
categorySlug: this.selectedCategorySlug,
|
||||||
@@ -152,6 +179,16 @@ export default {
|
|||||||
portalSlug: this.$route.params.portalSlug,
|
portalSlug: this.$route.params.portalSlug,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
onChangeLocale(locale) {
|
||||||
|
this.$router.push({
|
||||||
|
name: 'list_all_locale_articles',
|
||||||
|
params: {
|
||||||
|
portalSlug: this.$route.params.portalSlug,
|
||||||
|
locale,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
this.$emit('reload-locale');
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user