Skip to content
Merged
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 @@ -31,8 +31,9 @@ describe('FilterSection', () => {
expect(baseElement).toBeTruthy()
})

it('should not render any badges when no filters are applied', () => {
it('should render only Timestamp badge when no filters are applied', () => {
renderWithProviders(<FilterSection {...props} />)
screen.getByText(/Timestamp:/)
expect(screen.queryByRole('button', { name: /Clear all filters/i })).not.toBeInTheDocument()
})

Expand Down Expand Up @@ -116,8 +117,8 @@ describe('FilterSection', () => {
)

screen.getByText(/Project:/)
const element = container.querySelector('button')
expect(element?.textContent).toContain('My Project')
const buttons = container.querySelectorAll('button')
expect(buttons[1]?.textContent).toContain('My Project')
})

it('should render environment badge when environmentId is set with selectedItems', () => {
Expand All @@ -139,8 +140,8 @@ describe('FilterSection', () => {
)

screen.getByText(/Environment:/)
const element = container.querySelector('button')
expect(element?.textContent).toContain('Production')
const buttons = container.querySelectorAll('button')
expect(buttons[1]?.textContent).toContain('Production')
})

it('should render target badge when targetId is set with selectedItems', () => {
Expand All @@ -163,8 +164,8 @@ describe('FilterSection', () => {
)

screen.getByText(/Application:/)
const element = container.querySelector('button')
expect(element?.textContent).toContain('My App')
const buttons = container.querySelectorAll('button')
expect(buttons[1]?.textContent).toContain('My App')
})

it('should render multiple badges when multiple filters are set', () => {
Expand Down
34 changes: 27 additions & 7 deletions libs/pages/events/src/lib/ui/filter-section/filter-section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface Badge {
key: string
displayedName: string
value: string
isDeletable: boolean
}

function buildBadges(
Expand All @@ -36,34 +37,46 @@ function buildBadges(
'" To "' +
dateYearMonthDayHourMinuteSecond(toDate, true, false) +
'"',
isDeletable: true,
})
} else {
badges.push({
key: 'timestamp',
displayedName: 'Timestamp',
value: 'Last 30 days',
isDeletable: false,
})
}
if (queryParams.eventType) {
badges.push({
key: 'event_type',
displayedName: 'Event Type',
value: upperCaseFirstLetter(queryParams.eventType).split('_').join(' '),
isDeletable: true,
})
}
if (queryParams.targetType) {
badges.push({
key: 'target_type',
displayedName: 'Target Type',
value: upperCaseFirstLetter(queryParams.targetType).split('_').join(' '),
isDeletable: true,
})
}
if (queryParams.triggeredBy) {
badges.push({
key: 'triggered_by',
displayedName: 'User',
value: upperCaseFirstLetter(queryParams.triggeredBy).split('_').join(' '),
isDeletable: true,
})
}
if (queryParams.origin) {
badges.push({
key: 'origin',
displayedName: 'Source',
value: upperCaseFirstLetter(queryParams.origin).split('_').join(' '),
isDeletable: true,
})
}
if (queryParams.projectId) {
Expand All @@ -75,6 +88,7 @@ function buildBadges(
key: 'project_id',
displayedName: 'Project',
value: projectName,
isDeletable: true,
})
}
}
Expand All @@ -87,6 +101,7 @@ function buildBadges(
key: 'environment_id',
displayedName: 'Environment',
value: environmentName,
isDeletable: true,
})
}
}
Expand All @@ -101,6 +116,7 @@ function buildBadges(
key: 'target_id',
displayedName: targetType,
value: targetName,
isDeletable: true,
})
}
}
Expand Down Expand Up @@ -177,11 +193,13 @@ export function FilterSection({ clearFilter, queryParams, targetTypeSelectedItem
{`${badge.displayedName}: `}
{badge.key === 'timestamp' && badge.value}
{badge.key !== 'timestamp' && <Truncate text={badge.value} truncateLimit={23} />}
<Icon
iconName="xmark"
className="text-sm leading-4 text-neutral-300 hover:text-neutral-400"
onClick={() => deleteFilter(badge.key, setFilter)}
/>
{badge.isDeletable && (
<Icon
iconName="xmark"
className="text-sm leading-4 text-neutral-300 hover:text-neutral-400"
onClick={() => deleteFilter(badge.key, setFilter)}
/>
)}
</Button>
))}
<div className="flex flex-row-reverse">
Expand Down Expand Up @@ -229,7 +247,9 @@ export function FilterSection({ clearFilter, queryParams, targetTypeSelectedItem
onClick={() => deleteFilter(badge.key, setFilter)}
aria-label="Delete filter"
>
<Icon iconName="xmark" className="text-sm leading-4 text-neutral-300 hover:text-neutral-400" />
{badge.isDeletable && (
<Icon iconName="xmark" className="text-sm leading-4 text-neutral-300 hover:text-neutral-400" />
)}
</button>
</Button>
{!isLast && (
Expand All @@ -252,7 +272,7 @@ export function FilterSection({ clearFilter, queryParams, targetTypeSelectedItem
</div>

{/* RIGHT: Button stays fixed at top-right */}
{badges.length > 0 && (
{badges.filter((b) => b.isDeletable).length > 0 && (
<div className="flex-shrink-0 self-start">
<Button className="gap-2" size="xs" color="neutral" variant="surface" onClick={clearFilter}>
Clear all filters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export function TableHeadDatePickerFilter({
variant={isDark ? 'solid' : 'surface'}
color="neutral"
size="xs"
className="items-center gap-1.5"
className="items-center gap-1.5 bg-brand-500 text-white active:bg-brand-600 hover:[&:not(:active):not(:disabled)]:bg-brand-400"
onClick={() => {
setIsOpenTimestamp(!isOpenTimestamp)
}}
Expand Down