Skip to content

Commit 8afb7ba

Browse files
committed
fix(admin): fix admin panel failing to build due to direct imports from plugin-i18n
The i18n plugin has added the "exports" field to its package.json file, preventing direct import of some utilities that need here. Instead of the import, the needed functions are now added here directly with some minor modifications fix #378
1 parent 60b42c5 commit 8afb7ba

File tree

1 file changed

+23
-11
lines changed
  • plugin/admin/src/components/CMEditViewTranslateLocale

1 file changed

+23
-11
lines changed

plugin/admin/src/components/CMEditViewTranslateLocale/index.js

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ import {
4747
CheckPermissions,
4848
request,
4949
} from '@strapi/helper-plugin'
50-
import { generateOptions } from '@strapi/plugin-i18n/admin/src/components/CMEditViewInjectedComponents/CMEditViewCopyLocale/utils'
51-
import useContentTypePermissions from '@strapi/plugin-i18n/admin/src/hooks/useContentTypePermissions'
52-
import selectI18NLocales from '@strapi/plugin-i18n/admin/src/selectors/selectI18nLocales'
5350
import _ from 'lodash'
5451
import { getTrad } from '../../utils'
5552
import permissions from '../../permissions'
@@ -73,9 +70,12 @@ const CenteredTypography = styled(Typography)`
7370

7471
const CMEditViewTranslateLocale = () => {
7572
const [{ query }] = useQueryParams()
76-
const locales = useSelector(selectI18NLocales)
73+
const locales = useSelector((state) => state.i18n_locales.locales)
7774
const { layout, modifiedData, slug } = useCMEditViewDataManager()
78-
const { readPermissions } = useContentTypePermissions(slug)
75+
const readPermissions =
76+
(useSelector(
77+
(state) => state.rbacProvider.collectionTypesRelatedPermissions
78+
)[slug] || [])['plugin::content-manager.explorer.read'] || []
7979

8080
const defaultLocale = locales.find((loc) => loc.isDefault)
8181
const currentLocale = get(query, 'plugins.i18n.locale', defaultLocale.code)
@@ -90,6 +90,8 @@ const CMEditViewTranslateLocale = () => {
9090
return null
9191
}
9292

93+
console.log(readPermissions)
94+
9395
return (
9496
<CheckPermissions permissions={permissions.translate}>
9597
<Content
@@ -113,12 +115,22 @@ const Content = ({
113115
const { allLayoutData, initialData, slug, onChange } =
114116
useCMEditViewDataManager()
115117

116-
const options = generateOptions(
117-
appLocales,
118-
currentLocale,
119-
localizations,
120-
readPermissions
121-
)
118+
const options = appLocales
119+
.filter(({ code }) => {
120+
return (
121+
code !== currentLocale &&
122+
localizations.map(({ locale }) => locale).includes(code) &&
123+
readPermissions.some(({ properties }) =>
124+
get(properties, 'locales', []).includes(code)
125+
)
126+
)
127+
})
128+
.map(({ name, code }) => {
129+
return {
130+
label: name,
131+
value: localizations.find(({ locale }) => code === locale).id,
132+
}
133+
})
122134

123135
const toggleNotification = useNotification()
124136
const { formatMessage } = useIntl()

0 commit comments

Comments
 (0)