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(data-warehouse): link the view created toast to the view page (#115582)

Sinan Kucukkoselerefc26716f9db
diff --git a/frontend/src/scenes/data-warehouse/saved_queries/dataWarehouseViewsLogic.test.ts b/frontend/src/scenes/data-warehouse/saved_queries/dataWarehouseViewsLogic.test.ts
index 0370c776addd..3ce5e1107e8b 100644
--- a/frontend/src/scenes/data-warehouse/saved_queries/dataWarehouseViewsLogic.test.ts
+++ b/frontend/src/scenes/data-warehouse/saved_queries/dataWarehouseViewsLogic.test.ts
@@ -151,6 +151,53 @@ describe('dataWarehouseViewsLogic', () => {
toastErrorSpy.mockRestore()
})
+ // Regression: the view page is keyed by the node id, so a link built from the view id opens a
+ // missing model. A view with no node must still open somewhere. The toast can outlive the logic
+ // when the person leaves the editor, so the button must work with the logic unmounted.
+ it.each([
+ [
+ 'its page',
+ [
+ 200,
+ {
+ nodes: [
+ { id: 'node-upstream', saved_query_id: 'view-upstream' },
+ { id: 'node-9', saved_query_id: 'view-9' },
+ ],
+ edges: [],
+ },
+ ],
+ urls.nodeDetail('node-9'),
+ ],
+ [
+ 'the SQL editor when it has no node',
+ [404, { error: 'Node not found' }],
+ urls.sqlEditor({ view_id: 'view-9' }),
+ ],
+ ])('links a created view to %s', async (_name, lineageResponse, expectedUrl) => {
+ const toastSuccessSpy = jest.spyOn(lemonToast, 'success').mockImplementation(() => 'x')
+ useMocks({
+ get: { '/api/projects/:team_id/data_modeling_nodes/lineage/': lineageResponse },
+ post: { '/api/environments/:team_id/warehouse_saved_queries/': [201, { id: 'view-9', name: 'orders' }] },
+ })
+
+ await expectLogic(logic, () => {
+ logic.actions.createDataWarehouseSavedQuery({ name: 'orders', types: [] })
+ }).toDispatchActions(['createDataWarehouseSavedQuerySuccess'])
+
+ const createdToast = toastSuccessSpy.mock.calls.find(([message]) => message === 'orders successfully created')
+ const button = (createdToast?.[1] as { button?: { label: string; action: () => Promise<void> } } | undefined)
+ ?.button
+ expect(button?.label).toBe('Go to view')
+
+ logic.unmount()
+ await button?.action()
+ const { pathname, search } = router.values.location
+ expect(`${pathname}${search}`).toContain(expectedUrl)
+ toastSuccessSpy.mockRestore()
+ logic.mount()
+ })
+
// Regression: a freshly materialized view showed as a plain view in the sidebar until a manual
// refresh because is_materialized flips asynchronously and the list was fetched only once. The
// poll must keep reloading until it settles, then stop (not loop forever).
diff --git a/frontend/src/scenes/data-warehouse/saved_queries/dataWarehouseViewsLogic.tsx b/frontend/src/scenes/data-warehouse/saved_queries/dataWarehouseViewsLogic.tsx
index cdddcc42d7e6..7287d2469e81 100644
--- a/frontend/src/scenes/data-warehouse/saved_queries/dataWarehouseViewsLogic.tsx
+++ b/frontend/src/scenes/data-warehouse/saved_queries/dataWarehouseViewsLogic.tsx
@@ -18,6 +18,7 @@ import {
DataWarehouseSavedQueryIncremental,
} from '~/types'
+import { dataModelingNodesLineageRetrieve } from 'products/data_modeling/frontend/generated/api'
import {
warehouseSavedQueriesList,
warehouseSavedQueriesMaterializeCreate,
@@ -49,6 +50,23 @@ export interface DataWarehouseSavedQueryUpdate extends Partial<DataWarehouseSave
soft_update?: boolean
}
+// A plain function, not a logic action: the toast that calls it can outlive the logic, and an
+// unmounted logic has no listeners.
+async function openViewPage(viewId: string): Promise<void> {
+ // The view page is keyed by the data modeling node, and the saved query response carries no node id.
+ let nodeId: string | undefined
+ try {
+ const lineage = await dataModelingNodesLineageRetrieve(String(ApiConfig.getCurrentTeamId()), {
+ saved_query_id: viewId,
+ })
+ nodeId = lineage.nodes.find((node) => node.saved_query_id === viewId)?.id
+ } catch {
+ // A view with no node still opens in the SQL editor.
+ }
+ posthog.capture('view page opened from created toast', { destination: nodeId ? 'model' : 'sql_editor' })
+ router.actions.push(nodeId ? urls.nodeDetail(nodeId) : urls.sqlEditor({ view_id: viewId }))
+}
+
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface dataWarehouseViewsLogicValues {
databaseLoading: boolean // databaseTableListLogic
@@ -500,7 +518,13 @@ export const dataWarehouseViewsLogic = kea<dataWarehouseViewsLogicType>([
) => {
const newView = await api.dataWarehouseSavedQueries.create(view)
- lemonToast.success(`${newView.name ?? 'View'} successfully created`)
+ lemonToast.success(`${newView.name ?? 'View'} successfully created`, {
+ button: {
+ label: 'Go to view',
+ action: () => openViewPage(newView.id),
+ },
+ })
+ posthog.capture('view created')
globalSetupLogic.findMounted()?.actions.markTaskAsCompleted(SetupTaskId.CreateSavedView)
return [...values.dataWarehouseSavedQueries, newView]