@plone/volto 18.32.2 → 18.32.4
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.
- package/CHANGELOG.md +23 -0
- package/locales/af/LC_MESSAGES/volto.po +15 -0
- package/locales/af.json +1 -1
- package/locales/ar/LC_MESSAGES/volto.po +15 -0
- package/locales/ar.json +1 -1
- package/locales/bg/LC_MESSAGES/volto.po +15 -0
- package/locales/bg.json +1 -1
- package/locales/bn/LC_MESSAGES/volto.po +15 -0
- package/locales/bn.json +1 -1
- package/locales/ca/LC_MESSAGES/volto.po +15 -0
- package/locales/ca.json +1 -1
- package/locales/cs/LC_MESSAGES/volto.po +15 -0
- package/locales/cs.json +1 -1
- package/locales/cy/LC_MESSAGES/volto.po +15 -0
- package/locales/cy.json +1 -1
- package/locales/da/LC_MESSAGES/volto.po +15 -0
- package/locales/da.json +1 -1
- package/locales/de/LC_MESSAGES/volto.po +15 -0
- package/locales/de.json +1 -1
- package/locales/el/LC_MESSAGES/volto.po +15 -0
- package/locales/el.json +1 -1
- package/locales/en/LC_MESSAGES/volto.po +15 -0
- package/locales/en.json +1 -1
- package/locales/en_AU/LC_MESSAGES/volto.po +15 -0
- package/locales/en_AU.json +1 -1
- package/locales/en_GB/LC_MESSAGES/volto.po +15 -0
- package/locales/en_GB.json +1 -1
- package/locales/eo/LC_MESSAGES/volto.po +15 -0
- package/locales/eo.json +1 -1
- package/locales/es/LC_MESSAGES/volto.po +15 -0
- package/locales/es.json +1 -1
- package/locales/et/LC_MESSAGES/volto.po +15 -0
- package/locales/et.json +1 -1
- package/locales/eu/LC_MESSAGES/volto.po +15 -0
- package/locales/eu.json +1 -1
- package/locales/fa/LC_MESSAGES/volto.po +15 -0
- package/locales/fa.json +1 -1
- package/locales/fi/LC_MESSAGES/volto.po +15 -0
- package/locales/fi.json +1 -1
- package/locales/fr/LC_MESSAGES/volto.po +15 -0
- package/locales/fr.json +1 -1
- package/locales/fu/LC_MESSAGES/volto.po +15 -0
- package/locales/fu.json +1 -1
- package/locales/gl/LC_MESSAGES/volto.po +15 -0
- package/locales/gl.json +1 -1
- package/locales/he/LC_MESSAGES/volto.po +15 -0
- package/locales/he.json +1 -1
- package/locales/hi/LC_MESSAGES/volto.po +15 -0
- package/locales/hi.json +1 -1
- package/locales/hr/LC_MESSAGES/volto.po +15 -0
- package/locales/hr.json +1 -1
- package/locales/hu/LC_MESSAGES/volto.po +15 -0
- package/locales/hu.json +1 -1
- package/locales/hy/LC_MESSAGES/volto.po +15 -0
- package/locales/hy.json +1 -1
- package/locales/id/LC_MESSAGES/volto.po +15 -0
- package/locales/id.json +1 -1
- package/locales/it/LC_MESSAGES/volto.po +27 -12
- package/locales/it.json +1 -1
- package/locales/ja/LC_MESSAGES/volto.po +15 -0
- package/locales/ja.json +1 -1
- package/locales/ka/LC_MESSAGES/volto.po +15 -0
- package/locales/ka.json +1 -1
- package/locales/kn/LC_MESSAGES/volto.po +15 -0
- package/locales/kn.json +1 -1
- package/locales/ko/LC_MESSAGES/volto.po +15 -0
- package/locales/ko.json +1 -1
- package/locales/lt/LC_MESSAGES/volto.po +15 -0
- package/locales/lt.json +1 -1
- package/locales/lv/LC_MESSAGES/volto.po +15 -0
- package/locales/lv.json +1 -1
- package/locales/mi/LC_MESSAGES/volto.po +15 -0
- package/locales/mi.json +1 -1
- package/locales/mk/LC_MESSAGES/volto.po +15 -0
- package/locales/mk.json +1 -1
- package/locales/my/LC_MESSAGES/volto.po +15 -0
- package/locales/my.json +1 -1
- package/locales/nb_NO/LC_MESSAGES/volto.po +15 -0
- package/locales/nb_NO.json +1 -1
- package/locales/nl/LC_MESSAGES/volto.po +15 -0
- package/locales/nl.json +1 -1
- package/locales/nn/LC_MESSAGES/volto.po +15 -0
- package/locales/nn.json +1 -1
- package/locales/pl/LC_MESSAGES/volto.po +15 -0
- package/locales/pl.json +1 -1
- package/locales/pt/LC_MESSAGES/volto.po +15 -0
- package/locales/pt.json +1 -1
- package/locales/pt_BR/LC_MESSAGES/volto.po +15 -0
- package/locales/pt_BR.json +1 -1
- package/locales/rm/LC_MESSAGES/volto.po +15 -0
- package/locales/rm.json +1 -1
- package/locales/ro/LC_MESSAGES/volto.po +15 -0
- package/locales/ro.json +1 -1
- package/locales/ru/LC_MESSAGES/volto.po +15 -0
- package/locales/ru.json +1 -1
- package/locales/sk/LC_MESSAGES/volto.po +15 -0
- package/locales/sk.json +1 -1
- package/locales/sl/LC_MESSAGES/volto.po +15 -0
- package/locales/sl.json +1 -1
- package/locales/sm/LC_MESSAGES/volto.po +15 -0
- package/locales/sm.json +1 -1
- package/locales/sq/LC_MESSAGES/volto.po +15 -0
- package/locales/sq.json +1 -1
- package/locales/sr/LC_MESSAGES/volto.po +15 -0
- package/locales/sr.json +1 -1
- package/locales/sr@cyrl/LC_MESSAGES/volto.po +15 -0
- package/locales/sr@cyrl.json +1 -1
- package/locales/sr@latn/LC_MESSAGES/volto.po +15 -0
- package/locales/sr@latn.json +1 -1
- package/locales/sv/LC_MESSAGES/volto.po +15 -0
- package/locales/sv.json +1 -1
- package/locales/ta/LC_MESSAGES/volto.po +15 -0
- package/locales/ta.json +1 -1
- package/locales/te/LC_MESSAGES/volto.po +15 -0
- package/locales/te.json +1 -1
- package/locales/th/LC_MESSAGES/volto.po +15 -0
- package/locales/th.json +1 -1
- package/locales/to/LC_MESSAGES/volto.po +15 -0
- package/locales/to.json +1 -1
- package/locales/tr/LC_MESSAGES/volto.po +15 -0
- package/locales/tr.json +1 -1
- package/locales/uk/LC_MESSAGES/volto.po +15 -0
- package/locales/uk.json +1 -1
- package/locales/vi/LC_MESSAGES/volto.po +15 -0
- package/locales/vi.json +1 -1
- package/locales/volto.pot +16 -1
- package/locales/zh_CN/LC_MESSAGES/volto.po +15 -0
- package/locales/zh_CN.json +1 -1
- package/locales/zh_Hant/LC_MESSAGES/volto.po +15 -0
- package/locales/zh_Hant.json +1 -1
- package/locales/zh_Hant_HK/LC_MESSAGES/volto.po +15 -0
- package/locales/zh_Hant_HK.json +1 -1
- package/package.json +3 -4
- package/src/components/manage/Blocks/Block/EditBlockWrapper.jsx +10 -1
- package/src/components/manage/Contents/Contents.jsx +8 -2
- package/src/components/manage/Widgets/FormFieldWrapper.jsx +168 -146
- package/src/config/validation.ts +8 -0
- package/src/helpers/FormValidation/FormValidation.test.js +47 -0
- package/src/helpers/FormValidation/validators.ts +21 -0
- package/src/helpers/MessageLabels/MessageLabels.js +5 -0
- package/src/reducers/users/users.js +1 -1
- package/theme/themes/pastanaga/extras/main.less +0 -2
- package/types/components/manage/Widgets/FormFieldWrapper.d.ts +5 -28
- package/types/components/manage/Widgets/index.d.ts +1 -1
- package/types/helpers/FormValidation/validators.d.ts +7 -0
- package/types/helpers/MessageLabels/MessageLabels.d.ts +100 -94
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
* FormFieldWrapper component.
|
|
3
3
|
* @module components/manage/Widgets/FormFieldWrapper
|
|
4
4
|
*/
|
|
5
|
-
import React from 'react';
|
|
5
|
+
import React, { Component } from 'react';
|
|
6
6
|
import PropTypes from 'prop-types';
|
|
7
7
|
import { Form, Grid, Icon as IconOld, Label } from 'semantic-ui-react';
|
|
8
8
|
import map from 'lodash/map';
|
|
9
9
|
import cx from 'classnames';
|
|
10
|
-
import { defineMessages,
|
|
10
|
+
import { defineMessages, injectIntl } from 'react-intl';
|
|
11
11
|
import LanguageSVG from '@plone/volto/icons/language.svg';
|
|
12
12
|
import Icon from '@plone/volto/components/theme/Icon/Icon';
|
|
13
13
|
|
|
@@ -31,156 +31,178 @@ const messages = defineMessages({
|
|
|
31
31
|
},
|
|
32
32
|
});
|
|
33
33
|
/**
|
|
34
|
-
* FormFieldWrapper component.
|
|
35
|
-
* @
|
|
36
|
-
* @
|
|
37
|
-
* @returns {JSX.Element} Markup for the component.
|
|
34
|
+
* FormFieldWrapper component class.
|
|
35
|
+
* @class FormFieldWrapper
|
|
36
|
+
* @extends Component
|
|
38
37
|
*/
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
38
|
+
class FormFieldWrapper extends Component {
|
|
39
|
+
/**
|
|
40
|
+
* Property types.
|
|
41
|
+
* @property {Object} propTypes Property types.
|
|
42
|
+
* @static
|
|
43
|
+
*/
|
|
44
|
+
static propTypes = {
|
|
45
|
+
id: PropTypes.string.isRequired,
|
|
46
|
+
title: PropTypes.string.isRequired,
|
|
47
|
+
description: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
|
|
48
|
+
required: PropTypes.bool,
|
|
49
|
+
error: PropTypes.arrayOf(PropTypes.string),
|
|
50
|
+
wrapped: PropTypes.bool,
|
|
51
|
+
columns: PropTypes.number,
|
|
52
|
+
draggable: PropTypes.bool,
|
|
53
|
+
isDisabled: PropTypes.bool,
|
|
54
|
+
onEdit: PropTypes.func,
|
|
55
|
+
className: PropTypes.string,
|
|
56
|
+
onDelete: PropTypes.func,
|
|
57
|
+
intl: PropTypes.object,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Default properties
|
|
62
|
+
* @property {Object} defaultProps Default properties.
|
|
63
|
+
* @static
|
|
64
|
+
*/
|
|
65
|
+
static defaultProps = {
|
|
66
|
+
description: null,
|
|
67
|
+
required: false,
|
|
68
|
+
error: [],
|
|
69
|
+
wrapped: true,
|
|
70
|
+
columns: 2,
|
|
71
|
+
onDelete: null,
|
|
72
|
+
intl: null,
|
|
73
|
+
isDisabled: null,
|
|
74
|
+
draggable: null,
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Render method.
|
|
79
|
+
* @method render
|
|
80
|
+
* @returns {string} Markup for the component.
|
|
81
|
+
*/
|
|
82
|
+
render() {
|
|
83
|
+
const {
|
|
84
|
+
id,
|
|
85
|
+
title,
|
|
86
|
+
description,
|
|
87
|
+
fieldSet,
|
|
88
|
+
required,
|
|
89
|
+
error,
|
|
90
|
+
wrapped,
|
|
91
|
+
columns,
|
|
92
|
+
draggable,
|
|
93
|
+
onEdit,
|
|
94
|
+
className,
|
|
95
|
+
isDisabled,
|
|
96
|
+
onDelete,
|
|
97
|
+
intl,
|
|
98
|
+
noForInFieldLabel,
|
|
99
|
+
multilingual_options,
|
|
100
|
+
} = this.props;
|
|
101
|
+
|
|
102
|
+
const languageIndependent = multilingual_options?.language_independent;
|
|
59
103
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
104
|
+
const wdg = (
|
|
105
|
+
<>
|
|
106
|
+
{this.props.children}
|
|
63
107
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
108
|
+
{map(error, (message) => (
|
|
109
|
+
<Label key={message} basic color="red" className="form-error-label">
|
|
110
|
+
{message}
|
|
111
|
+
</Label>
|
|
112
|
+
))}
|
|
113
|
+
</>
|
|
114
|
+
);
|
|
71
115
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
/>
|
|
98
|
-
)}
|
|
99
|
-
{title}
|
|
100
|
-
{languageIndependent && (
|
|
101
|
-
<div className="languageIndependent-icon">
|
|
102
|
-
<Icon
|
|
103
|
-
title={intl.formatMessage(
|
|
104
|
-
messages.language_independent_icon_title,
|
|
105
|
-
)}
|
|
106
|
-
name={LanguageSVG}
|
|
107
|
-
size="24px"
|
|
108
|
-
color="#555"
|
|
116
|
+
return wrapped ? (
|
|
117
|
+
<Form.Field
|
|
118
|
+
inline
|
|
119
|
+
required={required}
|
|
120
|
+
error={error && error.length > 0}
|
|
121
|
+
className={cx(
|
|
122
|
+
description ? 'help' : '',
|
|
123
|
+
className,
|
|
124
|
+
`field-wrapper-${id}`,
|
|
125
|
+
languageIndependent ? 'language-independent-field' : null,
|
|
126
|
+
)}
|
|
127
|
+
>
|
|
128
|
+
<Grid>
|
|
129
|
+
<Grid.Row stretched>
|
|
130
|
+
{columns === 2 && (
|
|
131
|
+
<Grid.Column width="4">
|
|
132
|
+
<div className="wrapper">
|
|
133
|
+
<label
|
|
134
|
+
id={`fieldset-${fieldSet}-field-label-${id}`}
|
|
135
|
+
htmlFor={noForInFieldLabel ? null : `field-${id}`}
|
|
136
|
+
>
|
|
137
|
+
{draggable && onEdit && (
|
|
138
|
+
<i
|
|
139
|
+
aria-hidden="true"
|
|
140
|
+
className="grey bars icon drag handle"
|
|
109
141
|
/>
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
<IconOld name="write square" size="large" color="blue" />
|
|
128
|
-
</button>
|
|
129
|
-
<button
|
|
130
|
-
aria-label={intl.formatMessage(messages.delete)}
|
|
131
|
-
className="item ui noborder button"
|
|
132
|
-
onClick={(evt) => {
|
|
133
|
-
evt.preventDefault();
|
|
134
|
-
onDelete(id);
|
|
135
|
-
}}
|
|
136
|
-
>
|
|
137
|
-
<IconOld name="close" size="large" color="red" />
|
|
138
|
-
</button>
|
|
139
|
-
</div>
|
|
142
|
+
)}
|
|
143
|
+
{title}
|
|
144
|
+
{languageIndependent && (
|
|
145
|
+
<div className="languageIndependent-icon">
|
|
146
|
+
<Icon
|
|
147
|
+
title={intl.formatMessage(
|
|
148
|
+
messages.language_independent_icon_title,
|
|
149
|
+
)}
|
|
150
|
+
name={LanguageSVG}
|
|
151
|
+
size="24px"
|
|
152
|
+
color="#555"
|
|
153
|
+
/>
|
|
154
|
+
</div>
|
|
155
|
+
)}
|
|
156
|
+
</label>
|
|
157
|
+
</div>
|
|
158
|
+
</Grid.Column>
|
|
140
159
|
)}
|
|
141
|
-
{
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
160
|
+
<Grid.Column width={columns === 2 ? 8 : 12}>
|
|
161
|
+
{onEdit && !isDisabled && (
|
|
162
|
+
<div className="toolbar" style={{ zIndex: '2' }}>
|
|
163
|
+
<button
|
|
164
|
+
aria-label={intl.formatMessage(messages.edit)}
|
|
165
|
+
className="item ui noborder button"
|
|
166
|
+
onClick={(evt) => {
|
|
167
|
+
evt.preventDefault();
|
|
168
|
+
onEdit(id);
|
|
169
|
+
}}
|
|
170
|
+
>
|
|
171
|
+
<IconOld name="write square" size="large" color="blue" />
|
|
172
|
+
</button>
|
|
173
|
+
<button
|
|
174
|
+
aria-label={intl.formatMessage(messages.delete)}
|
|
175
|
+
className="item ui noborder button"
|
|
176
|
+
onClick={(evt) => {
|
|
177
|
+
evt.preventDefault();
|
|
178
|
+
onDelete(id);
|
|
179
|
+
}}
|
|
180
|
+
>
|
|
181
|
+
<IconOld name="close" size="large" color="red" />
|
|
182
|
+
</button>
|
|
183
|
+
</div>
|
|
184
|
+
)}
|
|
185
|
+
{wdg}
|
|
153
186
|
</Grid.Column>
|
|
154
187
|
</Grid.Row>
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
columns: PropTypes.number,
|
|
175
|
-
draggable: PropTypes.bool,
|
|
176
|
-
isDisabled: PropTypes.bool,
|
|
177
|
-
onEdit: PropTypes.func,
|
|
178
|
-
className: PropTypes.string,
|
|
179
|
-
onDelete: PropTypes.func,
|
|
180
|
-
fieldSet: PropTypes.string,
|
|
181
|
-
noForInFieldLabel: PropTypes.bool,
|
|
182
|
-
multilingual_options: PropTypes.object,
|
|
183
|
-
children: PropTypes.node,
|
|
184
|
-
};
|
|
188
|
+
{description && (
|
|
189
|
+
<Grid.Row stretched>
|
|
190
|
+
<Grid.Column stretched width="12">
|
|
191
|
+
<p className="help">
|
|
192
|
+
{this.props.multilingual_options
|
|
193
|
+
? `${intl.formatMessage(messages.language_independent)} `
|
|
194
|
+
: null}
|
|
195
|
+
{description}
|
|
196
|
+
</p>
|
|
197
|
+
</Grid.Column>
|
|
198
|
+
</Grid.Row>
|
|
199
|
+
)}
|
|
200
|
+
</Grid>
|
|
201
|
+
</Form.Field>
|
|
202
|
+
) : (
|
|
203
|
+
<>{wdg}</>
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
185
207
|
|
|
186
|
-
export default FormFieldWrapper;
|
|
208
|
+
export default injectIntl(FormFieldWrapper);
|
package/src/config/validation.ts
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
endEventDateRangeValidator,
|
|
17
17
|
patternValidator,
|
|
18
18
|
defaultLanguageControlPanelValidator,
|
|
19
|
+
sizeValidator,
|
|
19
20
|
} from '@plone/volto/helpers/FormValidation/validators';
|
|
20
21
|
|
|
21
22
|
const registerValidators = (config: ConfigType) => {
|
|
@@ -33,6 +34,13 @@ const registerValidators = (config: ConfigType) => {
|
|
|
33
34
|
method: maxLengthValidator,
|
|
34
35
|
});
|
|
35
36
|
|
|
37
|
+
config.registerUtility({
|
|
38
|
+
name: 'size',
|
|
39
|
+
type: 'validator',
|
|
40
|
+
dependencies: { fieldType: 'object' },
|
|
41
|
+
method: sizeValidator,
|
|
42
|
+
});
|
|
43
|
+
|
|
36
44
|
config.registerUtility({
|
|
37
45
|
name: 'pattern',
|
|
38
46
|
type: 'validator',
|
|
@@ -8,6 +8,18 @@ const schema = {
|
|
|
8
8
|
username: { title: 'Username', type: 'string', description: '' },
|
|
9
9
|
email: { title: 'Email', type: 'string', widget: 'email', description: '' },
|
|
10
10
|
url: { title: 'url', type: 'string', widget: 'url', description: '' },
|
|
11
|
+
file: {
|
|
12
|
+
title: 'file',
|
|
13
|
+
type: 'object',
|
|
14
|
+
description: '',
|
|
15
|
+
size: 5,
|
|
16
|
+
},
|
|
17
|
+
notafile: {
|
|
18
|
+
title: 'notafile',
|
|
19
|
+
type: 'object',
|
|
20
|
+
description: '',
|
|
21
|
+
whatever: 1,
|
|
22
|
+
},
|
|
11
23
|
},
|
|
12
24
|
fieldsets: [
|
|
13
25
|
{ id: 'default', title: 'FIXME: User Data', fields: ['username'] },
|
|
@@ -181,6 +193,41 @@ describe('FormValidation', () => {
|
|
|
181
193
|
).toEqual({});
|
|
182
194
|
});
|
|
183
195
|
|
|
196
|
+
it('file - validates invalid size', () => {
|
|
197
|
+
const validationErrorMessages = [messages.maxSize.defaultMessage];
|
|
198
|
+
validationErrorMessages.title = 'file';
|
|
199
|
+
|
|
200
|
+
expect(
|
|
201
|
+
FormValidation.validateFieldsPerFieldset({
|
|
202
|
+
schema,
|
|
203
|
+
formData: { ...formData, file: { size: 10 } },
|
|
204
|
+
formatMessage,
|
|
205
|
+
}),
|
|
206
|
+
).toEqual({
|
|
207
|
+
file: validationErrorMessages,
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it('file - validates size', () => {
|
|
212
|
+
expect(
|
|
213
|
+
FormValidation.validateFieldsPerFieldset({
|
|
214
|
+
schema,
|
|
215
|
+
formData: { ...formData, file: { size: 1 } },
|
|
216
|
+
formatMessage,
|
|
217
|
+
}),
|
|
218
|
+
).toEqual({});
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it('notafile - the size validator does nothing', () => {
|
|
222
|
+
expect(
|
|
223
|
+
FormValidation.validateFieldsPerFieldset({
|
|
224
|
+
schema,
|
|
225
|
+
formData: { ...formData, notafile: { whatever: 1 } },
|
|
226
|
+
formatMessage,
|
|
227
|
+
}),
|
|
228
|
+
).toEqual({});
|
|
229
|
+
});
|
|
230
|
+
|
|
184
231
|
it('widget - validator from block - Fails', () => {
|
|
185
232
|
let newSchema = {
|
|
186
233
|
properties: {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { validationMessage } from '@plone/volto/helpers/FormValidation/FormValidation';
|
|
2
2
|
import { messages } from '@plone/volto/helpers/MessageLabels/MessageLabels';
|
|
3
|
+
import config from '@plone/volto/registry';
|
|
3
4
|
|
|
4
5
|
type MinMaxValidator = {
|
|
5
6
|
value: string | number;
|
|
@@ -26,6 +27,13 @@ type ChoiceValidator = {
|
|
|
26
27
|
formatMessage: Function;
|
|
27
28
|
};
|
|
28
29
|
|
|
30
|
+
type FileValidator = {
|
|
31
|
+
value: Record<string, any>;
|
|
32
|
+
field: Record<string, any>;
|
|
33
|
+
formData: any;
|
|
34
|
+
formatMessage: Function;
|
|
35
|
+
};
|
|
36
|
+
|
|
29
37
|
export const isMaxPropertyValid = ({
|
|
30
38
|
value,
|
|
31
39
|
fieldSpec,
|
|
@@ -232,3 +240,16 @@ export const defaultLanguageControlPanelValidator = ({
|
|
|
232
240
|
formData.available_languages.includes(token));
|
|
233
241
|
return !isValid ? formatMessage(messages.defaultLanguage) : null;
|
|
234
242
|
};
|
|
243
|
+
|
|
244
|
+
export const sizeValidator = ({
|
|
245
|
+
value,
|
|
246
|
+
field,
|
|
247
|
+
formatMessage,
|
|
248
|
+
}: FileValidator) => {
|
|
249
|
+
const maxSize = field.size
|
|
250
|
+
? parseInt(field.size, 10)
|
|
251
|
+
: config.settings.maxFileUploadSize;
|
|
252
|
+
return maxSize && value.size > maxSize
|
|
253
|
+
? formatMessage(messages.maxSize, { maxSize, size: value.size })
|
|
254
|
+
: null;
|
|
255
|
+
};
|
|
@@ -25,6 +25,11 @@ export const messages = defineMessages({
|
|
|
25
25
|
id: 'Maximum value is {len}.',
|
|
26
26
|
defaultMessage: 'Maximum value is {len}.',
|
|
27
27
|
},
|
|
28
|
+
maxSize: {
|
|
29
|
+
id: 'Maximum file size is {maxSize} bytes, but the uploaded file is {size} bytes.',
|
|
30
|
+
defaultMessage:
|
|
31
|
+
'Maximum file size is {maxSize} bytes, but the uploaded file is {size} bytes.',
|
|
32
|
+
},
|
|
28
33
|
uniqueItems: {
|
|
29
34
|
id: 'Items must be unique.',
|
|
30
35
|
defaultMessage: 'Items must be unique.',
|
|
@@ -117,7 +117,7 @@ export default function users(state = initialState, action = {}) {
|
|
|
117
117
|
case `${LIST_USERS}_SUCCESS`:
|
|
118
118
|
return {
|
|
119
119
|
...state,
|
|
120
|
-
users: action.result,
|
|
120
|
+
users: action.result.items ? action.result.items : action.result,
|
|
121
121
|
[getRequestKey(action.type)]: {
|
|
122
122
|
loading: false,
|
|
123
123
|
loaded: true,
|
|
@@ -1,28 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* @returns {JSX.Element} Markup for the component.
|
|
7
|
-
*/
|
|
8
|
-
declare function FormFieldWrapper({ id, title, description, fieldSet, required, error, wrapped, columns, draggable, onEdit, className, isDisabled, onDelete, noForInFieldLabel, multilingual_options, children, }: any): JSX.Element;
|
|
9
|
-
declare namespace FormFieldWrapper {
|
|
10
|
-
namespace propTypes {
|
|
11
|
-
let id: any;
|
|
12
|
-
let title: any;
|
|
13
|
-
let description: any;
|
|
14
|
-
let required: any;
|
|
15
|
-
let error: any;
|
|
16
|
-
let wrapped: any;
|
|
17
|
-
let columns: any;
|
|
18
|
-
let draggable: any;
|
|
19
|
-
let isDisabled: any;
|
|
20
|
-
let onEdit: any;
|
|
21
|
-
let className: any;
|
|
22
|
-
let onDelete: any;
|
|
23
|
-
let fieldSet: any;
|
|
24
|
-
let noForInFieldLabel: any;
|
|
25
|
-
let multilingual_options: any;
|
|
26
|
-
let children: any;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
1
|
+
declare const _default: React.FC<import("react-intl").WithIntlProps<any>> & {
|
|
2
|
+
WrappedComponent: React.ComponentType<any>;
|
|
3
|
+
};
|
|
4
|
+
export default _default;
|
|
5
|
+
import React from 'react';
|
|
@@ -121,4 +121,4 @@ export declare const ColorPickerWidget: import("@loadable/component").LoadableCo
|
|
|
121
121
|
export declare const DatetimeWidget: import("@loadable/component").LoadableClassComponent<any>;
|
|
122
122
|
export declare const TimeWidget: import("@loadable/component").LoadableClassComponent<any>;
|
|
123
123
|
export declare const RecurrenceWidget: import("@loadable/component").LoadableClassComponent<any>;
|
|
124
|
-
export declare const FormFieldWrapper: import("@loadable/component").LoadableComponent<any
|
|
124
|
+
export declare const FormFieldWrapper: import("@loadable/component").LoadableComponent<import("react-intl").WithIntlProps<any>>;
|
|
@@ -20,6 +20,12 @@ type ChoiceValidator = {
|
|
|
20
20
|
formData: any;
|
|
21
21
|
formatMessage: Function;
|
|
22
22
|
};
|
|
23
|
+
type FileValidator = {
|
|
24
|
+
value: Record<string, any>;
|
|
25
|
+
field: Record<string, any>;
|
|
26
|
+
formData: any;
|
|
27
|
+
formatMessage: Function;
|
|
28
|
+
};
|
|
23
29
|
export declare const isMaxPropertyValid: ({ value, fieldSpec, criterion, formatMessage, }: MinMaxValidator) => any;
|
|
24
30
|
export declare const isMinPropertyValid: ({ value, fieldSpec, criterion, formatMessage, }: MinMaxValidator) => any;
|
|
25
31
|
export declare const minLengthValidator: ({ value, field, formatMessage, }: Validator) => any;
|
|
@@ -37,4 +43,5 @@ export declare const patternValidator: ({ value, field, formatMessage, }: Valida
|
|
|
37
43
|
export declare const maxItemsValidator: ({ value, field, formatMessage, }: Validator) => any;
|
|
38
44
|
export declare const minItemsValidator: ({ value, field, formatMessage, }: Validator) => any;
|
|
39
45
|
export declare const defaultLanguageControlPanelValidator: ({ value, formData, formatMessage, }: ChoiceValidator) => any;
|
|
46
|
+
export declare const sizeValidator: ({ value, field, formatMessage, }: FileValidator) => any;
|
|
40
47
|
export {};
|