Skip to content

Commit 1e77bec

Browse files
priyanshu92mrchief
authored andcommitted
fix: Show partial select with empty children (#139) 🐛
* fix: Fix outside click in case of multiple dropdowns * test: Add unit test for not checking parent with empty children
1 parent 18ab0d9 commit 1e77bec

File tree

6 files changed

+161
-75
lines changed

6 files changed

+161
-75
lines changed

docs/bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class DropdownTreeSelect extends Component {
100100
}
101101

102102
handleOutsideClick = e => {
103-
if (!isOutsideClick(e)) {
103+
if (!isOutsideClick(e, this.props.className)) {
104104
return
105105
}
106106

src/tree-manager/flatten-tree.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import getPartialState from './getPartialState'
22

3+
import { isEmpty } from '../utils'
4+
35
/**
46
* Converts a nested node into an associative array with pointers to child and parent nodes
57
* Given:
@@ -159,7 +161,7 @@ function walkNodes({ nodes, list = new Map(), parent, depth = 0, simple, showPar
159161
node.partial = getPartialState(node)
160162

161163
// re-check if all children are checked. if so, check thyself
162-
if (node.children.every(c => c.checked)) {
164+
if (!isEmpty(node.children) && node.children.every(c => c.checked)) {
163165
node.checked = true
164166
}
165167
}

src/tree-manager/tests/flatten-tree.test.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,3 +347,56 @@ test('sets default values', t => {
347347
t.deepEqual(defaultValues, expectedDefaultValues)
348348
t.deepEqual(mapToObject(list), expectedTree)
349349
})
350+
351+
test('does not check parent with empty children when showing partial state', t => {
352+
const tree = [
353+
{
354+
name: 'item1',
355+
value: 'value1',
356+
children: []
357+
},
358+
{
359+
name: 'item2',
360+
value: 'value2',
361+
children: []
362+
},
363+
{
364+
name: 'item3',
365+
value: 'value3',
366+
children: []
367+
}
368+
]
369+
370+
const expectedTree = {
371+
0: {
372+
_id: '0',
373+
_children: [],
374+
_depth: 0,
375+
children: undefined,
376+
name: 'item1',
377+
value: 'value1',
378+
partial: false
379+
},
380+
1: {
381+
_id: '1',
382+
_children: [],
383+
_depth: 0,
384+
children: undefined,
385+
name: 'item2',
386+
value: 'value2',
387+
partial: false
388+
},
389+
2: {
390+
_id: '2',
391+
_children: [],
392+
_depth: 0,
393+
children: undefined,
394+
name: 'item3',
395+
value: 'value3',
396+
partial: false
397+
},
398+
}
399+
400+
const { list } = flattenTree(tree, false, true)
401+
t.deepEqual(mapToObject(list), expectedTree)
402+
})

src/utils/isOutsideClick.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ const getPath = e => {
1212
return path
1313
}
1414

15-
export default e => {
15+
export default (e, className) => {
1616
if (!(e instanceof Event)) return false
17-
return !getPath(e).some(node => node.className && node.className.indexOf('react-dropdown-tree-select') >= 0)
17+
const completeClassName = className ? `${className} react-dropdown-tree-select` : 'react-dropdown-tree-select'
18+
return !getPath(e).some(node => node.className && node.className.indexOf(completeClassName) >= 0)
1819
}

yarn.lock

Lines changed: 100 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -651,103 +651,125 @@
651651
lodash "^4.17.5"
652652
to-fast-properties "^2.0.0"
653653

654-
"@commitlint/cli@^6.1.0":
655-
version "6.1.0"
656-
resolved "https://registry.yarnpkg.com/@commitlint/cli/-/cli-6.1.0.tgz#0a545088b4e0268cca1dca7e8ccd95bd55847b88"
654+
"@commitlint/cli@^7.0.0":
655+
version "7.0.0"
656+
resolved "https://registry.yarnpkg.com/@commitlint/cli/-/cli-7.0.0.tgz#3bf86d8ab2fbd5074c3114b7ba3f4b41b775f3dc"
657657
dependencies:
658-
"@commitlint/core" "^6.1.0"
658+
"@commitlint/format" "^7.0.0"
659+
"@commitlint/lint" "^7.0.0"
660+
"@commitlint/load" "^7.0.0"
661+
"@commitlint/read" "^7.0.0"
659662
babel-polyfill "6.26.0"
660-
chalk "2.3.0"
663+
chalk "2.3.1"
661664
get-stdin "5.0.1"
662-
lodash.merge "4.6.0"
665+
lodash.merge "4.6.1"
663666
lodash.pick "4.4.0"
664-
meow "3.7.0"
665-
666-
"@commitlint/config-conventional@^6.1.0":
667-
version "6.1.0"
668-
resolved "https://registry.yarnpkg.com/@commitlint/config-conventional/-/config-conventional-6.1.0.tgz#1f1c1577f1ca10f112e4346d9c94af1f8936f0c5"
667+
meow "^5.0.0"
669668

670-
"@commitlint/core@^6.1.0":
671-
version "6.1.0"
672-
resolved "https://registry.yarnpkg.com/@commitlint/core/-/core-6.1.0.tgz#41b2482044039435cb9673995598717038f2f6d0"
673-
dependencies:
674-
"@commitlint/execute-rule" "^6.1.0"
675-
"@commitlint/is-ignored" "^6.1.0"
676-
"@commitlint/parse" "^6.1.0"
677-
"@commitlint/resolve-extends" "^6.1.0"
678-
"@commitlint/rules" "^6.1.0"
679-
"@commitlint/top-level" "^6.1.0"
680-
"@marionebl/sander" "^0.6.0"
681-
babel-runtime "^6.23.0"
682-
chalk "^2.0.1"
683-
cosmiconfig "^4.0.0"
684-
git-raw-commits "^1.3.0"
685-
lodash.merge "4.6.0"
686-
lodash.mergewith "4.6.0"
687-
lodash.pick "4.4.0"
688-
lodash.topairs "4.3.0"
689-
resolve-from "4.0.0"
669+
"@commitlint/config-conventional@^7.0.0":
670+
version "7.0.1"
671+
resolved "https://registry.yarnpkg.com/@commitlint/config-conventional/-/config-conventional-7.0.1.tgz#276977f8ee60d8c56d7fdd43296af76dfee9b5f7"
690672

691-
"@commitlint/ensure@^6.1.0":
692-
version "6.1.0"
693-
resolved "https://registry.yarnpkg.com/@commitlint/ensure/-/ensure-6.1.0.tgz#567f029d816b6b5ca16bf62499230324c99a8fa9"
673+
"@commitlint/ensure@^7.0.0":
674+
version "7.0.0"
675+
resolved "https://registry.yarnpkg.com/@commitlint/ensure/-/ensure-7.0.0.tgz#3d5210bb988416844926895a782a55815731779d"
694676
dependencies:
695677
lodash.camelcase "4.3.0"
696678
lodash.kebabcase "4.1.1"
697679
lodash.snakecase "4.1.1"
698680
lodash.startcase "4.4.0"
699681
lodash.upperfirst "4.3.1"
700682

701-
"@commitlint/execute-rule@^6.1.0":
702-
version "6.1.0"
703-
resolved "https://registry.yarnpkg.com/@commitlint/execute-rule/-/execute-rule-6.1.0.tgz#4f56e5855a5e25ebcbc985d2209ea29f1bb89774"
683+
"@commitlint/execute-rule@^7.0.0":
684+
version "7.0.0"
685+
resolved "https://registry.yarnpkg.com/@commitlint/execute-rule/-/execute-rule-7.0.0.tgz#cbc65314fa9ebb9cd2c5b8cdd4dca6185b3aca4c"
704686
dependencies:
705687
babel-runtime "6.26.0"
706688

707-
"@commitlint/is-ignored@^6.1.0":
708-
version "6.1.0"
709-
resolved "https://registry.yarnpkg.com/@commitlint/is-ignored/-/is-ignored-6.1.0.tgz#0b86f8b37dfc693d6d66760b36fee1aba50882d8"
689+
"@commitlint/format@^7.0.0":
690+
version "7.0.0"
691+
resolved "https://registry.yarnpkg.com/@commitlint/format/-/format-7.0.0.tgz#3be1fdf0c3c41feb98e275b4f605c598c509b920"
692+
dependencies:
693+
babel-runtime "^6.23.0"
694+
chalk "^2.0.1"
695+
696+
"@commitlint/is-ignored@^7.0.0":
697+
version "7.0.0"
698+
resolved "https://registry.yarnpkg.com/@commitlint/is-ignored/-/is-ignored-7.0.0.tgz#d328a2976274c9f106e319b1cac75dd848360fc9"
710699
dependencies:
711700
semver "5.5.0"
712701

713-
"@commitlint/message@^6.1.0":
714-
version "6.1.0"
715-
resolved "https://registry.yarnpkg.com/@commitlint/message/-/message-6.1.0.tgz#ee4ca775ad876ba59d23d02ba386c9b9038969e3"
702+
"@commitlint/lint@^7.0.0":
703+
version "7.0.0"
704+
resolved "https://registry.yarnpkg.com/@commitlint/lint/-/lint-7.0.0.tgz#aede9e15f551b822af7d9da55df4881ad38390d9"
705+
dependencies:
706+
"@commitlint/is-ignored" "^7.0.0"
707+
"@commitlint/parse" "^7.0.0"
708+
"@commitlint/rules" "^7.0.0"
709+
babel-runtime "^6.23.0"
710+
lodash.topairs "4.3.0"
716711

717-
"@commitlint/parse@^6.1.0":
718-
version "6.1.0"
719-
resolved "https://registry.yarnpkg.com/@commitlint/parse/-/parse-6.1.0.tgz#e4ba58ab632371078b9b9609ae7af03c2e7b3a3e"
712+
"@commitlint/load@^7.0.0":
713+
version "7.0.0"
714+
resolved "https://registry.yarnpkg.com/@commitlint/load/-/load-7.0.0.tgz#d924f4c5c06d8845b16a50b563829a7fffa230a8"
715+
dependencies:
716+
"@commitlint/execute-rule" "^7.0.0"
717+
"@commitlint/resolve-extends" "^7.0.0"
718+
babel-runtime "^6.23.0"
719+
cosmiconfig "^4.0.0"
720+
lodash.merge "4.6.1"
721+
lodash.mergewith "4.6.1"
722+
lodash.pick "4.4.0"
723+
lodash.topairs "4.3.0"
724+
resolve-from "4.0.0"
725+
726+
"@commitlint/message@^7.0.0":
727+
version "7.0.0"
728+
resolved "https://registry.yarnpkg.com/@commitlint/message/-/message-7.0.0.tgz#6fb22563e31901ff5da4391db1346fda7115fa53"
729+
730+
"@commitlint/parse@^7.0.0":
731+
version "7.0.0"
732+
resolved "https://registry.yarnpkg.com/@commitlint/parse/-/parse-7.0.0.tgz#ed024cc4d8f0874421a8dd6d16674233b68592d4"
720733
dependencies:
721734
conventional-changelog-angular "^1.3.3"
722735
conventional-commits-parser "^2.1.0"
723736

724-
"@commitlint/resolve-extends@^6.1.0":
725-
version "6.1.0"
726-
resolved "https://registry.yarnpkg.com/@commitlint/resolve-extends/-/resolve-extends-6.1.0.tgz#b3d92f69e3746e94de0023f8be3b1f605a20839a"
737+
"@commitlint/read@^7.0.0":
738+
version "7.0.0"
739+
resolved "https://registry.yarnpkg.com/@commitlint/read/-/read-7.0.0.tgz#c9bf222e37e04c33c1e25b498657fef68377e2c8"
740+
dependencies:
741+
"@commitlint/top-level" "^7.0.0"
742+
"@marionebl/sander" "^0.6.0"
743+
babel-runtime "^6.23.0"
744+
git-raw-commits "^1.3.0"
745+
746+
"@commitlint/resolve-extends@^7.0.0":
747+
version "7.0.0"
748+
resolved "https://registry.yarnpkg.com/@commitlint/resolve-extends/-/resolve-extends-7.0.0.tgz#34937525ea3bc037365c530bce9b1c73ef4eb74d"
727749
dependencies:
728750
babel-runtime "6.26.0"
729-
lodash.merge "4.6.0"
751+
lodash.merge "4.6.1"
730752
lodash.omit "4.5.0"
731753
require-uncached "^1.0.3"
732754
resolve-from "^4.0.0"
733755
resolve-global "^0.1.0"
734756

735-
"@commitlint/rules@^6.1.0":
736-
version "6.1.0"
737-
resolved "https://registry.yarnpkg.com/@commitlint/rules/-/rules-6.1.0.tgz#564b69503a3a4d09d03a9a077731c9655ee8f4df"
757+
"@commitlint/rules@^7.0.0":
758+
version "7.0.0"
759+
resolved "https://registry.yarnpkg.com/@commitlint/rules/-/rules-7.0.0.tgz#9a710891c350c10d6f62debb820fee4fdef1e026"
738760
dependencies:
739-
"@commitlint/ensure" "^6.1.0"
740-
"@commitlint/message" "^6.1.0"
741-
"@commitlint/to-lines" "^6.1.0"
761+
"@commitlint/ensure" "^7.0.0"
762+
"@commitlint/message" "^7.0.0"
763+
"@commitlint/to-lines" "^7.0.0"
742764
babel-runtime "^6.23.0"
743765

744-
"@commitlint/to-lines@^6.1.0":
745-
version "6.1.0"
746-
resolved "https://registry.yarnpkg.com/@commitlint/to-lines/-/to-lines-6.1.0.tgz#9e130254c980dbd456e1693df1082a77ba7114a0"
766+
"@commitlint/to-lines@^7.0.0":
767+
version "7.0.0"
768+
resolved "https://registry.yarnpkg.com/@commitlint/to-lines/-/to-lines-7.0.0.tgz#adb229368e2b6c7a657c909754fb40ec47363ce2"
747769

748-
"@commitlint/top-level@^6.1.0":
749-
version "6.1.0"
750-
resolved "https://registry.yarnpkg.com/@commitlint/top-level/-/top-level-6.1.0.tgz#b420c1e9166df3afa000186a42b7f49cae4014cc"
770+
"@commitlint/top-level@^7.0.0":
771+
version "7.0.0"
772+
resolved "https://registry.yarnpkg.com/@commitlint/top-level/-/top-level-7.0.0.tgz#ff28580ab8c1431290e37b1d507e0ef370c38d99"
751773
dependencies:
752774
find-up "^2.1.0"
753775

@@ -2488,6 +2510,14 @@ [email protected]:
24882510
escape-string-regexp "^1.0.5"
24892511
supports-color "^4.0.0"
24902512

2513+
2514+
version "2.3.1"
2515+
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.3.1.tgz#523fe2678aec7b04e8041909292fe8b17059b796"
2516+
dependencies:
2517+
ansi-styles "^3.2.0"
2518+
escape-string-regexp "^1.0.5"
2519+
supports-color "^5.2.0"
2520+
24912521
chalk@^0.4.0:
24922522
version "0.4.0"
24932523
resolved "https://registry.yarnpkg.com/chalk/-/chalk-0.4.0.tgz#5199a3ddcd0c1efe23bc08c1b027b06176e0c64f"
@@ -6163,17 +6193,17 @@ lodash.memoize@^4.1.2:
61636193
version "4.1.2"
61646194
resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe"
61656195

6166-
[email protected], lodash.merge@^4.6.0:
6167-
version "4.6.0"
6168-
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.0.tgz#69884ba144ac33fe699737a6086deffadd0f89c5"
6169-
6170-
lodash.merge@^4.6.1:
6196+
[email protected], lodash.merge@^4.6.1:
61716197
version "4.6.1"
61726198
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.1.tgz#adc25d9cb99b9391c59624f379fbba60d7111d54"
61736199

6174-
lodash.mergewith@4.6.0:
6200+
lodash.merge@^4.6.0:
61756201
version "4.6.0"
6176-
resolved "https://registry.yarnpkg.com/lodash.mergewith/-/lodash.mergewith-4.6.0.tgz#150cf0a16791f5903b8891eab154609274bdea55"
6202+
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.0.tgz#69884ba144ac33fe699737a6086deffadd0f89c5"
6203+
6204+
6205+
version "4.6.1"
6206+
resolved "https://registry.yarnpkg.com/lodash.mergewith/-/lodash.mergewith-4.6.1.tgz#639057e726c3afbdb3e7d42741caa8d6e4335927"
61776207

61786208
61796209
version "4.5.0"
@@ -6421,7 +6451,7 @@ memory-fs@^0.4.0, memory-fs@~0.4.1:
64216451
errno "^0.1.3"
64226452
readable-stream "^2.0.1"
64236453

6424-
meow@3.7.0, meow@^3.3.0, meow@^3.7.0:
6454+
meow@^3.3.0, meow@^3.7.0:
64256455
version "3.7.0"
64266456
resolved "https://registry.yarnpkg.com/meow/-/meow-3.7.0.tgz#72cb668b425228290abbfa856892587308a801fb"
64276457
dependencies:

0 commit comments

Comments
 (0)