fix(deps): update react-select to v3 (#5394)

This commit is contained in:
Erez Rokah
2021-05-18 10:37:33 +03:00
committed by GitHub
parent a2735b5fd6
commit 03be13c1e8
7 changed files with 37 additions and 158 deletions

View File

@ -33,6 +33,6 @@
},
"dependencies": {
"react-codemirror2": "^7.0.0",
"react-select": "^2.4.3"
"react-select": "^3.0.0"
}
}

View File

@ -26,7 +26,6 @@
"is-hotkey": "^0.2.0",
"mdast-util-definitions": "^1.2.3",
"mdast-util-to-string": "^1.0.5",
"react-select": "^2.4.3",
"rehype-parse": "^6.0.0",
"rehype-remark": "^8.0.0",
"rehype-stringify": "^7.0.0",

View File

@ -22,7 +22,7 @@
"build:esm": "cross-env NODE_ENV=esm babel src --out-dir dist/esm --ignore \"**/__tests__\" --root-mode upward"
},
"dependencies": {
"react-select": "^2.4.2",
"react-select": "^3.0.0",
"react-window": "^1.8.5"
},
"peerDependencies": {

View File

@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';
import { Async as AsyncSelect } from 'react-select';
import AsyncSelect from 'react-select/async';
import { find, isEmpty, last, debounce, get, uniqBy } from 'lodash';
import { List, Map, fromJS } from 'immutable';
import { reactSelectStyles } from 'netlify-cms-ui-default';
@ -165,17 +165,16 @@ export default class RelationControl extends React.Component {
handleChange = selectedOption => {
const { onChange, field } = this.props;
let value;
let metadata;
if (Array.isArray(selectedOption)) {
this.setState({ initialOptions: selectedOption.filter(Boolean) });
value = selectedOption.map(optionToString);
metadata =
(!isEmpty(selectedOption) && {
if (this.isMultiple()) {
const options = selectedOption || [];
this.setState({ initialOptions: options.filter(Boolean) });
const value = options.map(optionToString);
const metadata =
(!isEmpty(options) && {
[field.get('name')]: {
[field.get('collection')]: {
[last(value)]: last(selectedOption).data,
[last(value)]: last(options).data,
},
},
}) ||
@ -183,8 +182,8 @@ export default class RelationControl extends React.Component {
onChange(fromJS(value), metadata);
} else {
this.setState({ initialOptions: [selectedOption].filter(Boolean) });
value = optionToString(selectedOption);
metadata = selectedOption && {
const value = optionToString(selectedOption);
const metadata = selectedOption && {
[field.get('name')]: {
[field.get('collection')]: { [value]: selectedOption.data },
},

View File

@ -31,6 +31,6 @@
"react-immutable-proptypes": "^2.1.0"
},
"dependencies": {
"react-select": "^2.4.2"
"react-select": "^3.0.0"
}
}

View File

@ -79,7 +79,7 @@ export default class SelectControl extends React.Component {
handleChange = selectedOption => {
const { onChange, field } = this.props;
const isMultiple = field.get('multiple', false);
const isEmpty = isMultiple ? !selectedOption?.length : !selectedOption;
const isEmpty = selectedOption === null;
if (field.get('required') && isEmpty && isMultiple) {
onChange(List());