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): paginate and filter the custom properties table (#78949)

Arthur Moreira de Deus8457b2d41b31
diff --git a/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/CustomPropertiesConfig.tsx b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/CustomPropertiesConfig.tsx
index 183584eee496..684401bb9ac3 100644
--- a/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/CustomPropertiesConfig.tsx
+++ b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/CustomPropertiesConfig.tsx
@@ -2,7 +2,14 @@ import { useActions, useValues } from 'kea'
import { useState } from 'react'
import { IconInfo, IconLogomark, IconPencil, IconTrash } from '@posthog/icons'
-import { LemonButton, LemonInput, LemonTable, LemonTableColumns, Tooltip } from '@posthog/lemon-ui'
+import {
+ LemonButton,
+ LemonInput,
+ LemonSegmentedButton,
+ LemonTable,
+ LemonTableColumns,
+ Tooltip,
+} from '@posthog/lemon-ui'
import { RestrictionScope, useRestrictedArea } from 'lib/components/RestrictedArea'
import { TZLabel } from 'lib/components/TZLabel'
@@ -30,8 +37,9 @@ const TAG_TYPE_BY_SYNC_LEVEL: Record<SourceSyncStatusLevel, LemonTagType> = {
}
export function CustomPropertiesConfig(): JSX.Element {
- const { filteredDefinitions, definitionsLoading, searchTerm } = useValues(customPropertyDefinitionsLogic)
- const { openCreateModal, openEditModal, deleteDefinition, setSearchTerm } =
+ const { filteredDefinitions, definitionsLoading, searchTerm, targetTypeFilter } =
+ useValues(customPropertyDefinitionsLogic)
+ const { openCreateModal, openEditModal, deleteDefinition, setSearchTerm, setTargetTypeFilter } =
useActions(customPropertyDefinitionsLogic)
const restrictionReason = useRestrictedArea({
scope: RestrictionScope.Project,
@@ -71,6 +79,8 @@ export function CustomPropertiesConfig(): JSX.Element {
render: (_, definition) =>
definition.target_type === 'person' ? (
<LemonTag type="completion">Person</LemonTag>
+ ) : definition.target_type === 'group' ? (
+ <LemonTag type="caution">Group</LemonTag>
) : (
<LemonTag type="default">Account</LemonTag>
),
@@ -175,21 +185,36 @@ export function CustomPropertiesConfig(): JSX.Element {
New custom property
</LemonButton>
</div>
- <LemonInput
- type="search"
- placeholder="Search custom properties"
- value={searchTerm}
- onChange={setSearchTerm}
- className="max-w-80"
- />
+ <div className="flex items-center gap-2">
+ <LemonInput
+ type="search"
+ size="small"
+ placeholder="Search custom properties"
+ value={searchTerm}
+ onChange={setSearchTerm}
+ className="max-w-80"
+ />
+ <LemonSegmentedButton
+ size="small"
+ value={targetTypeFilter}
+ onChange={setTargetTypeFilter}
+ options={[
+ { value: 'all', label: 'All' },
+ { value: 'account', label: 'Accounts' },
+ { value: 'person', label: 'Persons' },
+ { value: 'group', label: 'Groups' },
+ ]}
+ />
+ </div>
<LemonTable
columns={columns}
dataSource={filteredDefinitions}
loading={definitionsLoading}
rowKey="id"
+ pagination={{ pageSize: 20, hideOnSinglePage: true }}
emptyState={
- searchTerm
- ? 'No custom properties match your search.'
+ searchTerm || targetTypeFilter !== 'all'
+ ? 'No custom properties match your filters.'
: 'No custom properties yet. Create one to get started.'
}
/>
diff --git a/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyDefinitionsLogic.test.ts b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyDefinitionsLogic.test.ts
index 2bf3a70ee58e..9ff70cb461f5 100644
--- a/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyDefinitionsLogic.test.ts
+++ b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyDefinitionsLogic.test.ts
@@ -116,6 +116,34 @@ describe('customPropertyDefinitionsLogic', () => {
.toMatchValues({ definitions: [expect.objectContaining({ id: 'def-1', name: 'ARR' })] })
})
+ it('filters definitions by target type combined with search', async () => {
+ useMocks({
+ ...defaultMocks(),
+ get: {
+ ...defaultMocks().get,
+ [DEFINITIONS_URL]: {
+ count: 3,
+ results: [
+ buildDefinition({ id: 'def-a', name: 'ARR', target_type: 'account' }),
+ buildDefinition({ id: 'def-p', name: 'Plan', target_type: 'person' }),
+ buildDefinition({ id: 'def-g', name: 'Region', target_type: 'group' }),
+ ],
+ },
+ },
+ })
+ mountLogic()
+ await expectLogic(logic).toDispatchActions(['loadDefinitionsSuccess'])
+
+ logic.actions.setTargetTypeFilter('person')
+ expect(logic.values.filteredDefinitions.map((d) => d.id)).toEqual(['def-p'])
+
+ logic.actions.setSearchTerm('arr')
+ expect(logic.values.filteredDefinitions).toEqual([])
+
+ logic.actions.setTargetTypeFilter('all')
+ expect(logic.values.filteredDefinitions.map((d) => d.id)).toEqual(['def-a'])
+ })
+
it('hydrates the form, including the source fields, when editing a synced definition', async () => {
useMocks(defaultMocks())
mountLogic()
diff --git a/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyDefinitionsLogic.ts b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyDefinitionsLogic.ts
index f87193e519bf..4eeba47d6a60 100644
--- a/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyDefinitionsLogic.ts
+++ b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyDefinitionsLogic.ts
@@ -38,6 +38,7 @@ import { NEW_OPTION_ID_PREFIX, isNumericDisplayType, optionLabelError } from './
export type CustomPropertySourceMode = 'manual' | 'data_warehouse' | 'workflow'
export type CustomPropertyTargetType = 'account' | 'person' | 'group'
+export type CustomPropertyTargetTypeFilter = 'all' | CustomPropertyTargetType
// Poll until a source's run settles so the UI reflects completion without a manual refresh: fast at
// first (a small table finishes in seconds), then slower, and bounded so a stuck run can't poll
@@ -220,6 +221,7 @@ export interface customPropertyDefinitionsLogicValues {
serializedColumnDescriptions: Record<string, string>
serializedColumnPropertyMap: Record<string, string>
showCustomPropertyFormErrors: boolean
+ targetTypeFilter: CustomPropertyTargetTypeFilter
targetTypeLocked: boolean
triggeringSourceIds: string[]
warehouseTables: DataWarehouseTable[]
@@ -405,6 +407,9 @@ export interface customPropertyDefinitionsLogicActions {
setSearchTerm: (searchTerm: string) => {
searchTerm: string
}
+ setTargetTypeFilter: (targetTypeFilter: CustomPropertyTargetTypeFilter) => {
+ targetTypeFilter: CustomPropertyTargetTypeFilter
+ }
submitCustomPropertyForm: () => {
value: boolean
}
@@ -453,7 +458,8 @@ export interface customPropertyDefinitionsLogicMeta {
) => (string | null)[]
filteredDefinitions: (
definitions: CustomPropertyDefinitionApi[],
- searchTerm: string
+ searchTerm: string,
+ targetTypeFilter: CustomPropertyTargetTypeFilter
) => CustomPropertyDefinitionApi[]
editingReferences: (
definitions: CustomPropertyDefinitionApi[],
@@ -494,6 +500,7 @@ export const customPropertyDefinitionsLogic = kea<customPropertyDefinitionsLogic
openEditModal: (definition: CustomPropertyDefinitionApi) => ({ definition }),
closeModal: true,
setSearchTerm: (searchTerm: string) => ({ searchTerm }),
+ setTargetTypeFilter: (targetTypeFilter: CustomPropertyTargetTypeFilter) => ({ targetTypeFilter }),
setEditingDefinition: (definition: CustomPropertyDefinitionApi) => ({ definition }),
// Person sources only. triggerSync re-runs the underlying warehouse sync; triggerBackfill
// starts a full-table backfill. add/removeTriggeringSource drive the per-row double-submit
@@ -521,6 +528,12 @@ export const customPropertyDefinitionsLogic = kea<customPropertyDefinitionsLogic
setSearchTerm: (_, { searchTerm }) => searchTerm,
},
],
+ targetTypeFilter: [
+ 'all' as CustomPropertyTargetTypeFilter,
+ {
+ setTargetTypeFilter: (_, { targetTypeFilter }) => targetTypeFilter,
+ },
+ ],
modalVisible: [
false,
{
@@ -590,8 +603,22 @@ export const customPropertyDefinitionsLogic = kea<customPropertyDefinitionsLogic
[] as CustomPropertyDefinitionApi[],
{
loadDefinitions: async (): Promise<CustomPropertyDefinitionApi[]> => {
- const response = await customPropertyDefinitionsList(String(values.currentProjectId))
- return response.results
+ // Follow pagination so search and the table cover every definition, not just the
+ // backend's first page (bounded so a runaway count can't pull forever).
+ const PAGE_SIZE = 300
+ const MAX_PAGES = 10
+ const collected: CustomPropertyDefinitionApi[] = []
+ for (let page = 0; page < MAX_PAGES; page += 1) {
+ const response = await customPropertyDefinitionsList(String(values.currentProjectId), {
+ limit: PAGE_SIZE,
+ offset: page * PAGE_SIZE,
+ })
+ collected.push(...response.results)
+ if (!response.next) {
+ break
+ }
+ }
+ return collected
},
deleteDefinition: async ({ id }: { id: string }): Promise<CustomPropertyDefinitionApi[]> => {
await customPropertyDefinitionsDestroy(String(values.currentProjectId), id)
@@ -913,16 +940,19 @@ export const customPropertyDefinitionsLogic = kea<customPropertyDefinitionsLogic
},
],
filteredDefinitions: [
- (s) => [s.definitions, s.searchTerm],
- (definitions: CustomPropertyDefinitionApi[], searchTerm: string): CustomPropertyDefinitionApi[] => {
+ (s) => [s.definitions, s.searchTerm, s.targetTypeFilter],
+ (
+ definitions: CustomPropertyDefinitionApi[],
+ searchTerm: string,
+ targetTypeFilter: CustomPropertyTargetTypeFilter
+ ): CustomPropertyDefinitionApi[] => {
const query = searchTerm.trim().toLowerCase()
- if (!query) {
- return definitions
- }
return definitions.filter(
(definition) =>
- definition.name.toLowerCase().includes(query) ||
- definition.description?.toLowerCase().includes(query)
+ (targetTypeFilter === 'all' || (definition.target_type ?? 'account') === targetTypeFilter) &&
+ (!query ||
+ definition.name.toLowerCase().includes(query) ||
+ definition.description?.toLowerCase().includes(query))
)
},
],