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): show refresh mode loading state (#121730)

Jovan Sakovic9510e35e50bc
diff --git a/frontend/src/scenes/data-warehouse/editor/IncrementalConfigFields.tsx b/frontend/src/scenes/data-warehouse/editor/IncrementalConfigFields.tsx
index 1b440fc6efc2..ee8e8c6ed73a 100644
--- a/frontend/src/scenes/data-warehouse/editor/IncrementalConfigFields.tsx
+++ b/frontend/src/scenes/data-warehouse/editor/IncrementalConfigFields.tsx
@@ -4,6 +4,7 @@ import { LemonField } from 'lib/lemon-ui/LemonField'
import { LemonInputSelect } from 'lib/lemon-ui/LemonInputSelect'
import { LemonRadio, LemonRadioOption } from 'lib/lemon-ui/LemonRadio'
import { LemonSelect } from 'lib/lemon-ui/LemonSelect'
+import { LemonSkeleton } from 'lib/lemon-ui/LemonSkeleton'
import { LemonTag } from 'lib/lemon-ui/LemonTag'
import { DataWarehouseSavedQueryIncrementalCheck } from '~/types'
@@ -181,12 +182,19 @@ function LookbackInput({ value, onChange }: { value: number; onChange: (value: n
}
interface IncrementalConfigOptionsProps {
- /** Result of the backend eligibility check for the view's query. Nothing renders until it arrives. */
+ /** Result of the backend eligibility check for the view's query. */
check: DataWarehouseSavedQueryIncrementalCheck | null
draft: IncrementalConfigDraft
onChange: (draft: Partial<IncrementalConfigDraft>) => void
}
+export const INCREMENTAL_CHECK_LOADING: DataWarehouseSavedQueryIncrementalCheck = {
+ eligible: false,
+ key_candidates: [],
+ blockers: [],
+ warnings: [],
+}
+
/**
* Controlled version of the incremental settings, for surfaces without a kea form —
* the materialization panel and modal.
@@ -196,6 +204,14 @@ export function IncrementalConfigOptions({
draft,
onChange,
}: IncrementalConfigOptionsProps): JSX.Element | null {
+ if (check === INCREMENTAL_CHECK_LOADING) {
+ return (
+ <div className="mt-4 deprecated-space-y-2" data-attr="materialization-refresh-mode-loading">
+ <LemonSkeleton className="h-8 w-full" repeat={2} />
+ </div>
+ )
+ }
+
if (!check) {
return null
}
diff --git a/frontend/src/scenes/data-warehouse/saved_queries/materializationJobsLogic.test.ts b/frontend/src/scenes/data-warehouse/saved_queries/materializationJobsLogic.test.ts
index 2f98eba930b1..7ddd8de367d5 100644
--- a/frontend/src/scenes/data-warehouse/saved_queries/materializationJobsLogic.test.ts
+++ b/frontend/src/scenes/data-warehouse/saved_queries/materializationJobsLogic.test.ts
@@ -352,6 +352,37 @@ describe('materializationJobsLogic', () => {
expect(checkCalls).toBe(1)
})
+ it('shows a refresh mode loading state while the eligibility check runs', async () => {
+ let releaseCheck!: () => void
+ const heldCheck = new Promise<void>((resolve) => {
+ releaseCheck = resolve
+ })
+ const mocks = apiMocks({ isMaterialized: true })
+ mocks.post!['/api/environments/:team_id/warehouse_saved_queries/check_incremental/'] = async () => {
+ await heldCheck
+ return [200, ELIGIBLE_CHECK]
+ }
+ useMocks(mocks)
+ logic = materializationJobsLogic({ viewId: 'view-1' })
+ logic.mount()
+
+ await expectLogic(logic).toDispatchActions(['loadSavedQuerySuccess'])
+ render(
+ createElement(MaterializationStatusPanel, {
+ viewId: 'view-1',
+ showRunActions: false,
+ showStatusSummary: false,
+ })
+ )
+
+ expect(screen.getByText('Refresh mode')).toBeTruthy()
+ expect(document.querySelector('[data-attr="materialization-refresh-mode-loading"]')).toBeTruthy()
+
+ releaseCheck()
+ await expectLogic(logic).toDispatchActions(['loadIncrementalCheckSuccess']).toFinishAllListeners()
+ expect(document.querySelector('[data-attr="materialization-refresh-mode-loading"]')).toBeNull()
+ })
+
// Regression: a rejected eligibility check used to surface as a "Load incremental check failed"
// toast on a healthy materialized view. A 4xx is an expected refusal and is not retried; a 5xx is
// ours to record, and the next savedQuery reload (every jobs poll) retries it.
diff --git a/frontend/src/scenes/data-warehouse/saved_queries/materializationJobsLogic.ts b/frontend/src/scenes/data-warehouse/saved_queries/materializationJobsLogic.ts
index adf828f08dc3..8899dc802896 100644
--- a/frontend/src/scenes/data-warehouse/saved_queries/materializationJobsLogic.ts
+++ b/frontend/src/scenes/data-warehouse/saved_queries/materializationJobsLogic.ts
@@ -24,9 +24,16 @@ import type { DataWarehouseSavedQuery } from '~/types'
import { DataModelingSyncInterval, DataWarehouseSavedQueryIncrementalCheck } from '~/types'
import { dataModelingJobsList, warehouseSavedQueriesResumeCreate } from 'products/data_warehouse/frontend/generated/api'
-import type { PaginatedDataModelingJobListApi } from 'products/data_warehouse/frontend/generated/api.schemas'
+import type {
+ DataModelingJobApi,
+ PaginatedDataModelingJobListApi,
+} from 'products/data_warehouse/frontend/generated/api.schemas'
-import { EMPTY_INCREMENTAL_DRAFT, IncrementalConfigDraft } from '../editor/IncrementalConfigFields'
+import {
+ EMPTY_INCREMENTAL_DRAFT,
+ INCREMENTAL_CHECK_LOADING,
+ IncrementalConfigDraft,
+} from '../editor/IncrementalConfigFields'
import { DEFAULT_MATERIALIZE_SYNC_FREQUENCY, dataWarehouseViewsLogic } from './dataWarehouseViewsLogic'
import { latestSuccessfulSyncAt } from './materializationJobUtils'
import { SyncFrequencyValue } from './SyncFrequencySelect'
@@ -38,6 +45,10 @@ const IDLE_REFRESH_INTERVAL_MS = 60000
const STARTING_TIMEOUT_MS = 120000
export const DEFAULT_JOBS_PAGE_SIZE = 10
+function isNewRunVisible(newestJob: DataModelingJobApi | undefined, previousJobId: string | null | undefined): boolean {
+ return !!newestJob && newestJob.id !== previousJobId
+}
+
export interface MaterializationJobsLogicProps {
viewId: string
/** Endpoints own their saved query's materialization lifecycle, so incremental setup is hidden for them. */
@@ -334,7 +345,7 @@ export const materializationJobsLogic = kea<materializationJobsLogicType>([
},
],
incrementalCheck: [
- null as DataWarehouseSavedQueryIncrementalCheck | null,
+ INCREMENTAL_CHECK_LOADING as DataWarehouseSavedQueryIncrementalCheck | null,
{
loadIncrementalCheck: async () => {
const sql = values.savedQuery?.query?.query
@@ -762,7 +773,7 @@ export const materializationJobsLogic = kea<materializationJobsLogicType>([
}
cache.newestJobState = newestJobState
// Until the new run's job row exists, the newest job is the run before the click.
- if (values.startingMaterialization && newestJob && newestJob.id !== cache.newestJobIdBeforeStart) {
+ if (values.startingMaterialization && isNewRunVisible(newestJob, cache.newestJobIdBeforeStart)) {
actions.setStartingMaterialization(false)
}
const active = values.startingMaterialization || running