From ef5052c64e6e94e3e4178652b4fce8a8cc9e3e40 Mon Sep 17 00:00:00 2001 From: soupette Date: Wed, 31 Mar 2021 13:14:06 +0200 Subject: [PATCH] Only display not used locales Signed-off-by: soupette --- .../admin/src/components/LocaleList/index.js | 6 ++++- .../admin/src/components/ModalCreate/index.js | 27 ++++++++++++++----- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/packages/strapi-plugin-i18n/admin/src/components/LocaleList/index.js b/packages/strapi-plugin-i18n/admin/src/components/LocaleList/index.js index 4842f54e7a..1da888762d 100644 --- a/packages/strapi-plugin-i18n/admin/src/components/LocaleList/index.js +++ b/packages/strapi-plugin-i18n/admin/src/components/LocaleList/index.js @@ -52,7 +52,11 @@ const LocaleList = ({ canUpdateLocale, canDeleteLocale, onToggleCreateModal, isC )} /> - + diff --git a/packages/strapi-plugin-i18n/admin/src/components/ModalCreate/index.js b/packages/strapi-plugin-i18n/admin/src/components/ModalCreate/index.js index 4347e485a6..6afe81e41f 100644 --- a/packages/strapi-plugin-i18n/admin/src/components/ModalCreate/index.js +++ b/packages/strapi-plugin-i18n/admin/src/components/ModalCreate/index.js @@ -12,7 +12,7 @@ import useAddLocale from '../../hooks/useAddLocale'; import BaseForm from './BaseForm'; import AdvancedForm from './AdvancedForm'; -const ModalCreate = ({ onClose, isOpened }) => { +const ModalCreate = ({ alreadyUsedLocales, onClose, isOpened }) => { const { defaultLocales, isLoading } = useDefaultLocales(); const { isAdding, addLocale } = useAddLocale(); const { formatMessage } = useIntl(); @@ -38,10 +38,16 @@ const ModalCreate = ({ onClose, isOpened }) => { shouldUpdatePermissions.current = true; }; - const options = (defaultLocales || []).map(locale => ({ - label: locale.code, - value: locale.name, - })); + const options = (defaultLocales || []) + .map(locale => ({ + label: locale.code, + value: locale.name, + })) + .filter(({ label }) => { + const foundLocale = alreadyUsedLocales.find(({ code }) => code === label); + + return !foundLocale; + }); const defaultOption = options[0]; @@ -84,7 +90,11 @@ const ModalCreate = ({ onClose, isOpened }) => { tabsId="i18n-settings-tabs-create" > - + @@ -113,7 +123,12 @@ const ModalCreate = ({ onClose, isOpened }) => { ); }; +ModalCreate.defaultProps = { + alreadyUsedLocales: [], +}; + ModalCreate.propTypes = { + alreadyUsedLocales: PropTypes.array, onClose: PropTypes.func.isRequired, isOpened: PropTypes.bool.isRequired, };