Skip to content
Merged
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
29 changes: 8 additions & 21 deletions static/app/views/insights/pages/domainViewHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {Fragment} from 'react';
import styled from '@emotion/styled';
import type {LocationDescriptor} from 'history';

import {Breadcrumbs, type Crumb} from 'sentry/components/breadcrumbs';
import ButtonBar from 'sentry/components/buttonBar';
Expand All @@ -8,7 +9,6 @@ import * as Layout from 'sentry/components/layouts/thirds';
import {TabList, Tabs} from 'sentry/components/tabs';
import {IconBusiness} from 'sentry/icons';
import {space} from 'sentry/styles/space';
import {useNavigate} from 'sentry/utils/useNavigate';
import useOrganization from 'sentry/utils/useOrganization';
import {useModuleTitles} from 'sentry/views/insights/common/utils/useModuleTitle';
import {
Expand Down Expand Up @@ -37,6 +37,7 @@ export type Props = {
type Tab = {
key: string;
label: React.ReactNode;
to: LocationDescriptor;
};

export function DomainViewHeader({
Expand All @@ -50,7 +51,6 @@ export function DomainViewHeader({
domainBaseUrl,
tabs,
}: Props) {
const navigate = useNavigate();
const organization = useOrganization();
const moduleURLBuilder = useModuleURLBuilder();
const moduleTitles = useModuleTitles();
Expand Down Expand Up @@ -78,30 +78,14 @@ export function DomainViewHeader({

const showModuleTabs = organization.features.includes('insights-entry-points');

const defaultHandleTabChange = (key: ModuleName | typeof OVERVIEW_PAGE_TITLE) => {
if (key === selectedModule || (key === OVERVIEW_PAGE_TITLE && !module)) {
return;
}
if (!key) {
return;
}
if (key === OVERVIEW_PAGE_TITLE) {
navigate(domainBaseUrl);
return;
}
navigate(`${moduleURLBuilder(key as RoutableModuleNames)}/`);
};

const tabValue =
hideDefaultTabs && tabs?.value ? tabs.value : selectedModule ?? OVERVIEW_PAGE_TITLE;

const handleTabChange =
hideDefaultTabs && tabs ? tabs.onTabChange : defaultHandleTabChange;

const tabList: Tab[] = [
{
key: OVERVIEW_PAGE_TITLE,
label: OVERVIEW_PAGE_TITLE,
to: domainBaseUrl,
},
];

Expand All @@ -110,6 +94,7 @@ export function DomainViewHeader({
...modules.map(moduleName => ({
key: moduleName,
label: <TabLabel moduleName={moduleName} />,
to: `${moduleURLBuilder(moduleName as RoutableModuleNames)}/`,
}))
);
}
Expand All @@ -128,11 +113,13 @@ export function DomainViewHeader({
<FeedbackWidgetButton />
</ButtonBar>
</Layout.HeaderActions>
<Tabs value={tabValue} onChange={handleTabChange}>
<Tabs value={tabValue} onChange={tabs?.onTabChange}>
{!hideDefaultTabs && (
<TabList hideBorder>
{tabList.map(tab => (
<TabList.Item key={tab.key}>{tab.label}</TabList.Item>
<TabList.Item key={tab.key} to={tab.to}>
{tab.label}
</TabList.Item>
))}
</TabList>
)}
Expand Down
Loading