Skip to content

Commit

Permalink
async select
Browse files Browse the repository at this point in the history
  • Loading branch information
dinfyru committed Feb 20, 2019
1 parent 1f9a316 commit e347687
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 18 deletions.
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,24 @@
"babel-plugin-transform-imports": "1.5.1",
"babel-plugin-transform-react-remove-prop-types": "0.4.20",
"core-js": "2.5.7",
"debounce-promise": "^3.1.0",
"eslint": "5.8.0",
"eslint-config-airbnb": "17.1.0",
"eslint-loader": "2.1.1",
"eslint-plugin-import": "2.14.0",
"eslint-plugin-jsx-a11y": "6.1.2",
"eslint-plugin-react": "7.11.1",
"lodash.debounce": "^4.0.8",
"prettier": "1.15.1",
"prop-types": "^15.6.2",
"react-select": "^2.1.2",
"react": "^16.8.2",
"react-dom": "^16.8.2",
"react-select": "^2.4.1",
"rollup": "^0.67.3",
"rollup-plugin-babel": "^4.0.3",
"rollup-plugin-commonjs": "^9.2.0",
"rollup-plugin-node-resolve": "^3.4.0",
"rollup-plugin-uglify": "^6.0.0"
},
"peerDependencies": {
"react": "^15.0.0 || ^16.0.0",
"react-dom": "^15.0.0 || ^16.0.0"
}
"peerDependencies": {}
}
20 changes: 18 additions & 2 deletions packages/SelectTemplate/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import Select from 'react-select';
import AsyncSelect from 'react-select/lib/Async';
import debounce from 'debounce-promise';

export default class SelectTemplate extends Component {
static defaultProps = {
Expand All @@ -17,7 +19,9 @@ export default class SelectTemplate extends Component {
disabled: false,
trackValue: false,
noOptionsMessage: () => 'No data',
multi: false
multi: false,
async: false,
loadOptions: null
};
static propTypes = {
nameParams: PropTypes.string,
Expand All @@ -34,7 +38,9 @@ export default class SelectTemplate extends Component {
disabled: PropTypes.bool,
creatable: PropTypes.bool,
trackValue: PropTypes.bool,
multi: PropTypes.bool
multi: PropTypes.bool,
async: PropTypes.bool,
loadOptions: PropTypes.func
};

constructor(props) {
Expand All @@ -48,6 +54,9 @@ export default class SelectTemplate extends Component {
value,
isFetching: props.isFetching && (!props.options || !props.options.length)
};
this.debounceLoadOptions = props.async
? debounce(props.loadOptions, 300)
: null;
}

componentDidMount() {
Expand Down Expand Up @@ -89,6 +98,7 @@ export default class SelectTemplate extends Component {
const { nameParams } = this.props;
const { multi } = this.state;
let newValue = value;

if (multi) {
if (value && value.length) {
newValue = value.map(el => {
Expand Down Expand Up @@ -188,11 +198,17 @@ export default class SelectTemplate extends Component {
onOpen: this.onOpenSelect,
noOptionsMessage
};
if (this.props.async) {
delete props.value;
props.loadOptions = this.debounceLoadOptions;
}

return (
<>
{this.props.creatable ? (
<Select.Creatable {...props} />
) : this.props.async ? (
<AsyncSelect cacheOptions debounceInterval={300} {...props} />
) : (
<Select {...props} />
)}
Expand Down
2 changes: 1 addition & 1 deletion public/packages/SelectTemplate/index.js

Large diffs are not rendered by default.

53 changes: 43 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1553,6 +1553,11 @@ damerau-levenshtein@^1.0.4:
resolved "https://registry.yarnpkg.com/damerau-levenshtein/-/damerau-levenshtein-1.0.4.tgz#03191c432cb6eea168bb77f3a55ffdccb8978514"
integrity sha1-AxkcQyy27qFou3fzpV/9zLiXhRQ=

debounce-promise@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/debounce-promise/-/debounce-promise-3.1.0.tgz#25035f4b45017bd51a7bef8b3bd9f6401dc47423"
integrity sha1-JQNfS0UBe9Uae++LO9n2QB3EdCM=

debug@^2.1.2, debug@^2.2.0, debug@^2.3.3, debug@^2.6.8, debug@^2.6.9:
version "2.6.9"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
Expand Down Expand Up @@ -2764,7 +2769,7 @@ lodash@^4.17.10, lodash@^4.17.4, lodash@^4.17.5:
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d"
integrity sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==

loose-envify@^1.0.0, loose-envify@^1.3.1, loose-envify@^1.4.0:
loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.3.1, loose-envify@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==
Expand Down Expand Up @@ -2802,10 +2807,10 @@ math-random@^1.0.1:
resolved "https://registry.yarnpkg.com/math-random/-/math-random-1.0.1.tgz#8b3aac588b8a66e4975e3cdea67f7bb329601fac"
integrity sha1-izqsWIuKZuSXXjzepn97sylgH6w=

memoize-one@^4.0.0:
version "4.0.3"
resolved "https://registry.yarnpkg.com/memoize-one/-/memoize-one-4.0.3.tgz#cdfdd942853f1a1b4c71c5336b8c49da0bf0273c"
integrity sha512-QmpUu4KqDmX0plH4u+tf0riMc1KHE1+lw95cMrLlXQAFOx/xnBtwhZ52XJxd9X2O6kwKBqX32kmhbhlobD0cuw==
memoize-one@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/memoize-one/-/memoize-one-5.0.0.tgz#d55007dffefb8de7546659a1722a5d42e128286e"
integrity sha512-7g0+ejkOaI9w5x6LvQwmj68kUj6rxROywPSCqmclG/HBacmFnZqhVscQ8kovkn9FBCNJmOz6SY42+jnvZzDWdw==

merge-stream@^1.0.1:
version "1.0.1"
Expand Down Expand Up @@ -3395,6 +3400,16 @@ rc@^1.2.7:
minimist "^1.2.0"
strip-json-comments "~2.0.1"

react-dom@^16.8.2:
version "16.8.2"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.8.2.tgz#7c8a69545dd554d45d66442230ba04a6a0a3c3d3"
integrity sha512-cPGfgFfwi+VCZjk73buu14pYkYBR1b/SRMSYqkLDdhSEHnSwcuYTPu6/Bh6ZphJFIk80XLvbSe2azfcRzNF+Xg==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
prop-types "^15.6.2"
scheduler "^0.13.2"

react-input-autosize@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/react-input-autosize/-/react-input-autosize-2.2.1.tgz#ec428fa15b1592994fb5f9aa15bb1eb6baf420f8"
Expand All @@ -3407,14 +3422,14 @@ react-lifecycles-compat@^3.0.4:
resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362"
integrity sha512-fBASbA6LnOU9dOU2eW7aQ8xmYBSXUIWr+UmF9b1efZBazGNO+rcXT/icdKnYm2pTwcRylVUYwW7H1PHfLekVzA==

react-select@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/react-select/-/react-select-2.1.2.tgz#7a3e4c2b9efcd8c44ae7cf6ebb8b060ef69c513c"
integrity sha512-+ceiz2KwIeEBxT/PgAXBIGohLXfa9YhkfwFSHMlqpTL55JYvjhgkGoBxoasGcMGeQ49J3RhAKZDD+x6ZHKmj6g==
react-select@^2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/react-select/-/react-select-2.4.1.tgz#99dd9c8b7700b5ebd38007dd707b1abdbad2e70f"
integrity sha512-je1cVAFsyQrGxkruQnNCuwo3+P0+1dyq7M4/gTlSwhO4ptPeTjf0eNrvCJ9iurVyorrnI88zgx2/yxrr2/oLLQ==
dependencies:
classnames "^2.2.5"
emotion "^9.1.2"
memoize-one "^4.0.0"
memoize-one "^5.0.0"
prop-types "^15.6.0"
raf "^3.4.0"
react-input-autosize "^2.2.1"
Expand All @@ -3430,6 +3445,16 @@ react-transition-group@^2.2.1:
prop-types "^15.6.2"
react-lifecycles-compat "^3.0.4"

react@^16.8.2:
version "16.8.2"
resolved "https://registry.yarnpkg.com/react/-/react-16.8.2.tgz#83064596feaa98d9c2857c4deae1848b542c9c0c"
integrity sha512-aB2ctx9uQ9vo09HVknqv3DGRpI7OIGJhCx3Bt0QqoRluEjHSaObJl+nG12GDdYH6sTgE7YiPJ6ZUyMx9kICdXw==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
prop-types "^15.6.2"
scheduler "^0.13.2"

read-pkg-up@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/read-pkg-up/-/read-pkg-up-2.0.0.tgz#6b72a8048984e0c41e79510fd5e9fa99b3b549be"
Expand Down Expand Up @@ -3696,6 +3721,14 @@ sax@^1.2.4:
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"
integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==

scheduler@^0.13.2:
version "0.13.2"
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.13.2.tgz#969eaee2764a51d2e97b20a60963b2546beff8fa"
integrity sha512-qK5P8tHS7vdEMCW5IPyt8v9MJOHqTrOUgPXib7tqm9vh834ibBX5BNhwkplX/0iOzHW5sXyluehYfS9yrkz9+w==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"

"semver@2 || 3 || 4 || 5", semver@^5.3.0, semver@^5.4.1, semver@^5.5.0, semver@^5.5.1:
version "5.6.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.6.0.tgz#7e74256fbaa49c75aa7c7a205cc22799cac80004"
Expand Down

0 comments on commit e347687

Please sign in to comment.