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): merge the created and materialized view toasts (#116473)

Sinan Kucukkoseler359cf1a7163a
diff --git a/frontend/src/queries/nodes/HogQLQuery/hogQLQueryEditorLogic.tsx b/frontend/src/queries/nodes/HogQLQuery/hogQLQueryEditorLogic.tsx
index 2a7c70266612..dc381f63b1fb 100644
--- a/frontend/src/queries/nodes/HogQLQuery/hogQLQueryEditorLogic.tsx
+++ b/frontend/src/queries/nodes/HogQLQuery/hogQLQueryEditorLogic.tsx
@@ -70,11 +70,13 @@ export interface hogQLQueryEditorLogicActions {
types: string[][]
} // dataWarehouseSettingsSceneLogic
createDataWarehouseSavedQuery: (
- view: Partial<DataWarehouseSavedQuery> & {
+ payload: Partial<DataWarehouseSavedQuery> & {
+ deferCreatedToast?: boolean
folder_id?: string | null
types: string[][]
}
) => Partial<DataWarehouseSavedQuery> & {
+ deferCreatedToast?: boolean
folder_id?: string | null
types: string[][]
} // dataWarehouseViewsLogic
diff --git a/frontend/src/scenes/data-warehouse/editor/sidebar/queryDatabaseLogic.tsx b/frontend/src/scenes/data-warehouse/editor/sidebar/queryDatabaseLogic.tsx
index e46284beb971..7954ca1aaee4 100644
--- a/frontend/src/scenes/data-warehouse/editor/sidebar/queryDatabaseLogic.tsx
+++ b/frontend/src/scenes/data-warehouse/editor/sidebar/queryDatabaseLogic.tsx
@@ -1777,6 +1777,7 @@ export interface queryDatabaseLogicActions {
dataWarehouseSavedQueries: DataWarehouseSavedQuerySummary[],
payload?:
| (Partial<import('~/types').DataWarehouseSavedQuery> & {
+ deferCreatedToast?: boolean
folder_id?: string | null
types: string[][]
})
@@ -1784,6 +1785,7 @@ export interface queryDatabaseLogicActions {
) => {
dataWarehouseSavedQueries: DataWarehouseSavedQuerySummary[]
payload?: Partial<import('~/types').DataWarehouseSavedQuery> & {
+ deferCreatedToast?: boolean
folder_id?: string | null
types: string[][]
}
diff --git a/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.test.ts b/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.test.ts
index dfcfe16cdb22..6fd43e087b11 100644
--- a/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.test.ts
+++ b/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.test.ts
@@ -6,6 +6,7 @@ import { expectLogic, partial } from 'kea-test-utils'
import { LemonDialog } from '@posthog/lemon-ui'
import { FEATURE_FLAGS } from 'lib/constants'
+import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { databaseTableListLogic } from 'scenes/data-management/database/databaseTableListLogic'
import { draftsLogic } from 'scenes/data-warehouse/editor/draftsLogic'
@@ -3416,10 +3417,54 @@ describe('sqlEditorLogic', () => {
})
describe('materialize on save', () => {
+ afterEach(() => {
+ jest.restoreAllMocks()
+ })
+
it.each([
- { name: 'materializes the created view when materializeAfterSave is true', materialize: true },
- { name: 'does not materialize when materializeAfterSave is false', materialize: false },
- ])('$name', async ({ materialize }) => {
+ {
+ name: 'materializes the created view when materializeAfterSave is true',
+ materialize: true,
+ materializeResponse: [200, {}],
+ toasts: [
+ {
+ type: 'success',
+ message: 'Materialized view successfully created and materialized',
+ button: 'Go to view',
+ },
+ ],
+ },
+ {
+ name: 'does not materialize when materializeAfterSave is false',
+ materialize: false,
+ materializeResponse: [200, {}],
+ toasts: [{ type: 'success', message: 'Materialized view successfully created', button: 'Go to view' }],
+ },
+ {
+ name: 'warns that the created view is not materialized when the materialization fails',
+ materialize: true,
+ materializeResponse: [400, { detail: 'Pick 1 week instead.' }],
+ toasts: [
+ {
+ type: 'warning',
+ message: 'Materialized view was created but not materialized. Pick 1 week instead.',
+ button: 'Go to view',
+ },
+ ],
+ },
+ ])('$name', async ({ materialize, materializeResponse, toasts }) => {
+ const shownToasts: { type: string; message: unknown; button: string | undefined }[] = []
+ const recordToast =
+ (type: string) =>
+ (message: unknown, options?: { button?: { label: string } }): string => {
+ shownToasts.push({ type, message, button: options?.button?.label })
+ return 'x'
+ }
+ jest.spyOn(lemonToast, 'success').mockImplementation(recordToast('success'))
+ jest.spyOn(lemonToast, 'warning').mockImplementation(recordToast('warning'))
+ jest.spyOn(lemonToast, 'error').mockImplementation(recordToast('error'))
+ materializeEndpointMock.mockImplementation(() => materializeResponse)
+
const viewsLogic = dataWarehouseViewsLogic()
viewsLogic.mount()
@@ -3456,6 +3501,7 @@ describe('sqlEditorLogic', () => {
} else {
expect(materializeEndpointMock).toHaveBeenCalledTimes(0)
}
+ expect(shownToasts).toEqual(toasts)
editorDataNodeLogic.unmount()
viewsLogic.unmount()
diff --git a/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.tsx b/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.tsx
index 345dd27bdc07..8991db32d9eb 100644
--- a/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.tsx
+++ b/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.tsx
@@ -706,6 +706,7 @@ export interface sqlEditorLogicActions {
dataWarehouseSavedQueries: DataWarehouseSavedQuerySummary[],
payload?:
| (Partial<DataWarehouseSavedQuery> & {
+ deferCreatedToast?: boolean
folder_id?: string | null
types: string[][]
})
@@ -713,6 +714,7 @@ export interface sqlEditorLogicActions {
) => {
dataWarehouseSavedQueries: DataWarehouseSavedQuerySummary[]
payload?: Partial<DataWarehouseSavedQuery> & {
+ deferCreatedToast?: boolean
folder_id?: string | null
types: string[][]
}
@@ -735,8 +737,10 @@ export interface sqlEditorLogicActions {
materializeDataWarehouseSavedQuery: (
viewId: string,
syncFrequency?: import('~/types').DataModelingSyncInterval | undefined,
- incremental?: DataWarehouseSavedQueryIncremental | null | undefined
+ incremental?: DataWarehouseSavedQueryIncremental | null | undefined,
+ createdViewName?: string | undefined
) => {
+ createdViewName: string | undefined
incremental: DataWarehouseSavedQueryIncremental | null | undefined
syncFrequency: import('~/types').DataModelingSyncInterval | undefined
viewId: string
@@ -2690,6 +2694,7 @@ export const sqlEditorLogic = kea<sqlEditorLogicType>([
...(folderId ? { folder_id: folderId } : {}),
...(isTest ? { is_test: true } : {}),
...(incremental ? { incremental } : {}),
+ ...(materializeAfterSave ? { deferCreatedToast: true } : {}),
})
captureBIEditorQuerySaved(biEditorState, 'view', 'create')
@@ -2699,7 +2704,12 @@ export const sqlEditorLogic = kea<sqlEditorLogicType>([
)
if (materializeAfterSave && savedQuery) {
- await dataWarehouseViewsLogic.asyncActions.materializeDataWarehouseSavedQuery(savedQuery.id)
+ await dataWarehouseViewsLogic.asyncActions.materializeDataWarehouseSavedQuery(
+ savedQuery.id,
+ undefined,
+ undefined,
+ savedQuery.name
+ )
}
if (fromDraft) {
actions.deleteDraft(fromDraft, savedQuery?.name)
diff --git a/frontend/src/scenes/data-warehouse/saved_queries/dataWarehouseViewsLogic.tsx b/frontend/src/scenes/data-warehouse/saved_queries/dataWarehouseViewsLogic.tsx
index 7287d2469e81..3f50b948dbb3 100644
--- a/frontend/src/scenes/data-warehouse/saved_queries/dataWarehouseViewsLogic.tsx
+++ b/frontend/src/scenes/data-warehouse/saved_queries/dataWarehouseViewsLogic.tsx
@@ -67,6 +67,23 @@ async function openViewPage(viewId: string): Promise<void> {
router.actions.push(nodeId ? urls.nodeDetail(nodeId) : urls.sqlEditor({ view_id: viewId }))
}
+function goToViewButton(viewId: string): { label: string; action: () => Promise<void> } {
+ return {
+ label: 'Go to view',
+ action: () => openViewPage(viewId),
+ }
+}
+
+function showViewCreatedToast(
+ viewId: string,
+ viewName: string | null | undefined,
+ materialized: boolean = false
+): void {
+ lemonToast.success(`${viewName ?? 'View'} successfully created${materialized ? ' and materialized' : ''}`, {
+ button: goToViewButton(viewId),
+ })
+}
+
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface dataWarehouseViewsLogicValues {
databaseLoading: boolean // databaseTableListLogic
@@ -123,13 +140,16 @@ export interface dataWarehouseViewsLogicActions {
viewId: string
}
createDataWarehouseSavedQuery: (
- view: Partial<DataWarehouseSavedQuery> & {
+ payload: Partial<DataWarehouseSavedQuery> & {
+ // The caller must then pass the view name to `materializeDataWarehouseSavedQuery`, which shows the toast.
+ deferCreatedToast?: boolean
folder_id?: string | null
types: string[][]
}
) => Partial<DataWarehouseSavedQuery> & {
types: string[][]
folder_id?: string | null
+ deferCreatedToast?: boolean
}
createDataWarehouseSavedQueryFailure: (
error: string,
@@ -158,12 +178,14 @@ export interface dataWarehouseViewsLogicActions {
payload?: Partial<DataWarehouseSavedQuery> & {
types: string[][]
folder_id?: string | null
+ deferCreatedToast?: boolean
}
) => {
dataWarehouseSavedQueries: DataWarehouseSavedQuerySummary[]
payload?: Partial<DataWarehouseSavedQuery> & {
types: string[][]
folder_id?: string | null
+ deferCreatedToast?: boolean
}
}
deleteDataWarehouseSavedQuery: (viewId: string) => string
@@ -232,8 +254,10 @@ export interface dataWarehouseViewsLogicActions {
materializeDataWarehouseSavedQuery: (
viewId: string,
syncFrequency?: DataModelingSyncInterval,
- incremental?: DataWarehouseSavedQueryIncremental | null
+ incremental?: DataWarehouseSavedQueryIncremental | null,
+ createdViewName?: string
) => {
+ createdViewName: string | undefined
incremental: DataWarehouseSavedQueryIncremental | null | undefined
syncFrequency: DataModelingSyncInterval | undefined
viewId: string
@@ -248,6 +272,7 @@ export interface dataWarehouseViewsLogicActions {
materializeDataWarehouseSavedQuerySuccess: (
materializationAction: null,
payload?: {
+ createdViewName: string | undefined
incremental: DataWarehouseSavedQueryIncremental | null | undefined
syncFrequency: DataModelingSyncInterval | undefined
viewId: string
@@ -255,6 +280,7 @@ export interface dataWarehouseViewsLogicActions {
) => {
materializationAction: null
payload?: {
+ createdViewName: string | undefined
incremental: DataWarehouseSavedQueryIncremental | null | undefined
syncFrequency: DataModelingSyncInterval | undefined
viewId: string
@@ -422,11 +448,13 @@ export const dataWarehouseViewsLogic = kea<dataWarehouseViewsLogicType>([
materializeDataWarehouseSavedQuery: (
viewId: string,
syncFrequency?: DataModelingSyncInterval,
- incremental?: DataWarehouseSavedQueryIncremental | null
+ incremental?: DataWarehouseSavedQueryIncremental | null,
+ createdViewName?: string
) => ({
viewId,
syncFrequency,
incremental,
+ createdViewName,
}),
revertMaterialization: (viewId: string) => ({ viewId }),
addMaterializingViews: (viewIds: string[]) => ({ viewIds }),
@@ -436,8 +464,22 @@ export const dataWarehouseViewsLogic = kea<dataWarehouseViewsLogicType>([
materializationAction: [
null as null,
{
- materializeDataWarehouseSavedQuery: async ({ viewId, syncFrequency, incremental }) => {
+ materializeDataWarehouseSavedQuery: async ({ viewId, syncFrequency, incremental, createdViewName }) => {
const requestedFrequency = syncFrequency ?? DEFAULT_MATERIALIZE_SYNC_FREQUENCY
+ const followsCreation = createdViewName !== undefined
+ const reportFailure = (detail: string | null | undefined, fallback: string): null => {
+ if (followsCreation) {
+ // The view exists, so a single warning names it and says it is not materialized.
+ // A server reason such as a cadence refusal does not say "materialize" on its own.
+ lemonToast.warning(
+ `${createdViewName} was created but not materialized. ${detail || 'Open the view to try again.'}`,
+ { button: goToViewButton(viewId) }
+ )
+ } else {
+ lemonToast.error(detail || fallback)
+ }
+ return null
+ }
if (incremental !== undefined) {
// Write the config first so the materialization run picks it up. Same shape as the
// save-as-view flow, which creates the view with the config before materializing.
@@ -447,8 +489,7 @@ export const dataWarehouseViewsLogic = kea<dataWarehouseViewsLogicType>([
await api.dataWarehouseSavedQueries.update(viewId, { incremental })
} catch (error: any) {
// The server names the construct blocking incremental — surface it over a generic failure.
- lemonToast.error(error?.detail || 'Failed to save incremental settings')
- return null
+ return reportFailure(error?.detail, 'Failed to save incremental settings')
}
}
try {
@@ -456,10 +497,15 @@ export const dataWarehouseViewsLogic = kea<dataWarehouseViewsLogicType>([
sync_frequency: requestedFrequency,
})
actions.materializationChanged(viewId)
- lemonToast.success('View materialized successfully')
+ if (followsCreation) {
+ showViewCreatedToast(viewId, createdViewName, true)
+ } else {
+ lemonToast.success('View materialized successfully')
+ }
posthog.capture('materialized view created', {
sync_frequency: requestedFrequency,
incremental: !!incremental,
+ with_view_creation: followsCreation,
})
actions.addMaterializingViews([viewId])
actions.loadDataWarehouseSavedQueries()
@@ -467,7 +513,7 @@ export const dataWarehouseViewsLogic = kea<dataWarehouseViewsLogicType>([
} catch (error: any) {
// The server rejects a cadence the query's lineage can't support and says which one
// to pick instead, so the reason has to reach the user rather than a generic failure.
- lemonToast.error(error?.detail || 'Failed to materialize view')
+ return reportFailure(error?.detail, 'Failed to materialize view')
}
return null
},
@@ -511,19 +557,19 @@ export const dataWarehouseViewsLogic = kea<dataWarehouseViewsLogicType>([
) as unknown as DataWarehouseSavedQuerySummary[]
},
createDataWarehouseSavedQuery: async (
- view: Partial<DataWarehouseSavedQuery> & {
+ payload: Partial<DataWarehouseSavedQuery> & {
types: string[][]
folder_id?: string | null
+ // The caller must then pass the view name to `materializeDataWarehouseSavedQuery`, which shows the toast.
+ deferCreatedToast?: boolean
}
) => {
+ const { deferCreatedToast, ...view } = payload
const newView = await api.dataWarehouseSavedQueries.create(view)
- lemonToast.success(`${newView.name ?? 'View'} successfully created`, {
- button: {
- label: 'Go to view',
- action: () => openViewPage(newView.id),
- },
- })
+ if (!deferCreatedToast) {
+ showViewCreatedToast(newView.id, newView.name)
+ }
posthog.capture('view created')
globalSetupLogic.findMounted()?.actions.markTaskAsCompleted(SetupTaskId.CreateSavedView)