Move _locale to locale

This commit is contained in:
Alexandre Bodin 2021-10-11 21:22:16 +02:00
parent edbad96c2c
commit 435ce3bc88
7 changed files with 14 additions and 36 deletions

View File

@ -89,6 +89,7 @@ function ListView({
try {
const opts = source ? { cancelToken: source.token } : null;
const {
data: { results, pagination: paginationResult },
} = await axiosInstance.get(endPoint, opts);
@ -126,8 +127,6 @@ function ListView({
return;
}
console.log('iii');
console.error(err);
toggleNotification({
type: 'warning',
@ -355,6 +354,9 @@ export function mapDispatchToProps(dispatch) {
dispatch
);
}
const withConnect = connect(mapStateToProps, mapDispatchToProps);
const withConnect = connect(
mapStateToProps,
mapDispatchToProps
);
export default compose(withConnect)(memo(ListView, isEqual));

View File

@ -1,13 +1,4 @@
const createPluginsFilter = obj =>
Object.values(obj || {}).reduce((acc, current) => {
return {
...acc,
...Object.keys(current).reduce((accumulator, key) => {
accumulator[`_${key}`] = current[key];
return accumulator;
}, {}),
};
}, {});
Object.values(obj || {}).reduce((acc, current) => Object.assign(acc, current), {});
export default createPluginsFilter;

View File

@ -25,7 +25,7 @@ describe('buildQueryString', () => {
const queryString = buildQueryString(queryParams);
expect(queryString).toBe('?page=1&pageSize=10&sort=name:ASC&_locale=en');
expect(queryString).toBe('?page=1&pageSize=10&sort=name:ASC&locale=en');
});
it('creates a valid query string with a filters clause', () => {
@ -55,7 +55,7 @@ describe('buildQueryString', () => {
const queryString = buildQueryString(queryParams);
expect(queryString).toBe(
'?page=1&pageSize=10&sort=name:ASC&filters[0][name]=hello world&_locale=en'
'?page=1&pageSize=10&sort=name:ASC&filters[0][name]=hello world&locale=en'
);
});
});

View File

@ -19,7 +19,7 @@ const enhanceRelationLayout = (layout, locale) =>
if (get(current, ['targetModelPluginOptions', 'i18n', 'localized'], false)) {
queryInfos = {
...queryInfos,
defaultParams: { ...queryInfos.defaultParams, _locale: locale },
defaultParams: { ...queryInfos.defaultParams, locale },
paramsToKeep: ['plugins.i18n.locale'],
};
}
@ -82,7 +82,7 @@ const enhanceComponentLayoutForRelations = (layout, locale) =>
) {
const queryInfos = {
...field.queryInfos,
defaultParams: { ...field.queryInfos.defaultParams, _locale: locale },
defaultParams: { ...field.queryInfos.defaultParams, locale },
paramsToKeep: ['plugins.i18n.locale'],
};

View File

@ -277,7 +277,7 @@ describe('i18n | contentManagerHooks | mutateEditViewLayout', () => {
fieldSchema: { type: 'relation' },
targetModelPluginOptions: { i18n: { localized: true } },
queryInfos: {
defaultParams: { test: true, _locale: 'en' },
defaultParams: { test: true, locale: 'en' },
paramsToKeep: ['plugins.i18n.locale'],
},
},
@ -299,7 +299,7 @@ describe('i18n | contentManagerHooks | mutateEditViewLayout', () => {
fieldSchema: { type: 'relation' },
targetModelPluginOptions: { i18n: { localized: true } },
queryInfos: {
defaultParams: { test: true, _locale: 'en' },
defaultParams: { test: true, locale: 'en' },
paramsToKeep: ['plugins.i18n.locale'],
},
},
@ -518,7 +518,7 @@ describe('i18n | contentManagerHooks | mutateEditViewLayout', () => {
queryInfos: {
defaultParams: {
test: true,
_locale: 'en',
locale: 'en',
},
paramsToKeep: ['plugins.i18n.locale'],
},

View File

@ -141,7 +141,7 @@ describe('Entity service decorator', () => {
}
);
test('Replaces _locale param', async () => {
test('Replaces locale param', async () => {
const defaultService = {
wrapParams: jest.fn(opts => Promise.resolve(opts)),
};

View File

@ -19,7 +19,6 @@ const paramsContain = (key, params) => {
* @param {object} params - query params
* @param {object} ctx
*/
// TODO: remove _locale
const wrapParams = async (params = {}, ctx = {}) => {
const { action } = ctx;
@ -36,20 +35,6 @@ const wrapParams = async (params = {}, ctx = {}) => {
};
}
// TODO: remove when the _locale is renamed to locale
if (has('_locale', params)) {
if (params['_locale'] === 'all') {
return omit('_locale', params);
}
return {
...omit('_locale', params),
filters: {
$and: [{ locale: params['_locale'] }].concat(params.filters || []),
},
};
}
const entityDefinedById = paramsContain('id', params) && SINGLE_ENTRY_ACTIONS.includes(action);
const entitiesDefinedByIds = paramsContain('id.$in', params) && BULK_ACTIONS.includes(action);