: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(warehouse-suggestions): show view deprecations on the models page (#129501)
Thiago Salvatored716b72754ce
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex b2e9b2b93e52..07cba91aa993 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -17503,13 +17503,21 @@ snapshots:warehouse-suggestions-suggested-certifications--review-dialog-narrow--light:hash: v1.k794b7964.b50eac0dbd82aa276d178cebb9041a89ba689f376f3b8509b910aa3a291a4441.6LJGfUarId3i8ZJYqoBfGZ1zaK_btz8bo1q6t4RSs38warehouse-suggestions-suggested-models-strip--banner--dark:- hash: v1.k794b7964.f4b1753fb8f7f72bc726754edc2af9890d58bad769aef29e0535aaaa9862a0cb.DJOIQ1B3uve853HT-qkIbooHSJMhcVHE1F0DGqrTQ0g+ hash: v1.k794b7964.f13038333d85596e78433d59a195551bf3f063f91fcda1c78f7f4e80dba15058.YFZGD2-XpWYmpuX2y-EwjnOEjH_O2EZ5INA391J4Z9Uwarehouse-suggestions-suggested-models-strip--banner--light:- hash: v1.k794b7964.067b7d595dfb3c45861e60e1c479bcf3b1093e748f996ae628b60d8e3582449a.e4cUdU_PGjeC9mqyBHwozZ8UhuFadtIVbU2HV2_d9tA+ hash: v1.k794b7964.e3a1aa45322e24759f41bd453727d30f997171c5bfccca831a99b60c06470b04.0cHZECH2pSaeFVsapH3DNwc4inzITbn9LMM6mfc0Ohowarehouse-suggestions-suggested-models-strip--banner-narrow--dark:- hash: v1.k794b7964.6d5603167d875c5dd2e3a48a329e18d5ac951d63471d833ed1384d1c18761212.4UrtyPwOVvgs4Kl-9zJsXXgzYwJs8d1IIanHEcjCMes+ hash: v1.k794b7964.b7cdf1c4640f97ebd320e7b508154f482ff8c059cbfcc8e70098caf020e57b2d.-OvK0B2qHjdD00ClAvyX-cPkDgYqxbLGepGHg8Txkhgwarehouse-suggestions-suggested-models-strip--banner-narrow--light:- hash: v1.k794b7964.4e1894a911c620104b0cb8a776ccaab6b31818a2733caa0a6cb5ea414e5c009c.qOnUdghMNhGn8b9VTGLfRwpF5XA5e6TKTfAv97cFjeo+ hash: v1.k794b7964.0bd4bbd234b540089209175bc2f99b89c5b9649ca66260f924475ef79e455a1d.bxp2bHO6p5KAzK9aCPfvmSNFCvtsm4wfNE-loI6HZcs+ warehouse-suggestions-suggested-models-strip--banner-only-unused-views--dark:+ hash: v1.k794b7964.76743b55c1028b1c7e38da8a5de81f9183c254393077d1230b6fbd2d0d11eac3.Qy7i57Rpp-Iv-RT9s5C2GFt8shOHOh69gXwop9Hrmho+ warehouse-suggestions-suggested-models-strip--banner-only-unused-views--light:+ hash: v1.k794b7964.a6e1659dc0f0ab61aa58d59b693abce554b0cf6fceb86ee201eef02bece5c8d2.NiDGIw_3v_8WlASuCbYc40qwoGPANEZY9QMNpC8t5dM+ warehouse-suggestions-suggested-models-strip--deprecate-dialog--dark:+ hash: v1.k794b7964.af4db1942d749b712d8fc5f84904ad4794779e1c6092ab4a02ca8a6077838aa0.FWGXoZOh8vJxyzQzA9buipVncdjOadieQwcUlHzhEg4+ warehouse-suggestions-suggested-models-strip--deprecate-dialog--light:+ hash: v1.k794b7964.4b6f6ea963d6d689f2b3e471ad1e20af85d81b2a2dddea0a04445c745afd372b.J6Laj881jdUETbhvv5pJHRCoR6l1EcnCX16_3AWi7jswarehouse-suggestions-suggested-models-strip--load-failed--dark:hash: v1.k794b7964.d93ab3575b7bebf7f869bc5b41c0a8e0581679f22bd0251c31f031b0f43ee7c0.iXXukenkQJA0ayAlRoqei_RQx1XW-b9MLaTjdhxfkoMwarehouse-suggestions-suggested-models-strip--load-failed--light:@@ -17527,9 +17535,9 @@ snapshots:warehouse-suggestions-suggested-models-strip--not-eligible--light:hash: v1.k794b7964.a66ac5be916b459b6f8b15621e3bdeb12226d34c1e24feb15900940652fc238b.gzxwnKSQkZQfg5wdIMriKJO-aaxIteiXVzfSx1R7w8cwarehouse-suggestions-suggested-models-strip--review-dialog--dark:- hash: v1.k794b7964.3ce6732f7e7e53eed4c1b97ae82d929f55597946c16dc485a44033e87c0d812e.jXmFDVw5SUPT6kShyBsznWyAfdlqs0kK1RFF8SJFxsY+ hash: v1.k794b7964.e38b8a7b93ed61e6eb2cadd6084054b4bc36b90733239e56296b019a914ecbd2.i0bFtzmKZGc491w7NhsyPbTkV5-0BCGrdoVMljpgxb0warehouse-suggestions-suggested-models-strip--review-dialog--light:- hash: v1.k794b7964.a3626ebfb53ca9f53ee5e6437d50163c686a5fcc56a2fa3a7223751d110462c9.hVKPaFbueFpouk0eaqw0FHLM_tXQFyAomVQCr9vxYfs+ hash: v1.k794b7964.7bb063f441497d7450405e81db40fe06e522af0ef73f117e3400610ef9d3c7e9.8H5nTOySUs4OpkpKTQ0TqqWt07A-rh9UDmsU0VlzfAwwarehouse-suggestions-suggested-models-strip--review-dialog-many-suggestions--dark:hash: v1.k794b7964.825b125bcc53a5c7f1141c6b51fb2bd4f0d5afdf70858a557571f30d619241d8.q0jvTBZUDDrMwbWchF-gUZ1_QRtCdguQA0xWIZvIjiUwarehouse-suggestions-suggested-models-strip--review-dialog-many-suggestions--light:@@ -17539,9 +17547,9 @@ snapshots:warehouse-suggestions-suggested-models-strip--review-dialog-viewer-without-edit-access--light:hash: v1.k794b7964.384d979d79f514d57c0437cb8537aa33c3cb9605bae6b4232bfb6a0d0780ab1f.mpr7tkufxhbHtPc7hVRiYubOViBJqijmVf_V0Fud2vUwarehouse-suggestions-suggested-models-strip--stop-materializing-dialog--dark:- hash: v1.k794b7964.3de8918a7d4549c7b94f1880811300aa0be9ad3b43f0ca0ddbf7ce4263cbff5f.JEGq_DJuFHfCX_EXG0nFvX009s0vOUZj8_mSnZTXKEE+ hash: v1.k794b7964.ab21d8969f6d8ab3f060364500d9cbffab46d3ce8b6636ccfd48eccc43ae1d5b.8Oz67H_QqJVyCcqWuAyHmdkfpfHgKjn4k_f91EW7f3Mwarehouse-suggestions-suggested-models-strip--stop-materializing-dialog--light:- hash: v1.k794b7964.2d92023ad6d3dc2226605434a4ae789ddae657f3f8a5750a6279a55780ad4139.DnwVKCy6Pmp3hY9LRaIzCtirVwlhWxThIosF4FZV35g+ hash: v1.k794b7964.ccdcc6c3bf48edcdf8f6c8189d5bf9c79a5bafbca81f70c1bc3e14012f6125f1.HE_-Gp5rsmRGdbcX4vjdZ4TYOVpbn3oNnWouM8BpEeswarehouse-suggestions-suggested-models-strip--warming-up--dark:hash: v1.k794b7964.860407091149fedd6c4e056cda79d92213e59dd9e00886e0cedee320fc267c48.x5QcsRUSRT66uOc237oq_n4D-eQWpY2GzsTRTC-SL6wwarehouse-suggestions-suggested-models-strip--warming-up--light:diff --git a/products/data_modeling/frontend/viewsTabLogic.test.ts b/products/data_modeling/frontend/viewsTabLogic.test.tsindex 00fdc17b52ba..529b28140419 100644--- a/products/data_modeling/frontend/viewsTabLogic.test.ts+++ b/products/data_modeling/frontend/viewsTabLogic.test.ts@@ -3,6 +3,7 @@ import { expectLogic } from 'kea-test-utils'import { LemonDialog } from '@posthog/lemon-ui'import { lemonToast } from 'lib/lemon-ui/LemonToast'+import { databaseTableListLogic } from 'scenes/data-management/database/databaseTableListLogic'import { dataWarehouseViewsLogic } from 'scenes/data-warehouse/saved_queries/dataWarehouseViewsLogic'import { useMocks } from '~/mocks/jest'@@ -129,6 +130,12 @@ describe('viewsTabLogic', () => {})+ it('reloads the database schema so certification tags follow an accepted suggestion', async () => {+ await expectLogic(logic, () => logic.actions.suggestionAccepted('mat-0', false)).toDispatchActions([+ databaseTableListLogic.actionCreators.refreshDatabaseSchema(),+ ])+ })+it('keeps polling an accepted materialize until the view reports it is materialized', async () => {logic.actions.suggestionAccepted('plain-a', true)await expectLogic(dataWarehouseViewsLogic).toFinishAllListeners()diff --git a/products/data_modeling/frontend/viewsTabLogic.ts b/products/data_modeling/frontend/viewsTabLogic.tsindex 73f5a24fe7b4..f81367a1ed0d 100644--- a/products/data_modeling/frontend/viewsTabLogic.ts+++ b/products/data_modeling/frontend/viewsTabLogic.ts@@ -86,6 +86,9 @@ export interface viewsTabLogicActions {force?: booleanshallow?: boolean} // databaseTableListLogic+ refreshDatabaseSchema: () => {+ value: true+ } // databaseTableListLogiccloseAccessControlModal: () => {value: true}@@ -191,7 +194,7 @@ export const viewsTabLogic = kea<viewsTabLogicType>(['loadDataWarehouseSavedQueriesSuccess',],databaseTableListLogic,- ['loadDatabase'],+ ['loadDatabase', 'refreshDatabaseSchema'],],})),actions({@@ -372,6 +375,7 @@ export const viewsTabLogic = kea<viewsTabLogicType>([actions.addMaterializingViews([viewId])}actions.loadDataWarehouseSavedQueries()+ actions.refreshDatabaseSchema()},loadDataWarehouseSavedQueriesSuccess: () => {const lastPage = Math.max(1, Math.ceil(values.filteredViews.length / PAGE_SIZE))diff --git a/products/warehouse_suggestions/backend/facade/api.py b/products/warehouse_suggestions/backend/facade/api.pyindex 4ff553ab7460..16434212cfe7 100644--- a/products/warehouse_suggestions/backend/facade/api.py+++ b/products/warehouse_suggestions/backend/facade/api.py@@ -36,6 +36,7 @@ from .enums import (WarehouseSuggestionKind,WarehouseSuggestionStatus,WarehouseSuggestionSubjectKind,+ WarehouseSuggestionSurface,)if TYPE_CHECKING:@@ -116,6 +117,7 @@ def dismiss_suggestion(reason: WarehouseSuggestionDismissalReason,note: str | None,subject_kinds: SubjectKinds,+ surface: WarehouseSuggestionSurface | None = None,) -> Suggestion:row, access = _actionable_suggestion(team.pk, user_access_control, suggestion_id, subject_kinds)dismissed = suggestions.transition_to(@@ -127,7 +129,7 @@ def dismiss_suggestion(note=note,transitions=suggestions.HUMAN_TRANSITIONS,)- report_outcomes(SuggestionOutcome.DISMISSED, [dismissed], team=team, user=user)+ report_outcomes(SuggestionOutcome.DISMISSED, [dismissed], team=team, user=user, properties={"surface": surface})return _single_contract(team.pk, user_access_control, dismissed, access)@@ -178,9 +180,11 @@ def accept_suggestion(options: AcceptOptions,was_impersonated: bool,subject_kinds: SubjectKinds,+ surface: WarehouseSuggestionSurface | None = None,) -> Suggestion:row, access = _actionable_suggestion(team.pk, user_access_control, suggestion_id, subject_kinds)- _require_catalog_edit_access(row, user_access_control)+ if not options.delete_view:+ _require_catalog_edit_access(row, user_access_control)outcome = accept.accept(team.pk,row.id,@@ -192,7 +196,7 @@ def accept_suggestion([outcome.suggestion],team=team,user=user,- properties={"changed_fields": list(outcome.changed_fields), **asdict(outcome.savings)},+ properties={"changed_fields": list(outcome.changed_fields), "surface": surface, **asdict(outcome.savings)},)return _single_contract(team.pk, user_access_control, outcome.suggestion, access)diff --git a/products/warehouse_suggestions/backend/facade/enums.py b/products/warehouse_suggestions/backend/facade/enums.pyindex 2d46298386dd..d2ea647fdb81 100644--- a/products/warehouse_suggestions/backend/facade/enums.py+++ b/products/warehouse_suggestions/backend/facade/enums.py@@ -35,6 +35,11 @@ class WarehouseSuggestionAssetOutcome(LabeledStrEnum):UNUSED = "unused"+class WarehouseSuggestionSurface(LabeledStrEnum):+ MODELS = "models"+ CATALOG = ("catalog", "Data catalog")++class WarehouseSuggestionRefreshMode(LabeledStrEnum):FULL = "full"INCREMENTAL = "incremental"diff --git a/products/warehouse_suggestions/backend/presentation/serializers.py b/products/warehouse_suggestions/backend/presentation/serializers.pyindex 6ec608c90dd2..91b14d0ce072 100644--- a/products/warehouse_suggestions/backend/presentation/serializers.py+++ b/products/warehouse_suggestions/backend/presentation/serializers.py@@ -30,6 +30,7 @@ from ..facade.enums import (WarehouseSuggestionRefreshMode,WarehouseSuggestionStatus,WarehouseSuggestionSubjectKind,+ WarehouseSuggestionSurface,)MAX_REFRESH_INTERVAL_SECONDS = int(timedelta(days=30).total_seconds())@@ -341,6 +342,14 @@ class WarehouseSuggestionListQuerySerializer(serializers.Serializer):)+class WarehouseSuggestionDecisionQuerySerializer(serializers.Serializer):+ surface = serializers.ChoiceField(+ choices=WarehouseSuggestionSurface.choices,+ required=False,+ help_text="Page the decision was made on. Only recorded on the analytics event.",+ )++class AssignWarehouseSuggestionSerializer(serializers.Serializer):assignee_id = serializers.IntegerField(allow_null=True,diff --git a/products/warehouse_suggestions/backend/presentation/views.py b/products/warehouse_suggestions/backend/presentation/views.pyindex 329d56ff1c46..ab029759356d 100644--- a/products/warehouse_suggestions/backend/presentation/views.py+++ b/products/warehouse_suggestions/backend/presentation/views.py@@ -44,11 +44,17 @@ from ..facade.contracts import (SuggestionOutdatedError,SuggestionSubjectGoneError,)-from ..facade.enums import WarehouseSuggestionKind, WarehouseSuggestionStatus, WarehouseSuggestionSubjectKind+from ..facade.enums import (+ WarehouseSuggestionKind,+ WarehouseSuggestionStatus,+ WarehouseSuggestionSubjectKind,+ WarehouseSuggestionSurface,+)from .serializers import (AcceptWarehouseSuggestionSerializer,AssignWarehouseSuggestionSerializer,DismissWarehouseSuggestionSerializer,+ WarehouseSuggestionDecisionQuerySerializer,WarehouseSuggestionListQuerySerializer,WarehouseSuggestionSerializer,WarehouseSuggestionStatusSerializer,@@ -79,6 +85,11 @@ ACCEPT_SCOPES = ["data_catalog_approval:write", "warehouse_view:write"]ScopeLevel = Literal["read", "write"]+def _surface(request: ValidatedRequest) -> WarehouseSuggestionSurface | None:+ surface = request.validated_query_data.get("surface")+ return WarehouseSuggestionSurface(surface) if surface else None++class SuggestionPagination(FacadeLimitOffsetPagination):default_limit = DEFAULT_PAGE_SIZEmax_limit = DEFAULT_PAGE_SIZE@@ -172,6 +183,7 @@ class WarehouseSuggestionViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet@validated_request(request_serializer=DismissWarehouseSuggestionSerializer,+ query_serializer=WarehouseSuggestionDecisionQuerySerializer,responses={200: OpenApiResponse(response=WarehouseSuggestionSerializer)},)@action(detail=True, methods=["post"])@@ -185,11 +197,13 @@ class WarehouseSuggestionViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSetreason=request.validated_data["reason"],note=request.validated_data.get("note") or None,subject_kinds=self._subject_kinds,+ surface=_surface(request),))@validated_request(request_serializer=AcceptWarehouseSuggestionSerializer,+ query_serializer=WarehouseSuggestionDecisionQuerySerializer,responses={200: OpenApiResponse(response=WarehouseSuggestionSerializer)},)@action(detail=True, methods=["post"])@@ -203,6 +217,7 @@ class WarehouseSuggestionViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSetoptions=request.validated_data,was_impersonated=is_impersonated(request),subject_kinds=self._subject_kinds,+ surface=_surface(request),))diff --git a/products/warehouse_suggestions/backend/tests/test_accept.py b/products/warehouse_suggestions/backend/tests/test_accept.pyindex 24dffb4754c7..40a5a3568803 100644--- a/products/warehouse_suggestions/backend/tests/test_accept.py+++ b/products/warehouse_suggestions/backend/tests/test_accept.py@@ -259,8 +259,8 @@ class TestAcceptSuggestion(APIBaseTest):draft = make_draft(fingerprint="materialize:orders", subject_id=self.view.id)return ingest_surfaced(self.team.id, replace(draft, kind=WarehouseSuggestionKind.MATERIALIZE, payload=payload))- def _accept(self, suggestion_id: UUID, body: dict | None = None) -> dict:- response = self.client.post(f"{self.url}/{suggestion_id}/accept/", body or {})+ def _accept(self, suggestion_id: UUID, body: dict | None = None, query: str = "") -> dict:+ response = self.client.post(f"{self.url}/{suggestion_id}/accept/{query}", body or {})return {**response.json(), "http_status": response.status_code}def _certification_status(self) -> str | None:@@ -292,10 +292,12 @@ class TestAcceptSuggestion(APIBaseTest):suggestion = self._suggest(WarehouseSuggestionKind.CERTIFY)with patch(REPORT) as report:- self._accept(suggestion.id)+ self._accept(suggestion.id, query="?surface=models")self._accept(suggestion.id)- assert [call.args[0] for call in report.call_args_list] == ["warehouse suggestion accepted"]+ assert [(call.args[0], call.args[1]["surface"]) for call in report.call_args_list] == [+ ("warehouse suggestion accepted", "models")+ ]@parameterized.expand([@@ -466,6 +468,31 @@ class TestAcceptSuggestion(APIBaseTest):else None)+ @parameterized.expand(+ [+ ("mark_deprecated", {}, status.HTTP_403_FORBIDDEN),+ ("delete", {"delete_view": True}, status.HTTP_200_OK),+ ]+ )+ def test_a_catalog_viewer_can_delete_an_unused_view_but_not_mark_it_deprecated(+ self, _name: str, body: dict, expected_http_status: int+ ) -> None:+ suggestion = self._suggest_deprecate()+ self.organization.available_product_features = [+ {"key": AvailableFeature.ACCESS_CONTROL, "name": AvailableFeature.ACCESS_CONTROL}+ ]+ self.organization.save(update_fields=["available_product_features"])+ create_access_control(+ team_id=self.team.id,+ resource="data_catalog",+ access_level="viewer",+ organization_member_id=self.organization_membership.id,+ )++ accepted = self._accept(suggestion.id, body)++ assert accepted["http_status"] == expected_http_status, accepted+def test_a_second_accept_cannot_turn_a_deprecation_into_a_delete(self) -> None:suggestion = self._suggest_deprecate()self._accept(suggestion.id)diff --git a/products/warehouse_suggestions/backend/tests/test_today_highlights.py b/products/warehouse_suggestions/backend/tests/test_today_highlights.pyindex a421ac882294..3d4c180fbe88 100644--- a/products/warehouse_suggestions/backend/tests/test_today_highlights.py+++ b/products/warehouse_suggestions/backend/tests/test_today_highlights.py@@ -134,6 +134,7 @@ class TestModelSuggestionsHighlight(BaseTest):def test_counts_the_open_model_suggestions_the_viewer_can_act_on(self) -> None:self._suggest(WarehouseSuggestionKind.MATERIALIZE, self._view("orders").id)self._suggest(WarehouseSuggestionKind.UNMATERIALIZE, self._view("events_daily").id)+ self._suggest(WarehouseSuggestionKind.DEPRECATE, self._view("old_rollup").id)self._suggest(WarehouseSuggestionKind.CERTIFY, self._view("users").id)ingest_one(self.team.id, self._draft(WarehouseSuggestionKind.MATERIALIZE, self._view("unsurfaced").id))dismissed = self._suggest(WarehouseSuggestionKind.MATERIALIZE, self._view("dismissed").id)@@ -145,7 +146,7 @@ class TestModelSuggestionsHighlight(BaseTest):found = today_highlights.find_model_suggestions(self._context())assert [(item.title, item.detail, item.url) for item in found.items] == [- ("2 model suggestions wait for review", "Review them in Models.", "/models?tab=models")+ ("3 model suggestions wait for review", "Review them in Models.", "/models?tab=models")]@parameterized.expand(diff --git a/products/warehouse_suggestions/backend/today_highlights.py b/products/warehouse_suggestions/backend/today_highlights.pyindex cfcccb15e4db..19b31fc97ca8 100644--- a/products/warehouse_suggestions/backend/today_highlights.py+++ b/products/warehouse_suggestions/backend/today_highlights.py@@ -16,7 +16,10 @@ ONE_DETAIL = "Review it in the data catalog."MANY_DETAIL = "Review them in the data catalog."CERTIFICATION_SUGGESTION_NOUN = "certification suggestion"-MODEL_KINDS = frozenset({WarehouseSuggestionKind.MATERIALIZE, WarehouseSuggestionKind.UNMATERIALIZE})+MODEL_KINDS = frozenset(+ {WarehouseSuggestionKind.MATERIALIZE, WarehouseSuggestionKind.UNMATERIALIZE, WarehouseSuggestionKind.DEPRECATE}+)+MODEL_SUBJECT_KINDS = frozenset({WarehouseSuggestionSubjectKind.SAVED_QUERY})ONE_MODEL_TITLE = "1 model suggestion waits for review"MANY_MODEL_TITLE = "{count} model suggestions wait for review"ONE_MODEL_DETAIL = "Review it in Models."@@ -50,7 +53,7 @@ def find_catalog_approvals(context: HighlightContext) -> HighlightFindings:def find_model_suggestions(context: HighlightContext) -> HighlightFindings:- count = _open_count(context, MODEL_KINDS)+ count = _open_count(context, MODEL_KINDS, MODEL_SUBJECT_KINDS)if not count:return HighlightFindings()one = count == 1@@ -86,8 +89,12 @@ def _pending_groups(context: HighlightContext) -> list[PendingGroup]:return groups-def _open_count(context: HighlightContext, kinds: frozenset[WarehouseSuggestionKind]) -> int:- return actionable_open_count(context.team, context.user, kinds, _writable_subject_kinds(context))+def _open_count(+ context: HighlightContext,+ kinds: frozenset[WarehouseSuggestionKind],+ subject_kinds: frozenset[WarehouseSuggestionSubjectKind] = frozenset(WarehouseSuggestionSubjectKind),+) -> int:+ return actionable_open_count(context.team, context.user, kinds, _writable_subject_kinds(context) & subject_kinds)def _writable_subject_kinds(context: HighlightContext) -> frozenset[WarehouseSuggestionSubjectKind]:diff --git a/products/warehouse_suggestions/frontend/components/CertificationSuggestionRow.tsx b/products/warehouse_suggestions/frontend/components/CertificationSuggestionRow.tsxindex 7e8dc0a1ab56..e024442e55d5 100644--- a/products/warehouse_suggestions/frontend/components/CertificationSuggestionRow.tsx+++ b/products/warehouse_suggestions/frontend/components/CertificationSuggestionRow.tsx@@ -3,21 +3,17 @@ import { useActions, useValues } from 'kea'import { IconCheckCircle, IconWarning } from '@posthog/icons'import { LemonButton, Tooltip } from '@posthog/lemon-ui'-import { userHasAccess } from 'lib/utils/accessControlUtils'-import { iconForType } from '~/layout/panel-layout/ProjectTree/defaultTree'-import { AccessControlLevel, AccessControlResourceType } from '~/types'import type { WarehouseSuggestionApi } from '../generated/api.schemas'import { daysReadLabel, isDeprecatePayload, noReadsLabel, readSummary, refreshCostLabel } from '../suggestionCopy'-import { warehouseSuggestionsLogic } from '../warehouseSuggestionsLogic'+import { catalogEditBlockedReason, warehouseSuggestionsLogic } from '../warehouseSuggestionsLogic'import { DismissSuggestionButtons } from './DismissSuggestionButtons'import { SuggestionRow } from './SuggestionRow'import { SuggestionSubjectLink } from './SuggestionSubjectLink'import { WhyThisSuggestion } from './WhyThisSuggestion'const EDIT_ACCESS_REASON = 'You need edit access to this view or table'-const CATALOG_EDIT_ACCESS_REASON = 'You need edit access to the data catalog'export interface CertificationSuggestionRowProps {suggestion: WarehouseSuggestionApi@@ -32,14 +28,10 @@ export function CertificationSuggestionRow({ suggestion, windowDays }: Certificaconst leaving = leavingSuggestionIds.includes(suggestion.id)const inFlight = !!actionsInFlight[suggestion.id]const blockedReason = !suggestion.can_act ? EDIT_ACCESS_REASON : leaving ? 'Working' : undefined- const acceptBlockedReason =- blockedReason ??- (userHasAccess(AccessControlResourceType.DataCatalog, AccessControlLevel.Editor)- ? undefined- : CATALOG_EDIT_ACCESS_REASON)const deprecating = isDeprecatePayload(payload)const refreshes = deprecating && payload.materialized !== falseconst confirmsFirst = deprecating && !isTable+ const acceptBlockedReason = blockedReason ?? (confirmsFirst ? undefined : catalogEditBlockedReason())return (<SuggestionRowdiff --git a/products/warehouse_suggestions/frontend/components/DeprecateSuggestionModal.tsx b/products/warehouse_suggestions/frontend/components/DeprecateSuggestionModal.tsxindex e5c98fd7b8f7..f7a5967a0c0f 100644--- a/products/warehouse_suggestions/frontend/components/DeprecateSuggestionModal.tsx+++ b/products/warehouse_suggestions/frontend/components/DeprecateSuggestionModal.tsx@@ -5,7 +5,7 @@ import { LemonButton, LemonModal } from '@posthog/lemon-ui'import { LemonRadio, LemonRadioOption } from 'lib/lemon-ui/LemonRadio'import { deleteDisabledReason, isDeprecatePayload, noReadsLabel, refreshCostLabel } from '../suggestionCopy'-import { warehouseSuggestionsLogic } from '../warehouseSuggestionsLogic'+import { catalogEditBlockedReason, warehouseSuggestionsLogic } from '../warehouseSuggestionsLogic'type RefreshChoice = 'stop' | 'keep'type ActionChoice = 'deprecate' | 'delete'@@ -55,10 +55,12 @@ export function DeprecateSuggestionModal(): JSX.Element | null {const materialized = payload.materialized !== falseconst windowDays = status?.window_days ?? 0const noReads = noReadsLabel(windowDays)- const deleteBlockedReason = deleteDisabledReason(acceptConfirmSuggestion.evidence, windowDays)- const actionChoices = ACTION_CHOICES.map((choice) =>- choice.value === 'delete' ? { ...choice, disabledReason: deleteBlockedReason } : choice- )+ const blockedReasons: Record<ActionChoice, string | undefined> = {+ deprecate: catalogEditBlockedReason(),+ delete: deleteDisabledReason(acceptConfirmSuggestion.evidence, windowDays),+ }+ const actionChoices = ACTION_CHOICES.map((choice) => ({ ...choice, disabledReason: blockedReasons[choice.value] }))+ const chosen: ActionChoice = deleteView ? 'delete' : 'deprecate'return (<LemonModal@@ -79,6 +81,7 @@ export function DeprecateSuggestionModal(): JSX.Element | null {type="primary"status={deleteView ? 'danger' : undefined}loading={inFlight}+ disabledReason={blockedReasons[chosen]}onClick={() => confirmAccept()}data-attr={deleteView@@ -99,7 +102,7 @@ export function DeprecateSuggestionModal(): JSX.Element | null {<h4 className="m-0 text-sm font-semibold">What to do</h4><LemonRadioaria-label="What to do"- value={deleteView ? 'delete' : 'deprecate'}+ value={chosen}onChange={(choice) => setDeleteView(choice === 'delete')}options={actionChoices}radioPosition="top"diff --git a/products/warehouse_suggestions/frontend/components/SavingsBannerMessage.tsx b/products/warehouse_suggestions/frontend/components/SavingsBannerMessage.tsxindex 13cf3d64536d..8e93fcfa223f 100644--- a/products/warehouse_suggestions/frontend/components/SavingsBannerMessage.tsx+++ b/products/warehouse_suggestions/frontend/components/SavingsBannerMessage.tsx@@ -1,13 +1,22 @@-import { SavingsSummary, bannerSavings, countOf, summarySavings } from '../suggestionCopy'+import { SavingsSummary, bannerSavings, countOf, summarySavings, unusedViewsNote } from '../suggestionCopy'export interface SavingsBannerMessageProps {summary: SavingsSummary+ unusedViews: number}-export function SavingsBannerMessage({ summary }: SavingsBannerMessageProps): JSX.Element {+export function SavingsBannerMessage({ summary, unusedViews }: SavingsBannerMessageProps): JSX.Element {+ if (summary.views === 0) {+ return (+ <span translate="no">+ <strong>{countOf(unusedViews, 'unused view', 'unused views')}</strong>+ <span> to mark deprecated</span>+ </span>+ )+ }const savings = summarySavings(summary)if (!savings) {- return <LegacySavingsMessage summary={summary} />+ return <LegacySavingsMessage summary={summary} unusedViews={unusedViews} />}return (<span className="flex flex-col gap-0.5">@@ -23,13 +32,13 @@ export function SavingsBannerMessage({ summary }: SavingsBannerMessageProps): JS<span translate="no">{savings.headline}</span>)}<span translate="no" className="text-xs text-secondary">- {savings.detail}+ {`${savings.detail}${unusedViewsNote(unusedViews)}`}</span></span>)}-function LegacySavingsMessage({ summary }: SavingsBannerMessageProps): JSX.Element {+function LegacySavingsMessage({ summary, unusedViews }: SavingsBannerMessageProps): JSX.Element {return (<><strong translate="no">{countOf(summary.views, 'view', 'views')}</strong>@@ -44,6 +53,7 @@ function LegacySavingsMessage({ summary }: SavingsBannerMessageProps): JSX.Eleme</span>))}<span> a month</span>+ <span translate="no">{unusedViewsNote(unusedViews)}</span></>)}diff --git a/products/warehouse_suggestions/frontend/components/SuggestedModelsSection.tsx b/products/warehouse_suggestions/frontend/components/SuggestedModelsSection.tsxindex 86c0ca88ec51..bea46d14ea6a 100644--- a/products/warehouse_suggestions/frontend/components/SuggestedModelsSection.tsx+++ b/products/warehouse_suggestions/frontend/components/SuggestedModelsSection.tsx@@ -7,10 +7,16 @@ import { SAVING_COLUMNS_CLASS } from './SuggestionRow'export interface SuggestedModelsSectionProps {title: stringdescription: string+ showsSaving?: booleanchildren: ReactNode}-export function SuggestedModelsSection({ title, description, children }: SuggestedModelsSectionProps): JSX.Element {+export function SuggestedModelsSection({+ title,+ description,+ showsSaving = true,+ children,+}: SuggestedModelsSectionProps): JSX.Element {return (<section aria-label={title}><div className={cn('grid grid-cols-1 items-end px-3 pt-4 pb-1', SAVING_COLUMNS_CLASS)}>@@ -18,9 +24,11 @@ export function SuggestedModelsSection({ title, description, children }: Suggest<h4 className="m-0 text-sm font-semibold">{title}</h4><span className="text-xs text-secondary">{description}</span></div>- <span className="hidden text-right text-xs text-secondary @min-[36rem]/suggestions:block">- Main saving a month- </span>+ {showsSaving && (+ <span className="hidden text-right text-xs text-secondary @min-[36rem]/suggestions:block">+ Main saving a month+ </span>+ )}</div><div className="divide-y divide-primary">{children}</div></section>diff --git a/products/warehouse_suggestions/frontend/components/SuggestedModelsStrip.stories.tsx b/products/warehouse_suggestions/frontend/components/SuggestedModelsStrip.stories.tsxindex e3e6ecb55763..b99f1f217dff 100644--- a/products/warehouse_suggestions/frontend/components/SuggestedModelsStrip.stories.tsx+++ b/products/warehouse_suggestions/frontend/components/SuggestedModelsStrip.stories.tsx@@ -118,6 +118,21 @@ function unmaterialize(id: string, name: string): WarehouseSuggestionApi {}}+function deprecate(id: string, name: string): WarehouseSuggestionApi {+ const base = materialize(id, name, 0)+ return {+ ...base,+ kind: 'deprecate',+ payload: {+ subject_name: name,+ materialized: true,+ refresh_seconds_per_month: 2700,+ refresh_bytes_per_month: 2 * 10 ** 12,+ },+ evidence: { human_requests: 0, human_users: 0, human_days: 0, days_with_data: 30 },+ }+}+const suggestions = [materialize('1', 'customer_monthly_revenue', 1080, { backgroundSeconds: -720, readSeconds: 45 }),materialize('2', 'team_usage_rollup', 32400, { backgroundSeconds: 32400, main: 'background' }),@@ -127,6 +142,7 @@ const suggestions = [savedBytes: 100 * 10 ** 12,}),unmaterialize('4', 'legacy_signup_funnel'),+ deprecate('5', 'old_campaign_rollup'),]const manySuggestions = Array.from({ length: 7 }, (_, index) =>@@ -254,3 +270,12 @@ export const StopMaterializingDialog: Story = {args: { confirmSuggestionId: '4' },parameters: DIALOG_SNAPSHOT,}++export const BannerOnlyUnusedViews: Story = {+ args: { results: [deprecate('5', 'old_campaign_rollup'), deprecate('6', 'q3_signup_export')] },+}++export const DeprecateDialog: Story = {+ args: { confirmSuggestionId: '5' },+ parameters: DIALOG_SNAPSHOT,+}diff --git a/products/warehouse_suggestions/frontend/components/SuggestedModelsStripContent.tsx b/products/warehouse_suggestions/frontend/components/SuggestedModelsStripContent.tsxindex c62656b11707..39b4f3752c32 100644--- a/products/warehouse_suggestions/frontend/components/SuggestedModelsStripContent.tsx+++ b/products/warehouse_suggestions/frontend/components/SuggestedModelsStripContent.tsx@@ -7,7 +7,10 @@ import { LemonProgress } from 'lib/lemon-ui/LemonProgress'import { iconForType } from '~/layout/panel-layout/ProjectTree/defaultTree'+import type { WarehouseSuggestionApi } from '../generated/api.schemas'import { warehouseSuggestionsLogic } from '../warehouseSuggestionsLogic'+import { CertificationSuggestionRow } from './CertificationSuggestionRow'+import { DeprecateSuggestionModal } from './DeprecateSuggestionModal'import { MaterializeSuggestionModal } from './MaterializeSuggestionModal'import { MaterializeSuggestionRow } from './MaterializeSuggestionRow'import { SavingsBannerMessage } from './SavingsBannerMessage'@@ -18,7 +21,7 @@ import { SuggestionsStatusNotice } from './SuggestionsStatusNotice'import { UnmaterializeSuggestionModal } from './UnmaterializeSuggestionModal'import { UnmaterializeSuggestionRow } from './UnmaterializeSuggestionRow'-const SECTION_COPY: Record<string, { title: string; description: string }> = {+const SECTION_COPY: Record<string, { title: string; description: string; showsSaving?: boolean }> = {materialize: {title: 'Materialize',description: 'Store these views so reads and other refreshes can reuse their results.',@@ -27,10 +30,25 @@ const SECTION_COPY: Record<string, { title: string; description: string }> = {title: 'Stop materializing',description: 'These views cost more to refresh than to run on each read.',},+ deprecate: {+ title: 'Mark deprecated',+ description: 'No one has read these views recently.',+ showsSaving: false,+ },+}++const ROW_FOR_KIND: Record<+ string,+ (props: { suggestion: WarehouseSuggestionApi; windowDays: number }) => JSX.Element | null+> = {+ materialize: MaterializeSuggestionRow,+ unmaterialize: UnmaterializeSuggestionRow,+ deprecate: CertificationSuggestionRow,}export function SuggestedModelsStripContent(): JSX.Element | null {- const { stripState, suggestionGroups, savingsSummary, status } = useValues(warehouseSuggestionsLogic)+ const { stripState, suggestionGroups, savingsSummary, surfaceSuggestions, status } =+ useValues(warehouseSuggestionsLogic)const { reload } = useActions(warehouseSuggestionsLogic)const windowDays = status?.window_days ?? 0@@ -76,40 +94,25 @@ export function SuggestedModelsStripContent(): JSX.Element | null {return null}+ const unusedViews = surfaceSuggestions.filter((suggestion) => suggestion.kind === 'deprecate').length+ const summary = <SavingsBannerMessage summary={savingsSummary} unusedViews={unusedViews} />+return (<>- {stripState === 'active' && (- <SuggestionsBanner- icon={iconForType('data_modeling')}- message={<SavingsBannerMessage summary={savingsSummary} />}- />- )}- <SuggestionsReviewModal- title="Suggested models"- summary={<SavingsBannerMessage summary={savingsSummary} />}- >+ {stripState === 'active' && <SuggestionsBanner icon={iconForType('data_modeling')} message={summary} />}+ <SuggestionsReviewModal title="Suggested models" summary={summary}>{suggestionGroups.map(({ kind, suggestions }) => (<SuggestedModelsSection key={kind} {...SECTION_COPY[kind]}>- {suggestions.map((suggestion) =>- kind === 'unmaterialize' ? (- <UnmaterializeSuggestionRow- key={suggestion.id}- suggestion={suggestion}- windowDays={windowDays}- />- ) : (- <MaterializeSuggestionRow- key={suggestion.id}- suggestion={suggestion}- windowDays={windowDays}- />- )- )}+ {suggestions.map((suggestion) => {+ const RowComponent = ROW_FOR_KIND[kind] ?? MaterializeSuggestionRow+ return <RowComponent key={suggestion.id} suggestion={suggestion} windowDays={windowDays} />+ })}</SuggestedModelsSection>))}</SuggestionsReviewModal><MaterializeSuggestionModal /><UnmaterializeSuggestionModal />+ <DeprecateSuggestionModal /></>)}diff --git a/products/warehouse_suggestions/frontend/generated/api.schemas.ts b/products/warehouse_suggestions/frontend/generated/api.schemas.tsindex 5b3d4ff8c873..bfad24bc3bf4 100644--- a/products/warehouse_suggestions/frontend/generated/api.schemas.ts+++ b/products/warehouse_suggestions/frontend/generated/api.schemas.ts@@ -511,3 +511,41 @@ export const WarehouseSuggestionsListStatus = {Expired: 'expired',AutoResolved: 'auto_resolved',} as const++export type WarehouseSuggestionsAcceptCreateParams = {+ /**+ * Page the decision was made on. Only recorded on the analytics event.+ *+ * * `models` - Models+ * * `catalog` - Data catalog+ * @minLength 1+ */+ surface?: WarehouseSuggestionsAcceptCreateSurface+}++export type WarehouseSuggestionsAcceptCreateSurface =+ (typeof WarehouseSuggestionsAcceptCreateSurface)[keyof typeof WarehouseSuggestionsAcceptCreateSurface]++export const WarehouseSuggestionsAcceptCreateSurface = {+ Models: 'models',+ Catalog: 'catalog',+} as const++export type WarehouseSuggestionsDismissCreateParams = {+ /**+ * Page the decision was made on. Only recorded on the analytics event.+ *+ * * `models` - Models+ * * `catalog` - Data catalog+ * @minLength 1+ */+ surface?: WarehouseSuggestionsDismissCreateSurface+}++export type WarehouseSuggestionsDismissCreateSurface =+ (typeof WarehouseSuggestionsDismissCreateSurface)[keyof typeof WarehouseSuggestionsDismissCreateSurface]++export const WarehouseSuggestionsDismissCreateSurface = {+ Models: 'models',+ Catalog: 'catalog',+} as constdiff --git a/products/warehouse_suggestions/frontend/generated/api.ts b/products/warehouse_suggestions/frontend/generated/api.tsindex 073cccbc2f15..0681b2cf9e5b 100644--- a/products/warehouse_suggestions/frontend/generated/api.ts+++ b/products/warehouse_suggestions/frontend/generated/api.ts@@ -15,6 +15,8 @@ import type {PaginatedWarehouseSuggestionListApi,WarehouseSuggestionApi,WarehouseSuggestionStatusApi,+ WarehouseSuggestionsAcceptCreateParams,+ WarehouseSuggestionsDismissCreateParams,WarehouseSuggestionsListParams,} from './api.schemas'@@ -60,17 +62,34 @@ export const warehouseSuggestionsRetrieve = async (})}-export const getWarehouseSuggestionsAcceptCreateUrl = (projectId: string, id: string) => {- return `/api/projects/${projectId}/warehouse_suggestions/${id}/accept/`+export const getWarehouseSuggestionsAcceptCreateUrl = (+ projectId: string,+ id: string,+ params?: WarehouseSuggestionsAcceptCreateParams+) => {+ const normalizedParams = new URLSearchParams()++ Object.entries(params || {}).forEach(([key, value]) => {+ if (value !== undefined) {+ normalizedParams.append(key, value === null ? 'null' : String(value))+ }+ })++ const stringifiedParams = normalizedParams.toString()++ return stringifiedParams.length > 0+ ? `/api/projects/${projectId}/warehouse_suggestions/${id}/accept/?${stringifiedParams}`+ : `/api/projects/${projectId}/warehouse_suggestions/${id}/accept/`}export const warehouseSuggestionsAcceptCreate = async (projectId: string,id: string,acceptWarehouseSuggestionApi?: AcceptWarehouseSuggestionApi,+ params?: WarehouseSuggestionsAcceptCreateParams,options?: RequestInit): Promise<WarehouseSuggestionApi> => {- return apiMutator<WarehouseSuggestionApi>(getWarehouseSuggestionsAcceptCreateUrl(projectId, id), {+ return apiMutator<WarehouseSuggestionApi>(getWarehouseSuggestionsAcceptCreateUrl(projectId, id, params), {...options,method: 'POST',headers: { 'Content-Type': 'application/json', ...options?.headers },@@ -96,17 +115,34 @@ export const warehouseSuggestionsAssignCreate = async (})}-export const getWarehouseSuggestionsDismissCreateUrl = (projectId: string, id: string) => {- return `/api/projects/${projectId}/warehouse_suggestions/${id}/dismiss/`+export const getWarehouseSuggestionsDismissCreateUrl = (+ projectId: string,+ id: string,+ params?: WarehouseSuggestionsDismissCreateParams+) => {+ const normalizedParams = new URLSearchParams()++ Object.entries(params || {}).forEach(([key, value]) => {+ if (value !== undefined) {+ normalizedParams.append(key, value === null ? 'null' : String(value))+ }+ })++ const stringifiedParams = normalizedParams.toString()++ return stringifiedParams.length > 0+ ? `/api/projects/${projectId}/warehouse_suggestions/${id}/dismiss/?${stringifiedParams}`+ : `/api/projects/${projectId}/warehouse_suggestions/${id}/dismiss/`}export const warehouseSuggestionsDismissCreate = async (projectId: string,id: string,dismissWarehouseSuggestionApi: DismissWarehouseSuggestionApi,+ params?: WarehouseSuggestionsDismissCreateParams,options?: RequestInit): Promise<WarehouseSuggestionApi> => {- return apiMutator<WarehouseSuggestionApi>(getWarehouseSuggestionsDismissCreateUrl(projectId, id), {+ return apiMutator<WarehouseSuggestionApi>(getWarehouseSuggestionsDismissCreateUrl(projectId, id, params), {...options,method: 'POST',headers: { 'Content-Type': 'application/json', ...options?.headers },diff --git a/products/warehouse_suggestions/frontend/suggestionCopy.ts b/products/warehouse_suggestions/frontend/suggestionCopy.tsindex 85832603670e..f3037f780077 100644--- a/products/warehouse_suggestions/frontend/suggestionCopy.ts+++ b/products/warehouse_suggestions/frontend/suggestionCopy.ts@@ -465,6 +465,10 @@ export function spokenDuration(seconds: number, maxUnits: number): string {return parts.length > 0 ? parts.join(' and ') : 'under a minute'}+export function unusedViewsNote(unusedViews: number): string {+ return unusedViews > 0 ? `. ${countOf(unusedViews, 'unused view', 'unused views')} to mark deprecated` : ''+}+export function countOf(count: number, singular: string, plural: string): string {return `${count} ${count === 1 ? singular : plural}`}diff --git a/products/warehouse_suggestions/frontend/warehouseSuggestionsLogic.test.ts b/products/warehouse_suggestions/frontend/warehouseSuggestionsLogic.test.tsindex 4db00d56bb83..d5549f381eb0 100644--- a/products/warehouse_suggestions/frontend/warehouseSuggestionsLogic.test.ts+++ b/products/warehouse_suggestions/frontend/warehouseSuggestionsLogic.test.ts@@ -3,6 +3,7 @@ import { expectLogic } from 'kea-test-utils'import { ApiError } from 'lib/api-error'import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'+import { userHasAccess } from 'lib/utils/accessControlUtils'import { urls } from 'scenes/urls'import { initKeaTests } from '~/test/init'@@ -24,6 +25,7 @@ import type { WarehouseSuggestionApi, WarehouseSuggestionStatusApi } from './genimport { intervalForSeconds } from './refreshIntervals'import { ROW_LEAVE_MS, StripState, SuggestionSurface, warehouseSuggestionsLogic } from './warehouseSuggestionsLogic'+jest.mock('lib/utils/accessControlUtils', () => ({ userHasAccess: jest.fn(() => true) }))jest.mock('./generated/api', () => ({warehouseSuggestionsAcceptCreate: jest.fn(),warehouseSuggestionsAssignCreate: jest.fn(),@@ -156,6 +158,8 @@ function certification(id: string, kind: 'certify' | 'deprecate'): WarehouseSuggreturn { ...MATERIALIZE, id, kind, subject_kind: 'table', payload: { subject_name: id } }}+const MODELS_SURFACE = { surface: 'models' }+function page(results: WarehouseSuggestionApi[]): Awaited<ReturnType<typeof warehouseSuggestionsList>> {return { count: results.length, results } as Awaited<ReturnType<typeof warehouseSuggestionsList>>}@@ -166,6 +170,7 @@ describe('warehouseSuggestionsLogic', () => {beforeEach(() => {initKeaTests()jest.clearAllMocks()+ jest.mocked(userHasAccess).mockReturnValue(true)mockSavedQuery.mockReset()mockCheck.mockReset()jest.spyOn(lemonToast, 'error').mockImplementation(() => 'toast')@@ -359,7 +364,7 @@ describe('warehouseSuggestionsLogic', () => {logic.actions.confirmMaterialize()await expectLogic(logic).toDispatchActions(['suggestionAccepted'])- expect(mockAccept).toHaveBeenCalledWith(expect.any(String), INCREMENTAL.id, expectedBody)+ expect(mockAccept).toHaveBeenCalledWith(expect.any(String), INCREMENTAL.id, expectedBody, MODELS_SURFACE)})it('materializes with a full refresh when the view can no longer refresh incrementally', async () => {@@ -383,10 +388,12 @@ describe('warehouseSuggestionsLogic', () => {logic.actions.confirmMaterialize()await expectLogic(logic).toDispatchActions(['suggestionAccepted'])- expect(mockAccept).toHaveBeenCalledWith(expect.any(String), INCREMENTAL.id, {- refresh_interval_seconds: 86400,- refresh_mode: 'full',- })+ expect(mockAccept).toHaveBeenCalledWith(+ expect.any(String),+ INCREMENTAL.id,+ { refresh_interval_seconds: 86400, refresh_mode: 'full' },+ MODELS_SURFACE+ )})it('switching a full proposal to incremental sends the mode and the keys', async () => {@@ -399,13 +406,18 @@ describe('warehouseSuggestionsLogic', () => {logic.actions.confirmMaterialize()await expectLogic(logic).toDispatchActions(['suggestionAccepted'])- expect(mockAccept).toHaveBeenCalledWith(expect.any(String), MATERIALIZE.id, {- refresh_interval_seconds: 86400,- refresh_mode: 'incremental',- incremental_key: 'day',- unique_key: ['day'],- lookback_seconds: 0,- })+ expect(mockAccept).toHaveBeenCalledWith(+ expect.any(String),+ MATERIALIZE.id,+ {+ refresh_interval_seconds: 86400,+ refresh_mode: 'incremental',+ incremental_key: 'day',+ unique_key: ['day'],+ lookback_seconds: 0,+ },+ MODELS_SURFACE+ )})it.each<[string, Parameters<typeof logic.actions.setRefreshDraft>[0]]>([@@ -524,6 +536,11 @@ describe('warehouseSuggestionsLogic', () => {],['time-big', 'time-small', 'bytes-big', 'unread-mid'],],+ [+ 'models',+ [DEPRECATE, certification('old-table', 'deprecate'), unmaterialize('scan-led', 0, 0)],+ ['scan-led', DEPRECATE.id],+ ],['catalog', [certification('old', 'deprecate'), certification('used', 'certify')], ['used', 'old']],])('orders %s suggestions by kind, then by what they are worth', async (surface, results, expectedOrder) => {mockList.mockResolvedValue(page(results))@@ -753,11 +770,24 @@ describe('warehouseSuggestionsLogic', () => {logic.actions.confirmAccept()await expectLogic(logic).toDispatchActions(['suggestionAccepted'])- expect(mockAccept).toHaveBeenCalledWith(expect.any(String), DEPRECATE.id, body)+ expect(mockAccept).toHaveBeenCalledWith(expect.any(String), DEPRECATE.id, body, { surface: 'catalog' })expect((lemonToast.success as jest.Mock).mock.calls[0][0]).toEqual(toast)expect(logic.values.acceptConfirmSuggestion).toBeNull()})+ it.each([+ ['marks it deprecated for a data catalog editor', true, false],+ ['deletes it for someone who cannot edit the data catalog', false, true],+ ])('a view deprecation opens on the choice that %s', async (_name, canEditCatalog, expectedDeleteView) => {+ jest.mocked(userHasAccess).mockReturnValue(canEditCatalog)+ mockList.mockResolvedValue(page([DEPRECATE]))+ await mountLogic()++ logic.actions.openAcceptConfirm(DEPRECATE.id)++ expect(logic.values.deleteView).toBe(expectedDeleteView)+ })+it('reloads the list when an accept finds the view or table deleted', async () => {mockAccept.mockRejectedValue(new ApiError('Not found.', 404, undefined, { detail: 'Not found.' }))await mountLogic()diff --git a/products/warehouse_suggestions/frontend/warehouseSuggestionsLogic.ts b/products/warehouse_suggestions/frontend/warehouseSuggestionsLogic.tsindex 4f66207957cd..daa6978a7475 100644--- a/products/warehouse_suggestions/frontend/warehouseSuggestionsLogic.ts+++ b/products/warehouse_suggestions/frontend/warehouseSuggestionsLogic.ts@@ -18,10 +18,11 @@ import posthog from 'posthog-js'import { ApiConfig } from 'lib/api'import { ApiError } from 'lib/api-error'import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'+import { userHasAccess } from 'lib/utils/accessControlUtils'import { isNotNil } from 'lib/utils/guards'import { EMPTY_INCREMENTAL_DRAFT, IncrementalConfigDraft } from 'scenes/data-warehouse/editor/IncrementalConfigFields'-import { DataModelingSyncInterval } from '~/types'+import { AccessControlLevel, AccessControlResourceType, DataModelingSyncInterval } from '~/types'import {warehouseSavedQueriesCheckIncrementalCreate,@@ -71,11 +72,25 @@ export interface WarehouseSuggestionsLogicProps {}export const ROW_LEAVE_MS = 150-const KIND_ORDER: Record<string, number> = { certify: 0, deprecate: 1 }+const CATALOG_EDIT_ACCESS_REASON = 'You need edit access to the data catalog'-const SURFACE_KINDS: Record<SuggestionSurface, string[]> = {- models: ['materialize', 'unmaterialize'],- catalog: ['certify', 'deprecate'],+function canEditDataCatalog(): boolean {+ return userHasAccess(AccessControlResourceType.DataCatalog, AccessControlLevel.Editor)+}++export function catalogEditBlockedReason(): string | undefined {+ return canEditDataCatalog() ? undefined : CATALOG_EDIT_ACCESS_REASON+}++const KIND_ORDER: Record<string, number> = {+ certify: MAIN_SAVING_KINDS.length,+ deprecate: MAIN_SAVING_KINDS.length + 1,+}++const SHOWN_ON_SURFACE: Record<SuggestionSurface, (suggestion: WarehouseSuggestionApi) => boolean> = {+ models: ({ kind, subject_kind }) =>+ kind === 'materialize' || kind === 'unmaterialize' || (kind === 'deprecate' && subject_kind === 'saved_query'),+ catalog: ({ kind }) => kind === 'certify' || kind === 'deprecate',}const VIEW_ON_MODEL_PAGE_KINDS = ['materialize', 'unmaterialize']const CONFLICT_STATUS = 409@@ -641,7 +656,7 @@ export const warehouseSuggestionsLogic: LogicWrapper<warehouseSuggestionsLogicTy(suggestion) =>suggestion.surfaced_at !== null &&!hiddenIds.includes(suggestion.id) &&- SURFACE_KINDS[surface].includes(suggestion.kind)+ SHOWN_ON_SURFACE[surface](suggestion)).sort(compareSuggestions)return groupedByKind(byWorth).flatMap((group) => group.suggestions)@@ -800,14 +815,19 @@ export const warehouseSuggestionsLogic: LogicWrapper<warehouseSuggestionsLogicTy})},openAcceptConfirm: ({ id }) => {+ if (values.acceptConfirmSuggestion?.kind === 'deprecate' && !canEditDataCatalog()) {+ actions.setDeleteView(true)+ }posthog.capture('warehouse suggestion confirm opened', {suggestion_id: id,kind: values.acceptConfirmSuggestion?.kind,+ surface: props.surface,})},closeAcceptConfirm: (_, __, ___, previousState) => {posthog.capture('warehouse suggestion confirm cancelled', {suggestion_id: selectors.acceptConfirmSuggestionId(previousState),+ surface: props.surface,})},confirmAccept: () => {@@ -888,7 +908,9 @@ export const warehouseSuggestionsLogic: LogicWrapper<warehouseSuggestionsLogicTy}actions.setActionInFlight(id, true)try {- const accepted = await warehouseSuggestionsAcceptCreate(projectId(), id, options)+ const accepted = await warehouseSuggestionsAcceptCreate(projectId(), id, options, {+ surface: props.surface,+ })actions.hideSuggestion(id)actions.suggestionAccepted(accepted)props.onAccepted?.(accepted)@@ -915,7 +937,12 @@ export const warehouseSuggestionsLogic: LogicWrapper<warehouseSuggestionsLogicTyactions.setActionInFlight(id, true)actions.hideSuggestion(id)try {- await warehouseSuggestionsDismissCreate(project, id, { reason, note })+ await warehouseSuggestionsDismissCreate(+ project,+ id,+ { reason, note },+ { surface: props.surface }+ )lemonToast.success(dismissedMessage(reason, kind), {toastId: `warehouse-suggestion-dismissed-${id}`,button: {diff --git a/products/warehouse_suggestions/mcp/tools.yaml b/products/warehouse_suggestions/mcp/tools.yamlindex 50c9ec882a51..d93ea92d70aa 100644--- a/products/warehouse_suggestions/mcp/tools.yaml+++ b/products/warehouse_suggestions/mcp/tools.yaml@@ -42,6 +42,8 @@ tools:Check keys the person chose with view-check-incremental first. A 400 names the field the server refused andwhy. A 409 means the view changed since the suggestion was made and its suggested keys no longer apply.Requires human typed confirmation.+ exclude_params:+ - surfaceconfirmed_action:message: >About to accept warehouse suggestion '{id}'. This applies the change it proposes to the view or table.@@ -77,6 +79,8 @@ tools:description: >Dismiss a proposed warehouse suggestion with a reason: not_useful, not_now or other, plus an optional note.Nothing changes on the view or table. warehouse-suggestions-resume brings it back.+ exclude_params:+ - surfacewarehouse-suggestions-get:operation: warehouse_suggestions_retrieveenabled: truediff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex efc73ac978a8..e9b62230dfef 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -136901,6 +136901,44 @@ export namespace Schemas {AutoResolved: 'auto_resolved',} as const;+ export type WarehouseSuggestionsAcceptCreateParams = {+ /**+ * Page the decision was made on. Only recorded on the analytics event.+ *+ * * `models` - Models+ * * `catalog` - Data catalog+ * @minLength 1+ */+ surface?: WarehouseSuggestionsAcceptCreateSurface;+ };++ export type WarehouseSuggestionsAcceptCreateSurface = typeof WarehouseSuggestionsAcceptCreateSurface[keyof typeof WarehouseSuggestionsAcceptCreateSurface];+++ export const WarehouseSuggestionsAcceptCreateSurface = {+ Models: 'models',+ Catalog: 'catalog',+ } as const;++ export type WarehouseSuggestionsDismissCreateParams = {+ /**+ * Page the decision was made on. Only recorded on the analytics event.+ *+ * * `models` - Models+ * * `catalog` - Data catalog+ * @minLength 1+ */+ surface?: WarehouseSuggestionsDismissCreateSurface;+ };++ export type WarehouseSuggestionsDismissCreateSurface = typeof WarehouseSuggestionsDismissCreateSurface[keyof typeof WarehouseSuggestionsDismissCreateSurface];+++ export const WarehouseSuggestionsDismissCreateSurface = {+ Models: 'models',+ Catalog: 'catalog',+ } as const;+export type WarehouseTablesListParams = {/*** Include table columns. Disable for lightweight table existence or name lookups.diff --git a/services/mcp/src/generated/warehouse_suggestions/api.ts b/services/mcp/src/generated/warehouse_suggestions/api.tsindex 1615074eaaaa..bb2080908e18 100644--- a/services/mcp/src/generated/warehouse_suggestions/api.ts+++ b/services/mcp/src/generated/warehouse_suggestions/api.ts@@ -67,6 +67,15 @@ export const WarehouseSuggestionsAcceptCreateParams = () => zod.object({),})+export const WarehouseSuggestionsAcceptCreateQueryParams = () => zod.object({+ surface: zod+ .enum(['models', 'catalog'])+ .optional()+ .describe(+ 'Page the decision was made on. Only recorded on the analytics event.\n\n\* `models` - Models\n\* `catalog` - Data catalog'+ ),+})+export const warehouseSuggestionsAcceptCreateBodyRefreshIntervalSecondsMax = 2592000export const warehouseSuggestionsAcceptCreateBodyLookbackSecondsMin = 0@@ -157,6 +166,15 @@ export const WarehouseSuggestionsDismissCreateParams = () => zod.object({),})+export const WarehouseSuggestionsDismissCreateQueryParams = () => zod.object({+ surface: zod+ .enum(['models', 'catalog'])+ .optional()+ .describe(+ 'Page the decision was made on. Only recorded on the analytics event.\n\n\* `models` - Models\n\* `catalog` - Data catalog'+ ),+})+export const warehouseSuggestionsDismissCreateBodyNoteMax = 1000export const WarehouseSuggestionsDismissCreateBody = () => zod.object({