fix(frontend): hide redundant card badges when section headers apply

Suppress duplicate origin, builtin, role, and org-name pills on knowledge
base, agent, and organization list cards when the visible group header or
sidebar filter already conveys the same information.
This commit is contained in:
wizardchen
2026-06-26 16:54:23 +08:00
committed by lyingbug
parent b8ce6a699c
commit 4588e95ba3
4 changed files with 94 additions and 21 deletions
+49
View File
@@ -0,0 +1,49 @@
/**
* Helpers to suppress card corner badges that repeat what a visible section
* header (Group) already communicates.
*/
export type ListCardSectionKey =
| 'pinned'
| 'mine'
| 'tenantOthers'
| 'builtin'
| 'sharedByMe'
| 'sharedEditable'
| 'sharedReadonly'
| 'created'
| 'joined'
export type ResourceOriginVariant = 'mine' | 'tenant' | 'creator' | 'space' | 'shared'
/** ResourceOriginBadge on KB / Agent cards. */
export function shouldShowResourceOriginBadge(opts: {
section: ListCardSectionKey | null
variant: ResourceOriginVariant
creatorName?: string
showSectionHeaders?: boolean
}): boolean {
if (!opts.showSectionHeaders) return true
const { section, variant, creatorName } = opts
const hasCreator = Boolean(creatorName?.trim())
if (section === 'mine' && variant === 'mine') return false
if (section === 'builtin') return false
if (section === 'tenantOthers' && variant === 'creator' && !hasCreator) return false
return true
}
/** Owner / role tag on organization cards. */
export function shouldShowOrgRelationTag(opts: {
spaceSelection: 'all' | 'created' | 'joined'
isOwner: boolean
myRole?: string
}): boolean {
if (opts.spaceSelection === 'created') return false
if (opts.spaceSelection === 'joined' && !opts.myRole) return false
if (opts.spaceSelection === 'all' && opts.isOwner) return false
if (opts.spaceSelection === 'all' && !opts.isOwner && !opts.myRole) return false
return true
}