forked from XiaoMi/hiui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(filter): 支持配置字段别名(XiaoMi#2915) * chore: 生成变更记录文件 * feat(filter): 修改fieldNames类型 * feat(filter): 增加类型约束 * feat(filter): 代码规范 --------- Co-authored-by: xiamiao <[email protected]>
- Loading branch information
1 parent
cfc6c97
commit 9b2dc02
Showing
4 changed files
with
52 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@hi-ui/filter": minor | ||
--- | ||
|
||
feat: 支持配置字段别名 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@hi-ui/hiui": patch | ||
--- | ||
|
||
feat(filter): 支持配置字段别名 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { HiBaseFieldNameKeys, HiBaseFieldNames } from '@hi-ui/core' | ||
import { FilterDataItem } from './types' | ||
import React from 'react' | ||
|
||
export const transformTreeData = ( | ||
data: FilterDataItem[], | ||
fieldNames?: HiBaseFieldNames | ||
): FilterDataItem[] => { | ||
const getKeyFields = (node: FilterDataItem, key: HiBaseFieldNameKeys) => { | ||
if (fieldNames) { | ||
return node[(fieldNames[key] || key) as keyof FilterDataItem] | ||
} | ||
return node[key] | ||
} | ||
|
||
const traverseNode = (node: FilterDataItem): FilterDataItem => { | ||
const newNode: FilterDataItem = { ...node } | ||
|
||
newNode.id = getKeyFields(newNode, 'id') as React.ReactText | ||
newNode.title = getKeyFields(newNode, 'title') as React.ReactText | ||
newNode.disabled = (getKeyFields(newNode, 'disabled') ?? false) as boolean | ||
newNode.children = getKeyFields(newNode, 'children') as FilterDataItem[] | ||
|
||
if (newNode.children) { | ||
newNode.children = newNode.children.map(traverseNode) | ||
} | ||
|
||
return newNode | ||
} | ||
|
||
return data.map(traverseNode) | ||
} |