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): configure missing account links inline (#61455)

Arthur Moreira de Deus45d42921c152
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 15f6ece17999..f6c708838a4c 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -4287,9 +4287,9 @@ snapshots:
scenes-app-customer-analytics-accounts--row-expanded-empty--light:
hash: v1.k794b7964.904bd5b939f99d43408ae3a8a814a3c299bd57bf13a0fd1d98ff6033fd66e343.K1Z16ICEF6-O9kIej8kGnYyarloq2oZH5rdtmx-8Hu0
scenes-app-customer-analytics-accounts--row-expanded-links-disabled--dark:
- hash: v1.k794b7964.92be80889ae455a05c5e79357b0b86fadeb9cb7f93761089d48b1315cc1b8448.A3_TCemtV73Ig2IEi-D8h9T4buy_xGLaVH1EYQ7B7II
+ hash: v1.k794b7964.f8d8a5c20d80ca1683d5fc3177ffbc4738d71505a39d7bbed0533ee19a98f949.9wsoIV1txvBqzEcGpRqs-7HEHXBF06-yZvQIvxXFSjU
scenes-app-customer-analytics-accounts--row-expanded-links-disabled--light:
- hash: v1.k794b7964.507c607813892eeabec48171f50ab7220f2a5b2a6bd1bdb77cb64c89f0bc88b1.bQIl5-n8IuVD1CTj6b2fpXagCUDsoTOKycNebvdBBbU
+ hash: v1.k794b7964.7e0417ec68b8e0dbecf3d7c3a81edf5d74ef9814b952678a753246c72aaff10b.bH4HCkNLMeiFZpX2Ko6LhdEp8TH0VgejsNB4Wp1UI24
scenes-app-customer-analytics-accounts--row-expanded-with-note--dark:
hash: v1.k794b7964.3c9ce002ecb9931c56ef82618cc1625ee847a7f8df2a35c490006e4b356e6fb5.bK3yVZfb-U4TUMJHKvLemkMdqx6YNKdkFC2lnrWBgYg
scenes-app-customer-analytics-accounts--row-expanded-with-note--light:
diff --git a/products/customer_analytics/frontend/components/Accounts/AccountNotebooksExpansion.tsx b/products/customer_analytics/frontend/components/Accounts/AccountNotebooksExpansion.tsx
index 59c56c9712de..fec3b316e7b5 100644
--- a/products/customer_analytics/frontend/components/Accounts/AccountNotebooksExpansion.tsx
+++ b/products/customer_analytics/frontend/components/Accounts/AccountNotebooksExpansion.tsx
@@ -12,6 +12,7 @@ import type { AccountNotebookApi } from 'products/customer_analytics/frontend/ge
import { accountLinksLogic } from './accountLinksLogic'
import { accountNotebooksLogic } from './accountNotebooksLogic'
+import { EditAccountLinksButton } from './EditAccountLinksButton'
const PREVIEW_MAX_CHARS = 200
@@ -36,7 +37,10 @@ function UsefulLinks({ accountId }: { accountId: string }): JSX.Element {
const { links, accountLoading } = useValues(accountLinksLogic({ accountId }))
return (
<div className="flex flex-col gap-1">
- <h4 className="secondary uppercase text-secondary mb-1">Useful links</h4>
+ <div className="flex items-center gap-1 mb-1">
+ <h4 className="secondary uppercase text-secondary mb-0">Useful links</h4>
+ <EditAccountLinksButton accountId={accountId} />
+ </div>
{accountLoading ? (
<>
<LemonSkeleton className="h-7 w-32" />
diff --git a/products/customer_analytics/frontend/components/Accounts/EditAccountLinksButton.tsx b/products/customer_analytics/frontend/components/Accounts/EditAccountLinksButton.tsx
new file mode 100644
index 000000000000..df633800b961
--- /dev/null
+++ b/products/customer_analytics/frontend/components/Accounts/EditAccountLinksButton.tsx
@@ -0,0 +1,60 @@
+import { useActions, useValues } from 'kea'
+
+import { IconPencil } from '@posthog/icons'
+import { LemonButton, LemonDivider, LemonDropdown, LemonInput } from '@posthog/lemon-ui'
+
+import { ACCOUNT_LINK_FIELDS, accountLinksLogic } from './accountLinksLogic'
+
+export function EditAccountLinksButton({ accountId }: { accountId: string }): JSX.Element {
+ const logic = accountLinksLogic({ accountId })
+ const { editorOpen, formValues, savingLinks } = useValues(logic)
+ const { openEditor, closeEditor, setFieldValue, saveLinks } = useActions(logic)
+
+ return (
+ <LemonDropdown
+ closeOnClickInside={false}
+ visible={editorOpen}
+ onVisibilityChange={(visible) => {
+ if (!visible) {
+ closeEditor()
+ }
+ }}
+ showArrow
+ overlay={
+ <div className="flex flex-col gap-2 w-72">
+ {ACCOUNT_LINK_FIELDS.map((field) => (
+ <div key={field.key} className="flex flex-col gap-1">
+ <span className="text-xs font-semibold text-secondary">{field.label}</span>
+ <LemonInput
+ type="text"
+ size="small"
+ value={formValues[field.key]}
+ onChange={(value) => setFieldValue(field.key, value)}
+ placeholder={field.placeholder}
+ onPressEnter={saveLinks}
+ />
+ </div>
+ ))}
+ <LemonDivider className="my-1" />
+ <div className="flex flex-row gap-2 justify-end">
+ <LemonButton size="xsmall" type="secondary" onClick={closeEditor}>
+ Cancel
+ </LemonButton>
+ <LemonButton size="xsmall" type="primary" onClick={saveLinks} loading={savingLinks}>
+ Save
+ </LemonButton>
+ </div>
+ </div>
+ }
+ >
+ <LemonButton
+ size="xsmall"
+ type="tertiary"
+ icon={<IconPencil />}
+ tooltip="Edit links"
+ data-attr="edit-account-links"
+ onClick={openEditor}
+ />
+ </LemonDropdown>
+ )
+}
diff --git a/products/customer_analytics/frontend/components/Accounts/accountLinksLogic.test.ts b/products/customer_analytics/frontend/components/Accounts/accountLinksLogic.test.ts
new file mode 100644
index 000000000000..1df4cb0bee67
--- /dev/null
+++ b/products/customer_analytics/frontend/components/Accounts/accountLinksLogic.test.ts
@@ -0,0 +1,175 @@
+import { MOCK_DEFAULT_TEAM } from '~/lib/api.mock'
+
+import { expectLogic } from 'kea-test-utils'
+
+import { initKeaTests } from '~/test/init'
+
+import { accountsPartialUpdate, accountsRetrieve } from 'products/customer_analytics/frontend/generated/api'
+import type { AccountApi } from 'products/customer_analytics/frontend/generated/api.schemas'
+
+import { accountLinksLogic } from './accountLinksLogic'
+
+jest.mock('products/customer_analytics/frontend/generated/api', () => ({
+ accountsRetrieve: jest.fn(),
+ accountsPartialUpdate: jest.fn(),
+}))
+
+const mockAccountsRetrieve = accountsRetrieve as jest.MockedFunction<typeof accountsRetrieve>
+const mockAccountsPartialUpdate = accountsPartialUpdate as jest.MockedFunction<typeof accountsPartialUpdate>
+
+const TEAM = String(MOCK_DEFAULT_TEAM.id)
+
+const buildAccount = (overrides: Partial<AccountApi> = {}): AccountApi => ({
+ id: 'acc-1',
+ name: 'Acme',
+ external_id: 'ext-1',
+ properties: {
+ csm: { id: 1, email: '[email protected]' },
+ billing_id: 'cus_123',
+ },
+ tags: [],
+ notebooks: [],
+ created_at: '2026-01-01T00:00:00Z',
+ created_by: null,
+ updated_at: '2026-01-01T00:00:00Z',
+ ...overrides,
+})
+
+describe('accountLinksLogic', () => {
+ let logic: ReturnType<typeof accountLinksLogic.build>
+
+ const mountWith = async (initial: AccountApi): Promise<void> => {
+ mockAccountsRetrieve.mockResolvedValue(initial)
+ logic = accountLinksLogic({ accountId: 'acc-1' })
+ logic.mount()
+ await expectLogic(logic).toFinishAllListeners()
+ }
+
+ beforeEach(() => {
+ initKeaTests()
+ jest.resetAllMocks()
+ })
+
+ afterEach(() => {
+ logic?.unmount()
+ })
+
+ it('openEditor pre-fills the form from the current account', async () => {
+ await mountWith(
+ buildAccount({ external_id: 'ext-1', properties: { billing_id: 'cus_1', slack_channel_id: 'C1' } })
+ )
+ logic.actions.openEditor()
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(logic.values.editorOpen).toBe(true)
+ expect(logic.values.formValues).toEqual({
+ external_id: 'ext-1',
+ billing_id: 'cus_1',
+ slack_channel_id: 'C1',
+ usage_dashboard_link: '',
+ })
+ })
+
+ it('saveLinks PATCHes external_id top-level and spreads properties without clobbering', async () => {
+ await mountWith(
+ buildAccount({
+ external_id: 'ext-1',
+ properties: { csm: { id: 1, email: '[email protected]' }, billing_id: 'old' },
+ })
+ )
+ const updated = buildAccount({ external_id: 'ext-2' })
+ mockAccountsPartialUpdate.mockResolvedValue(updated)
+
+ logic.actions.openEditor()
+ logic.actions.setFormValues({
+ external_id: 'ext-2',
+ billing_id: 'new',
+ slack_channel_id: 'C9',
+ usage_dashboard_link: '',
+ })
+ logic.actions.saveLinks()
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(mockAccountsPartialUpdate).toHaveBeenCalledWith(TEAM, 'acc-1', {
+ external_id: 'ext-2',
+ properties: {
+ csm: { id: 1, email: '[email protected]' },
+ billing_id: 'new',
+ slack_channel_id: 'C9',
+ usage_dashboard_link: null,
+ },
+ })
+ expect(logic.values.account).toEqual(updated)
+ expect(logic.values.editorOpen).toBe(false)
+ })
+
+ it('saveLinks sends null for empty or whitespace fields', async () => {
+ await mountWith(buildAccount({ external_id: 'ext-1', properties: { billing_id: 'b' } }))
+ mockAccountsPartialUpdate.mockResolvedValue(buildAccount())
+
+ logic.actions.setFormValues({
+ external_id: '',
+ billing_id: '',
+ slack_channel_id: ' ',
+ usage_dashboard_link: '',
+ })
+ logic.actions.saveLinks()
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(mockAccountsPartialUpdate).toHaveBeenCalledWith(TEAM, 'acc-1', {
+ external_id: null,
+ properties: { billing_id: null, slack_channel_id: null, usage_dashboard_link: null },
+ })
+ })
+
+ it('flips savingLinks during the in-flight window', async () => {
+ await mountWith(buildAccount())
+ let resolveUpdate!: (value: AccountApi) => void
+ mockAccountsPartialUpdate.mockReturnValueOnce(
+ new Promise<AccountApi>((resolve) => {
+ resolveUpdate = resolve
+ })
+ )
+
+ logic.actions.saveLinks()
+ await new Promise<void>((r) => setTimeout(r, 0))
+ expect(logic.values.savingLinks).toBe(true)
+
+ resolveUpdate(buildAccount())
+ await expectLogic(logic).toFinishAllListeners()
+ expect(logic.values.savingLinks).toBe(false)
+ })
+
+ it('is a no-op while a save is already in flight', async () => {
+ await mountWith(buildAccount())
+ let resolveFirst!: (value: AccountApi) => void
+ mockAccountsPartialUpdate.mockReturnValueOnce(
+ new Promise<AccountApi>((resolve) => {
+ resolveFirst = resolve
+ })
+ )
+
+ logic.actions.saveLinks()
+ await new Promise<void>((r) => setTimeout(r, 0))
+ logic.actions.saveLinks()
+ await new Promise<void>((r) => setTimeout(r, 0))
+
+ expect(mockAccountsPartialUpdate).toHaveBeenCalledTimes(1)
+ resolveFirst(buildAccount())
+ await expectLogic(logic).toFinishAllListeners()
+ })
+
+ it('keeps the editor open and account unchanged on failure', async () => {
+ const initial = buildAccount({ external_id: 'ext-1' })
+ await mountWith(initial)
+ mockAccountsPartialUpdate.mockRejectedValueOnce(new Error('boom'))
+
+ logic.actions.openEditor()
+ logic.actions.saveLinks()
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(logic.values.editorOpen).toBe(true)
+ expect(logic.values.savingLinks).toBe(false)
+ expect(logic.values.account).toEqual(initial)
+ })
+})
diff --git a/products/customer_analytics/frontend/components/Accounts/accountLinksLogic.ts b/products/customer_analytics/frontend/components/Accounts/accountLinksLogic.ts
index 0b0f3918bd87..fb0d0bad639c 100644
--- a/products/customer_analytics/frontend/components/Accounts/accountLinksLogic.ts
+++ b/products/customer_analytics/frontend/components/Accounts/accountLinksLogic.ts
@@ -1,12 +1,16 @@
-import { afterMount, connect, kea, key, path, props, selectors } from 'kea'
+import { actions, afterMount, connect, kea, key, listeners, path, props, reducers, selectors } from 'kea'
import { loaders } from 'kea-loaders'
import posthog from 'posthog-js'
+import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
import { teamLogic } from 'scenes/teamLogic'
import { urls } from 'scenes/urls'
-import { accountsRetrieve } from 'products/customer_analytics/frontend/generated/api'
-import type { AccountApi } from 'products/customer_analytics/frontend/generated/api.schemas'
+import { accountsPartialUpdate, accountsRetrieve } from 'products/customer_analytics/frontend/generated/api'
+import type {
+ AccountApi,
+ PatchedAccountApiProperties,
+} from 'products/customer_analytics/frontend/generated/api.schemas'
import type { accountLinksLogicType } from './accountLinksLogicType'
@@ -19,6 +23,30 @@ export interface AccountLinksLogicProps {
accountId: string
}
+export type AccountLinkFieldKey = 'external_id' | 'billing_id' | 'slack_channel_id' | 'usage_dashboard_link'
+
+export interface AccountLinkFieldDef {
+ key: AccountLinkFieldKey
+ label: string
+ placeholder: string
+}
+
+export type AccountLinkFieldValues = Record<AccountLinkFieldKey, string>
+
+export const ACCOUNT_LINK_FIELDS: AccountLinkFieldDef[] = [
+ { key: 'external_id', label: 'External ID', placeholder: 'e.g. cust_acme_001' },
+ { key: 'billing_id', label: 'Billing ID', placeholder: 'e.g. cus_acme_123' },
+ { key: 'slack_channel_id', label: 'Slack channel ID', placeholder: 'e.g. C0123456789' },
+ { key: 'usage_dashboard_link', label: 'Usage dashboard link', placeholder: 'https://…' },
+]
+
+const EMPTY_FIELDS: AccountLinkFieldValues = {
+ external_id: '',
+ billing_id: '',
+ slack_channel_id: '',
+ usage_dashboard_link: '',
+}
+
export interface AccountLink {
key: string
label: string
@@ -39,6 +67,15 @@ export const accountLinksLogic = kea<accountLinksLogicType>([
connect(() => ({
values: [teamLogic, ['currentTeamId']],
})),
+ actions({
+ openEditor: true,
+ closeEditor: true,
+ setFieldValue: (fieldKey: AccountLinkFieldKey, value: string) => ({ fieldKey, value }),
+ setFormValues: (values: AccountLinkFieldValues) => ({ values }),
+ saveLinks: true,
+ saveStarted: true,
+ saveFinished: true,
+ }),
loaders(({ props, values }) => ({
account: [
null as AccountApi | null,
@@ -54,7 +91,39 @@ export const accountLinksLogic = kea<accountLinksLogicType>([
},
],
})),
+ reducers({
+ editorOpen: [
+ false,
+ {
+ openEditor: () => true,
+ closeEditor: () => false,
+ },
+ ],
+ formValues: [
+ EMPTY_FIELDS,
+ {
+ setFormValues: (_, { values }) => values,
+ setFieldValue: (state, { fieldKey, value }) => ({ ...state, [fieldKey]: value }),
+ },
+ ],
+ savingLinks: [
+ false,
+ {
+ saveStarted: () => true,
+ saveFinished: () => false,
+ },
+ ],
+ }),
selectors({
+ currentFieldValues: [
+ (s) => [s.account],
+ (account: AccountApi | null): AccountLinkFieldValues => ({
+ external_id: account?.external_id ?? '',
+ billing_id: account?.properties?.billing_id ?? '',
+ slack_channel_id: account?.properties?.slack_channel_id ?? '',
+ usage_dashboard_link: account?.properties?.usage_dashboard_link ?? '',
+ }),
+ ],
links: [
(s) => [s.account],
(account: AccountApi | null): AccountLink[] => {
@@ -102,6 +171,40 @@ export const accountLinksLogic = kea<accountLinksLogicType>([
},
],
}),
+ listeners(({ actions, values, props }) => ({
+ openEditor: () => {
+ actions.setFormValues(values.currentFieldValues)
+ },
+ saveLinks: async () => {
+ if (values.savingLinks) {
+ return
+ }
+ const projectId = String(values.currentTeamId)
+ const form = values.formValues
+ const orNull = (value: string): string | null => value.trim() || null
+ actions.saveStarted()
+ try {
+ const current = await accountsRetrieve(projectId, props.accountId)
+ const updated = await accountsPartialUpdate(projectId, props.accountId, {
+ external_id: orNull(form.external_id),
+ properties: {
+ ...current.properties,
+ billing_id: orNull(form.billing_id),
+ slack_channel_id: orNull(form.slack_channel_id),
+ usage_dashboard_link: orNull(form.usage_dashboard_link),
+ } as PatchedAccountApiProperties,
+ })
+ actions.loadAccountSuccess(updated)
+ actions.closeEditor()
+ lemonToast.success('Links updated')
+ } catch (error) {
+ posthog.captureException(error as Error, { scope: 'accountLinksLogic.saveLinks' })
+ lemonToast.error('Failed to save links')
+ } finally {
+ actions.saveFinished()
+ }
+ },
+ })),
afterMount(({ actions }) => {
actions.loadAccount()
}),