@@ -3,26 +3,32 @@ import type { DataEntity } from 'rc-tree/lib/interface';
3
3
import { conductCheck } from 'rc-tree/lib/utils/conductUtil' ;
4
4
import type { LabeledValueType , SafeKey } from '../interface' ;
5
5
6
- export default (
6
+ const useCheckedKeys = (
7
7
rawLabeledValues : LabeledValueType [ ] ,
8
8
rawHalfCheckedValues : LabeledValueType [ ] ,
9
9
treeConduction : boolean ,
10
10
keyEntities : Record < SafeKey , DataEntity > ,
11
- ) =>
12
- React . useMemo ( ( ) => {
13
- let checkedKeys : SafeKey [ ] = rawLabeledValues . map ( ( { value } ) => value ) ;
14
- let halfCheckedKeys : SafeKey [ ] = rawHalfCheckedValues . map ( ( { value } ) => value ) ;
11
+ ) => {
12
+ return React . useMemo ( ( ) => {
13
+ const extractValues = ( values : LabeledValueType [ ] ) : SafeKey [ ] =>
14
+ values . map ( ( { value } ) => value ) ;
15
+
16
+ const checkedKeys = extractValues ( rawLabeledValues ) ;
17
+ const halfCheckedKeys = extractValues ( rawHalfCheckedValues ) ;
15
18
16
19
const missingValues = checkedKeys . filter ( key => ! keyEntities [ key ] ) ;
17
20
21
+ let finalCheckedKeys = checkedKeys ;
22
+ let finalHalfCheckedKeys = halfCheckedKeys ;
23
+
18
24
if ( treeConduction ) {
19
- ( { checkedKeys, halfCheckedKeys } = conductCheck ( checkedKeys , true , keyEntities ) ) ;
25
+ const conductResult = conductCheck ( checkedKeys , true , keyEntities ) ;
26
+ finalCheckedKeys = conductResult . checkedKeys ;
27
+ finalHalfCheckedKeys = conductResult . halfCheckedKeys ;
20
28
}
21
29
22
- return [
23
- // Checked keys should fill with missing keys which should de-duplicated
24
- Array . from ( new Set ( [ ...missingValues , ...checkedKeys ] ) ) ,
25
- // Half checked keys
26
- halfCheckedKeys ,
27
- ] ;
30
+ return [ Array . from ( new Set ( [ ...missingValues , ...finalCheckedKeys ] ) ) , finalHalfCheckedKeys ] ;
28
31
} , [ rawLabeledValues , rawHalfCheckedValues , treeConduction , keyEntities ] ) ;
32
+ } ;
33
+
34
+ export default useCheckedKeys ;
0 commit comments