You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.3 KiB
45 lines
1.3 KiB
import React from 'react';
|
|
export function isDisabled(dataNode, skipType) {
|
|
if (!dataNode) {
|
|
return true;
|
|
}
|
|
|
|
var _dataNode$data = dataNode.data,
|
|
disabled = _dataNode$data.disabled,
|
|
disableCheckbox = _dataNode$data.disableCheckbox;
|
|
|
|
switch (skipType) {
|
|
case 'select':
|
|
return disabled;
|
|
|
|
case 'checkbox':
|
|
return disabled || disableCheckbox;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
export default function useKeyValueMapping(cacheKeyMap, cacheValueMap) {
|
|
var getEntityByKey = React.useCallback(function (key) {
|
|
var skipType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'select';
|
|
var ignoreDisabledCheck = arguments.length > 2 ? arguments[2] : undefined;
|
|
var dataNode = cacheKeyMap.get(key);
|
|
|
|
if (!ignoreDisabledCheck && isDisabled(dataNode, skipType)) {
|
|
return null;
|
|
}
|
|
|
|
return dataNode;
|
|
}, [cacheKeyMap]);
|
|
var getEntityByValue = React.useCallback(function (value) {
|
|
var skipType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'select';
|
|
var ignoreDisabledCheck = arguments.length > 2 ? arguments[2] : undefined;
|
|
var dataNode = cacheValueMap.get(value);
|
|
|
|
if (!ignoreDisabledCheck && isDisabled(dataNode, skipType)) {
|
|
return null;
|
|
}
|
|
|
|
return dataNode;
|
|
}, [cacheValueMap]);
|
|
return [getEntityByKey, getEntityByValue];
|
|
} |