-
Notifications
You must be signed in to change notification settings - Fork 194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
type: revert SafeKey and upgrade rc-tree #586
Changes from 6 commits
c4f2950
3b37259
9758aed
3b38bde
f44d6d9
ef3b85f
21d7795
a5c8201
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ import useMemo from 'rc-util/lib/hooks/useMemo'; | |
import * as React from 'react'; | ||
import LegacyContext from './LegacyContext'; | ||
import TreeSelectContext from './TreeSelectContext'; | ||
import type { SafeKey, TreeDataNode } from './interface'; | ||
import type { Key, SafeKey } from './interface'; | ||
import { getAllKeys, isCheckDisabled } from './utils/valueUtil'; | ||
|
||
const HIDDEN_STYLE = { | ||
|
@@ -23,7 +23,7 @@ const HIDDEN_STYLE = { | |
}; | ||
|
||
interface TreeEventInfo { | ||
node: { key: SafeKey }; | ||
node: { key: Key }; | ||
selected?: boolean; | ||
checked?: boolean; | ||
} | ||
|
@@ -77,8 +77,8 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_, | |
); | ||
|
||
// ========================== Active ========================== | ||
const [activeKey, setActiveKey] = React.useState<SafeKey>(null); | ||
const activeEntity = keyEntities[activeKey]; | ||
const [activeKey, setActiveKey] = React.useState<Key>(null); | ||
const activeEntity = keyEntities[activeKey as SafeKey]; | ||
Comment on lines
+80
to
+81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 检查 activeKey 的类型转换 虽然将 |
||
|
||
// ========================== Values ========================== | ||
const mergedCheckedKeys = React.useMemo(() => { | ||
|
@@ -112,8 +112,8 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_, | |
}; | ||
|
||
// =========================== Keys =========================== | ||
const [expandedKeys, setExpandedKeys] = React.useState<SafeKey[]>(treeDefaultExpandedKeys); | ||
const [searchExpandedKeys, setSearchExpandedKeys] = React.useState<SafeKey[]>(null); | ||
const [expandedKeys, setExpandedKeys] = React.useState<Key[]>(treeDefaultExpandedKeys); | ||
const [searchExpandedKeys, setSearchExpandedKeys] = React.useState<Key[]>(null); | ||
|
||
const mergedExpandedKeys = React.useMemo(() => { | ||
if (treeExpandedKeys) { | ||
|
@@ -129,7 +129,7 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_, | |
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [searchValue]); | ||
|
||
const onInternalExpand = (keys: SafeKey[]) => { | ||
const onInternalExpand = (keys: Key[]) => { | ||
setExpandedKeys(keys); | ||
setSearchExpandedKeys(keys); | ||
|
||
|
@@ -143,7 +143,7 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_, | |
event.preventDefault(); | ||
}; | ||
|
||
const onInternalSelect = (__: SafeKey[], info: TreeEventInfo) => { | ||
const onInternalSelect = (__: Key[], info: TreeEventInfo) => { | ||
const { node } = info; | ||
|
||
if (checkable && isCheckDisabled(node)) { | ||
|
@@ -227,7 +227,7 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_, | |
ref={treeRef} | ||
focusable={false} | ||
prefixCls={`${prefixCls}-tree`} | ||
treeData={memoTreeData as TreeDataNode[]} | ||
treeData={memoTreeData} | ||
height={listHeight} | ||
itemHeight={listItemHeight} | ||
itemScrollOffset={listItemScrollOffset} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
/* istanbul ignore file */ | ||
import type * as React from 'react'; | ||
import type { DataNode, SafeKey } from './interface'; | ||
import type { DataNode, Key } from './interface'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification 类型更改可能影响代码库的其他部分 在 🔗 Analysis chain导入语句更新 导入语句已从 请运行以下脚本以验证 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# 描述:验证 Key 类型的定义和使用
# 测试:搜索 Key 类型的定义
echo "Key 类型的定义:"
rg --type typescript "type\s+Key\s*=" ./src
# 测试:搜索 Key 类型的使用
echo "\nKey 类型的使用:"
rg --type typescript "\b(Key|SafeKey)\b" ./src
Length of output: 259 Script: #!/bin/bash
# 描述:验证 Key 类型的定义和使用
# 搜索 Key 类型的定义
echo "Key 类型的定义:"
rg "type\s+Key\s*=" ./src --glob "*.ts" --glob "*.tsx"
# 搜索 Key 和 SafeKey 类型的使用
echo "\nKey 和 SafeKey 类型的使用:"
rg "\b(Key|SafeKey)\b" ./src --glob "*.ts" --glob "*.tsx"
Length of output: 4993 |
||
|
||
export interface TreeNodeProps extends Omit<DataNode, 'children'> { | ||
value: SafeKey; | ||
value: Key; | ||
children?: React.ReactNode; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,72 +28,21 @@ import type { CheckedStrategy } from './utils/strategyUtil'; | |
import { formatStrategyValues, SHOW_ALL, SHOW_CHILD, SHOW_PARENT } from './utils/strategyUtil'; | ||
import { fillFieldNames, isNil, toArray } from './utils/valueUtil'; | ||
import warningProps from './utils/warningPropsUtil'; | ||
import type { LabeledValueType, SafeKey, SelectSource, DefaultValueType } from './interface'; | ||
|
||
export type OnInternalSelect = (value: SafeKey, info: { selected: boolean }) => void; | ||
|
||
/** @deprecated This is only used for legacy compatible. Not works on new code. */ | ||
export interface LegacyCheckedNode { | ||
pos: string; | ||
node: React.ReactElement; | ||
children?: LegacyCheckedNode[]; | ||
} | ||
|
||
export interface ChangeEventExtra { | ||
/** @deprecated Please save prev value by control logic instead */ | ||
preValue: LabeledValueType[]; | ||
triggerValue: SafeKey; | ||
/** @deprecated Use `onSelect` or `onDeselect` instead. */ | ||
selected?: boolean; | ||
/** @deprecated Use `onSelect` or `onDeselect` instead. */ | ||
checked?: boolean; | ||
|
||
// Not sure if exist user still use this. We have to keep but not recommend user to use | ||
/** @deprecated This prop not work as react node anymore. */ | ||
triggerNode: React.ReactElement; | ||
/** @deprecated This prop not work as react node anymore. */ | ||
allCheckedNodes: LegacyCheckedNode[]; | ||
} | ||
|
||
export interface FieldNames { | ||
value?: string; | ||
label?: string; | ||
children?: string; | ||
} | ||
|
||
export interface InternalFieldName extends Omit<FieldNames, 'label'> { | ||
_title: string[]; | ||
} | ||
|
||
export interface SimpleModeConfig { | ||
id?: SafeKey; | ||
pId?: SafeKey; | ||
rootPId?: SafeKey; | ||
} | ||
|
||
export interface BaseOptionType { | ||
disabled?: boolean; | ||
checkable?: boolean; | ||
disableCheckbox?: boolean; | ||
children?: BaseOptionType[]; | ||
[name: string]: any; | ||
} | ||
|
||
export interface DefaultOptionType extends BaseOptionType { | ||
value?: SafeKey; | ||
title?: React.ReactNode | ((data: DefaultOptionType) => React.ReactNode); | ||
label?: React.ReactNode; | ||
key?: SafeKey; | ||
children?: DefaultOptionType[]; | ||
} | ||
|
||
export interface LegacyDataNode extends DefaultOptionType { | ||
props: any; | ||
} | ||
export interface TreeSelectProps< | ||
ValueType = any, | ||
OptionType extends BaseOptionType = DefaultOptionType, | ||
> extends Omit<BaseSelectPropsWithoutPrivate, 'mode'> { | ||
import type { | ||
LabeledValueType, | ||
SafeKey, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 持续使用已移除的 在第28、365、521和535行,代码中仍在使用 Also applies to: 365-365, 521-521, 535-535 |
||
Key, | ||
DataNode, | ||
SimpleModeConfig, | ||
ChangeEventExtra, | ||
SelectSource, | ||
DefaultValueType, | ||
FieldNames, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 使用了可能已移除的 在第35和202行, Also applies to: 202-202 |
||
LegacyDataNode, | ||
} from './interface'; | ||
Comment on lines
+26
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 移除的类型仍在导入 在第26-37行,从 |
||
|
||
export interface TreeSelectProps<ValueType = any, OptionType extends DataNode = DataNode> | ||
extends Omit<BaseSelectPropsWithoutPrivate, 'mode'> { | ||
prefixCls?: string; | ||
id?: string; | ||
children?: React.ReactNode; | ||
|
@@ -109,7 +58,7 @@ export interface TreeSelectProps< | |
inputValue?: string; | ||
onSearch?: (value: string) => void; | ||
autoClearSearchValue?: boolean; | ||
filterTreeNode?: boolean | ((inputValue: string, treeNode: DefaultOptionType) => boolean); | ||
filterTreeNode?: boolean | ((inputValue: string, treeNode: DataNode) => boolean); | ||
treeNodeFilterProp?: string; | ||
|
||
// >>> Select | ||
|
@@ -255,7 +204,7 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref) | |
} | ||
|
||
// ========================= FieldNames ========================= | ||
const mergedFieldNames: InternalFieldName = React.useMemo( | ||
const mergedFieldNames: FieldNames = React.useMemo( | ||
() => fillFieldNames(fieldNames), | ||
/* eslint-disable react-hooks/exhaustive-deps */ | ||
[JSON.stringify(fieldNames)], | ||
|
@@ -310,7 +259,7 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref) | |
|
||
// =========================== Label ============================ | ||
const getLabel = React.useCallback( | ||
(item: DefaultOptionType) => { | ||
(item: DataNode) => { | ||
if (item) { | ||
if (treeNodeLabelProp) { | ||
return item[treeNodeLabelProp]; | ||
|
@@ -418,7 +367,7 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref) | |
const displayValues = React.useMemo(() => { | ||
// Collect keys which need to show | ||
const displayKeys = formatStrategyValues( | ||
rawCheckedValues, | ||
rawCheckedValues as SafeKey[], | ||
mergedShowCheckedStrategy, | ||
keyEntities, | ||
mergedFieldNames, | ||
|
@@ -574,7 +523,7 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref) | |
const keyList = existRawValues.map(val => valueEntities.get(val).key); | ||
|
||
// Conduction by selected or not | ||
let checkedKeys: SafeKey[]; | ||
let checkedKeys: Key[]; | ||
if (selected) { | ||
({ checkedKeys } = conductCheck(keyList, true, keyEntities)); | ||
} else { | ||
|
@@ -588,7 +537,7 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref) | |
// Fill back of keys | ||
newRawValues = [ | ||
...missingRawValues, | ||
...checkedKeys.map(key => keyEntities[key].node[mergedFieldNames.value]), | ||
...checkedKeys.map(key => keyEntities[key as SafeKey].node[mergedFieldNames.value]), | ||
]; | ||
} | ||
triggerChange(newRawValues, { selected, triggerValue: selectedValue }, source || 'option'); | ||
|
@@ -760,7 +709,7 @@ if (process.env.NODE_ENV !== 'production') { | |
|
||
const GenericTreeSelect = TreeSelect as unknown as (< | ||
ValueType = any, | ||
OptionType extends BaseOptionType | DefaultOptionType = DefaultOptionType, | ||
OptionType extends DataNode = DataNode, | ||
>( | ||
props: React.PropsWithChildren<TreeSelectProps<ValueType, OptionType>> & { | ||
ref?: React.Ref<BaseSelectRef>; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
将
checkedKeys
和halfCheckedKeys
的类型从SafeKey[]
更改为Key[]
在以下文件中仍然存在
SafeKey
的使用,请确保全部替换为Key
类型以保持一致性:🔗 Analysis chain
将
checkedKeys
和halfCheckedKeys
的类型从SafeKey[]
更改为Key[]
这个更改看起来是为了统一使用
Key
类型。这是一个好的改进,可以提高代码的一致性和类型安全性。请运行以下脚本以验证
SafeKey
到Key
的更改是否在整个代码库中保持一致:🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 225
Script:
Length of output: 5200
Script:
Length of output: 5132