Merge pull request #10292 from strapi/chore/load-i18n

Load i18n plugin
This commit is contained in:
cyril lopez 2021-05-12 07:54:21 +02:00 committed by GitHub
commit b70067f337
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 284 additions and 238 deletions

View File

@ -41,10 +41,12 @@ class StrapiApp {
this.appPlugins = appPlugins || {}; this.appPlugins = appPlugins || {};
this.componentApi = Components(); this.componentApi = Components();
this.fieldApi = Fields(); this.fieldApi = Fields();
// FIXME
this.middlewares = []; this.middlewares = [];
this.plugins = {}; this.plugins = {};
this.reducers = { ...reducers }; this.reducers = { ...reducers };
this.translations = translations; this.translations = translations;
// this.addMiddleware = this.addMiddleware.bind(this);
this.getPlugin = this.getPlugin.bind(this); this.getPlugin = this.getPlugin.bind(this);
} }

View File

@ -4,7 +4,7 @@ import createReducer from './createReducer';
const configureStore = app => { const configureStore = app => {
const middlewares = []; const middlewares = [];
middlewares.forEach(middleware => { app.middlewares.forEach(middleware => {
middlewares.push(middleware()); middlewares.push(middleware());
}); });

View File

@ -1,6 +1,7 @@
// TODO temp file // TODO temp file
import documentationPlugin from '../../../../plugins/documentation/admin/src'; import documentationPlugin from '../../../../plugins/documentation/admin/src';
import graphqlPlugin from '../../../../plugins/graphql/admin/src'; import graphqlPlugin from '../../../../plugins/graphql/admin/src';
import i18nPlugin from '../../../../plugins/i18n/admin/src';
import sentryPlugin from '../../../../plugins/sentry/admin/src'; import sentryPlugin from '../../../../plugins/sentry/admin/src';
import usersPermissionsPlugin from '../../../../plugins/users-permissions/admin/src'; import usersPermissionsPlugin from '../../../../plugins/users-permissions/admin/src';
import cmPlugin from '../../../content-manager/admin/src'; import cmPlugin from '../../../content-manager/admin/src';
@ -12,6 +13,7 @@ const plugins = {
'@strapi/plugin-content-manager': cmPlugin, '@strapi/plugin-content-manager': cmPlugin,
'@strapi/plugin-content-type-builder': ctbPlugin, '@strapi/plugin-content-type-builder': ctbPlugin,
'@strapi/plugin-documentation': documentationPlugin, '@strapi/plugin-documentation': documentationPlugin,
'@strapi/plugin-i18n': i18nPlugin,
'@strapi/plugin-email': emailPlugin, '@strapi/plugin-email': emailPlugin,
'@strapi/plugin-upload': uploadPlugin, '@strapi/plugin-upload': uploadPlugin,
'@strapi/plugin-graphql': graphqlPlugin, '@strapi/plugin-graphql': graphqlPlugin,

View File

@ -9,15 +9,15 @@ import PropTypes from 'prop-types';
import pluginId from '../pluginId'; import pluginId from '../pluginId';
import useLocales from '../hooks/useLocales'; import useLocales from '../hooks/useLocales';
const Initializer = ({ updatePlugin }) => { const Initializer = ({ setPlugin }) => {
const { isLoading, locales } = useLocales(); const { isLoading, locales } = useLocales();
const ref = useRef(); const ref = useRef();
ref.current = updatePlugin; ref.current = setPlugin;
useEffect(() => { useEffect(() => {
if (!isLoading && locales.length > 0) { if (!isLoading && locales.length > 0) {
ref.current(pluginId, 'isReady', true); ref.current(pluginId);
} }
}, [isLoading, locales]); }, [isLoading, locales]);
@ -25,7 +25,7 @@ const Initializer = ({ updatePlugin }) => {
}; };
Initializer.propTypes = { Initializer.propTypes = {
updatePlugin: PropTypes.func.isRequired, setPlugin: PropTypes.func.isRequired,
}; };
export default Initializer; export default Initializer;

View File

@ -1,10 +1,7 @@
/* eslint-disable react/prop-types */ /* eslint-disable react/prop-types */
import React from 'react'; import React from 'react';
import { createStore } from 'redux'; import { createStore, combineReducers } from 'redux';
import { combineReducers } from 'redux-immutable';
import { fromJS } from 'immutable';
import { Provider } from 'react-redux'; import { Provider } from 'react-redux';
import { request, useUserPermissions } from '@strapi/helper-plugin'; import { request, useUserPermissions } from '@strapi/helper-plugin';
import { fireEvent, render, screen, within, waitFor } from '@testing-library/react'; import { fireEvent, render, screen, within, waitFor } from '@testing-library/react';
@ -14,13 +11,13 @@ import LocaleSettingsPage from '..';
// TODO: move to @strapi/helper-plugin // TODO: move to @strapi/helper-plugin
import themes from '../../../../../../../core/admin/admin/src/themes'; import themes from '../../../../../../../core/admin/admin/src/themes';
import i18nReducers, { initialState } from '../../../hooks/reducers'; import i18nReducers, { initialState } from '../../../hooks/reducers';
import pluginId from '../../../pluginId';
const TestWrapper = ({ children }) => { const TestWrapper = ({ children }) => {
const queryClient = new QueryClient(); const queryClient = new QueryClient();
const initialStoreState = fromJS(initialState);
const rootReducer = combineReducers(i18nReducers); const rootReducer = combineReducers(i18nReducers);
const store = createStore(rootReducer, initialStoreState); const store = createStore(rootReducer, { [`${pluginId}_locales`]: initialState });
return ( return (
<Provider store={store}> <Provider store={store}>

View File

@ -2,7 +2,7 @@ import { useSelector } from 'react-redux';
import get from 'lodash/get'; import get from 'lodash/get';
const selectContentManagerListViewPluginOptions = state => const selectContentManagerListViewPluginOptions = state =>
state.get('content-manager_listView').contentType.pluginOptions; state['content-manager_listView'].contentType.pluginOptions;
const useHasI18n = () => { const useHasI18n = () => {
const pluginOptions = useSelector(selectContentManagerListViewPluginOptions); const pluginOptions = useSelector(selectContentManagerListViewPluginOptions);

View File

@ -22,8 +22,8 @@ const fetchLocalesList = async () => {
const useLocales = () => { const useLocales = () => {
const dispatch = useDispatch(); const dispatch = useDispatch();
const locales = useSelector(state => state.get('i18n_locales').locales); const locales = useSelector(state => state.i18n_locales.locales);
const isLoading = useSelector(state => state.get('i18n_locales').isLoading); const isLoading = useSelector(state => state.i18n_locales.isLoading);
useEffect(() => { useEffect(() => {
fetchLocalesList().then(locales => dispatch({ type: RESOLVE_LOCALES, locales })); fetchLocalesList().then(locales => dispatch({ type: RESOLVE_LOCALES, locales }));

View File

@ -18,152 +18,155 @@ import LOCALIZED_FIELDS from './utils/localizedFields';
import i18nReducers from './hooks/reducers'; import i18nReducers from './hooks/reducers';
import DeleteModalAdditionalInfos from './components/DeleteModalAdditionalInfos'; import DeleteModalAdditionalInfos from './components/DeleteModalAdditionalInfos';
export default strapi => { const pluginDescription = pluginPkg.strapi.description || pluginPkg.description;
const pluginDescription = pluginPkg.strapi.description || pluginPkg.description; const icon = pluginPkg.strapi.icon;
const name = pluginPkg.strapi.name;
middlewares.forEach(middleware => { export default {
strapi.middlewares.add(middleware); register(app) {
}); // FIXME
middlewares.forEach(middleware => {
app.addMiddleware(middleware);
});
const plugin = { app.addReducers(i18nReducers);
description: pluginDescription,
icon: pluginPkg.strapi.icon, app.registerPlugin({
id: pluginId, description: pluginDescription,
isReady: false, icon,
isRequired: pluginPkg.strapi.required || false, id: pluginId,
mainComponent: null, initializer: Initializer,
name: pluginPkg.strapi.name, isReady: false,
pluginLogo, isRequired: pluginPkg.strapi.required || false,
preventComponentRendering: false, mainComponent: null,
settings: { name,
global: { pluginLogo,
links: [ settings: {
{ global: {
title: { links: [
id: getTrad('plugin.name'), {
defaultMessage: 'Internationalization', title: {
id: getTrad('plugin.name'),
defaultMessage: 'Internationalization',
},
name: 'internationalization',
to: '/settings/internationalization',
Component: () => <SettingsPage />,
permissions: pluginPermissions.accessMain,
}, },
name: 'internationalization', ],
to: '/settings/internationalization', },
Component: () => <SettingsPage />,
permissions: pluginPermissions.accessMain,
},
],
}, },
}, trads,
trads, });
reducers: i18nReducers, },
boot(app) { boot(app) {
const ctbPlugin = app.getPlugin('content-type-builder'); const ctbPlugin = app.getPlugin('content-type-builder');
const cmPlugin = app.getPlugin('content-manager'); const cmPlugin = app.getPlugin('content-manager');
if (cmPlugin) { if (cmPlugin) {
cmPlugin.injectComponent('editView', 'informations', { cmPlugin.injectComponent('editView', 'informations', {
name: 'i18n-locale-filter-edit-view', name: 'i18n-locale-filter-edit-view',
Component: CMEditViewInjectedComponents, Component: CMEditViewInjectedComponents,
}); });
cmPlugin.injectComponent('listView', 'actions', { cmPlugin.injectComponent('listView', 'actions', {
name: 'i18n-locale-filter', name: 'i18n-locale-filter',
Component: LocalePicker, Component: LocalePicker,
}); });
cmPlugin.injectComponent('listView', 'deleteModalAdditionalInfos', { cmPlugin.injectComponent('listView', 'deleteModalAdditionalInfos', {
name: 'i18n-delete-bullets-in-modal', name: 'i18n-delete-bullets-in-modal',
Component: DeleteModalAdditionalInfos, Component: DeleteModalAdditionalInfos,
}); });
} }
if (ctbPlugin) { if (ctbPlugin) {
const ctbFormsAPI = ctbPlugin.apis.forms; const ctbFormsAPI = ctbPlugin.apis.forms;
ctbFormsAPI.addContentTypeSchemaMutation(mutateCTBContentTypeSchema); ctbFormsAPI.addContentTypeSchemaMutation(mutateCTBContentTypeSchema);
ctbFormsAPI.components.add({ id: 'checkboxConfirmation', component: CheckboxConfirmation }); ctbFormsAPI.components.add({ id: 'checkboxConfirmation', component: CheckboxConfirmation });
ctbFormsAPI.extendContentType({ ctbFormsAPI.extendContentType({
validator: () => ({ validator: () => ({
i18n: yup.object().shape({ i18n: yup.object().shape({
localized: yup.bool(), localized: yup.bool(),
}),
}), }),
form: { }),
advanced() { form: {
return [ advanced() {
[ return [
{ [
name: 'pluginOptions.i18n.localized', {
description: { name: 'pluginOptions.i18n.localized',
id: getTrad('plugin.schema.i18n.localized.description-content-type'), description: {
}, id: getTrad('plugin.schema.i18n.localized.description-content-type'),
type: 'checkboxConfirmation',
label: { id: getTrad('plugin.schema.i18n.localized.label-content-type') },
}, },
], type: 'checkboxConfirmation',
]; label: { id: getTrad('plugin.schema.i18n.localized.label-content-type') },
},
},
});
ctbFormsAPI.extendFields(LOCALIZED_FIELDS, {
validator: args => ({
i18n: yup.object().shape({
localized: yup.bool().test({
name: 'ensure-unique-localization',
message: getTrad('plugin.schema.i18n.ensure-unique-localization'),
test(value) {
if (value === undefined || value) {
return true;
}
const unique = get(args, ['3', 'modifiedData', 'unique'], null);
// Unique fields must be localized
if (unique && !value) {
return false;
}
return true;
}, },
}), ],
];
},
},
});
ctbFormsAPI.extendFields(LOCALIZED_FIELDS, {
validator: args => ({
i18n: yup.object().shape({
localized: yup.bool().test({
name: 'ensure-unique-localization',
message: getTrad('plugin.schema.i18n.ensure-unique-localization'),
test(value) {
if (value === undefined || value) {
return true;
}
const unique = get(args, ['3', 'modifiedData', 'unique'], null);
// Unique fields must be localized
if (unique && !value) {
return false;
}
return true;
},
}), }),
}), }),
form: { }),
advanced({ contentTypeSchema, forTarget, type, step }) { form: {
if (forTarget !== 'contentType') { advanced({ contentTypeSchema, forTarget, type, step }) {
return []; if (forTarget !== 'contentType') {
} return [];
}
const hasI18nEnabled = get( const hasI18nEnabled = get(
contentTypeSchema, contentTypeSchema,
['schema', 'pluginOptions', 'i18n', 'localized'], ['schema', 'pluginOptions', 'i18n', 'localized'],
false false
); );
if (!hasI18nEnabled) { if (!hasI18nEnabled) {
return []; return [];
} }
if (type === 'component' && step === '1') { if (type === 'component' && step === '1') {
return []; return [];
} }
return [ return [
[ [
{ {
name: 'pluginOptions.i18n.localized', name: 'pluginOptions.i18n.localized',
description: { description: {
id: getTrad('plugin.schema.i18n.localized.description-field'), id: getTrad('plugin.schema.i18n.localized.description-field'),
},
type: 'checkbox',
label: { id: getTrad('plugin.schema.i18n.localized.label-field') },
}, },
], type: 'checkbox',
]; label: { id: getTrad('plugin.schema.i18n.localized.label-field') },
}, },
],
];
}, },
}); },
} });
}, }
initializer: Initializer, },
};
return strapi.registerPlugin(plugin);
}; };

View File

@ -28,8 +28,9 @@ const addCommonFieldsToInitialDataMiddleware = () => ({ getState, dispatch }) =>
return next(action); return next(action);
} }
const cmDataStore = getState().get('content-manager_editViewCrudReducer'); const store = getState();
const cmLayoutStore = getState().get('content-manager_editViewLayoutManager'); const cmDataStore = store['content-manager_editViewCrudReducer'];
const cmLayoutStore = store['content-manager_editViewLayoutManager'];
const { contentTypeDataStructure } = cmDataStore; const { contentTypeDataStructure } = cmDataStore;
const { currentLayout } = cmLayoutStore; const { currentLayout } = cmLayoutStore;

View File

@ -14,7 +14,7 @@ const addLocaleColumnToListViewMiddleware = () => ({ getState }) => next => acti
} }
const store = getState(); const store = getState();
const { locales } = store.get('i18n_locales'); const { locales } = store.i18n_locales;
const locale = { const locale = {
key: '__locale_key__', key: '__locale_key__',

View File

@ -7,8 +7,8 @@ const addLocaleToCollectionTypesMiddleware = () => ({ getState }) => next => act
if (action.data.authorizedCtLinks.length) { if (action.data.authorizedCtLinks.length) {
const store = getState(); const store = getState();
const { locales } = store.get('i18n_locales'); const { locales } = store.i18n_locales;
const { collectionTypesRelatedPermissions } = store.get('permissionsManager'); const { collectionTypesRelatedPermissions } = store.permissionsManager;
action.data.authorizedCtLinks = addLocaleToLinksSearch( action.data.authorizedCtLinks = addLocaleToLinksSearch(
action.data.authorizedCtLinks, action.data.authorizedCtLinks,

View File

@ -7,8 +7,8 @@ const addLocaleToSingleTypesMiddleware = () => ({ getState }) => next => action
if (action.data.authorizedStLinks.length) { if (action.data.authorizedStLinks.length) {
const store = getState(); const store = getState();
const { locales } = store.get('i18n_locales'); const { locales } = store.i18n_locales;
const { collectionTypesRelatedPermissions } = store.get('permissionsManager'); const { collectionTypesRelatedPermissions } = store.permissionsManager;
action.data.authorizedStLinks = addLocaleToLinksSearch( action.data.authorizedStLinks = addLocaleToLinksSearch(
action.data.authorizedStLinks, action.data.authorizedStLinks,

View File

@ -4,8 +4,8 @@ const extendCTBAttributeInitialDataMiddleware = () => {
// the block here is to catch the error when trying to access the state // the block here is to catch the error when trying to access the state
// of the ctb when the plugin is not mounted // of the ctb when the plugin is not mounted
try { try {
const hasi18nEnabled = getState().getIn([ const store = getState();
'content-type-builder_dataManagerProvider', const hasi18nEnabled = store['content-type-builder_dataManagerProvider'].getIn([
'modifiedData', 'modifiedData',
'contentType', 'contentType',
'schema', 'schema',

View File

@ -14,12 +14,13 @@ describe('i18n | middlewares | addCommonFieldsToInitialDataMiddleware', () => {
const dispatch = jest.fn(); const dispatch = jest.fn();
beforeEach(() => { beforeEach(() => {
const store = new Map(); const store = {};
store.set('content-manager_editViewCrudReducer', { store['content-manager_editViewCrudReducer'] = {
contentTypeDataStructure: { name: 'test', common: 'common default value' }, contentTypeDataStructure: { name: 'test', common: 'common default value' },
}); };
store.set('content-manager_editViewLayoutManager', {
store['content-manager_editViewLayoutManager'] = {
currentLayout: { currentLayout: {
components: {}, components: {},
contentType: { contentType: {
@ -30,7 +31,7 @@ describe('i18n | middlewares | addCommonFieldsToInitialDataMiddleware', () => {
}, },
}, },
}, },
}); };
getState = () => store; getState = () => store;
}); });

View File

@ -4,9 +4,9 @@ describe('addLocaleColumnToListViewMiddleware', () => {
let getState; let getState;
beforeEach(() => { beforeEach(() => {
const store = new Map(); const store = {};
store.set('i18n_locales', { locales: [] }); store.i18n_locales = { locales: [] };
getState = () => store; getState = () => store;
}); });

View File

@ -4,17 +4,18 @@ describe('i18n | middlewares | addLocaleToCollectionTypesMiddleware', () => {
let getState; let getState;
beforeEach(() => { beforeEach(() => {
const store = new Map(); const store = {
store.set('i18n_locales', { locales: [] }); i18n_locales: { locales: [] },
store.set('permissionsManager', { userPermissions: [] }); permissionsManager: {
store.set('permissionsManager', { userPermissions: [],
collectionTypesRelatedPermissions: { collectionTypesRelatedPermissions: {
test: { test: {
'plugins::content-manager.explorer.read': [], 'plugins::content-manager.explorer.read': [],
'plugins::content-manager.explorer.create': [], 'plugins::content-manager.explorer.create': [],
},
}, },
}, },
}); };
getState = () => store; getState = () => store;
}); });
@ -75,17 +76,19 @@ describe('i18n | middlewares | addLocaleToCollectionTypesMiddleware', () => {
}); });
it('should add a search key with the default locale when the user has the right to read it', () => { it('should add a search key with the default locale when the user has the right to read it', () => {
const tempStore = new Map(); const tempStore = {
tempStore.set('i18n_locales', { locales: [{ code: 'en', isDefault: true }] }); i18n_locales: { locales: [{ code: 'en', isDefault: true }] },
tempStore.set('permissionsManager', { userPermissions: [] }); permissionsManager: {
tempStore.set('permissionsManager', { userPermissions: [],
collectionTypesRelatedPermissions: { collectionTypesRelatedPermissions: {
test: { test: {
'plugins::content-manager.explorer.read': [{ properties: { locales: ['en'] } }], 'plugins::content-manager.explorer.read': [{ properties: { locales: ['en'] } }],
'plugins::content-manager.explorer.create': [], 'plugins::content-manager.explorer.create': [],
},
}, },
}, },
}); };
const action = { const action = {
type: 'StrapiAdmin/LeftMenu/SET_CT_OR_ST_LINKS', type: 'StrapiAdmin/LeftMenu/SET_CT_OR_ST_LINKS',
data: { data: {
@ -113,16 +116,18 @@ describe('i18n | middlewares | addLocaleToCollectionTypesMiddleware', () => {
}); });
it('should set the isDisplayed key to false when the user does not have the right to read any locale', () => { it('should set the isDisplayed key to false when the user does not have the right to read any locale', () => {
const tempStore = new Map(); const tempStore = {
tempStore.set('i18n_locales', { locales: [{ code: 'en', isDefault: true }] }); i18n_locales: { locales: [{ code: 'en', isDefault: true }] },
tempStore.set('permissionsManager', { userPermissions: [] }); permissionsManager: {
tempStore.set('permissionsManager', { userPermissions: [],
collectionTypesRelatedPermissions: { collectionTypesRelatedPermissions: {
test: { test: {
'plugins::content-manager.explorer.read': [{ properties: { locales: [] } }], 'plugins::content-manager.explorer.read': [{ properties: { locales: [] } }],
},
}, },
}, },
}); };
const action = { const action = {
type: 'StrapiAdmin/LeftMenu/SET_CT_OR_ST_LINKS', type: 'StrapiAdmin/LeftMenu/SET_CT_OR_ST_LINKS',
data: { data: {
@ -156,17 +161,19 @@ describe('i18n | middlewares | addLocaleToCollectionTypesMiddleware', () => {
}); });
it('should keep the previous search', () => { it('should keep the previous search', () => {
const tempStore = new Map(); const tempStore = {
tempStore.set('i18n_locales', { locales: [{ code: 'en', isDefault: true }] }); i18n_locales: { locales: [{ code: 'en', isDefault: true }] },
tempStore.set('permissionsManager', { userPermissions: [] }); permissionsManager: {
tempStore.set('permissionsManager', { userPermissions: [],
collectionTypesRelatedPermissions: { collectionTypesRelatedPermissions: {
test: { test: {
'plugins::content-manager.explorer.read': [{ properties: { locales: ['en'] } }], 'plugins::content-manager.explorer.read': [{ properties: { locales: ['en'] } }],
'plugins::content-manager.explorer.create': [], 'plugins::content-manager.explorer.create': [],
},
}, },
}, },
}); };
const action = { const action = {
type: 'StrapiAdmin/LeftMenu/SET_CT_OR_ST_LINKS', type: 'StrapiAdmin/LeftMenu/SET_CT_OR_ST_LINKS',
data: { data: {

View File

@ -4,17 +4,18 @@ describe('i18n | middlewares | addLocaleToSingleTypesMiddleware', () => {
let getState; let getState;
beforeEach(() => { beforeEach(() => {
const store = new Map(); const store = {
store.set('i18n_locales', { locales: [] }); i18n_locales: { locales: [] },
store.set('permissionsManager', { userPermissions: [] }); permissionsManager: {
store.set('permissionsManager', { userPermissions: [],
collectionTypesRelatedPermissions: { collectionTypesRelatedPermissions: {
test: { test: {
'plugins::content-manager.explorer.read': [], 'plugins::content-manager.explorer.read': [],
'plugins::content-manager.explorer.create': [], 'plugins::content-manager.explorer.create': [],
},
}, },
}, },
}); };
getState = () => store; getState = () => store;
}); });
@ -75,17 +76,19 @@ describe('i18n | middlewares | addLocaleToSingleTypesMiddleware', () => {
}); });
it('should add a search key with the default locale when the user has the right to read it', () => { it('should add a search key with the default locale when the user has the right to read it', () => {
const tempStore = new Map(); const tempStore = {
tempStore.set('i18n_locales', { locales: [{ code: 'en', isDefault: true }] }); i18n_locales: { locales: [{ code: 'en', isDefault: true }] },
tempStore.set('permissionsManager', { userPermissions: [] }); permissionsManager: {
tempStore.set('permissionsManager', { userPermissions: [],
collectionTypesRelatedPermissions: { collectionTypesRelatedPermissions: {
test: { test: {
'plugins::content-manager.explorer.read': [{ properties: { locales: ['en'] } }], 'plugins::content-manager.explorer.read': [{ properties: { locales: ['en'] } }],
'plugins::content-manager.explorer.create': [], 'plugins::content-manager.explorer.create': [],
},
}, },
}, },
}); };
const action = { const action = {
type: 'StrapiAdmin/LeftMenu/SET_CT_OR_ST_LINKS', type: 'StrapiAdmin/LeftMenu/SET_CT_OR_ST_LINKS',
data: { data: {
@ -113,17 +116,28 @@ describe('i18n | middlewares | addLocaleToSingleTypesMiddleware', () => {
}); });
it('should set the isDisplayed key to false when the user does not have the right to read any locale', () => { it('should set the isDisplayed key to false when the user does not have the right to read any locale', () => {
const tempStore = new Map(); const tempStore = {
tempStore.set('i18n_locales', { locales: [{ code: 'en', isDefault: true }] }); i18n_locales: { locales: [{ code: 'en', isDefault: true }] },
tempStore.set('permissionsManager', { userPermissions: [] }); permissionsManager: {
tempStore.set('permissionsManager', { userPermissions: [],
collectionTypesRelatedPermissions: { collectionTypesRelatedPermissions: {
test: { test: {
'plugins::content-manager.explorer.read': [{ properties: { locales: [] } }], 'plugins::content-manager.explorer.read': [{ properties: { locales: [] } }],
'plugins::content-manager.explorer.create': [], 'plugins::content-manager.explorer.create': [],
},
}, },
}, },
}); };
// tempStore.set('i18n_locales', { locales: [{ code: 'en', isDefault: true }] });
// tempStore.set('permissionsManager', { userPermissions: [] });
// tempStore.set('permissionsManager', {
// collectionTypesRelatedPermissions: {
// test: {
// 'plugins::content-manager.explorer.read': [{ properties: { locales: [] } }],
// 'plugins::content-manager.explorer.create': [],
// },
// },
// });
const action = { const action = {
type: 'StrapiAdmin/LeftMenu/SET_CT_OR_ST_LINKS', type: 'StrapiAdmin/LeftMenu/SET_CT_OR_ST_LINKS',
data: { data: {
@ -149,17 +163,28 @@ describe('i18n | middlewares | addLocaleToSingleTypesMiddleware', () => {
}); });
it('should keep the previous search', () => { it('should keep the previous search', () => {
const tempStore = new Map(); const tempStore = {
tempStore.set('i18n_locales', { locales: [{ code: 'en', isDefault: true }] }); i18n_locales: { locales: [{ code: 'en', isDefault: true }] },
tempStore.set('permissionsManager', { userPermissions: [] }); permissionsManager: {
tempStore.set('permissionsManager', { userPermissions: [],
collectionTypesRelatedPermissions: { collectionTypesRelatedPermissions: {
test: { test: {
'plugins::content-manager.explorer.read': [{ properties: { locales: ['en'] } }], 'plugins::content-manager.explorer.read': [{ properties: { locales: ['en'] } }],
'plugins::content-manager.explorer.create': [], 'plugins::content-manager.explorer.create': [],
},
}, },
}, },
}); };
// tempStore.set('i18n_locales', { locales: [{ code: 'en', isDefault: true }] });
// tempStore.set('permissionsManager', { userPermissions: [] });
// tempStore.set('permissionsManager', {
// collectionTypesRelatedPermissions: {
// test: {
// 'plugins::content-manager.explorer.read': [{ properties: { locales: ['en'] } }],
// 'plugins::content-manager.explorer.create': [],
// },
// },
// });
const action = { const action = {
type: 'StrapiAdmin/LeftMenu/SET_CT_OR_ST_LINKS', type: 'StrapiAdmin/LeftMenu/SET_CT_OR_ST_LINKS',
data: { data: {

View File

@ -49,7 +49,9 @@ describe('i18n | middlewares | extendCTBAttributeInitialDataMiddleware', () => {
type: 'ContentTypeBuilder/FormModal/SET_ATTRIBUTE_DATA_SCHEMA', type: 'ContentTypeBuilder/FormModal/SET_ATTRIBUTE_DATA_SCHEMA',
}; };
const getState = jest.fn(() => ({ const getState = jest.fn(() => ({
getIn: jest.fn(() => false), 'content-type-builder_dataManagerProvider': {
getIn: jest.fn(() => false),
},
})); }));
const next = jest.fn(); const next = jest.fn();
@ -67,7 +69,9 @@ describe('i18n | middlewares | extendCTBAttributeInitialDataMiddleware', () => {
type: 'ContentTypeBuilder/FormModal/SET_ATTRIBUTE_DATA_SCHEMA', type: 'ContentTypeBuilder/FormModal/SET_ATTRIBUTE_DATA_SCHEMA',
}; };
const getState = jest.fn(() => ({ const getState = jest.fn(() => ({
getIn: undefined, 'content-type-builder_dataManagerProvider': {
getIn: undefined,
},
})); }));
const next = jest.fn(); const next = jest.fn();
@ -86,8 +90,10 @@ describe('i18n | middlewares | extendCTBAttributeInitialDataMiddleware', () => {
type: 'ContentTypeBuilder/FormModal/SET_ATTRIBUTE_DATA_SCHEMA', type: 'ContentTypeBuilder/FormModal/SET_ATTRIBUTE_DATA_SCHEMA',
}; };
const getState = jest.fn(() => ({ const getState = jest.fn(() => ({
// i18n is activated 'content-type-builder_dataManagerProvider': {
getIn: jest.fn(() => true), // i18n is activated
getIn: jest.fn(() => true),
},
})); }));
const next = jest.fn(); const next = jest.fn();
@ -108,8 +114,10 @@ describe('i18n | middlewares | extendCTBAttributeInitialDataMiddleware', () => {
options: { pluginOptions: { pluginTest: { ok: true } } }, options: { pluginOptions: { pluginTest: { ok: true } } },
}; };
const getState = jest.fn(() => ({ const getState = jest.fn(() => ({
// i18n is activated 'content-type-builder_dataManagerProvider': {
getIn: jest.fn(() => true), // i18n is activated
getIn: jest.fn(() => true),
},
})); }));
const next = jest.fn(); const next = jest.fn();

View File

@ -1,4 +1,4 @@
const selectCollectionTypesRelatedPermissions = state => const selectCollectionTypesRelatedPermissions = state =>
state.get('permissionsManager').collectionTypesRelatedPermissions; state.permissionsManager.collectionTypesRelatedPermissions;
export default selectCollectionTypesRelatedPermissions; export default selectCollectionTypesRelatedPermissions;

View File

@ -1,3 +1,3 @@
const selectI18NLocales = state => state.get('i18n_locales').locales; const selectI18NLocales = state => state.i18n_locales.locales;
export default selectI18NLocales; export default selectI18NLocales;