: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(customer-analytics): return feature requests to their origin (#87079)
Arthur Moreira de Deus317715409bfb
diff --git a/products/customer_analytics/frontend/components/Accounts/AGENTS.md b/products/customer_analytics/frontend/components/Accounts/AGENTS.mdindex 90aac394876e..ab655971545f 100644--- a/products/customer_analytics/frontend/components/Accounts/AGENTS.md+++ b/products/customer_analytics/frontend/components/Accounts/AGENTS.md@@ -50,7 +50,7 @@ AccountsTabContent ── binds dataNodeLogic(ACCOUNTS_TABLE_DATA_NODE_KEY, acc| `accountNotebooksLogic` | Notes/notebooks linked to one account (keyed by `accountId`): server-side pagination (`page`/`notebooksCount`), debounced title+content search (`searchTerm`), sort (`sorting` by created date/author), and `createNote` (creates an internal account notebook and opens it in the side panel). || `accountRelatedUsersLogic` | Group members / related users for one account (keyed by `externalId`). US-region orgs come from the org-members endpoint; when it returns no members, the logic falls back to the `eu_org_members` data warehouse view (a materialized pre-join of the EU postgres sync, prod-only, refreshed daily), fetched once per expansion and paginated client-side. A missing view (local dev) degrades to the normal empty state. || `accountRelationshipsLogic` | Relationship assignments for one account (keyed by `accountId`): fetches the full timeline once (`include_history=true` on the nested relationships endpoint) — the `displayedRelationships` selector (current assignments first, newest first, optionally narrowed by `definitionFilter`) feeds the (paginated) history tab, the `activeRelationships` selector feeds the sidebar summary. Also owns the tab's mutations: `assignRelationship` (definition picker + `MemberSelect`, POSTs the assign endpoint) and `endRelationship` (per active row, POSTs the end endpoint) — both guarded by a shared `relationshipSaving` flag, reload the timeline, and force-refresh the list's data nodes so relationship columns stay in sync. |-| `accountFeatureRequestsLogic` | Feature requests for one account (keyed by `accountId`): loads linked requests with server pagination and debounced search, then searches a bounded server page of accessible, editable active requests for the link picker. The picker exposes load failures with retry guidance and refreshes stale options after optimistic-concurrency conflicts. |+| `accountFeatureRequestsLogic` | Feature requests for one account (keyed by `accountId`): loads linked requests with server pagination and debounced search, then searches a bounded server page of accessible, editable active requests for the link picker. Request links carry the account's Feature requests deep link as their origin, so the detail breadcrumb returns to the same account tab. The picker exposes load failures with retry guidance and refreshes stale options after optimistic-concurrency conflicts. || `accountBillingLogic` | Billing data behind the Usage and Spend tabs (keyed by `accountId:kind`); injects the account's org + date range into saved billing insights' SQL variables, preloads each insight result when the account expands, and owns the per-view hidden-series state (`ephemeralHiddenSeriesKeysByShortId`) behind the chart chips. || `accountOpportunitiesLogic` | Salesforce opportunities behind the Opportunities tab (keyed by `accountId`): fetches the account's `sfdc_id`, then queries the data-warehouse `salesforce.opportunity` table via HogQL. Degrades to an empty state (not an error) when the table is absent — it's production-only. || `accountSummariesLogic` | The Summaries tab (keyed by `accountId`): fetches the account (for its linked `slack_channel_id` and `slack_summary_cadence`) plus the first page of the `accountsSummariesList` endpoint, navigates server pages via `loadSummariesPage` (5 per page, `page` reducer; each page replaces the last), holds per-summary collapse state (`expandedSummaryIds` / `toggleSummaryExpanded`), and owns the cadence opt-in (`setCadence` PATCHes the account through `accountsPartialUpdate`, guarded by a `cadenceSaving` flag). Turning the cadence on with no summaries yet starts `generatingFirstSummary` polling (`startFirstSummaryPolling` / `stopFirstSummaryPolling`, two `cache.disposables` keys) so the backfill the backend kicks off appears without a refresh; the poll deadline lives in a module-level map keyed by account id, because this logic unmounts whenever its row collapses while the backfill keeps running. Distinguishes not-loaded / no-channel-linked / generating / loaded-empty / load-failed; captures unexpected failures. |diff --git a/products/customer_analytics/frontend/components/Accounts/AccountFeatureRequestsExpansion.tsx b/products/customer_analytics/frontend/components/Accounts/AccountFeatureRequestsExpansion.tsxindex b9e400ebc1d1..ee8b6d859017 100644--- a/products/customer_analytics/frontend/components/Accounts/AccountFeatureRequestsExpansion.tsx+++ b/products/customer_analytics/frontend/components/Accounts/AccountFeatureRequestsExpansion.tsx@@ -1,5 +1,4 @@import { useActions, useValues } from 'kea'-import { combineUrl } from 'kea-router'import { IconPlus, IconSearch } from '@posthog/icons'import {@@ -19,6 +18,7 @@ import { urls } from 'scenes/urls'import { AccessControlLevel, AccessControlResourceType } from '~/types'import type { FeatureRequestApi } from '../../generated/api.schemas'+import { getFeatureRequestDetailUrl } from '../FeatureRequests/featureRequestNavigation'import { ACCOUNT_FEATURE_REQUESTS_PAGE_SIZE, accountFeatureRequestsLogic } from './accountFeatureRequestsLogic'export function AccountFeatureRequestsExpansion({ accountId }: { accountId: string }): JSX.Element {@@ -53,12 +53,13 @@ export function AccountFeatureRequestsExpansion({ accountId }: { accountId: striAccessControlLevel.Editor)+ const origin = urls.customerAnalyticsAccount(accountId, 'feature_requests')const columns: LemonTableColumns<FeatureRequestApi> = [{title: 'Request',key: 'title',render: (_, request) => (- <Link to={urls.customerAnalyticsFeatureRequests(request.id)} className="font-medium">+ <Link to={getFeatureRequestDetailUrl({ requestId: request.id, origin })} className="font-medium">{request.title}</Link>),@@ -80,11 +81,11 @@ export function AccountFeatureRequestsExpansion({ accountId }: { accountId: stri<LemonButtontype="secondary"size="xsmall"- to={- combineUrl(urls.customerAnalyticsFeatureRequests(request.id), {- evidence_account: accountId,- }).url- }+ to={getFeatureRequestDetailUrl({+ requestId: request.id,+ origin,+ searchParams: { evidence_account: accountId },+ })}disabledReason={editorDisabledReason}>Add evidencediff --git a/products/customer_analytics/frontend/components/FeatureRequests/FeatureRequestDetail.tsx b/products/customer_analytics/frontend/components/FeatureRequests/FeatureRequestDetail.tsxindex 666cf435d729..e626af646ba0 100644--- a/products/customer_analytics/frontend/components/FeatureRequests/FeatureRequestDetail.tsx+++ b/products/customer_analytics/frontend/components/FeatureRequests/FeatureRequestDetail.tsx@@ -1,5 +1,4 @@import { useActions, useValues } from 'kea'-import { combineUrl } from 'kea-router'import {IconArchive,@@ -15,7 +14,6 @@ import { LemonBanner, LemonButton, LemonTag } from '@posthog/lemon-ui'import { TZLabel } from 'lib/components/TZLabel'import { LemonMarkdown } from 'lib/lemon-ui/LemonMarkdown'import { getAccessControlDisabledReason } from 'lib/utils/accessControlUtils'-import { urls } from 'scenes/urls'import { AccessControlLevel, AccessControlResourceType } from '~/types'@@ -33,7 +31,7 @@ import { FeatureRequestStatusBadge } from './FeatureRequestStatusBadge'export function FeatureRequestDetail({ request }: { request: FeatureRequestApi }): JSX.Element {const {mutatingArchive,- listSearchParams,+ featureRequestBackUrl,activeRequestAccountLinks,activeRequestEvidenceCount,activeRequestImages,@@ -67,7 +65,7 @@ export function FeatureRequestDetail({ request }: { request: FeatureRequestApi }type="tertiary"size="small"icon={<IconArrowLeft />}- to={combineUrl(urls.customerAnalyticsFeatureRequests(), listSearchParams).url}+ to={featureRequestBackUrl}className="-ml-2">Feature requestsdiff --git a/products/customer_analytics/frontend/components/FeatureRequests/featureRequestNavigation.test.ts b/products/customer_analytics/frontend/components/FeatureRequests/featureRequestNavigation.test.tsnew file mode 100644index 000000000000..78933a6b8c38--- /dev/null+++ b/products/customer_analytics/frontend/components/FeatureRequests/featureRequestNavigation.test.ts@@ -0,0 +1,36 @@+import { urls } from 'scenes/urls'++import { getFeatureRequestBackUrl, getFeatureRequestDetailUrl } from './featureRequestNavigation'++describe('feature request navigation', () => {+ it('links an account request back to its feature requests tab', () => {+ const accountOrigin = urls.customerAnalyticsAccount('account-1', 'feature_requests')+ const detailUrl = new URL(+ getFeatureRequestDetailUrl({+ requestId: 'request-1',+ origin: accountOrigin,+ searchParams: { evidence_account: 'account-1' },+ }),+ 'https://posthog.test'+ )++ expect(detailUrl.pathname).toBe(urls.customerAnalyticsFeatureRequests('request-1'))+ expect(detailUrl.searchParams.get('origin')).toBe(accountOrigin)+ expect(detailUrl.searchParams.get('evidence_account')).toBe('account-1')+ })++ it('returns to the supplied internal origin', () => {+ const origin = `${urls.customerAnalyticsAccount('account-1', 'feature_requests')}?tab=details`++ expect(getFeatureRequestBackUrl(origin, { status: 'planned' })).toBe(origin)+ })++ it.each([undefined, 'https://example.com/accounts', '//example.com/accounts', '/\\example.com/accounts'])(+ 'returns direct visits with origin %s to the filtered request list',+ (origin) => {+ expect(getFeatureRequestBackUrl(origin, { status: 'planned' })).toBe(+ `${urls.customerAnalyticsFeatureRequests()}?status=planned`+ )+ }+ )+})diff --git a/products/customer_analytics/frontend/components/FeatureRequests/featureRequestNavigation.ts b/products/customer_analytics/frontend/components/FeatureRequests/featureRequestNavigation.tsnew file mode 100644index 000000000000..1a50aa7f6e6e--- /dev/null+++ b/products/customer_analytics/frontend/components/FeatureRequests/featureRequestNavigation.ts@@ -0,0 +1,35 @@+import { combineUrl } from 'kea-router'++import { urls } from 'scenes/urls'++export interface FeatureRequestDetailUrlOptions {+ requestId: string+ origin?: string+ searchParams?: Record<string, unknown>+}++export function getFeatureRequestDetailUrl({+ requestId,+ origin,+ searchParams = {},+}: FeatureRequestDetailUrlOptions): string {+ return combineUrl(urls.customerAnalyticsFeatureRequests(requestId), {+ ...searchParams,+ ...(origin ? { origin } : {}),+ }).url+}++function isInternalOrigin(origin: unknown): origin is string {+ if (typeof origin !== 'string' || !origin.startsWith('/')) {+ return false+ }+ try {+ return new URL(origin, 'https://posthog.local').origin === 'https://posthog.local'+ } catch {+ return false+ }+}++export function getFeatureRequestBackUrl(origin: unknown, listSearchParams: Record<string, string>): string {+ return isInternalOrigin(origin) ? origin : combineUrl(urls.customerAnalyticsFeatureRequests(), listSearchParams).url+}diff --git a/products/customer_analytics/frontend/components/FeatureRequests/featureRequestsLogic.ts b/products/customer_analytics/frontend/components/FeatureRequests/featureRequestsLogic.tsindex cf58d552ad3a..c760e4a21dc3 100644--- a/products/customer_analytics/frontend/components/FeatureRequests/featureRequestsLogic.ts+++ b/products/customer_analytics/frontend/components/FeatureRequests/featureRequestsLogic.ts@@ -40,6 +40,7 @@ import type {PaginatedFeatureRequestListApi,RequestPriorityEnumApi,} from '../../generated/api.schemas'+import { getFeatureRequestBackUrl } from './featureRequestNavigation'import {FEATURE_REQUEST_ORDERING_OPTIONS,FEATURE_REQUEST_PRIORITY_FILTER_OPTIONS,@@ -249,6 +250,7 @@ export interface featureRequestsLogicValues {evidenceSource: stringevidenceSummary: stringevidenceUrl: string+ featureRequestBackUrl: stringfeatureRequestsError: string | nullfeatureRequestsPage: numberfeatureRequestsResponse: PaginatedFeatureRequestListApi@@ -697,6 +699,7 @@ export interface featureRequestsLogicMeta {requestOrdering: FeatureRequestOrdering,featureRequestsPage: number) => Record<string, string>+ featureRequestBackUrl: (listSearchParams: Record<string, string>, searchParams: Record<string, any>) => string}}@@ -1571,6 +1574,11 @@ export const featureRequestsLogic = kea<featureRequestsLogicType>([featureRequestsPage,}),],+ featureRequestBackUrl: [+ (selectors) => [selectors.listSearchParams, router.selectors.searchParams],+ (listSearchParams: Record<string, string>, searchParams: Record<string, any>): string =>+ getFeatureRequestBackUrl(searchParams.origin, listSearchParams),+ ],}),listeners(({ values, actions }) => ({setFeatureRequestsPage: () => actions.loadFeatureRequests(),