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(customer-analytics): search accounts in the command palette (#78548)

Arthur Moreira de Deus89db6da7847c
diff --git a/frontend/src/lib/components/Search/Search.tsx b/frontend/src/lib/components/Search/Search.tsx
index 1fe12ba4675d..369d2e9bf232 100644
--- a/frontend/src/lib/components/Search/Search.tsx
+++ b/frontend/src/lib/components/Search/Search.tsx
@@ -157,6 +157,7 @@ const getItemTypeDisplayName = (type: string | null | undefined): string | null
persons: 'Person',
user: 'User',
group: 'Group',
+ account: 'Account',
heatmap: 'Heatmap',
sql_editor: 'SQL query',
logs: 'Logs',
diff --git a/frontend/src/lib/components/Search/searchLogic.tsx b/frontend/src/lib/components/Search/searchLogic.tsx
index e6ac86a2f2a0..2626eb78a406 100644
--- a/frontend/src/lib/components/Search/searchLogic.tsx
+++ b/frontend/src/lib/components/Search/searchLogic.tsx
@@ -2,10 +2,11 @@ import { MakeLogicType, actions, afterMount, connect, kea, key, listeners, path,
import { loaders } from 'kea-loaders'
import { router } from 'kea-router'
-import { IconBell, IconClock, IconDownload, IconLeave, IconNotification } from '@posthog/icons'
+import { IconBell, IconBuilding, IconClock, IconDownload, IconLeave, IconNotification } from '@posthog/icons'
import api from 'lib/api'
import { commandLogic } from 'lib/components/Command/commandLogic'
+import { FEATURE_FLAGS } from 'lib/constants'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { preflightLogic } from 'lib/logic/preflightLogic'
import { getEntryAccessDisabledReason, getProductAccessDisabledReason } from 'lib/utils/accessControlUtils'
@@ -14,6 +15,7 @@ import { removeProjectIdIfPresent } from 'lib/utils/kea-router'
import { newInternalTab } from 'lib/utils/newInternalTab'
import { toSentenceCase } from 'lib/utils/strings'
import { organizationIntegrationsLogic } from 'scenes/settings/organization/organizationIntegrationsLogic'
+import { teamLogic } from 'scenes/teamLogic'
import { urls } from 'scenes/urls'
import { userLogic } from 'scenes/userLogic'
@@ -28,6 +30,9 @@ import { matchesFlagDefinition } from '~/scenes/settings/flagGating'
import { Setting, SettingSection, SettingSectionId } from '~/scenes/settings/types'
import { ActivityTab, FileSystemIconColor, GroupTypeIndex, PersonType, SearchResponse } from '~/types'
+import { accountsList } from 'products/customer_analytics/frontend/generated/api'
+import type { AccountApi } from 'products/customer_analytics/frontend/generated/api.schemas'
+
import type { Noun } from '../../../models/groupsModel'
import type { FileSystemImport } from '../../../queries/schema/schema-general'
import type { GroupType, IntegrationType, UserType } from '../../../types'
@@ -178,7 +183,11 @@ export interface searchLogicValues {
recentsHasLoaded: boolean // recentItemsModel
sceneLogViewsByRef: Record<string, string> // recentItemsModel
sceneLogViewsHasLoaded: boolean // recentItemsModel
+ currentTeamId: number | null // teamLogic
user: UserType | null // userLogic
+ accountItems: SearchItem[]
+ accountSearchResults: AccountApi[]
+ accountSearchResultsLoading: boolean
allCategories: SearchCategory[]
dataManagementItems: SearchItem[]
groupItems: SearchItem[]
@@ -187,6 +196,7 @@ export interface searchLogicValues {
healthItems: SearchItem[]
isSearching: boolean
loadingStates: {
+ accountSearchResultsLoading: boolean
groupSearchResultsLoading: boolean
isToolsLoading: boolean
personSearchResultsLoading: boolean
@@ -222,6 +232,27 @@ export interface searchLogicValues {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface searchLogicActions {
+ loadAccountSearchResults: ({ searchTerm }: { searchTerm: string }) => {
+ searchTerm: string
+ }
+ loadAccountSearchResultsFailure: (
+ error: string,
+ errorObject?: any
+ ) => {
+ error: string
+ errorObject?: any
+ }
+ loadAccountSearchResultsSuccess: (
+ accountSearchResults: AccountApi[],
+ payload?: {
+ searchTerm: string
+ }
+ ) => {
+ accountSearchResults: AccountApi[]
+ payload?: {
+ searchTerm: string
+ }
+ }
loadGroupSearchResults: ({ searchTerm }: { searchTerm: string }) => {
searchTerm: string
}
@@ -344,6 +375,7 @@ export interface searchLogicMeta {
unifiedSearchResultsLoading: boolean,
groupSearchResultsLoading: boolean,
personSearchResultsLoading: boolean,
+ accountSearchResultsLoading: boolean,
playlistSearchResultsLoading: boolean,
searchPending: boolean,
search: string
@@ -378,6 +410,7 @@ export interface searchLogicMeta {
aggregationLabel: (groupTypeIndex: number | null | undefined, deferToUserWording?: boolean) => Noun // groupsModel
) => SearchItem[]
personItems: (personSearchResults: PersonType[]) => SearchItem[]
+ accountItems: (accountSearchResults: AccountApi[]) => SearchItem[]
playlistItems: (playlistSearchResults: FileSystemEntry[]) => SearchItem[]
healthItems: (sceneLogViewsByRef: Record<string, string>) => SearchItem[]
miscItems: (sceneLogViewsByRef: Record<string, string>) => SearchItem[]
@@ -394,8 +427,10 @@ export interface searchLogicMeta {
sceneLogViewsHasLoaded: boolean,
personSearchResultsLoading: boolean,
groupSearchResultsLoading: boolean,
+ accountSearchResultsLoading: boolean,
playlistSearchResultsLoading: boolean
) => {
+ accountSearchResultsLoading: boolean
groupSearchResultsLoading: boolean
isToolsLoading: boolean
personSearchResultsLoading: boolean
@@ -418,9 +453,11 @@ export interface searchLogicMeta {
newItems: SearchItem[],
personItems: SearchItem[],
groupItems: SearchItem[],
+ accountItems: SearchItem[],
playlistItems: SearchItem[],
unifiedSearchItems: Record<string, SearchItem[]>,
loadingStates: {
+ accountSearchResultsLoading: boolean
groupSearchResultsLoading: boolean
isToolsLoading: boolean
personSearchResultsLoading: boolean
@@ -454,6 +491,8 @@ export const searchLogic = kea<searchLogicType>([
['isDev'],
userLogic,
['user'],
+ teamLogic,
+ ['currentTeamId'],
recentItemsModel,
['recents as cachedRecents', 'recentsHasLoaded', 'sceneLogViewsByRef', 'sceneLogViewsHasLoaded'],
projectTreeDataLogic,
@@ -562,6 +601,26 @@ export const searchLogic = kea<searchLogicType>([
},
},
],
+ accountSearchResults: [
+ [] as AccountApi[],
+ {
+ loadAccountSearchResults: async ({ searchTerm }: { searchTerm: string }, breakpoint) => {
+ const trimmed = searchTerm.trim()
+
+ if (trimmed === '' || !values.currentTeamId) {
+ return []
+ }
+
+ const response = await accountsList(String(values.currentTeamId), {
+ search: trimmed,
+ limit: SEARCH_LIMIT,
+ })
+ breakpoint()
+
+ return response.results
+ },
+ },
+ ],
playlistSearchResults: [
[] as FileSystemEntry[],
{
@@ -613,6 +672,7 @@ export const searchLogic = kea<searchLogicType>([
s.unifiedSearchResultsLoading,
s.groupSearchResultsLoading,
s.personSearchResultsLoading,
+ s.accountSearchResultsLoading,
s.playlistSearchResultsLoading,
s.searchPending,
s.search,
@@ -622,6 +682,7 @@ export const searchLogic = kea<searchLogicType>([
unifiedSearchResultsLoading: boolean,
groupSearchResultsLoading: boolean,
personSearchResultsLoading: boolean,
+ accountSearchResultsLoading: boolean,
playlistSearchResultsLoading: boolean,
searchPending: boolean,
search: string
@@ -630,6 +691,7 @@ export const searchLogic = kea<searchLogicType>([
unifiedSearchResultsLoading ||
groupSearchResultsLoading ||
personSearchResultsLoading ||
+ accountSearchResultsLoading ||
playlistSearchResultsLoading ||
searchPending) &&
search.trim() !== '',
@@ -960,6 +1022,24 @@ export const searchLogic = kea<searchLogicType>([
})
},
],
+ accountItems: [
+ (s) => [s.accountSearchResults],
+ (accountSearchResults: AccountApi[]): SearchItem[] => {
+ return accountSearchResults.map((account) => {
+ const displayName = account.name || account.external_id || account.id
+ return {
+ id: `account-${account.id}`,
+ name: displayName,
+ displayName,
+ category: 'accounts',
+ href: urls.customerAnalyticsAccount(account.id),
+ icon: <IconBuilding />,
+ itemType: 'account',
+ record: { type: 'account', id: account.id },
+ }
+ })
+ },
+ ],
playlistItems: [
(s) => [s.playlistSearchResults],
(playlistSearchResults: FileSystemEntry[]): SearchItem[] => {
@@ -1233,6 +1313,7 @@ export const searchLogic = kea<searchLogicType>([
s.sceneLogViewsHasLoaded,
s.personSearchResultsLoading,
s.groupSearchResultsLoading,
+ s.accountSearchResultsLoading,
s.playlistSearchResultsLoading,
],
(
@@ -1242,6 +1323,7 @@ export const searchLogic = kea<searchLogicType>([
sceneLogViewsHasLoaded: boolean,
personSearchResultsLoading: boolean,
groupSearchResultsLoading: boolean,
+ accountSearchResultsLoading: boolean,
playlistSearchResultsLoading: boolean
) => ({
unifiedSearchResultsLoading,
@@ -1252,6 +1334,7 @@ export const searchLogic = kea<searchLogicType>([
isToolsLoading: !sceneLogViewsHasLoaded,
personSearchResultsLoading,
groupSearchResultsLoading,
+ accountSearchResultsLoading,
playlistSearchResultsLoading,
}),
],
@@ -1268,6 +1351,7 @@ export const searchLogic = kea<searchLogicType>([
s.newItems,
s.personItems,
s.groupItems,
+ s.accountItems,
s.playlistItems,
s.unifiedSearchItems,
s.loadingStates,
@@ -1285,6 +1369,7 @@ export const searchLogic = kea<searchLogicType>([
newItems: SearchItem[],
personItems: SearchItem[],
groupItems: SearchItem[],
+ accountItems: SearchItem[],
playlistItems: SearchItem[],
unifiedSearchItems: Record<string, SearchItem[]>,
loadingStates: {
@@ -1296,6 +1381,7 @@ export const searchLogic = kea<searchLogicType>([
isToolsLoading: boolean
personSearchResultsLoading: boolean
groupSearchResultsLoading: boolean
+ accountSearchResultsLoading: boolean
playlistSearchResultsLoading: boolean
},
search: string
@@ -1309,6 +1395,7 @@ export const searchLogic = kea<searchLogicType>([
isToolsLoading,
personSearchResultsLoading,
groupSearchResultsLoading,
+ accountSearchResultsLoading,
playlistSearchResultsLoading,
} = loadingStates
@@ -1501,13 +1588,22 @@ export const searchLogic = kea<searchLogicType>([
isLoading: groupSearchResultsLoading,
})
}
+
+ // Add accounts
+ if (accountItems.length > 0 || accountSearchResultsLoading) {
+ categories.push({
+ key: 'accounts',
+ items: accountItems,
+ isLoading: accountSearchResultsLoading,
+ })
+ }
}
return categories
},
],
}),
- listeners(({ actions }) => ({
+ listeners(({ actions, values }) => ({
setSearch: async ({ search }, breakpoint) => {
await breakpoint(150)
@@ -1516,6 +1612,9 @@ export const searchLogic = kea<searchLogicType>([
actions.loadUnifiedSearchResults({ searchTerm: search })
actions.loadPersonSearchResults({ searchTerm: search })
actions.loadGroupSearchResults({ searchTerm: search })
+ if (values.featureFlags[FEATURE_FLAGS.CUSTOMER_ANALYTICS_CSP]) {
+ actions.loadAccountSearchResults({ searchTerm: search })
+ }
actions.loadPlaylistSearchResults({ searchTerm: search })
}
},
diff --git a/frontend/src/lib/components/Search/utils.ts b/frontend/src/lib/components/Search/utils.ts
index 86baa09e7a63..7dfd0f7de896 100644
--- a/frontend/src/lib/components/Search/utils.ts
+++ b/frontend/src/lib/components/Search/utils.ts
@@ -66,6 +66,7 @@ export const getCategoryDisplayName = (category: string): string => {
folders: 'Folders',
persons: 'Persons',
groups: 'Groups',
+ accounts: 'Accounts',
eventDefinitions: 'Events',
propertyDefinitions: 'Properties',
ai: 'PostHog AI',