feat: add min and max fields to relation widget (resolves #5026) (#5238)

This commit is contained in:
Ned Zimmerman
2021-04-12 13:54:51 -03:00
committed by GitHub
parent 6561939d42
commit fe117e472e
25 changed files with 67 additions and 44 deletions

View File

@ -5,7 +5,7 @@ import { Async as AsyncSelect } from 'react-select';
import { find, isEmpty, last, debounce, get, uniqBy } from 'lodash';
import { List, Map, fromJS } from 'immutable';
import { reactSelectStyles } from 'netlify-cms-ui-default';
import { stringTemplate } from 'netlify-cms-lib-widgets';
import { stringTemplate, validations } from 'netlify-cms-lib-widgets';
import { FixedSizeList } from 'react-window';
function Option({ index, style, data }) {
@ -97,6 +97,26 @@ export default class RelationControl extends React.Component {
setInactiveStyle: PropTypes.func.isRequired,
};
isValid = () => {
const { field, value, t } = this.props;
const min = field.get('min');
const max = field.get('max');
if (!this.isMultiple()) {
return { error: false };
}
const error = validations.validateMinMax(
t,
field.get('label', field.get('name')),
value,
min,
max,
);
return error ? { error } : { error: false };
};
shouldComponentUpdate(nextProps) {
return (
this.props.value !== nextProps.value ||

View File

@ -133,7 +133,6 @@ const numberFieldsHits = [
},
},
];
class RelationController extends React.Component {
state = {
value: this.props.value,

View File

@ -5,6 +5,8 @@ export default {
search_fields: { type: 'array', minItems: 1, items: { type: 'string' } },
file: { type: 'string' },
multiple: { type: 'boolean' },
min: { type: 'integer' },
max: { type: 'integer' },
display_fields: { type: 'array', minItems: 1, items: { type: 'string' } },
options_length: { type: 'integer' },
},