This commit is contained in:
zlwu committed 2026-05-17 08:36:37 +08:00
1 parent 246ad2228e
commit 8e2dd8b9f0
186 files changed
+38821 -2571

No files matched your search

+13 -4
View File
@@ -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()