@akemona-org/strapi-plugin-i18n 3.7.0 → 3.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/admin/src/components/CMEditViewCopyLocale/index.js +4 -4
  2. package/admin/src/components/CMEditViewCopyLocale/utils/generateOptions.js +2 -2
  3. package/admin/src/components/CMEditViewCopyLocale/utils/removePasswordAndRelationsFieldFromData.js +2 -2
  4. package/admin/src/components/CMEditViewInjectedComponents/index.js +1 -1
  5. package/admin/src/components/CMEditViewLocalePicker/Option.js +2 -2
  6. package/admin/src/components/CMEditViewLocalePicker/index.js +1 -1
  7. package/admin/src/components/CheckboxConfirmation/index.js +2 -2
  8. package/admin/src/components/DeleteModalAdditionalInfos/index.js +1 -1
  9. package/admin/src/components/LocaleList/index.js +1 -1
  10. package/admin/src/components/LocaleListCell/LocaleListCell.js +6 -6
  11. package/admin/src/components/LocaleListCell/tests/LocaleListCell.test.js +2 -2
  12. package/admin/src/components/LocalePicker/index.js +7 -7
  13. package/admin/src/components/LocaleRow/index.js +1 -1
  14. package/admin/src/components/ModalCreate/BaseForm.js +1 -1
  15. package/admin/src/components/ModalCreate/index.js +2 -2
  16. package/admin/src/components/ModalEdit/index.js +2 -2
  17. package/admin/src/containers/SettingsPage/LocaleSettingsPage.js +2 -2
  18. package/admin/src/containers/SettingsPage/tests/SettingsPage.test.js +2 -2
  19. package/admin/src/hooks/reducers.js +4 -4
  20. package/admin/src/hooks/useAddLocale/index.js +1 -1
  21. package/admin/src/hooks/useContentTypePermissions/index.js +1 -1
  22. package/admin/src/hooks/useDeleteLocale/index.js +2 -2
  23. package/admin/src/hooks/useHasI18n/index.js +1 -1
  24. package/admin/src/hooks/useLocales/index.js +3 -3
  25. package/admin/src/index.js +3 -3
  26. package/admin/src/middlewares/addCommonFieldsToInitialDataMiddleware.js +61 -57
  27. package/admin/src/middlewares/addLocaleColumnToListViewMiddleware.js +27 -23
  28. package/admin/src/middlewares/addLocaleToCollectionTypesMiddleware.js +22 -18
  29. package/admin/src/middlewares/addLocaleToSingleTypesMiddleware.js +22 -18
  30. package/admin/src/middlewares/extendCMEditViewLayoutMiddleware.js +6 -6
  31. package/admin/src/middlewares/extendCTBAttributeInitialDataMiddleware.js +49 -47
  32. package/admin/src/middlewares/extendCTBInitialDataMiddleware.js +1 -1
  33. package/admin/src/middlewares/localePermissionMiddleware.js +2 -2
  34. package/admin/src/middlewares/tests/addCommonFieldsToInitialDataMiddleware.test.js +3 -3
  35. package/admin/src/middlewares/tests/localePermissionMiddleware.test.js +7 -7
  36. package/admin/src/middlewares/utils/addLocaleToLinksSearch.js +1 -1
  37. package/admin/src/pluginId.js +1 -1
  38. package/admin/src/selectors/selectCollectionTypesRelatedPermissions.js +1 -1
  39. package/admin/src/selectors/selectI18nLocales.js +1 -1
  40. package/admin/src/utils/getDefaultLocale.js +3 -3
  41. package/admin/src/utils/getInitialLocale.js +2 -2
  42. package/admin/src/utils/getLocaleFromQuery.js +1 -1
  43. package/admin/src/utils/getTrad.js +1 -1
  44. package/admin/src/utils/mutateCTBContentTypeSchema.js +2 -2
  45. package/config/functions/bootstrap.js +2 -2
  46. package/config/functions/migrations/content-type/disable/migrate-for-bookshelf.js +3 -6
  47. package/config/functions/migrations/content-type/disable/migrate-for-mongoose.js +2 -5
  48. package/config/functions/migrations/content-type/enable/index.js +1 -4
  49. package/config/functions/migrations/field/migrate-for-bookshelf.js +8 -9
  50. package/config/functions/migrations/field/migrate.js +2 -2
  51. package/domain/locale.js +1 -1
  52. package/middlewares/i18n/index.js +3 -3
  53. package/package.json +3 -3
  54. package/services/__tests__/content-types.test.js +115 -112
  55. package/services/__tests__/entity-service-decorator.test.js +5 -5
  56. package/services/entity-service-decorator.js +3 -3
  57. package/services/locales.js +6 -6
  58. package/services/localizations.js +5 -4
  59. package/services/permissions/actions.js +4 -4
  60. package/services/permissions/engine.js +1 -1
  61. package/services/permissions/sections-builder.js +1 -1
  62. package/tests/graphql.test.e2e.js +1 -1
  63. package/tests/locales.test.e2e.js +4 -4
  64. package/utils/index.js +1 -1
@@ -17,7 +17,7 @@ import {
17
17
  import { getTrad } from '../../utils';
18
18
  import { cleanData, generateOptions } from './utils';
19
19
 
20
- const CMEditViewCopyLocale = props => {
20
+ const CMEditViewCopyLocale = (props) => {
21
21
  if (!props.localizations.length) {
22
22
  return null;
23
23
  }
@@ -75,12 +75,12 @@ const Content = ({ appLocales, currentLocale, localizations, readPermissions })
75
75
  }
76
76
  };
77
77
 
78
- const handleChange = value => {
78
+ const handleChange = (value) => {
79
79
  setValue(value);
80
80
  };
81
81
 
82
82
  const handleToggle = () => {
83
- setIsOpen(prev => !prev);
83
+ setIsOpen((prev) => !prev);
84
84
  };
85
85
 
86
86
  const styles = selectStyles(theme);
@@ -149,7 +149,7 @@ const Content = ({ appLocales, currentLocale, localizations, readPermissions })
149
149
  ...styles.indicatorsContainer(base, state),
150
150
  height: '32px',
151
151
  }),
152
- valueContainer: base => ({
152
+ valueContainer: (base) => ({
153
153
  ...base,
154
154
  padding: '2px 0px 4px 10px',
155
155
  lineHeight: '18px',
@@ -11,10 +11,10 @@ const generateOptions = (appLocales, currentLocale, localizations, permissions)
11
11
  .filter(({ code }) => {
12
12
  return permissions.some(({ properties }) => get(properties, 'locales', []).includes(code));
13
13
  })
14
- .map(locale => {
14
+ .map((locale) => {
15
15
  return {
16
16
  label: locale.name,
17
- value: localizations.find(loc => locale.code === loc.locale).id,
17
+ value: localizations.find((loc) => locale.code === loc.locale).id,
18
18
  };
19
19
  });
20
20
  };
@@ -10,7 +10,7 @@ const removePasswordAndRelationsFieldFromData = (data, contentTypeSchema, compon
10
10
  const isRepeatable = getOtherInfos(schema, [current, 'repeatable']);
11
11
 
12
12
  if (attrType === 'dynamiczone') {
13
- acc[current] = value.map(componentValue => {
13
+ acc[current] = value.map((componentValue) => {
14
14
  const subCleanedData = recursiveCleanData(
15
15
  componentValue,
16
16
  componentSchema[componentValue.__component]
@@ -26,7 +26,7 @@ const removePasswordAndRelationsFieldFromData = (data, contentTypeSchema, compon
26
26
  if (isRepeatable) {
27
27
  /* eslint-disable indent */
28
28
  acc[current] = value
29
- ? value.map(compoData => {
29
+ ? value.map((compoData) => {
30
30
  const subCleanedData = recursiveCleanData(compoData, componentSchema[component]);
31
31
 
32
32
  return subCleanedData;
@@ -16,7 +16,7 @@ const CMEditViewInjectedComponents = () => {
16
16
 
17
17
  const id = get(params, 'id', null);
18
18
  const currentEntityId = id;
19
- const defaultLocale = locales.find(loc => loc.isDefault);
19
+ const defaultLocale = locales.find((loc) => loc.isDefault);
20
20
  const currentLocale = get(query, 'plugins.i18n.locale', defaultLocale.code);
21
21
  const hasI18nEnabled = get(layout, ['pluginOptions', 'i18n', 'localized'], false);
22
22
  const hasDraftAndPublishEnabled = get(layout, ['options', 'draftAndPublish'], false);
@@ -18,11 +18,11 @@ const statusToTitleMap = {
18
18
  'did-not-create-locale': getTrad('components.Select.locales.not-available'),
19
19
  };
20
20
 
21
- const Option = props => {
21
+ const Option = (props) => {
22
22
  const { formatMessage } = useIntl();
23
23
  const Component = components.Option;
24
24
  const options = get(props, ['selectProps', 'options'], {});
25
- const currentOption = options.find(option => option.value === props.value);
25
+ const currentOption = options.find((option) => option.value === props.value);
26
26
  const titleLabelID = statusToTitleMap[currentOption.status];
27
27
  const title = formatMessage({ id: titleLabelID });
28
28
  const fontWeight = props.isFocused ? 'bold' : 'regular';
@@ -116,7 +116,7 @@ const CMEditViewLocalePicker = ({
116
116
  ...styles.indicatorsContainer(base, state),
117
117
  height: '32px',
118
118
  }),
119
- valueContainer: base => ({
119
+ valueContainer: (base) => ({
120
120
  ...base,
121
121
  padding: '2px 0px 4px 10px',
122
122
  lineHeight: '18px',
@@ -10,7 +10,7 @@ const CheckboxConfirmation = ({ description, isCreating, label, name, onChange,
10
10
  const { formatMessage } = useIntl();
11
11
  const [isOpen, setIsOpen] = useState(false);
12
12
 
13
- const handleChange = e => {
13
+ const handleChange = (e) => {
14
14
  if (isCreating || e.target.value) {
15
15
  return onChange(e);
16
16
  }
@@ -27,7 +27,7 @@ const CheckboxConfirmation = ({ description, isCreating, label, name, onChange,
27
27
  setIsOpen(false);
28
28
  };
29
29
 
30
- const handleToggle = () => setIsOpen(prev => !prev);
30
+ const handleToggle = () => setIsOpen((prev) => !prev);
31
31
 
32
32
  return (
33
33
  <>
@@ -15,7 +15,7 @@ const DeleteModalAdditionalInfos = () => {
15
15
  <FormattedMessage
16
16
  id={getTrad('Settings.list.actions.deleteAdditionalInfos')}
17
17
  values={{
18
- em: chunks => <em>{chunks}</em>,
18
+ em: (chunks) => <em>{chunks}</em>,
19
19
  }}
20
20
  />
21
21
  </span>
@@ -47,7 +47,7 @@ const LocaleList = ({ canUpdateLocale, canDeleteLocale, onToggleCreateModal, isC
47
47
  title={listTitle}
48
48
  items={locales}
49
49
  isLoading={isLoading}
50
- customRowComponent={locale => (
50
+ customRowComponent={(locale) => (
51
51
  <LocaleRow locale={locale} onDelete={handleDeleteLocale} onEdit={handleEditLocale} />
52
52
  )}
53
53
  />
@@ -20,17 +20,17 @@ const LocaleName = styled.div`
20
20
 
21
21
  const LocaleListCell = ({ locales, localizations, locale: currentLocaleCode, id }) => {
22
22
  const allLocalizations = [{ locale: currentLocaleCode }, ...localizations];
23
- const localizationNames = allLocalizations.map(locale => locale.locale);
24
- const defaultLocale = locales.find(locale => locale.isDefault);
23
+ const localizationNames = allLocalizations.map((locale) => locale.locale);
24
+ const defaultLocale = locales.find((locale) => locale.isDefault);
25
25
  const hasDefaultLocale = localizationNames.includes(defaultLocale.code);
26
26
 
27
27
  let localesArray = [];
28
28
 
29
29
  if (hasDefaultLocale) {
30
30
  const ctLocalesWithoutDefault = localizationNames.filter(
31
- locale => locale !== defaultLocale.code
31
+ (locale) => locale !== defaultLocale.code
32
32
  );
33
- const ctLocalesNamesWithoutDefault = ctLocalesWithoutDefault.map(locale =>
33
+ const ctLocalesNamesWithoutDefault = ctLocalesWithoutDefault.map((locale) =>
34
34
  mapToLocaleName(locales, locale)
35
35
  );
36
36
 
@@ -43,7 +43,7 @@ const LocaleListCell = ({ locales, localizations, locale: currentLocaleCode, id
43
43
 
44
44
  localesArray = ctLocalesNamesWithDefault;
45
45
  } else {
46
- const ctLocales = localizationNames.map(locale => mapToLocaleName(locales, locale));
46
+ const ctLocales = localizationNames.map((locale) => mapToLocaleName(locales, locale));
47
47
  ctLocales.sort();
48
48
 
49
49
  localesArray = ctLocales;
@@ -58,7 +58,7 @@ const LocaleListCell = ({ locales, localizations, locale: currentLocaleCode, id
58
58
  {localesNames}
59
59
  </LocaleName>
60
60
  <Tooltip id={elId} place="bottom" delay={0}>
61
- {localesArray.map(name => (
61
+ {localesArray.map((name) => (
62
62
  <Padded key={name} top bottom size="xs">
63
63
  <Text ellipsis color="white">
64
64
  {name}
@@ -7,8 +7,8 @@ jest.mock('@buffetjs/styles', () => ({
7
7
  }));
8
8
 
9
9
  jest.mock('@buffetjs/core', () => ({
10
- Padded: props => <div {...props} />,
11
- Text: props => <p {...props} />,
10
+ Padded: (props) => <div {...props} />,
11
+ Text: (props) => <p {...props} />,
12
12
  }));
13
13
 
14
14
  describe('LocaleListCell', () => {
@@ -28,12 +28,12 @@ const ListItem = styled.li`
28
28
  justify-content: center;
29
29
 
30
30
  &:hover {
31
- background: ${props => props.theme.main.colors.mediumGrey};
31
+ background: ${(props) => props.theme.main.colors.mediumGrey};
32
32
  }
33
33
  `;
34
34
 
35
35
  const EllipsisParagraph = styled(Text)`
36
- width: ${props => props.width};
36
+ width: ${(props) => props.width};
37
37
  text-overflow: ellipsis;
38
38
  overflow: hidden;
39
39
  white-space: nowrap;
@@ -61,7 +61,7 @@ const LocalePicker = () => {
61
61
  return null;
62
62
  }
63
63
 
64
- const displayedLocales = locales.filter(locale => {
64
+ const displayedLocales = locales.filter((locale) => {
65
65
  const canCreate = createPermissions.find(({ properties }) => {
66
66
  return get(properties, 'locales', []).includes(locale.code);
67
67
  });
@@ -75,7 +75,7 @@ const LocalePicker = () => {
75
75
  return (
76
76
  <Picker
77
77
  position="right"
78
- renderButtonContent={isOpen => (
78
+ renderButtonContent={(isOpen) => (
79
79
  <Flex>
80
80
  <EllipsisParagraph width="20ch">{selected.name}</EllipsisParagraph>
81
81
 
@@ -84,8 +84,8 @@ const LocalePicker = () => {
84
84
  </Padded>
85
85
  </Flex>
86
86
  )}
87
- renderSectionContent={onToggle => {
88
- const handleClick = locale => {
87
+ renderSectionContent={(onToggle) => {
88
+ const handleClick = (locale) => {
89
89
  dispatch({ type: 'ContentManager/RBACManager/RESET_PERMISSIONS' });
90
90
  setSelected(locale);
91
91
 
@@ -100,7 +100,7 @@ const LocalePicker = () => {
100
100
  return hasMultipleLocales ? (
101
101
  <Padded left right>
102
102
  <List>
103
- {displayedLocales.map(locale => {
103
+ {displayedLocales.map((locale) => {
104
104
  if (locale.id === selected.id) {
105
105
  return null;
106
106
  }
@@ -30,7 +30,7 @@ const LocaleSettingsPage = ({ locale, onDelete, onEdit }) => {
30
30
  <FontAwesomeIcon icon="trash-alt" />
31
31
  </span>
32
32
  ) : null,
33
- onClick: e => {
33
+ onClick: (e) => {
34
34
  e.stopPropagation();
35
35
  onDelete(locale);
36
36
  },
@@ -41,7 +41,7 @@ const BaseForm = ({ options, defaultOption }) => {
41
41
  options={options}
42
42
  defaultValue={defaultOption}
43
43
  filterOption={reactSelectLocaleFilter}
44
- onChange={selection => {
44
+ onChange={(selection) => {
45
45
  setFieldValue('displayName', selection.value);
46
46
  setFieldValue('code', selection.label);
47
47
  }}
@@ -39,7 +39,7 @@ const ModalCreate = ({ alreadyUsedLocales, onClose, isOpened }) => {
39
39
  };
40
40
 
41
41
  const options = (defaultLocales || [])
42
- .map(locale => ({
42
+ .map((locale) => ({
43
43
  label: locale.code,
44
44
  value: locale.name,
45
45
  }))
@@ -63,7 +63,7 @@ const ModalCreate = ({ alreadyUsedLocales, onClose, isOpened }) => {
63
63
  displayName: defaultOption.value,
64
64
  isDefault: false,
65
65
  }}
66
- onSubmit={values =>
66
+ onSubmit={(values) =>
67
67
  addLocale({
68
68
  code: values.code,
69
69
  name: values.displayName,
@@ -41,8 +41,8 @@ const ModalEdit = ({ localeToEdit, onClose, locales }) => {
41
41
  let defaultOption;
42
42
 
43
43
  if (localeToEdit) {
44
- options = locales.map(locale => ({ label: locale.code, value: locale.id }));
45
- defaultOption = options.find(option => option.value === localeToEdit.id);
44
+ options = locales.map((locale) => ({ label: locale.code, value: locale.id }));
45
+ defaultOption = options.find((option) => option.value === localeToEdit.id);
46
46
  }
47
47
 
48
48
  return (
@@ -17,7 +17,7 @@ const LocaleSettingsPage = ({
17
17
  const [isOpenedCreateModal, setIsOpenedCreateModal] = useState(false);
18
18
 
19
19
  const handleToggleModalCreate = canCreateLocale
20
- ? () => setIsOpenedCreateModal(s => !s)
20
+ ? () => setIsOpenedCreateModal((s) => !s)
21
21
  : undefined;
22
22
 
23
23
  const actions = [
@@ -27,7 +27,7 @@ const LocaleSettingsPage = ({
27
27
  color: 'primary',
28
28
  type: 'button',
29
29
  icon: true,
30
- Component: props => (canCreateLocale ? <Button {...props} /> : null),
30
+ Component: (props) => (canCreateLocale ? <Button {...props} /> : null),
31
31
  style: {
32
32
  paddingLeft: 15,
33
33
  paddingRight: 15,
@@ -70,7 +70,7 @@ jest.mock('strapi-helper-plugin', () => ({
70
70
  }));
71
71
 
72
72
  jest.mock('../../../utils', () => ({
73
- getTrad: x => x,
73
+ getTrad: (x) => x,
74
74
  }));
75
75
 
76
76
  jest.mock('react-intl', () => ({
@@ -562,7 +562,7 @@ describe('i18n settings page', () => {
562
562
 
563
563
  describe('create', () => {
564
564
  beforeEach(() => {
565
- request.mockImplementation(url =>
565
+ request.mockImplementation((url) =>
566
566
  url.includes('/i18n/locales')
567
567
  ? Promise.resolve([])
568
568
  : Promise.resolve([
@@ -18,7 +18,7 @@ const localeReducer = produce((draftState = initialState, action) => {
18
18
 
19
19
  case ADD_LOCALE: {
20
20
  if (action.newLocale.isDefault) {
21
- draftState.locales.forEach(locale => {
21
+ draftState.locales.forEach((locale) => {
22
22
  locale.isDefault = false;
23
23
  });
24
24
  }
@@ -28,7 +28,7 @@ const localeReducer = produce((draftState = initialState, action) => {
28
28
  }
29
29
 
30
30
  case DELETE_LOCALE: {
31
- const locales = draftState.locales.filter(locale => locale.id !== action.id);
31
+ const locales = draftState.locales.filter((locale) => locale.id !== action.id);
32
32
 
33
33
  set(draftState, 'locales', locales);
34
34
  break;
@@ -36,13 +36,13 @@ const localeReducer = produce((draftState = initialState, action) => {
36
36
 
37
37
  case UPDATE_LOCALE: {
38
38
  if (action.editedLocale.isDefault) {
39
- draftState.locales.forEach(locale => {
39
+ draftState.locales.forEach((locale) => {
40
40
  locale.isDefault = false;
41
41
  });
42
42
  }
43
43
 
44
44
  const indexToEdit = draftState.locales.findIndex(
45
- locale => locale.id === action.editedLocale.id
45
+ (locale) => locale.id === action.editedLocale.id
46
46
  );
47
47
 
48
48
  set(draftState.locales, indexToEdit, action.editedLocale);
@@ -27,7 +27,7 @@ const useAddLocale = () => {
27
27
  const [isLoading, setLoading] = useState(false);
28
28
  const dispatch = useDispatch();
29
29
 
30
- const persistLocale = async locale => {
30
+ const persistLocale = async (locale) => {
31
31
  setLoading(true);
32
32
 
33
33
  try {
@@ -1,7 +1,7 @@
1
1
  import { useSelector } from 'react-redux';
2
2
  import selectCollectionTypesRelatedPermissions from '../../selectors/selectCollectionTypesRelatedPermissions';
3
3
 
4
- const useContentTypePermissions = slug => {
4
+ const useContentTypePermissions = (slug) => {
5
5
  const collectionTypesRelatedPermissions = useSelector(selectCollectionTypesRelatedPermissions);
6
6
 
7
7
  const currentCTRelatedPermissions = collectionTypesRelatedPermissions[slug];
@@ -4,7 +4,7 @@ import { useDispatch } from 'react-redux';
4
4
  import { getTrad } from '../../utils';
5
5
  import { DELETE_LOCALE } from '../constants';
6
6
 
7
- const deleteLocale = async id => {
7
+ const deleteLocale = async (id) => {
8
8
  try {
9
9
  const data = await request(`/i18n/locales/${id}`, {
10
10
  method: 'DELETE',
@@ -30,7 +30,7 @@ const useDeleteLocale = () => {
30
30
  const [isLoading, setLoading] = useState(false);
31
31
  const dispatch = useDispatch();
32
32
 
33
- const removeLocale = async id => {
33
+ const removeLocale = async (id) => {
34
34
  setLoading(true);
35
35
 
36
36
  await deleteLocale(id);
@@ -1,7 +1,7 @@
1
1
  import { useSelector } from 'react-redux';
2
2
  import get from 'lodash/get';
3
3
 
4
- const selectContentManagerListViewPluginOptions = state =>
4
+ const selectContentManagerListViewPluginOptions = (state) =>
5
5
  state.get('content-manager_listView').contentType.pluginOptions;
6
6
 
7
7
  const useHasI18n = () => {
@@ -22,11 +22,11 @@ const fetchLocalesList = async () => {
22
22
 
23
23
  const useLocales = () => {
24
24
  const dispatch = useDispatch();
25
- const locales = useSelector(state => state.get('i18n_locales').locales);
26
- const isLoading = useSelector(state => state.get('i18n_locales').isLoading);
25
+ const locales = useSelector((state) => state.get('i18n_locales').locales);
26
+ const isLoading = useSelector((state) => state.get('i18n_locales').isLoading);
27
27
 
28
28
  useEffect(() => {
29
- fetchLocalesList().then(locales => dispatch({ type: RESOLVE_LOCALES, locales }));
29
+ fetchLocalesList().then((locales) => dispatch({ type: RESOLVE_LOCALES, locales }));
30
30
  }, [dispatch]);
31
31
 
32
32
  return { locales, isLoading };
@@ -18,10 +18,10 @@ import LOCALIZED_FIELDS from './utils/localizedFields';
18
18
  import i18nReducers from './hooks/reducers';
19
19
  import DeleteModalAdditionalInfos from './components/DeleteModalAdditionalInfos';
20
20
 
21
- export default strapi => {
21
+ export default (strapi) => {
22
22
  const pluginDescription = pluginPkg.strapi.description || pluginPkg.description;
23
23
 
24
- middlewares.forEach(middleware => {
24
+ middlewares.forEach((middleware) => {
25
25
  strapi.middlewares.add(middleware);
26
26
  });
27
27
 
@@ -103,7 +103,7 @@ export default strapi => {
103
103
  });
104
104
 
105
105
  ctbFormsAPI.extendFields(LOCALIZED_FIELDS, {
106
- validator: args => ({
106
+ validator: (args) => ({
107
107
  i18n: yup.object().shape({
108
108
  localized: yup.bool().test({
109
109
  name: 'ensure-unique-localization',
@@ -9,75 +9,79 @@ import {
9
9
  } from 'strapi-helper-plugin';
10
10
  import pluginId from '../pluginId';
11
11
 
12
- const addCommonFieldsToInitialDataMiddleware = () => ({ getState, dispatch }) => next => action => {
13
- if (action.type !== 'ContentManager/CrudReducer/INIT_FORM') {
14
- return next(action);
15
- }
12
+ const addCommonFieldsToInitialDataMiddleware =
13
+ () =>
14
+ ({ getState, dispatch }) =>
15
+ (next) =>
16
+ (action) => {
17
+ if (action.type !== 'ContentManager/CrudReducer/INIT_FORM') {
18
+ return next(action);
19
+ }
20
+
21
+ if (!action.rawQuery) {
22
+ return next(action);
23
+ }
16
24
 
17
- if (!action.rawQuery) {
18
- return next(action);
19
- }
25
+ const search = action.rawQuery.substring(1);
26
+ const query = parse(search);
27
+ const relatedEntityId = get(query, 'plugins.i18n.relatedEntityId', null);
28
+ const locale = get(query, 'plugins.i18n.locale', null);
29
+ const isSingleType = action.isSingleType;
20
30
 
21
- const search = action.rawQuery.substring(1);
22
- const query = parse(search);
23
- const relatedEntityId = get(query, 'plugins.i18n.relatedEntityId', null);
24
- const locale = get(query, 'plugins.i18n.locale', null);
25
- const isSingleType = action.isSingleType;
31
+ if (!relatedEntityId && !isSingleType) {
32
+ return next(action);
33
+ }
26
34
 
27
- if (!relatedEntityId && !isSingleType) {
28
- return next(action);
29
- }
35
+ const cmDataStore = getState().get('content-manager_editViewCrudReducer');
36
+ const cmLayoutStore = getState().get('content-manager_editViewLayoutManager');
37
+ const { contentTypeDataStructure } = cmDataStore;
38
+ const { currentLayout } = cmLayoutStore;
30
39
 
31
- const cmDataStore = getState().get('content-manager_editViewCrudReducer');
32
- const cmLayoutStore = getState().get('content-manager_editViewLayoutManager');
33
- const { contentTypeDataStructure } = cmDataStore;
34
- const { currentLayout } = cmLayoutStore;
40
+ const getData = async () => {
41
+ // Show a loader
42
+ dispatch({ type: 'ContentManager/CrudReducer/GET_DATA' });
43
+ const defaultDataStructure = cloneDeep(contentTypeDataStructure);
35
44
 
36
- const getData = async () => {
37
- // Show a loader
38
- dispatch({ type: 'ContentManager/CrudReducer/GET_DATA' });
39
- const defaultDataStructure = cloneDeep(contentTypeDataStructure);
45
+ try {
46
+ const requestURL = `/${pluginId}/content-manager/actions/get-non-localized-fields`;
47
+ const body = { model: currentLayout.contentType.uid, id: relatedEntityId, locale };
40
48
 
41
- try {
42
- const requestURL = `/${pluginId}/content-manager/actions/get-non-localized-fields`;
43
- const body = { model: currentLayout.contentType.uid, id: relatedEntityId, locale };
49
+ const data = await request(requestURL, { method: 'POST', body });
44
50
 
45
- const data = await request(requestURL, { method: 'POST', body });
51
+ const { nonLocalizedFields, localizations } = data;
46
52
 
47
- const { nonLocalizedFields, localizations } = data;
53
+ const merged = merge(defaultDataStructure, nonLocalizedFields);
48
54
 
49
- const merged = merge(defaultDataStructure, nonLocalizedFields);
55
+ const fieldsToRemove = [
56
+ 'created_by',
57
+ 'updated_by',
58
+ 'published_at',
59
+ 'id',
60
+ '_id',
61
+ 'updated_at',
62
+ 'created_at',
63
+ ];
64
+ const cleanedMerged = contentManagementUtilRemoveFieldsFromData(
65
+ merged,
66
+ currentLayout.contentType,
67
+ currentLayout.components,
68
+ fieldsToRemove
69
+ );
70
+ cleanedMerged.localizations = localizations;
50
71
 
51
- const fieldsToRemove = [
52
- 'created_by',
53
- 'updated_by',
54
- 'published_at',
55
- 'id',
56
- '_id',
57
- 'updated_at',
58
- 'created_at',
59
- ];
60
- const cleanedMerged = contentManagementUtilRemoveFieldsFromData(
61
- merged,
62
- currentLayout.contentType,
63
- currentLayout.components,
64
- fieldsToRemove
65
- );
66
- cleanedMerged.localizations = localizations;
72
+ action.data = formatComponentData(
73
+ cleanedMerged,
74
+ currentLayout.contentType,
75
+ currentLayout.components
76
+ );
77
+ } catch (err) {
78
+ // Silent
79
+ }
67
80
 
68
- action.data = formatComponentData(
69
- cleanedMerged,
70
- currentLayout.contentType,
71
- currentLayout.components
72
- );
73
- } catch (err) {
74
- // Silent
75
- }
81
+ return next(action);
82
+ };
76
83
 
77
- return next(action);
84
+ return getData();
78
85
  };
79
86
 
80
- return getData();
81
- };
82
-
83
87
  export default addCommonFieldsToInitialDataMiddleware;
@@ -2,31 +2,35 @@ import React from 'react';
2
2
  import get from 'lodash/get';
3
3
  import LocaleListCell from '../components/LocaleListCell/LocaleListCell';
4
4
 
5
- const addLocaleColumnToListViewMiddleware = () => ({ getState }) => next => action => {
6
- if (action.type !== 'ContentManager/ListView/SET_LIST_LAYOUT ') {
7
- return next(action);
8
- }
9
-
10
- const isFieldLocalized = get(action, 'contentType.pluginOptions.i18n.localized', false);
5
+ const addLocaleColumnToListViewMiddleware =
6
+ () =>
7
+ ({ getState }) =>
8
+ (next) =>
9
+ (action) => {
10
+ if (action.type !== 'ContentManager/ListView/SET_LIST_LAYOUT ') {
11
+ return next(action);
12
+ }
13
+
14
+ const isFieldLocalized = get(action, 'contentType.pluginOptions.i18n.localized', false);
15
+
16
+ if (!isFieldLocalized) {
17
+ return next(action);
18
+ }
19
+
20
+ const store = getState();
21
+ const { locales } = store.get('i18n_locales');
22
+
23
+ const locale = {
24
+ key: '__locale_key__',
25
+ fieldSchema: { type: 'string' },
26
+ metadatas: { label: 'Content available in', searchable: false, sortable: false },
27
+ name: 'locales',
28
+ cellFormatter: (props) => <LocaleListCell {...props} locales={locales} />,
29
+ };
30
+
31
+ action.displayedHeaders = [...action.displayedHeaders, locale];
11
32
 
12
- if (!isFieldLocalized) {
13
33
  return next(action);
14
- }
15
-
16
- const store = getState();
17
- const { locales } = store.get('i18n_locales');
18
-
19
- const locale = {
20
- key: '__locale_key__',
21
- fieldSchema: { type: 'string' },
22
- metadatas: { label: 'Content available in', searchable: false, sortable: false },
23
- name: 'locales',
24
- cellFormatter: props => <LocaleListCell {...props} locales={locales} />,
25
34
  };
26
35
 
27
- action.displayedHeaders = [...action.displayedHeaders, locale];
28
-
29
- return next(action);
30
- };
31
-
32
36
  export default addLocaleColumnToListViewMiddleware;