Skip to content

Commit

Permalink
codecov
Browse files Browse the repository at this point in the history
  • Loading branch information
yoyo837 committed May 28, 2020
1 parent 4aaffc1 commit ea99434
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/OptionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ const OptionList: React.RefForwardingComponent<RefOptionListProps, OptionListPro
};

const onInternalSelect = (_: Key[], { node: { key } }: TreeEventInfo) => {
const entity = getEntityByKey(key, checkable ? 'checkbox' : 'select');
const entity = getEntityByKey(key);
if (entity !== null) {
onSelect(entity.data.value, {
selected: !checkedKeys.includes(entity.data.value),
Expand Down
22 changes: 1 addition & 21 deletions src/hooks/useKeyValueMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,10 @@ import { FlattenDataNode, Key, RawValueType } from '../interface';

export type SkipType = null | 'select' | 'checkbox';

// export function isDisabled(dataNode: FlattenDataNode, skipType: SkipType): boolean {
// if (!dataNode) {
// return true;
// }

// const { disabled, disableCheckbox } = dataNode.data;

// switch (skipType) {
// case 'select':
// return disabled;
// case 'checkbox':
// return disabled || disableCheckbox;
// }

// return false;
// }

export default function useKeyValueMapping(
cacheKeyMap: Map<Key, FlattenDataNode>,
cacheValueMap: Map<RawValueType, FlattenDataNode>,
): [
(key: Key, skipType?: SkipType) => FlattenDataNode,
(value: RawValueType, skipType?: SkipType) => FlattenDataNode,
] {
): [(key: Key) => FlattenDataNode, (value: RawValueType) => FlattenDataNode] {
const getEntityByKey = React.useCallback((key: Key) => cacheKeyMap.get(key), [cacheKeyMap]);

const getEntityByValue = React.useCallback((value: RawValueType) => cacheValueMap.get(value), [
Expand Down
5 changes: 2 additions & 3 deletions src/hooks/useSelectValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react';
import { DefaultValueType } from 'rc-select/lib/interface/generator';
import { DataEntity } from 'rc-tree/lib/interface';
import { RawValueType, FlattenDataNode, Key, LabelValueType, DataNode } from '../interface';
import { SkipType } from './useKeyValueMapping';
import { getRawValueLabeled } from '../utils/valueUtil';
import { formatStrategyKeys, CheckedStrategy } from '../utils/strategyUtil';

Expand All @@ -12,8 +11,8 @@ interface Config {
value: DefaultValueType;
showCheckedStrategy: CheckedStrategy;
conductKeyEntities: Record<Key, DataEntity>;
getEntityByKey: (key: Key, skipType?: SkipType) => FlattenDataNode;
getEntityByValue: (value: RawValueType, skipType?: SkipType) => FlattenDataNode;
getEntityByKey: (key: Key) => FlattenDataNode;
getEntityByValue: (value: RawValueType) => FlattenDataNode;
getLabelProp: (node: DataNode) => React.ReactNode;
}

Expand Down
13 changes: 0 additions & 13 deletions tests/utils.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { isValueDisabled } from '../src/utils/valueUtil';
// import { isDisabled } from '../src/hooks/useKeyValueMapping';

describe('TreeSelect.util', () => {
it('isValueDisabled', () => {
Expand All @@ -11,16 +10,4 @@ describe('TreeSelect.util', () => {
expect(isValueDisabled('pass', options)).toBeFalsy();
expect(isValueDisabled('not-exist', options)).toBeFalsy();
});

// it('isDisabled', () => {
// expect(isDisabled({ data: { disabled: true } }, 'select')).toBeTruthy();
// expect(
// isDisabled({ data: { disableCheckbox: true } }, 'select'),
// ).toBeFalsy();
// expect(isDisabled({ data: { disabled: true } }, 'checkbox')).toBeTruthy();
// expect(
// isDisabled({ data: { disableCheckbox: true } }, 'checkbox'),
// ).toBeTruthy();
// expect(isDisabled({ data: { disabled: true } }, null)).toBeFalsy();
// });
});

0 comments on commit ea99434

Please sign in to comment.