Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import { useMemo, useRef } from 'react'
import {
Badge,
Button,
CollapsibleCard,
Combobox,
type ComboboxOption,
cn,
handleKeyboardActivation,
Input,
Label,
OverflowText,
Trash,
} from '@sim/emcn'
import { Plus } from '@sim/emcn/icons'
Expand Down Expand Up @@ -235,55 +236,46 @@ export function DocumentTagEntry({
}

/**
* Renders the tag header with name, badge, and action buttons
* Renders the tag summary with its type badge
* Shows tag name only when collapsed (as summary), generic label when expanded
*/
const renderTagHeader = (tag: DocumentTag, index: number) => (
<div
role='group'
aria-label={`Tag ${index + 1}`}
className='flex cursor-pointer items-center justify-between rounded-t-[4px] bg-[var(--surface-4)] px-2.5 py-[5px]'
onClick={() => toggleCollapse(tag.id)}
onKeyDown={(event) => {
if (event.target !== event.currentTarget) return
handleKeyboardActivation(event, () => toggleCollapse(tag.id))
}}
>
<div className='flex min-w-0 flex-1 items-center gap-2'>
<span className='block truncate text-[var(--text-tertiary)] text-sm'>
{tag.collapsed ? tag.tagName || `Tag ${index + 1}` : `Tag ${index + 1}`}
</span>
{tag.collapsed && tag.tagName && (
<Badge variant='type' size='sm'>
{FIELD_TYPE_LABELS[tag.fieldType] || 'Text'}
</Badge>
)}
</div>
<div
role='presentation'
className='flex items-center gap-2 pl-2'
onClick={(e) => e.stopPropagation()}
const renderTitle = (tag: DocumentTag, index: number) => (
<span className='flex min-w-0 items-center gap-2'>
<OverflowText
label={tag.collapsed ? tag.tagName || `Tag ${index + 1}` : `Tag ${index + 1}`}
focusTarget='nearest-interactive'
>
<Button
variant='ghost'
onClick={addTag}
disabled={isReadOnly || !canAddMoreTags}
className='h-auto p-0'
>
<Plus className='size-[14px]' />
<span className='sr-only'>Add Tag</span>
</Button>
<Button
variant='ghost-destructive'
onClick={() => removeTag(tag.id)}
disabled={isReadOnly}
className='h-auto p-0'
>
<Trash className='size-[14px]' />
<span className='sr-only'>Delete Tag</span>
</Button>
</div>
</div>
{tag.collapsed ? tag.tagName || `Tag ${index + 1}` : `Tag ${index + 1}`}
</OverflowText>
{tag.collapsed && tag.tagName && (
<Badge variant='type' size='sm'>
{FIELD_TYPE_LABELS[tag.fieldType] || 'Text'}
</Badge>
)}
</span>
)

const renderActions = (tag: DocumentTag) => (
<>
<Button
variant='ghost'
onClick={addTag}
disabled={isReadOnly || !canAddMoreTags}
className='h-auto p-0'
>
<Plus className='size-[14px]' />
<span className='sr-only'>Add Tag</span>
</Button>
<Button
variant='ghost-destructive'
onClick={() => removeTag(tag.id)}
disabled={isReadOnly}
className='h-auto p-0'
>
<Trash className='size-[14px]' />
<span className='sr-only'>Delete Tag</span>
</Button>
</>
)

/**
Expand Down Expand Up @@ -385,7 +377,7 @@ export function DocumentTagEntry({
}))

return (
<div className='flex flex-col gap-2 rounded-b-[4px] border-[var(--border-1)] border-t bg-[var(--surface-2)] px-2.5 pt-1.5 pb-2.5'>
<>
<div className='flex flex-col gap-1.5'>
<Label className='text-small'>Tag</Label>
<Combobox
Expand All @@ -401,24 +393,25 @@ export function DocumentTagEntry({
<Label className='text-small'>Value</Label>
{renderValueInput(tag)}
</div>
</div>
</>
)
}

return (
<div className='space-y-2'>
{tags.map((tag, index) => (
<div
<CollapsibleCard
key={tag.id}
data-tag-id={tag.id}
className={cn(
'rounded-sm border border-[var(--border-1)]',
tag.collapsed ? 'overflow-hidden' : 'overflow-visible'
)}
role='group'
aria-label={`Tag ${index + 1}`}
title={renderTitle(tag, index)}
actions={renderActions(tag)}
collapsed={Boolean(tag.collapsed)}
onToggleCollapse={() => toggleCollapse(tag.id)}
>
{renderTagHeader(tag, index)}
{!tag.collapsed && renderTagContent(tag)}
</div>
</CollapsibleCard>
))}
</div>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import { useRef } from 'react'
import {
Badge,
Button,
CollapsibleCard,
Combobox,
type ComboboxOption,
cn,
handleKeyboardActivation,
Input,
Label,
OverflowText,
Trash,
} from '@sim/emcn'
import { Plus } from '@sim/emcn/icons'
Expand Down Expand Up @@ -102,56 +103,46 @@ export function FilterRuleRow({
label,
})

const renderHeader = () => (
<div
role='group'
aria-label={`Condition ${index + 1}`}
className='flex cursor-pointer items-center justify-between rounded-t-[4px] bg-[var(--surface-4)] px-2.5 py-[5px]'
onClick={() => onToggleCollapse(rule.id)}
onKeyDown={(event) => {
if (event.target !== event.currentTarget) return
handleKeyboardActivation(event, () => onToggleCollapse(rule.id))
}}
>
<div className='flex min-w-0 flex-1 items-center gap-2'>
<span className='block truncate text-[var(--text-tertiary)] text-sm'>
{rule.collapsed && rule.column
? formatDisplayText(getColumnLabel(rule.column), {
workflowSearchHighlight: getLabelHighlight('column', getColumnLabel(rule.column)),
})
: `Condition ${index + 1}`}
</span>
{rule.collapsed && rule.column && (
<Badge variant='type' size='sm'>
{formatDisplayText(getOperatorLabel(rule.operator), {
workflowSearchHighlight: getLabelHighlight(
'operator',
getOperatorLabel(rule.operator)
),
})}
</Badge>
)}
</div>
<div
role='presentation'
className='flex items-center gap-2 pl-2'
onClick={(e) => e.stopPropagation()}
const renderTitle = () => (
<span className='flex min-w-0 items-center gap-2'>
<OverflowText
label={
rule.collapsed && rule.column ? getColumnLabel(rule.column) : `Condition ${index + 1}`
}
focusTarget='nearest-interactive'
>
<Button variant='ghost' onClick={onAdd} disabled={isReadOnly} className='h-auto p-0'>
<Plus className='size-[14px]' />
<span className='sr-only'>Add Condition</span>
</Button>
<Button
variant='ghost-destructive'
onClick={() => onRemove(rule.id)}
disabled={isReadOnly}
className='h-auto p-0'
>
<Trash className='size-[14px]' />
<span className='sr-only'>Delete Condition</span>
</Button>
</div>
</div>
{rule.collapsed && rule.column
? formatDisplayText(getColumnLabel(rule.column), {
workflowSearchHighlight: getLabelHighlight('column', getColumnLabel(rule.column)),
})
: `Condition ${index + 1}`}
</OverflowText>
{rule.collapsed && rule.column && (
<Badge variant='type' size='sm'>
{formatDisplayText(getOperatorLabel(rule.operator), {
workflowSearchHighlight: getLabelHighlight('operator', getOperatorLabel(rule.operator)),
})}
</Badge>
)}
</span>
)

const renderActions = () => (
<>
<Button variant='ghost' onClick={onAdd} disabled={isReadOnly} className='h-auto p-0'>
<Plus className='size-[14px]' />
<span className='sr-only'>Add Condition</span>
</Button>
<Button
variant='ghost-destructive'
onClick={() => onRemove(rule.id)}
disabled={isReadOnly}
className='h-auto p-0'
>
<Trash className='size-[14px]' />
<span className='sr-only'>Delete Condition</span>
</Button>
</>
)

const renderValueInput = () => (
Expand Down Expand Up @@ -209,7 +200,7 @@ export function FilterRuleRow({
)

const renderContent = () => (
<div className='flex flex-col gap-2 rounded-b-[4px] border-[var(--border-1)] border-t bg-[var(--surface-2)] px-2.5 pt-1.5 pb-2.5'>
<>
{index > 0 && (
<div className='flex flex-col gap-1.5'>
<Label className='text-small'>Logic</Label>
Expand Down Expand Up @@ -281,19 +272,20 @@ export function FilterRuleRow({
<Label className='text-small'>Value</Label>
{renderValueInput()}
</div>
</div>
</>
)

return (
<div
<CollapsibleCard
data-filter-id={rule.id}
className={cn(
'rounded-sm border border-[var(--border-1)]',
rule.collapsed ? 'overflow-hidden' : 'overflow-visible'
)}
role='group'
aria-label={`Condition ${index + 1}`}
title={renderTitle()}
actions={renderActions()}
collapsed={Boolean(rule.collapsed)}
onToggleCollapse={() => onToggleCollapse(rule.id)}
>
{renderHeader()}
{!rule.collapsed && renderContent()}
</div>
</CollapsibleCard>
)
}
Loading
Loading