-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(search): 支持配置字段别名(#2885) * chore: 生成变更记录文件 * feat(breadcrumb): 修改fieldNames类型 * feat(breadcrumb): 代码规范 --------- Co-authored-by: xiamiao <[email protected]>
- Loading branch information
1 parent
179fd7f
commit 7fd686e
Showing
4 changed files
with
61 additions
and
6 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/hiui": patch | ||
--- | ||
|
||
feat(search): 支持配置字段别名 |
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/breadcrumb": 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
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,34 @@ | ||
import { HiBaseFieldNameKeys, HiBaseFieldNames } from '@hi-ui/core' | ||
import { BreadcrumbDataItem, BreadcrumbDataItemTargetEnum } from './types' | ||
import React from 'react' | ||
|
||
export const transformData = ( | ||
data: BreadcrumbDataItem[], | ||
fieldNames?: HiBaseFieldNames | ||
): BreadcrumbDataItem[] => { | ||
/** | ||
* 转换对象 | ||
*/ | ||
const getKeyFields = (node: BreadcrumbDataItem, key: HiBaseFieldNameKeys) => { | ||
if (fieldNames) { | ||
return node[(fieldNames[key] || key) as keyof BreadcrumbDataItem] | ||
} | ||
return node[key as keyof BreadcrumbDataItem] | ||
} | ||
|
||
const traverseNode = (node: BreadcrumbDataItem): BreadcrumbDataItem => { | ||
const newNode: BreadcrumbDataItem = { ...node } | ||
|
||
newNode.title = getKeyFields(newNode, 'title') | ||
newNode.href = getKeyFields(newNode, 'href' as HiBaseFieldNameKeys) as string | ||
newNode.icon = getKeyFields(newNode, 'icon' as HiBaseFieldNameKeys) as React.ReactNode | ||
newNode.target = getKeyFields( | ||
newNode, | ||
'target' as HiBaseFieldNameKeys | ||
) as BreadcrumbDataItemTargetEnum | ||
|
||
return newNode | ||
} | ||
|
||
return data.map(traverseNode) | ||
} |