diff --git a/.github/workflows/react-component-ci.yml b/.github/workflows/react-component-ci.yml index b0a42637..f860ff10 100644 --- a/.github/workflows/react-component-ci.yml +++ b/.github/workflows/react-component-ci.yml @@ -1,114 +1,6 @@ -name: CI - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - +name: ✅ test +on: [push, pull_request] jobs: - setup: - runs-on: ubuntu-latest - steps: - - name: checkout - uses: actions/checkout@master - - - uses: actions/setup-node@v1 - with: - node-version: '18' - - - 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 --ignore-scripts - - - 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 + test: + uses: react-component/rc-test/.github/workflows/test.yml@main + secrets: inherit diff --git a/.gitignore b/.gitignore index 82db6c0a..fe807dc0 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,5 @@ es/* .dumi/tmp-test .dumi/tmp-production .env.local + +bun.lockb \ No newline at end of file diff --git a/bunfig.toml b/bunfig.toml new file mode 100644 index 00000000..80d57b63 --- /dev/null +++ b/bunfig.toml @@ -0,0 +1,2 @@ +[install] +peer = false \ No newline at end of file diff --git a/examples/dynamic.tsx b/examples/dynamic.tsx index bf3ccbde..26cde9c4 100644 --- a/examples/dynamic.tsx +++ b/examples/dynamic.tsx @@ -30,7 +30,7 @@ class Demo extends React.Component { loadData = treeNode => { console.log('trigger load:', treeNode); - return new Promise(resolve => { + return new Promise(resolve => { setTimeout(() => { let { treeData } = this.state; treeData = treeData.slice(); diff --git a/examples/utils/dataUtil.ts b/examples/utils/dataUtil.ts index b02660d7..57ac9d25 100644 --- a/examples/utils/dataUtil.ts +++ b/examples/utils/dataUtil.ts @@ -1,7 +1,7 @@ /* eslint-disable no-plusplus, no-mixed-operators, no-underscore-dangle */ export function generateData(x = 3, y = 2, z = 1, gData = []) { // x:每一级下的节点总数。y:每级节点里有y个节点、存在子节点。z:树的level层级数(0表示一级) - function _loop(_level, _preKey, _tns) { + function _loop(_level, _preKey?, _tns?) { const preKey = _preKey || '0'; const tns = _tns || gData; @@ -88,7 +88,7 @@ export function getNewTreeData(treeData, curKey, child, level) { } function loopData(data, callback) { - const loop = (d, level = 0) => { + const loop = (d, level = '0') => { d.forEach((item, index) => { const pos = `${level}-${index}`; if (item.children) { diff --git a/package.json b/package.json index cde1aaca..04536dab 100644 --- a/package.json +++ b/package.json @@ -75,7 +75,8 @@ "rc-virtual-list": "^3.0.0", "react": "^16.8.0", "react-dom": "^16.8.0", - "typescript": "^5.0.0" + "typescript": "^5.0.0", + "cheerio": "1.0.0-rc.12" }, "peerDependencies": { "react": "*", diff --git a/src/TreeSelect.tsx b/src/TreeSelect.tsx index b71102b8..88778dc9 100644 --- a/src/TreeSelect.tsx +++ b/src/TreeSelect.tsx @@ -440,13 +440,7 @@ const TreeSelect = React.forwardRef((props, ref) // Back fill with origin label const labeledValues = values.map(val => { const targetItem = rawLabeledValues.find(item => item.value === val); - let label; - // Ensure that when labelInValue is true, if label is undefined, it remains undefined. - if (labelInValue && targetItem.label !== undefined) { - label = targetItem.label; - } else if (!labelInValue && treeTitleRender) { - label = treeTitleRender(targetItem); - } + const label = labelInValue ? targetItem?.label : treeTitleRender?.(targetItem); return { value: val, label, diff --git a/tests/Select.checkable.spec.tsx b/tests/Select.checkable.spec.tsx index 2da83c0e..e98887e5 100644 --- a/tests/Select.checkable.spec.tsx +++ b/tests/Select.checkable.spec.tsx @@ -489,7 +489,7 @@ describe('TreeSelect.checkable', () => { describe('labelInValue', () => { it('basic', () => { const wrapper = mount( - + diff --git a/tests/Select.multiple.spec.js b/tests/Select.multiple.spec.js index b7e68f4e..20a75c45 100644 --- a/tests/Select.multiple.spec.js +++ b/tests/Select.multiple.spec.js @@ -32,7 +32,7 @@ describe('TreeSelect.multiple', () => { it('remove by backspace key', () => { const wrapper = mount(createSelect({ defaultValue: ['0', '1'] })); - wrapper.find('input').first().simulate('keyDown', { which: KeyCode.BACKSPACE }); + wrapper.find('input').first().simulate('keyDown', { which: KeyCode.BACKSPACE, key: 'Backspace' }); expect(wrapper.getSelection()).toHaveLength(1); expect(wrapper.getSelection(0).text()).toBe('label0'); }); @@ -59,9 +59,9 @@ describe('TreeSelect.multiple', () => { } } const wrapper = mount(); - wrapper.find('input').first().simulate('keyDown', { which: KeyCode.BACKSPACE }); + wrapper.find('input').first().simulate('keyDown', { which: KeyCode.BACKSPACE, key: 'Backspace' }); wrapper.selectNode(1); - wrapper.find('input').first().simulate('keyDown', { which: KeyCode.BACKSPACE }); + wrapper.find('input').first().simulate('keyDown', { which: KeyCode.BACKSPACE, key: 'Backspace' }); expect(wrapper.getSelection()).toHaveLength(1); expect(wrapper.getSelection(0).text()).toBe('label0'); });