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.

fix(data-warehouse): keep the wizard step when reconnecting an account (#106581)

Tom Owers0d9a035a0de7
diff --git a/products/data_warehouse/frontend/shared/components/forms/IntegrationAccountSelector.test.tsx b/products/data_warehouse/frontend/shared/components/forms/IntegrationAccountSelector.test.tsx
index ac7cb00ce309..1836efb069c0 100644
--- a/products/data_warehouse/frontend/shared/components/forms/IntegrationAccountSelector.test.tsx
+++ b/products/data_warehouse/frontend/shared/components/forms/IntegrationAccountSelector.test.tsx
@@ -1,4 +1,4 @@
-import { accountsDropdownEmptyMessage } from './IntegrationAccountSelector'
+import { accountsDropdownEmptyMessage, reconnectReturnUrl } from './IntegrationAccountSelector'
describe('IntegrationAccountSelector', () => {
// A failed listing request leaves the same empty list as a connection that reaches no accounts,
@@ -9,4 +9,20 @@ describe('IntegrationAccountSelector', () => {
)
expect(accountsDropdownEmptyMessage(null)).toContain('No accounts accessible')
})
+
+ it.each([
+ [
+ '/project/1/data-warehouse/new-source',
+ '?kind=googlesearchconsole',
+ '/project/1/data-warehouse/new-source?kind=googlesearchconsole',
+ ],
+ [
+ '/project/1/data-warehouse/new-source',
+ '?kind=googlesearchconsole&integration_id=5&integration_error=access_denied',
+ '/project/1/data-warehouse/new-source?kind=googlesearchconsole',
+ ],
+ ['/project/1/data-warehouse/sources/abc', '', '/project/1/data-warehouse/sources/abc'],
+ ])('returns a reconnect from %s%s to the same wizard step', (pathname, search, expected) => {
+ expect(reconnectReturnUrl(pathname, search)).toEqual(expected)
+ })
})
diff --git a/products/data_warehouse/frontend/shared/components/forms/IntegrationAccountSelector.tsx b/products/data_warehouse/frontend/shared/components/forms/IntegrationAccountSelector.tsx
index ccd646463b25..558e96be26b2 100644
--- a/products/data_warehouse/frontend/shared/components/forms/IntegrationAccountSelector.tsx
+++ b/products/data_warehouse/frontend/shared/components/forms/IntegrationAccountSelector.tsx
@@ -7,6 +7,7 @@ import { LemonInput, LemonInputSelect, LemonSkeleton, LemonTag, Link } from '@po
import api from 'lib/api'
import { integrationAccountsLogic } from 'lib/integrations/integrationAccountsLogic'
import { integrationsLogic } from 'lib/integrations/integrationsLogic'
+import { INTEGRATION_ERROR_PARAM } from 'lib/integrations/oauthCallbackErrors'
import { getIntegrationNameFromKind } from 'lib/integrations/utils'
import { LemonField } from 'lib/lemon-ui/LemonField'
import type { LemonInputSelectOption } from 'lib/lemon-ui/LemonInputSelect/LemonInputSelect'
@@ -191,6 +192,17 @@ function captionHelp(caption?: string): JSX.Element | undefined {
return caption ? <LemonMarkdown className="text-xs">{caption}</LemonMarkdown> : undefined
}
+/** Where the in-place reconnect returns to. The wizard keeps the chosen source in `?kind=`, so a
+ * bare pathname lands the user back on the source catalog. The previous callback's result params
+ * are dropped because the new callback sets its own. */
+export function reconnectReturnUrl(pathname: string, search: string): string {
+ const params = new URLSearchParams(search)
+ params.delete('integration_id')
+ params.delete(INTEGRATION_ERROR_PARAM)
+ const query = params.toString()
+ return query ? `${pathname}?${query}` : pathname
+}
+
/** Re-run OAuth for the connected integration in place, so a failed account load is recoverable
* without hunting for the disconnect/reconnect action elsewhere on the page. */
function ReconnectLink({ integrationKind }: { integrationKind: string }): JSX.Element {
@@ -199,7 +211,10 @@ function ReconnectLink({ integrationKind }: { integrationKind: string }): JSX.El
return (
<Link
disableClientSideRouting
- to={api.integrations.authorizeUrl({ kind: integrationKind, next: window.location.pathname })}
+ to={api.integrations.authorizeUrl({
+ kind: integrationKind,
+ next: reconnectReturnUrl(window.location.pathname, window.location.search),
+ })}
onClick={() =>
reportIntegrationConnectClicked(integrationKind, integrationKind, 'warehouse_source_reconnect')
}