提交
This commit is contained in:
1 parent
246ad2228e
commit
8e2dd8b9f0
186 files changed
+38821
-2571
No files matched your search
@@ -11,8 +11,16 @@ export type TreePathFlatNode = Record<string, unknown>
|
||||
export function buildTreePathLabelFromFlat(
|
||||
nodeId: string | null | undefined,
|
||||
flatList: TreePathFlatNode[] | null | undefined,
|
||||
separator: string = DEFAULT_TREE_PATH_SEPARATOR
|
||||
separatorOrOpts?: string | { separator?: string; nameKey?: string }
|
||||
): string {
|
||||
const separator =
|
||||
typeof separatorOrOpts === 'string'
|
||||
? separatorOrOpts
|
||||
: separatorOrOpts?.separator ?? DEFAULT_TREE_PATH_SEPARATOR
|
||||
const nameKey =
|
||||
typeof separatorOrOpts === 'string'
|
||||
? 'name'
|
||||
: separatorOrOpts?.nameKey ?? 'name'
|
||||
const cid = String(nodeId ?? '').trim()
|
||||
if (!cid) return ''
|
||||
const byId = new Map<string, TreePathFlatNode>()
|
||||
@@ -26,7 +34,7 @@ export function buildTreePathLabelFromFlat(
|
||||
while (cur && byId.has(cur) && !seen.has(cur)) {
|
||||
seen.add(cur)
|
||||
const cat: TreePathFlatNode = byId.get(cur)!
|
||||
const nm = String(cat?.name ?? '').trim()
|
||||
const nm = String(cat?.[nameKey] ?? '').trim()
|
||||
if (nm) names.unshift(nm)
|
||||
const pid: string = String(cat?.parentId ?? cat?.parent_id ?? '').trim()
|
||||
cur = pid || null
|
||||
@@ -70,12 +78,13 @@ export function resolveTreePathDisplay(
|
||||
flatList: TreePathFlatNode[] | null | undefined,
|
||||
fallbackName?: unknown,
|
||||
separator: string = DEFAULT_TREE_PATH_SEPARATOR,
|
||||
emptyPlaceholder = '—'
|
||||
emptyPlaceholder = '—',
|
||||
nameKey?: string
|
||||
): string {
|
||||
const path = buildTreePathLabelFromFlat(
|
||||
String(nodeId ?? '').trim() || undefined,
|
||||
flatList,
|
||||
separator
|
||||
{ separator, nameKey }
|
||||
)
|
||||
if (path) return path
|
||||
const fb = String(fallbackName ?? '').trim()
|
||||
|
||||
Reference in new issue
Block a user