: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
feat(sql-editor): filter materialized views by status (#122102)
Marius Andra3ad53dd07df7
diff --git a/docs/internal/sql-editor-schema-tree.md b/docs/internal/sql-editor-schema-tree.mdindex 5a6b4fc5338e..ade0dcdf5355 100644--- a/docs/internal/sql-editor-schema-tree.md+++ b/docs/internal/sql-editor-schema-tree.md@@ -45,6 +45,12 @@ After that request, catalog reloads also restore complete fields for consumers oSchema mutations refresh previously hydrated or pending tables, as well as expanded nodes.Saved-query lists expose metadata only; refreshing them preserves the query and columns already fetched for an open editor tab.+In PostHog Warehouse, the **…** menu beside sidebar search filters materialized views by their latest run status: **Failed**, **Running**, or **Completed**.+Select multiple statuses to include views matching any of them. **Failed** includes views paused after repeated failures.+Matching views retain their folders and expandable columns. The menu button highlights while a status filter is active.+These filters combine with sidebar search and do not apply to direct connections.+**Clear filters** or deselecting every status restores the full tree. Locating a table also clears the status filters so the requested table can appear.+## Saved-query writesThe saved-query API accepts `sync_frequency` on create and update.diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 074563cb568d..ffceec9a538b 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -10471,29 +10471,29 @@ snapshots:scenes-app-data-warehouse-sql-editor--customer-images--light:hash: v1.k794b7964.ce993f3850f54ddccef58a05eceb9e2c97aa9a55a10c79ccec026ab34b41ef2c.wKHSElvN1JjL3MGp2vC9ReSCbeinqDlJse66vWOjUDMscenes-app-data-warehouse-sql-editor--edited-insight--dark:- hash: v1.k794b7964.4e81f33deba8184b2e4d8c90c20967f98d4cfac08a1903c8b1805604ad94983f.ZI5eb066W3jZYoEroMzzCE08QMOQvQmyTaxzxOZey88+ hash: v1.k794b7964.abdad45eda3e55d49184f287c8b9420cd51049214a4e373af2a2ce4a51a1f380.Am_pA69gDN8zJ0H5XBaRSA5ftzncD6v-fQf-StsCtcUscenes-app-data-warehouse-sql-editor--edited-insight--light:- hash: v1.k794b7964.1b9f92806a628c4f9fa9fe08a0d1f2102ff41f00c7b03907d014a75acc09fa70.KwEmvIN4XlyI9VtFb0Df823i3G9fqLFossNoMgEiYqM+ hash: v1.k794b7964.8b4b5e9d27e30dce860efa4ce720bb3b94b009ca4fbe2936e22bcffbd4e57d80.xkqB3l0Rj9En-0bg_bEmUZ4OPip0k9_0w76It2BKo_cscenes-app-data-warehouse-sql-editor--edited-view--dark:- hash: v1.k794b7964.57136a6dbeab9ac511a2a5e0c7401b23a4cb0ac00d82a2be177b84f74a60ebb0.QicPm3hXLpA9re3ShhfrqX6bKcWmuAvRBCtbRpHrSFQ+ hash: v1.k794b7964.938a62a81937113f22cf7e37329390813a11b16fb3e0f86076f353442d723a9f.98wO_IsLncv5LEivgTAi5xNjCgHijdNRi0BfiM2r9d0scenes-app-data-warehouse-sql-editor--edited-view--light:- hash: v1.k794b7964.1bada9403e11b62a50423adde53ce13fcd10a5bd6c33a210f5dd58a10a956cf8.2N9MES9JfDzATg0m-6cJnj7FWTzNt6ZlLxGqqoAI54A+ hash: v1.k794b7964.50bdfff99f78788822f0718cacd6c41ed4c852e0820c7b5ee578e85f457e9d76.3oaEflI_FEOzbB6MPUOz66IoLl8yNR60fH7LJA7BcpQscenes-app-data-warehouse-sql-editor--harness-logo-in-results--dark:- hash: v1.k794b7964.83437273f5119c5f292fad5fe8a6c389444776d534a134111b0b9049430ffffd.cz4bKXqalkafd6knGBg3gj7x0-8T5p7NLuix9rG6GPw+ hash: v1.k794b7964.f925fa9b1ee9b88bb2867cad7844db5d79b05883ac592d5b3c7c4781861e6bc1.6EezFaCVaI8MMgxEmjKSm2bYptkPL2_Va7bln2H8oBYscenes-app-data-warehouse-sql-editor--harness-logo-in-results--light:- hash: v1.k794b7964.261adb2063efa109811c70908e6d117f1efa1229135bcd341ec2da3507b5975b.tvMMteHD7B5av-EjfaSoJx8R3FPAPozw8oL3Ur4_lM4+ hash: v1.k794b7964.c172b386d0f1185b8fc80dee491199ecb8a97947493aa0f5ad9baa0b4e25e382.nODk2wrlKLhsjdhSdxQGqLdjZzCIA-6egORi4hU82m4scenes-app-data-warehouse-sql-editor--hosted-trino--dark:hash: v1.k794b7964.ed1e698c1e589fef66b1788f5ce8144a60e3dd45d2f4f75b5ba4035379eb90ed.CQYsVP8IhyvD6ayH0_G6E-lbEDtJL15sNlk9tr3X94Qscenes-app-data-warehouse-sql-editor--hosted-trino--light:hash: v1.k794b7964.647221a6ff5285e22a729959258f9080f822b8b637fb9e356d64858ffc810297.xDMwpQ08PB4xYTX3ilprjooK9Q-2nzPa1Kv2Sx9V4sgscenes-app-data-warehouse-sql-editor--lazy-schema--dark:- hash: v1.k794b7964.520af6c94de8ab081cff352b32dbee68c1054c8fdc6632a87bcecccaf497cf5d.SBsaeAFwZNnQLj-vhwcaUBLbOT1r7VTPn8dgApUR_Mw+ hash: v1.k794b7964.183adbbe028e98fcea5e9178ae26fcac9fb15d7a151cf0ef63c60b2de09cd7a9.Pd09tfmXU1nN4C8FvE0QkjC7dCv2qoelqyz7CMtEPy8scenes-app-data-warehouse-sql-editor--lazy-schema--light:- hash: v1.k794b7964.46f82cf80402c360318cf7c21d6c1d89ab01e7dad8853a8d882ed75f6509f87d.4bs5KStWG3w60fPsa01nPYvaM3o2HBIXt6fHg4lKGaM+ hash: v1.k794b7964.09b241f2cd52673b034101f7d69dad53def23fe7330dc9d38a831fed9c42d4f2.g80q-xBDa3gpn6AMi2U4EvWX3OKYphzISVQLxLo1TOkscenes-app-data-warehouse-sql-editor--loading-insight--dark:- hash: v1.k794b7964.3943daf2885879b6fbe3573213278be56c09f47bba90bc133ebfbc64a80f9323.Q4NvArXBY5VdTtnNlhmMG7aK481zSBRFCfpQqiLPgIw+ hash: v1.k794b7964.cf70e96e659a5221f6231ca31507c42c071cd6bce8b6dcab221797042da29929.WGQS080OemF32Jo3RhwbvjznJxf_yh_mU59XUw_QJHgscenes-app-data-warehouse-sql-editor--loading-insight--light:- hash: v1.k794b7964.03be9cdcfabc5c9299d7e9dbe28ac04d1de2808c0701a173b2421a90f5d795ee.j1vfupbc6XDFc08rCy0o-WXyxtFOTRMNT_eE6MyB0oY+ hash: v1.k794b7964.b019029e7cac13d35269d39707554e43c4119741db978fb233898f5a30d3c5fb.xCgPMHXk5WnATu_gOBEoI1B2VAkzZem1ZIEznSoNFYcscenes-app-data-warehouse-sql-editor--managed-warehouse-connection--dark:hash: v1.k794b7964.a214e35f699dae99e7aa4f0beca162d35c0095df90f2b0da43cf78114de5470e.ZG5dRjculzef5ATiURJhJ3M35ZFy6Jf3EG0m2LHnzcgscenes-app-data-warehouse-sql-editor--managed-warehouse-connection--light:@@ -10503,13 +10503,13 @@ snapshots:scenes-app-data-warehouse-sql-editor--materialization-settings--light:hash: v1.k794b7964.99aa3bde7ac4497a83b2008869c8efd14317eda8d8c08950e851089092df8df9.05p6Le0a2itun96QCw7Mk7VkwfAp50woApgM8ZyaHMsscenes-app-data-warehouse-sql-editor--sidebar-materialization-status--dark:- hash: v1.k794b7964.61679b7880682c4f20d03ffae8424f40d458539af169f5968e2669479ea7995c.B-7a_Mcdz3VVb92UpNggKiXjLIFliluBrQB6Y-eg-_Q+ hash: v1.k794b7964.85acd8a7662a18e3cb74064b89ec1b5bf7f1dafc7040e3c03e89f8f216c3f4c7.hp3JoyDds6n5wOcIirv45esRuHBSQmVvjGgIqT_R934scenes-app-data-warehouse-sql-editor--sidebar-materialization-status--light:- hash: v1.k794b7964.ba71002ed62cdc4ba3f788f63825706e798ea2320d6edcd165926e3e7bb12caf.oanDT3feuobHrZN0Lsrvxe6JqUKKHBDgkKnZZIb-Co0+ hash: v1.k794b7964.b1674ecfd22563c6441cf6e1f10ec61bc2fcb7051d44ef18ed3ca5ed46fe63ed.9mjwnaC0hdz6WDbXMPFJWxMW5VYWhn8JIADGdiNVADoscenes-app-data-warehouse-sql-editor--top-tools-per-server--dark:- hash: v1.k794b7964.09cbf4fb6c6774ac241e66543414a19356914a2def3c34d7063172dd37cff494.tizuoPtWR7f-Cdka3_-mp0O9CBQ1CPPGRprgEpK0Zzc+ hash: v1.k794b7964.086bd9bfadf0b7475bf78bdce3fe0669526cb84dff71535797ea45443020ad94.Ueu17JcKwrRz-y1P0C3egpr6rN-iTMbldFo5N_VoEWEscenes-app-data-warehouse-sql-editor--top-tools-per-server--light:- hash: v1.k794b7964.2c0e2af910c16e301d1ab2d533a703068282ffbe68db8caf490d425f3c76f94f.4rfOB50ow9LE-i-5Ckh6qe-sYoNiPdIqKDfCzcLRt-U+ hash: v1.k794b7964.2a368172e76cd4dc368f15e8f21374965bcb0dd0f8b3ee7c02ff0023701ba749.kZKMxF8IsPF8udDM-J8EZUSqJXVQwE9qJyNV-wM8xyIscenes-app-discussions--replying-to-thread--dark:hash: v1.k794b7964.c2c9d9beff1e3fa0fc6a314aa073610d674eb9cd4af235b31a81e09462b5b58e.-fbBmBjOrnXiwY_8KrKftI-k7wWP9L77S8rFDSiiI3Uscenes-app-discussions--replying-to-thread--light:@@ -12779,9 +12779,9 @@ snapshots:scenes-app-insights-side-panel-actions--unsaved-insight--light:hash: v1.k794b7964.d1ae4193c6ddd6ec8ec70b8181cd1fa1e33cfa0728d586423355601166b2e8b2.GFGdmioAb_Lqr7qiZik9jLMbbO6yC4abdURWyrSNeOsscenes-app-insights-sqlboxplot--edit-options--dark:- hash: v1.k794b7964.bb9343c44dfcb6715d5dd3e75804d343c6f19745c0a94c1bdaa47a537c170534.hwZN8OVxGdrDLJR8bRo0DXfv9sSBhbUnp4ARuI-6Eww+ hash: v1.k794b7964.308341cd522a4bd2fab85a8705cbcc008fab22bf951e4ebe054a14d33ab9c4af.3rsxL_RsaZvnIIYCFuaz3Zr3M3kpJYecNWcWDyJpbTUscenes-app-insights-sqlboxplot--edit-options--light:- hash: v1.k794b7964.1539a8a8d4d19728490331fac7430332d2e1bbac19da9ed11ad6d571976e7864.2fmBRJA-TEOHgC7ODM42naay_EdDGTMjFH9HQFYfbLc+ hash: v1.k794b7964.355f2119731714f7c84a2443841ca489f7d3275e26f697bb31fc7ecce6fc84d4.0pKjvw68pUVvD78l6SSrXN7Wm9X1rMMCPZImjqsikO0scenes-app-insights-sqlboxplot--grouped-series--dark:hash: v1.k794b7964.e8e02705d2c2c04c95c28531323ac3afda9177a46f6d3207f1566faa0bdb357d.3VyKBqkXAnxXNZufZ_HlYp7q3M3J3E2go7zXqIPKQzEscenes-app-insights-sqlboxplot--grouped-series--light:diff --git a/frontend/src/scenes/data-warehouse/editor/sidebar/DatabaseSearchField.tsx b/frontend/src/scenes/data-warehouse/editor/sidebar/DatabaseSearchField.tsxindex 92cb54d9fcb0..203e0b35a8b9 100644--- a/frontend/src/scenes/data-warehouse/editor/sidebar/DatabaseSearchField.tsx+++ b/frontend/src/scenes/data-warehouse/editor/sidebar/DatabaseSearchField.tsx@@ -1,7 +1,12 @@import { useActions, useValues } from 'kea'+import { IconEllipsis } from '@posthog/icons'+import { LemonButton, LemonCheckbox, LemonMenu } from '@posthog/lemon-ui'+import { SearchAutocomplete } from 'lib/components/SearchAutocomplete/SearchAutocomplete'+import { MATERIALIZATION_STATUS_FILTER_OPTIONS } from 'products/data_warehouse/frontend/shared/filterMaterializedViewsByStatus'+import { queryDatabaseLogic } from './queryDatabaseLogic'interface TreeSearchFieldProps {@@ -9,9 +14,9 @@ interface TreeSearchFieldProps {}export function DatabaseSearchField({ placeholder }: TreeSearchFieldProps): JSX.Element {- const { treeRef } = useValues(queryDatabaseLogic)- const { searchTerm } = useValues(queryDatabaseLogic)- const { setSearchTerm, clearSearch } = useActions(queryDatabaseLogic)+ const { treeRef, searchTerm, connectionId, materializationStatusFilters } = useValues(queryDatabaseLogic)+ const { setSearchTerm, clearSearch, toggleMaterializationStatusFilter, clearMaterializationStatusFilters } =+ useActions(queryDatabaseLogic)function handleKeyDown(e: React.KeyboardEvent<HTMLInputElement>): void {if (e.key === 'ArrowDown') {@@ -25,13 +30,67 @@ export function DatabaseSearchField({ placeholder }: TreeSearchFieldProps): JSX.}return (- <SearchAutocomplete- inputPlaceholder={placeholder}- includeNegation- defaultValue={searchTerm}- onKeyDown={(e) => handleKeyDown(e)}- onClear={() => clearSearch()}- onChange={(value) => setSearchTerm(value)}- />+ <div className="flex items-center gap-1 min-w-0">+ <div className="flex-1 min-w-0">+ <SearchAutocomplete+ inputPlaceholder={placeholder}+ includeNegation+ defaultValue={searchTerm}+ onKeyDown={(e) => handleKeyDown(e)}+ onClear={() => clearSearch()}+ onChange={(value) => setSearchTerm(value)}+ />+ </div>+ {!connectionId && (+ <LemonMenu+ placement="bottom-end"+ closeOnClickInside={false}+ items={[+ {+ title: 'Materialization status',+ items: MATERIALIZATION_STATUS_FILTER_OPTIONS.map((status) => ({+ key: status,+ label: status,+ role: 'menuitemcheckbox',+ 'aria-checked': materializationStatusFilters.includes(status),+ onClick: () => toggleMaterializationStatusFilter(status),+ 'data-attr':+ status === 'Failed'+ ? 'sql-editor-failed-materializations-filter'+ : `sql-editor-materialization-status-${status.toLowerCase()}`,+ icon: (+ <LemonCheckbox+ checked={materializationStatusFilters.includes(status)}+ decorative+ className="pointer-events-none"+ size="small"+ />+ ),+ })),+ },+ {+ items: [+ {+ label: 'Clear filters',+ onClick: clearMaterializationStatusFilters,+ disabledReason:+ materializationStatusFilters.length === 0 ? 'No active filters' : null,+ 'data-attr': 'sql-editor-clear-materialization-filters',+ },+ ],+ },+ ]}+ >+ <LemonButton+ icon={<IconEllipsis />}+ size="small"+ active={materializationStatusFilters.length > 0}+ tooltip="Filter tables and views"+ aria-label="Filter tables and views"+ data-attr="sql-editor-table-filters-menu"+ />+ </LemonMenu>+ )}+ </div>)}diff --git a/frontend/src/scenes/data-warehouse/editor/sidebar/QueryDatabase.tsx b/frontend/src/scenes/data-warehouse/editor/sidebar/QueryDatabase.tsxindex 78c29e936777..0c15b2e350be 100644--- a/frontend/src/scenes/data-warehouse/editor/sidebar/QueryDatabase.tsx+++ b/frontend/src/scenes/data-warehouse/editor/sidebar/QueryDatabase.tsx@@ -143,6 +143,8 @@ export const QueryDatabase = ({highlightViewsSectionDrop,featureFlags,editingPropertyDefinition,+ materializationStatusFilters,+ dataWarehouseSavedQueriesLoading,} = useValues(queryDatabaseLogic)const {setExpandedFolders,@@ -164,6 +166,7 @@ export const QueryDatabase = ({closePropertyDefinitionEditor,updatePropertyDefinition,} = useActions(queryDatabaseLogic)+ const { dataWarehouseSavedQueriesLoaded } = useValues(dataWarehouseViewsLogic)const {createDataWarehouseSavedQueryFolder,deleteDataWarehouseSavedQueryFolder,@@ -1417,6 +1420,13 @@ export const QueryDatabase = ({return (<>+ {!connectionId &&+ materializationStatusFilters.length > 0 &&+ dataWarehouseSavedQueriesLoaded &&+ !dataWarehouseSavedQueriesLoading &&+ treeData.length === 0 && (+ <p className="px-3 py-2 text-muted text-sm">No materialized views match your filters.</p>+ )}{tree}{editingPropertyDefinition ? (<PropertyDefinitionEditModaldiff --git a/frontend/src/scenes/data-warehouse/editor/sidebar/queryDatabaseLogic.test.ts b/frontend/src/scenes/data-warehouse/editor/sidebar/queryDatabaseLogic.test.tsindex 41d2c63a8e36..c7a56651cc25 100644--- a/frontend/src/scenes/data-warehouse/editor/sidebar/queryDatabaseLogic.test.ts+++ b/frontend/src/scenes/data-warehouse/editor/sidebar/queryDatabaseLogic.test.ts@@ -580,6 +580,58 @@ describe('queryDatabaseLogic', () => {logic.unmount()})+ it('combines materialization statuses with search and clears them when locating a table', async () => {+ initKeaTests()+ const logic = queryDatabaseLogic()+ logic.mount()+ const viewsLogic = dataWarehouseViewsLogic.findMounted()!+ await expectLogic(viewsLogic).toFinishAllListeners()+ viewsLogic.actions.loadDataWarehouseSavedQueriesSuccess(+ [+ ['orders_daily', 'Failed'],+ ['orders_weekly', 'Completed'],+ ['revenue_daily', 'Failed'],+ ].map(([name, status]) => ({+ id: name,+ name,+ status,+ is_materialized: true,+ columns: [],+ managed_viewset_kind: null,+ })) as unknown as DataWarehouseSavedQuery[]+ )++ logic.actions.toggleMaterializationStatusFilter('Failed')+ expect(logic.values.displayedTreeData.map((item) => item.name)).toEqual(['Views'])+ expect(logic.values.displayedTreeData[0].children!.map((item) => item.name)).toEqual([+ 'orders_daily',+ 'revenue_daily',+ ])++ logic.actions.setSearchTerm('orders')+ expect(logic.values.displayedTreeData[0].children!.map((item) => item.name)).toEqual(['orders_daily'])+ logic.actions.toggleMaterializationStatusFilter('Completed')+ expect(logic.values.displayedTreeData[0].children!.map((item) => item.name)).toEqual([+ 'orders_daily',+ 'orders_weekly',+ ])+ logic.actions.toggleMaterializationStatusFilter('Failed')+ expect(logic.values.displayedTreeData[0].children!.map((item) => item.name)).toEqual(['orders_weekly'])+ logic.actions.toggleMaterializationStatusFilter('Completed')+ expect(logic.values.materializationStatusFilters).toEqual([])+ logic.actions.toggleMaterializationStatusFilter('Failed')+ logic.actions.setSearchTerm('orders_weekly')+ expect(logic.values.displayedTreeData).toEqual([])+ logic.actions.clearSearch()+ logic.actions.clearMaterializationStatusFilters()+ expect(logic.values.displayedTreeData.find((item) => item.name === 'Views')!.children).toHaveLength(3)++ logic.actions.toggleMaterializationStatusFilter('Failed')+ logic.actions.locateTable('events')+ expect(logic.values.materializationStatusFilters).toEqual([])+ logic.unmount()+ })+it('lists only SQL metrics under a metrics section in browsing and search', async () => {initKeaTests()mockDataCatalogMetricsList.mockResolvedValueOnce({@@ -986,6 +1038,7 @@ describe('queryDatabaseLogic', () => {it.each(['source-id', MANAGED_TRINO_SCHEMA_SCOPE])('hides unrelated folders for schema scope %s', (scope) => {databaseTableListLogic.findMounted()?.actions.setConnection(scope)+ logic.actions.toggleMaterializationStatusFilter('Failed')featureFlagLogic.actions.setFeatureFlags([FEATURE_FLAGS.EDITOR_DRAFTS], {[FEATURE_FLAGS.EDITOR_DRAFTS]: true,})diff --git a/frontend/src/scenes/data-warehouse/editor/sidebar/queryDatabaseLogic.tsx b/frontend/src/scenes/data-warehouse/editor/sidebar/queryDatabaseLogic.tsxindex 0c48f7c8178a..8bd51607e81d 100644--- a/frontend/src/scenes/data-warehouse/editor/sidebar/queryDatabaseLogic.tsx+++ b/frontend/src/scenes/data-warehouse/editor/sidebar/queryDatabaseLogic.tsx@@ -61,6 +61,10 @@ import {createVirtualTableField,resolveFieldTraverserTarget,} from 'products/data_warehouse/frontend/shared/fieldTraversal'+import {+ filterMaterializedViewsByStatus,+ MaterializationStatusFilter,+} from 'products/data_warehouse/frontend/shared/filterMaterializedViewsByStatus'import {connectionSelectorLogic,POSTHOG_WAREHOUSE,@@ -1746,6 +1750,7 @@ export interface queryDatabaseLogicValues {highlightedDropFolderId: string | nullhogqlMetrics: DataCatalogMetricApi[]joinsByFieldName: Record<string, DataWarehouseViewLink>+ materializationStatusFilters: MaterializationStatusFilter[]metricsLoadFailed: booleanpendingViewFolderOverrides: Record<string, string | null>propertyDefinitionLists: Record<string, SidebarPropertyDefinitionList>@@ -1856,6 +1861,9 @@ export interface queryDatabaseLogicActions {clearDraggedViewState: () => {value: true}+ clearMaterializationStatusFilters: () => {+ value: true+ }clearPendingViewFolderOverride: (viewId: string) => {viewId: string}@@ -2038,6 +2046,9 @@ export interface queryDatabaseLogicActions {folderId: stringisExpanded: boolean}+ toggleMaterializationStatusFilter: (status: MaterializationStatusFilter) => {+ status: 'Completed' | 'Failed' | 'Running'+ }updateDraggedViewDropTarget: (dropTargetId: string | null) => {dropTargetId: string | null}@@ -2165,7 +2176,8 @@ export interface queryDatabaseLogicMeta {selectedDirectSource: ExternalDataSourceConnectionOptionApi | undefined,databaseLoading: boolean,databaseLoadError: string | null,- allTablesMap: Record<string, DatabaseSchemaTable>+ allTablesMap: Record<string, DatabaseSchemaTable>,+ materializationStatusFilters: ('Completed' | 'Failed' | 'Running')[]) => TreeDataItem[]activeExpandedFolderIds: (searchTerm: string,@@ -2214,6 +2226,8 @@ export const queryDatabaseLogic = kea<queryDatabaseLogicType>([toggleFolderOpen: (folderId: string, isExpanded: boolean) => ({ folderId, isExpanded }),setTreeRef: (ref: EditorSidebarTreeRef | null) => ({ ref }),setSearchTerm: (searchTerm: string) => ({ searchTerm }),+ toggleMaterializationStatusFilter: (status: MaterializationStatusFilter) => ({ status }),+ clearMaterializationStatusFilters: true,setPropertyDefinitionSearch: (propertyFieldKey: string,target: SidebarPropertyDefinitionTarget,@@ -2393,6 +2407,15 @@ export const queryDatabaseLogic = kea<queryDatabaseLogicType>([},],+ materializationStatusFilters: [+ [] as MaterializationStatusFilter[],+ {+ toggleMaterializationStatusFilter: (state, { status }) =>+ state.includes(status) ? state.filter((value) => value !== status) : [...state, status],+ clearMaterializationStatusFilters: () => [],+ locateTable: () => [],+ },+ ],searchTerm: ['',{@@ -3489,6 +3512,7 @@ export const queryDatabaseLogic = kea<queryDatabaseLogicType>([s.databaseLoading,s.databaseLoadError,s.allTablesMap,+ s.materializationStatusFilters,],(searchTerm: string,@@ -3498,12 +3522,13 @@ export const queryDatabaseLogic = kea<queryDatabaseLogicType>([selectedDirectSource: ExternalDataSourceConnectionOptionApi | undefined,databaseLoading: boolean,databaseLoadError: string | null,- allTablesMap: Record<string, DatabaseSchemaTable>+ allTablesMap: Record<string, DatabaseSchemaTable>,+ materializationStatusFilters: MaterializationStatusFilter[]): TreeDataItem[] => {const sourceData = searchTerm ? searchTreeData : treeDataif (!shouldUseDirectConnectionTree(connectionId)) {- return sourceData+ return filterMaterializedViewsByStatus(sourceData, materializationStatusFilters)}const flattenedTables: TreeDataItem[] = []diff --git a/products/data_warehouse/frontend/shared/filterMaterializedViewsByStatus.test.ts b/products/data_warehouse/frontend/shared/filterMaterializedViewsByStatus.test.tsnew file mode 100644index 000000000000..df48acf1267c--- /dev/null+++ b/products/data_warehouse/frontend/shared/filterMaterializedViewsByStatus.test.ts@@ -0,0 +1,100 @@+import type { TreeDataItem } from 'lib/lemon-ui/LemonTree/LemonTree'++import { filterMaterializedViewsByStatus, MaterializationStatusFilter } from './filterMaterializedViewsByStatus'++describe('filterMaterializedViewsByStatus', () => {+ it.each<{ statuses: MaterializationStatusFilter[]; expected: string[] }>([+ { statuses: [], expected: ['failed', 'running', 'completed', 'plain'] },+ { statuses: ['Running'], expected: ['running'] },+ { statuses: ['Completed'], expected: ['completed'] },+ { statuses: ['Failed', 'Running'], expected: ['failed', 'running'] },+ ])('matches any selected status: $statuses', ({ statuses, expected }) => {+ const items: TreeDataItem[] = [+ ['failed', 'Failed', true],+ ['running', 'Running', true],+ ['completed', 'Completed', true],+ ['plain', 'Running', false],+ ].map(([id, status, isMaterialized]) => ({+ id: String(id),+ name: String(id),+ record: { type: 'view', view: { is_materialized: isMaterialized, status } },+ }))++ expect(filterMaterializedViewsByStatus(items, statuses).map((item) => item.id)).toEqual(expected)+ })++ it('keeps failed materialized views and their columns inside matching folders', () => {+ const columns: TreeDataItem[] = [{ id: 'column', name: 'total', record: { type: 'column' } }]+ const views: TreeDataItem[] = [+ {+ id: 'failed',+ name: 'failed',+ record: { type: 'view', view: { is_materialized: true, status: 'Failed' } },+ children: columns,+ },+ {+ id: 'healthy',+ name: 'healthy',+ record: { type: 'view', view: { is_materialized: true, status: 'Completed' } },+ },+ {+ id: 'running',+ name: 'running',+ record: { type: 'view', view: { is_materialized: true, status: 'Running' } },+ },+ {+ id: 'plain',+ name: 'plain',+ record: { type: 'view', view: { is_materialized: false, status: 'Failed' } },+ },+ { id: 'pending', name: 'pending', record: { type: 'view', view: { is_materialized: true, status: null } } },+ ]+ const folder: TreeDataItem = {+ id: 'folder',+ name: 'Reporting',+ record: { type: 'folder', folderType: 'view-folder' },+ children: views,+ }+ const paused: TreeDataItem = {+ id: 'paused',+ name: 'paused',+ record: {+ type: 'view',+ view: {+ is_materialized: true,+ status: 'Failed',+ suspended: { clickhouse: { reason: 'Example failure' } },+ },+ },+ }+ const root: TreeDataItem = {+ id: 'views',+ name: 'Views',+ record: { type: 'views' },+ children: [folder, paused, { ...folder, id: 'empty', children: [views[1]] }],+ }+ const result = filterMaterializedViewsByStatus(+ [+ { id: 'sources', name: 'Sources', record: { type: 'sources' }, children: views },+ root,+ { id: 'drafts', name: 'Drafts', record: { type: 'drafts' } },+ ],+ ['Failed']+ )++ expect(result).toEqual([{ ...root, children: [{ ...folder, children: [views[0]] }, paused] }])+ expect(result[0].children![0].children![0].children).toBe(columns)+ expect(folder.children).toHaveLength(5)+ })++ it.each([+ ['empty', [], []],+ ['loading', [{ id: 'loading', name: 'Loading...', type: 'loading-indicator' }], ['views']],+ ])('distinguishes %s views from a completed filter with no matches', (_name, children, expectedIds) => {+ const result = filterMaterializedViewsByStatus(+ [{ id: 'views', name: 'Views', record: { type: 'views' }, children: children as TreeDataItem[] }],+ ['Failed']+ )+ expect(result.map((item) => item.id)).toEqual(expectedIds)+ })+})diff --git a/products/data_warehouse/frontend/shared/filterMaterializedViewsByStatus.ts b/products/data_warehouse/frontend/shared/filterMaterializedViewsByStatus.tsnew file mode 100644index 000000000000..bcec33b853f2--- /dev/null+++ b/products/data_warehouse/frontend/shared/filterMaterializedViewsByStatus.ts@@ -0,0 +1,30 @@+import type { TreeDataItem } from 'lib/lemon-ui/LemonTree/LemonTree'++export const MATERIALIZATION_STATUS_FILTER_OPTIONS = ['Failed', 'Running', 'Completed'] as const+export type MaterializationStatusFilter = (typeof MATERIALIZATION_STATUS_FILTER_OPTIONS)[number]++export function filterMaterializedViewsByStatus(+ items: TreeDataItem[],+ statuses: MaterializationStatusFilter[]+): TreeDataItem[] {+ if (statuses.length === 0) {+ return items+ }++ return items.flatMap((item) => {+ if (item.record?.type === 'view') {+ return item.record.view?.is_materialized && statuses.includes(item.record.view.status) ? [item] : []+ }++ if (item.type === 'loading-indicator') {+ return [item]+ }++ if (item.record?.type === 'views' || item.record?.folderType === 'view-folder') {+ const children = filterMaterializedViewsByStatus(item.children ?? [], statuses)+ return children.length ? [{ ...item, children }] : []+ }++ return []+ })+}