Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref(insights): Simplify means of feature flag disabling tabs #82477

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions static/app/views/insights/crons/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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_HIDDEN_FEATURES = ['insights-crons'];
23 changes: 8 additions & 15 deletions static/app/views/insights/pages/domainViewHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -83,19 +81,14 @@ export function DomainViewHeader({
},
];

if (showModuleTabs) {
tabList.push(
...modules.map(
moduleName =>
({
key: moduleName,
children: <TabLabel moduleName={moduleName} />,
to: `${moduleURLBuilder(moduleName as RoutableModuleNames)}/`,
hidden: isModuleHidden(moduleName, organization),
}) satisfies TabListItemProps
)
);
}
modules.forEach(moduleName =>
tabList.push({
key: moduleName,
children: <TabLabel moduleName={moduleName} />,
to: `${moduleURLBuilder(moduleName as RoutableModuleNames)}/`,
hidden: isModuleHidden(moduleName, organization),
})
);

return (
<Fragment>
Expand Down
8 changes: 2 additions & 6 deletions static/app/views/insights/pages/utils.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import type {Organization} from 'sentry/types/organization';
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,
} from 'sentry/views/insights/settings';
import {MODULE_FEATURE_MAP, MODULE_FEATURE_SHOWN} 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);
!MODULE_FEATURE_SHOWN[module].every(f => organization.features.includes(f));

export const getModuleView = (module: ModuleName): DomainView => {
if (DOMAIN_VIEW_MODULES.backend.includes(module)) {
Expand Down
28 changes: 23 additions & 5 deletions static/app/views/insights/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
DATA_TYPE_PLURAL as CRONS_DATA_TYPE_PLURAL,
MODULE_DOC_LINK as CRONS_MODULE_DOC_LINK,
MODULE_FEATURES as CRONS_MODULE_FEATURES,
MODULE_HIDDEN_FEATURES as CRONS_MODULE_HIDDEN_FEATURES,
MODULE_TITLE as CRONS_MODULE_TITLE,
} from 'sentry/views/insights/crons/settings';
import {
Expand Down Expand Up @@ -93,6 +94,7 @@ import {
DATA_TYPE_PLURAL as UPTIME_DATA_TYPE_PLURAL,
MODULE_DOC_LINK as UPTIME_MODULE_DOC_LINK,
MODULE_FEATURES as UPTIME_MODULE_FEATURES,
MODULE_HIDDEN_FEATURES as UPTIME_MODULE_HIDDEN_FEATURES,
MODULE_TITLE as UPTIME_MODULE_TITLE,
} from 'sentry/views/insights/uptime/settings';

Expand Down Expand Up @@ -177,6 +179,9 @@ export const MODULE_PRODUCT_DOC_LINKS: Record<ModuleName, string> = {
[ModuleName.OTHER]: '',
};

/**
* Features that control gating of modules, falling back to upsell style hooks.
*/
export const MODULE_FEATURE_MAP: Record<ModuleName, string[]> = {
[ModuleName.DB]: DB_MODULE_FEATURES,
[ModuleName.APP_START]: APP_STARTS_MODULE_FEATURES,
Expand All @@ -196,9 +201,22 @@ export const MODULE_FEATURE_MAP: Record<ModuleName, string[]> = {
};

/**
* 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_SHOWN: Record<ModuleName, string[]> = {
[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_HIDDEN_FEATURES],
[ModuleName.CRONS]: ['insights-entry-points', ...CRONS_MODULE_HIDDEN_FEATURES],
[ModuleName.OTHER]: ['insights-entry-points'],
};
1 change: 1 addition & 0 deletions static/app/views/insights/uptime/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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_HIDDEN_FEATURES = ['insights-uptime'];
Loading