From 67e9215aa4e333dce191d96c717d5b74ba35c8e0 Mon Sep 17 00:00:00 2001 From: Evan Purkhiser Date: Fri, 20 Dec 2024 12:42:13 -0500 Subject: [PATCH] ref(insights): Simplify means of feature flag disabling tabs This is a follow up to @DominikB2014's comment here https://github.com/getsentry/sentry/pull/82365#discussion_r1892587801 --- static/app/views/insights/crons/settings.ts | 1 + .../views/insights/pages/domainViewHeader.tsx | 25 ++++++----------- static/app/views/insights/pages/utils.ts | 7 ++--- static/app/views/insights/settings.ts | 28 +++++++++++++++---- static/app/views/insights/uptime/settings.ts | 1 + 5 files changed, 36 insertions(+), 26 deletions(-) diff --git a/static/app/views/insights/crons/settings.ts b/static/app/views/insights/crons/settings.ts index 3807da623c7739..585d75ebcf08c6 100644 --- a/static/app/views/insights/crons/settings.ts +++ b/static/app/views/insights/crons/settings.ts @@ -12,3 +12,4 @@ export const MODULE_DESCRIPTION = t( export const MODULE_DOC_LINK = 'https://docs.sentry.io/product/crons/'; export const MODULE_FEATURES = ['insights-crons']; +export const MODULE_VISIBLE_FEATURES = ['insights-crons']; diff --git a/static/app/views/insights/pages/domainViewHeader.tsx b/static/app/views/insights/pages/domainViewHeader.tsx index 6c4157d4fbc836..de1c9879ba47ea 100644 --- a/static/app/views/insights/pages/domainViewHeader.tsx +++ b/static/app/views/insights/pages/domainViewHeader.tsx @@ -19,7 +19,7 @@ import { DOMAIN_VIEW_BASE_TITLE, OVERVIEW_PAGE_TITLE, } from 'sentry/views/insights/pages/settings'; -import {isModuleEnabled, isModuleHidden} from 'sentry/views/insights/pages/utils'; +import {isModuleEnabled, isModuleVisible} from 'sentry/views/insights/pages/utils'; import type {ModuleName} from 'sentry/views/insights/types'; export type Props = { @@ -70,8 +70,6 @@ export function DomainViewHeader({ ...additionalBreadCrumbs, ]; - const showModuleTabs = organization.features.includes('insights-entry-points'); - const tabValue = hideDefaultTabs && tabs?.value ? tabs.value : selectedModule ?? OVERVIEW_PAGE_TITLE; @@ -81,22 +79,15 @@ export function DomainViewHeader({ children: OVERVIEW_PAGE_TITLE, to: domainBaseUrl, }, + ...modules + .filter(moduleName => isModuleVisible(moduleName, organization)) + .map(moduleName => ({ + key: moduleName, + children: , + to: `${moduleURLBuilder(moduleName as RoutableModuleNames)}/`, + })), ]; - if (showModuleTabs) { - tabList.push( - ...modules.map( - moduleName => - ({ - key: moduleName, - children: , - to: `${moduleURLBuilder(moduleName as RoutableModuleNames)}/`, - hidden: isModuleHidden(moduleName, organization), - }) satisfies TabListItemProps - ) - ); - } - return ( diff --git a/static/app/views/insights/pages/utils.ts b/static/app/views/insights/pages/utils.ts index 76dd92626f6d9f..7f388f626f256c 100644 --- a/static/app/views/insights/pages/utils.ts +++ b/static/app/views/insights/pages/utils.ts @@ -3,16 +3,15 @@ import {DOMAIN_VIEW_MODULES} from 'sentry/views/insights/pages/settings'; import type {DomainView} from 'sentry/views/insights/pages/useFilters'; import { MODULE_FEATURE_MAP, - MODULE_HIDDEN_WHEN_FEAUTRE_DISABLED, + MODULE_FEATURE_VISIBLE_MAP, } from 'sentry/views/insights/settings'; import type {ModuleName} from 'sentry/views/insights/types'; export const isModuleEnabled = (module: ModuleName, organization: Organization) => MODULE_FEATURE_MAP[module].every(f => organization.features.includes(f)); -export const isModuleHidden = (module: ModuleName, organization: Organization) => - MODULE_HIDDEN_WHEN_FEAUTRE_DISABLED.includes(module) && - !isModuleEnabled(module, organization); +export const isModuleVisible = (module: ModuleName, organization: Organization) => + MODULE_FEATURE_VISIBLE_MAP[module].every(f => organization.features.includes(f)); export const getModuleView = (module: ModuleName): DomainView => { if (DOMAIN_VIEW_MODULES.backend.includes(module)) { diff --git a/static/app/views/insights/settings.ts b/static/app/views/insights/settings.ts index c77bfbc3c8bbbc..949e5842eabda4 100644 --- a/static/app/views/insights/settings.ts +++ b/static/app/views/insights/settings.ts @@ -26,6 +26,7 @@ import { MODULE_DOC_LINK as CRONS_MODULE_DOC_LINK, MODULE_FEATURES as CRONS_MODULE_FEATURES, MODULE_TITLE as CRONS_MODULE_TITLE, + MODULE_VISIBLE_FEATURES as CRONS_MODULE_VISIBLE_FEATURES, } from 'sentry/views/insights/crons/settings'; import { DATA_TYPE as DB_DATA_TYPE, @@ -94,6 +95,7 @@ import { MODULE_DOC_LINK as UPTIME_MODULE_DOC_LINK, MODULE_FEATURES as UPTIME_MODULE_FEATURES, MODULE_TITLE as UPTIME_MODULE_TITLE, + MODULE_VISIBLE_FEATURES as UPTIME_MODULE_VISIBLE_FEATURES, } from 'sentry/views/insights/uptime/settings'; import {ModuleName} from './types'; @@ -177,6 +179,9 @@ export const MODULE_PRODUCT_DOC_LINKS: Record = { [ModuleName.OTHER]: '', }; +/** + * Features that control gating of modules, falling back to upsell style hooks. + */ export const MODULE_FEATURE_MAP: Record = { [ModuleName.DB]: DB_MODULE_FEATURES, [ModuleName.APP_START]: APP_STARTS_MODULE_FEATURES, @@ -196,9 +201,22 @@ export const MODULE_FEATURE_MAP: Record = { }; /** - * Modules that will not display tabs when the feature is not enabled + * Features that control the visibility of modules. */ -export const MODULE_HIDDEN_WHEN_FEAUTRE_DISABLED: ModuleName[] = [ - ModuleName.CRONS, - ModuleName.UPTIME, -]; +export const MODULE_FEATURE_VISIBLE_MAP: Record = { + [ModuleName.DB]: ['insights-entry-points'], + [ModuleName.APP_START]: ['insights-entry-points'], + [ModuleName.HTTP]: ['insights-entry-points'], + [ModuleName.RESOURCE]: ['insights-entry-points'], + [ModuleName.VITAL]: ['insights-entry-points'], + [ModuleName.CACHE]: ['insights-entry-points'], + [ModuleName.QUEUE]: ['insights-entry-points'], + [ModuleName.AI]: ['insights-entry-points'], + [ModuleName.SCREEN_LOAD]: ['insights-entry-points'], + [ModuleName.MOBILE_UI]: ['insights-entry-points'], + [ModuleName.MOBILE_SCREENS]: ['insights-entry-points'], + [ModuleName.SCREEN_RENDERING]: ['insights-entry-points'], + [ModuleName.UPTIME]: ['insights-entry-points', ...UPTIME_MODULE_VISIBLE_FEATURES], + [ModuleName.CRONS]: ['insights-entry-points', ...CRONS_MODULE_VISIBLE_FEATURES], + [ModuleName.OTHER]: ['insights-entry-points'], +}; diff --git a/static/app/views/insights/uptime/settings.ts b/static/app/views/insights/uptime/settings.ts index 82c1ebc9ce780b..649531c85aea4b 100644 --- a/static/app/views/insights/uptime/settings.ts +++ b/static/app/views/insights/uptime/settings.ts @@ -10,3 +10,4 @@ export const MODULE_DESCRIPTION = t('Monitor availability of HTTP URLs.'); export const MODULE_DOC_LINK = 'https://docs.sentry.io/product/alerts/uptime-monitoring/'; export const MODULE_FEATURES = ['insights-uptime']; +export const MODULE_VISIBLE_FEATURES = ['insights-uptime'];