diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 95b44c28b..000000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,54 +0,0 @@ -version: 2 -jobs: - lint: - docker: - - image: circleci/node:latest - steps: - - checkout - - restore_cache: - keys: - - v1-dependencies-{{ checksum "package.json" }} - - run: npm install - - save_cache: - paths: - - node_modules - key: v1-dependencies-{{ checksum "package.json" }} - - run: npm run lint - test: - docker: - - image: circleci/node:latest - environment: - BASH_ENV: "~/.bashrc" - working_directory: ~/repo - steps: - - checkout - - restore_cache: - keys: - - v1-dependencies-{{ checksum "package.json" }} - - run: npm install - - save_cache: - paths: - - node_modules - key: v1-dependencies-{{ checksum "package.json" }} - - run: npm test -- --coverage && bash <(curl -s https://codecov.io/bash) - compile: - docker: - - image: circleci/node:latest - steps: - - checkout - - restore_cache: - keys: - - v1-dependencies-{{ checksum "package.json" }} - - run: npm install - - save_cache: - paths: - - node_modules - key: v1-dependencies-{{ checksum "package.json" }} - - run: npm run compile -workflows: - version: 2 - build_and_test: - jobs: - - lint - - test - - compile diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 000000000..432a3fb30 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,114 @@ +name: CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + setup: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@master + + - uses: actions/setup-node@v1 + with: + node-version: '12' + + - name: cache package-lock.json + uses: actions/cache@v2 + with: + path: package-temp-dir + key: lock-${{ github.sha }} + + - name: create package-lock.json + run: npm i --package-lock-only + + - name: hack for singe file + run: | + if [ ! -d "package-temp-dir" ]; then + mkdir package-temp-dir + fi + cp package-lock.json package-temp-dir + + - name: cache node_modules + id: node_modules_cache_id + uses: actions/cache@v2 + with: + path: node_modules + key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }} + + - name: install + if: steps.node_modules_cache_id.outputs.cache-hit != 'true' + run: npm ci + + lint: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@master + + - name: restore cache from package-lock.json + uses: actions/cache@v2 + with: + path: package-temp-dir + key: lock-${{ github.sha }} + + - name: restore cache from node_modules + uses: actions/cache@v2 + with: + path: node_modules + key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }} + + - name: lint + run: npm run lint + + needs: setup + + compile: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@master + + - name: restore cache from package-lock.json + uses: actions/cache@v2 + with: + path: package-temp-dir + key: lock-${{ github.sha }} + + - name: restore cache from node_modules + uses: actions/cache@v2 + with: + path: node_modules + key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }} + + - name: compile + run: npm run compile + + needs: setup + + coverage: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@master + + - name: restore cache from package-lock.json + uses: actions/cache@v2 + with: + path: package-temp-dir + key: lock-${{ github.sha }} + + - name: restore cache from node_modules + uses: actions/cache@v2 + with: + path: node_modules + key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }} + + - name: coverage + run: npm test -- --coverage && bash <(curl -s https://codecov.io/bash) + + needs: setup diff --git a/README.md b/README.md index c368d11ce..2e7cbbe05 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ React Select [![NPM version][npm-image]][npm-url] [![npm download][download-image]][download-url] -[![build status][circleci-image]][circleci-url] +[![build status][github-actions-image]][github-actions-url] [![Test coverage][coveralls-image]][coveralls-url] [![Dependencies][david-image]](david-url) [![DevDependencies][david-dev-image]][david-dev-url] @@ -16,8 +16,8 @@ React Select [npm-url]: http://npmjs.org/package/rc-select [travis-image]: https://img.shields.io/travis/react-component/select/master?style=flat-square [travis-url]: https://travis-ci.com/react-component/select -[circleci-image]: https://img.shields.io/circleci/build/github/react-component/select.svg?style=flat-square -[circleci-url]: https://circleci.com/gh/react-component/select +[github-actions-image]: https://github.com/react-component/select/workflows/CI/badge.svg +[github-actions-url]: https://github.com/react-component/select/actions [coveralls-image]: https://img.shields.io/coveralls/react-component/select.svg?style=flat-square [coveralls-url]: https://coveralls.io/r/react-component/select?branch=master [codecov-image]: https://img.shields.io/codecov/c/github/react-component/select/master.svg?style=flat-square @@ -100,6 +100,7 @@ export default () => ( | disabled | whether disabled select | bool | false | | filterOption | whether filter options by input value. default filter by option's optionFilterProp prop's value | bool | true/Function(inputValue:string, option:Option) | | optionFilterProp | which prop value of option will be used for filter if filterOption is true | String | 'value' | +| filterSort | Sort function for search options sorting, see [Array.sort](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)'s compareFunction. | Function(optionA:Option, optionB: Option) | - | | optionLabelProp | render option value or option children as content of select | String: 'value'/'children' | 'value' | | defaultValue | initial selected option(s) | String/Array | - | | value | current selected option(s) | String/Array/{key:String, label:React.Node}/Array<{key, label}> | - | diff --git a/examples/filterSort.tsx b/examples/filterSort.tsx new file mode 100644 index 000000000..299f70349 --- /dev/null +++ b/examples/filterSort.tsx @@ -0,0 +1,36 @@ +import React from 'react'; +import Select from '../src'; +import '../assets/index.less'; + +const incidencesStateResource = [ + { value: 4, label: 'Not Identified' }, + { value: 3, label: 'Closed' }, + { value: 2, label: 'Communicated' }, + { value: 6, label: 'Identified' }, + { value: 1, label: 'Resolved' }, + { value: 5, label: 'Cancelled' }, +]; + +const sorterByLabel = (optionA, optionB) => optionA.label.localeCompare(optionB.label); + +const Test = () => ( +
+

with filter sort

+ +

without filter sort

+ + (optionA.label as string).localeCompare(optionB.label as string) + } + optionFilterProp="label" + options={[ + { value: 4, label: 'Not Identified' }, + { value: 3, label: 'Closed' }, + { value: 2, label: 'Communicated' }, + { value: 5, label: 'Cancelled' }, + ]} + />, + ); + + wrapper.find('input').simulate('change', { target: { value: 'i' } }); + expect( + wrapper + .find('.rc-select-item-option-content') + .first() + .text(), + ).toBe('Communicated'); + }); });