Skip to content

Commit 16fad36

Browse files
committed
Ensure unique fields are localized
Signed-off-by: soupette <cyril.lpz@gmail.com>
1 parent 54b51d9 commit 16fad36

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

packages/strapi-plugin-content-type-builder/admin/src/components/CheckboxWithDescription/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
33
import { Checkbox, Text } from '@buffetjs/core';
44
import Wrapper from './Wrapper';
55

6-
const CheckboxWithDescription = ({ description, label, value, ...rest }) => {
6+
const CheckboxWithDescription = ({ description, error, label, value, ...rest }) => {
77
return (
88
<>
99
<Wrapper>
@@ -13,19 +13,26 @@ const CheckboxWithDescription = ({ description, label, value, ...rest }) => {
1313
{description}
1414
</Text>
1515
)}
16+
{error && (
17+
<Text color="lightOrange" lineHeight="18px">
18+
{error}
19+
</Text>
20+
)}
1621
</Wrapper>
1722
</>
1823
);
1924
};
2025

2126
CheckboxWithDescription.defaultProps = {
2227
description: null,
28+
error: null,
2329
label: null,
2430
value: false,
2531
};
2632

2733
CheckboxWithDescription.propTypes = {
2834
description: PropTypes.string,
35+
error: PropTypes.string,
2936
label: PropTypes.string,
3037
value: PropTypes.bool,
3138
};

packages/strapi-plugin-i18n/admin/src/index.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { get } from 'lodash';
2+
import get from 'lodash/get';
33
import * as yup from 'yup';
44
import pluginPkg from '../../package.json';
55
import pluginLogo from './assets/images/logo.svg';
@@ -103,9 +103,26 @@ export default strapi => {
103103
});
104104

105105
ctbFormsAPI.extendFields(LOCALIZED_FIELDS, {
106-
validator: () => ({
106+
validator: args => ({
107107
i18n: yup.object().shape({
108-
localized: yup.bool(),
108+
localized: yup.bool().test({
109+
name: 'ensure-unique-localization',
110+
message: getTrad('plugin.schema.i18n.ensure-unique-localization'),
111+
test(value) {
112+
if (value === undefined || value) {
113+
return true;
114+
}
115+
116+
const unique = get(args, ['3', 'modifiedData', 'unique'], null);
117+
118+
// Unique fields must be localized
119+
if (unique && !value) {
120+
return false;
121+
}
122+
123+
return true;
124+
},
125+
}),
109126
}),
110127
}),
111128
form: {

packages/strapi-plugin-i18n/admin/src/translations/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"plugin.schema.i18n.localized.description-content-type": "Allow you to have content in different locales",
1212
"plugin.schema.i18n.localized.label-field": "Enable localization for this field",
1313
"plugin.schema.i18n.localized.description-field": "The field can have different values in each locale",
14+
"plugin.schema.i18n.ensure-unique-localization": "Unique fields must be localized",
1415
"CheckboxConfirmation.Modal.content": "Disabling localization will engender the deletion of all your content but the one associated to your default locale (if existing).",
1516
"CheckboxConfirmation.Modal.body": "Do you want to disable it?",
1617
"CheckboxConfirmation.Modal.button-confirm": "Yes, disable",

packages/strapi-plugin-i18n/admin/src/utils/localizedFields.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ const LOCALIZED_FIELDS = [
1818
'string',
1919
'text',
2020
'time',
21-
'uid',
2221
];
2322

2423
export default LOCALIZED_FIELDS;

0 commit comments

Comments
 (0)