Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(dashboards): filter dashboards by clicked tag (#89521)

Matt Pua35a0062461fa
diff --git a/frontend/src/scenes/dashboard/dashboards/DashboardsTable.test.tsx b/frontend/src/scenes/dashboard/dashboards/DashboardsTable.test.tsx
index 1badc3fb9bb3..2d76c20c2d6e 100644
--- a/frontend/src/scenes/dashboard/dashboards/DashboardsTable.test.tsx
+++ b/frontend/src/scenes/dashboard/dashboards/DashboardsTable.test.tsx
@@ -21,7 +21,11 @@ jest.mock('lib/lemon-ui/LemonTable', () => ({
<div>
{bulkSelection ? bulkSelection.renderActions(mockCtx) : null}
{dataSource.map((row: any) => (
- <div key={row.id}>{columns.at(-1).render(undefined, row)}</div>
+ <div key={row.id}>
+ {columns.map((column: any, index: number) =>
+ column.render ? <span key={index}>{column.render(row[column.dataIndex], row)}</span> : null
+ )}
+ </div>
))}
</div>
),
@@ -99,4 +103,43 @@ describe('DashboardsTable move to folder', () => {
fireEvent.click(screen.getByText('Move to folder'))
expect(moveDashboardsToFolder).not.toHaveBeenCalled()
})
+
+ it('filters dashboards by a clicked tag', () => {
+ const setFilters = jest.fn()
+ ;(useActions as jest.Mock).mockReturnValue({
+ unpinDashboard: jest.fn(),
+ pinDashboard: jest.fn(),
+ tableSortingChanged: jest.fn(),
+ setFilters,
+ showDuplicateDashboardModal: jest.fn(),
+ showDeleteDashboardModal: jest.fn(),
+ moveDashboardsToFolder,
+ })
+ ;(useValues as jest.Mock).mockReturnValue({
+ tableSorting: null,
+ filters: { search: '' },
+ currentTeam: { id: 1 },
+ filedDashboardIds: new Set([1]),
+ })
+
+ render(
+ <DashboardsTable
+ dashboards={
+ [
+ {
+ id: 1,
+ name: 'Dashboard 1',
+ tags: ['finance'],
+ user_access_level: AccessControlLevel.Editor,
+ },
+ ] as any
+ }
+ dashboardsLoading={false}
+ />
+ )
+
+ fireEvent.click(screen.getByText('finance'))
+
+ expect(setFilters).toHaveBeenCalledWith({ tags: ['finance'] })
+ })
})
diff --git a/frontend/src/scenes/dashboard/dashboards/DashboardsTable.tsx b/frontend/src/scenes/dashboard/dashboards/DashboardsTable.tsx
index a336c5749cc9..0f9f47582dc7 100644
--- a/frontend/src/scenes/dashboard/dashboards/DashboardsTable.tsx
+++ b/frontend/src/scenes/dashboard/dashboards/DashboardsTable.tsx
@@ -177,7 +177,9 @@ export function DashboardsTable({
title: 'Tags',
dataIndex: 'tags' as keyof DashboardType,
render: function Render(tags: DashboardType['tags']) {
- return tags ? <ObjectTags tags={[...tags].sort()} staticOnly /> : null
+ return tags ? (
+ <ObjectTags tags={[...tags].sort()} staticOnly onTagClick={(tag) => setFilters({ tags: [tag] })} />
+ ) : null
},
} as LemonTableColumn<DashboardType, keyof DashboardType | undefined>,
{