From 9b9d81ae4e66dc40fd5139bf8b030f8e44831de1 Mon Sep 17 00:00:00 2001 From: TkDodo Date: Tue, 6 Oct 2026 10:06:37 +0200 Subject: [PATCH 01/39] ref: unify breadcrumbs and title slot in TopBar --- .../core/breadcrumbList/breadcrumbList.mdx | 35 ++- static/app/components/core/slot/index.tsx | 2 +- static/app/components/core/slot/slot.spec.tsx | 45 +--- static/app/components/core/slot/slot.tsx | 12 -- .../components/profiling/profileHeader.tsx | 68 +++--- .../alerts/builder/builderBreadCrumbs.tsx | 33 ++- static/app/views/automations/detail.tsx | 8 +- .../components/details/error/index.tsx | 22 +- .../components/forms/error/index.tsx | 8 +- .../detectors/components/uptime/details.tsx | 22 +- static/app/views/detectors/new.tsx | 28 +-- static/app/views/discover/breadcrumb.tsx | 7 +- static/app/views/discover/landing.tsx | 10 +- .../components/conversationsBreadcrumbs.tsx | 62 +++--- .../views/explore/multiQueryMode/index.tsx | 34 ++- .../releases/detail/header/releaseHeader.tsx | 114 +++++----- .../header/replayDetailsPageBreadcrumbs.tsx | 200 ++++++++---------- .../app/views/issueDetails/header/header.tsx | 5 +- static/app/views/navigation/topBar.spec.tsx | 89 +++++++- static/app/views/navigation/topBar.tsx | 52 ++++- .../traceHeader/traceBreadcrumbs.tsx | 100 ++++----- .../transactionBreadcrumbs.tsx | 73 +++---- .../app/views/projectDetail/projectDetail.tsx | 42 ++-- 23 files changed, 532 insertions(+), 539 deletions(-) diff --git a/static/app/components/core/breadcrumbList/breadcrumbList.mdx b/static/app/components/core/breadcrumbList/breadcrumbList.mdx index f39fff0f73ac..15ab0a377ced 100644 --- a/static/app/components/core/breadcrumbList/breadcrumbList.mdx +++ b/static/app/components/core/breadcrumbList/breadcrumbList.mdx @@ -33,21 +33,17 @@ import {BreadcrumbList} from '@sentry/scraps/breadcrumbList'; import {TopBar} from 'sentry/views/navigation/topBar'; ``` -The `title` slot is always the page's single `

`. `BreadcrumbList.Title` -renders title content _without_ a heading of its own, so the slot supplies the -heading and the item supplies everything else — a leading graphic, a tooltip, -pagination, trailing actions, or an editable field. Never change the title -slot's element. +Pass the page title as a typed `title` prop to `TopBar.Slot name="breadcrumbs"`. +TopBar renders `BreadcrumbList.Title` internally and supplies the page's single +`

`. The title item supports a leading graphic, a tooltip, pagination, +trailing actions, or an editable field. -Use `BreadcrumbList.Title` on every page, whether or not it has parents. A plain -string in the title slot renders, but it forfeits every one of those props. +The separate `name="title"` slot is deprecated. It remains available for legacy +pages while their custom titles migrate to typed title items. ### Index pages -An index page has no parents, so it renders the title slot alone — no `items` -array and no `breadcrumbs` slot. Reaching for `BreadcrumbList.Title` here rather -than a bare string is what keeps a leading graphic or a trailing action -available if the page needs one later. +An index page has no parents. Pass only `title` and omit the slot's children. ```tsx - - - + ``` ### Pages with parents -Add the `breadcrumbs` slot, which renders to the left of the title. Pass parent -crumbs in a typed `items` array: each entry is a discriminated union, a `type` -key plus that type's own props flattened onto the same object. +Render `BreadcrumbList` as the slot's child to show parents to the left of the +title. Pass parent crumbs in a typed `items` array: each entry is a discriminated +union, a `type` key plus that type's own props flattened onto the same object. Keep the current page out of `items`. It is the title, not a crumb — leaving it in renders the page name twice. @@ -87,7 +81,7 @@ in renders the page name twice. /> ```tsx - + - - - ``` Because `BreadcrumbList.Title` carries no heading, this composition still @@ -195,7 +186,7 @@ Page filters are not carried automatically — see [Page filters](#page-filters) The `page-title` item is rendered with `BreadcrumbList.Title`, not in the `BreadcrumbList.items` array. It is bold, non-interactive, and renders as inline -content. The surrounding `TopBar.Slot name="title"` provides the `

`; the +content. TopBar provides the `

` when the item is passed through `title`; the demo below mirrors that heading and flex layout. diff --git a/static/app/components/core/slot/index.tsx b/static/app/components/core/slot/index.tsx index c270ab4e2a50..6b828734321c 100644 --- a/static/app/components/core/slot/index.tsx +++ b/static/app/components/core/slot/index.tsx @@ -1 +1 @@ -export {slot, withSlots} from './slot'; +export {slot} from './slot'; diff --git a/static/app/components/core/slot/slot.spec.tsx b/static/app/components/core/slot/slot.spec.tsx index 8c6ac5b71ef2..af7f61073054 100644 --- a/static/app/components/core/slot/slot.spec.tsx +++ b/static/app/components/core/slot/slot.spec.tsx @@ -2,7 +2,7 @@ import {render, screen} from 'sentry-test/reactTestingLibrary'; import {SizeProvider, useSizeContext} from '@sentry/scraps/sizeContext'; -import {slot, withSlots} from './'; +import {slot} from './'; describe('slot', () => { it('returns a module with Provider, Outlet, and Fallback sub-components', () => { @@ -384,47 +384,4 @@ describe('slot', () => { expect(screen.getByTestId('size-value')).toHaveTextContent('none'); }); }); - - describe('withSlots', () => { - it('attaches a Slot property to a component', () => { - const SlotModule = slot(['header'] as const); - - function MyComponent() { - return
; - } - - const WithSlots = withSlots(MyComponent, SlotModule); - - expect(WithSlots.Slot).toBe(SlotModule); - }); - - it('renders the wrapped component and allows slot injection', () => { - const SlotModule = slot(['title'] as const); - - function MyComponent() { - return ( -
- - {props => } - -
- ); - } - - const WithSlots = withSlots(MyComponent, SlotModule); - - render( - - - - injected title - - - ); - - expect(screen.getByTestId('title-outlet')).toContainHTML( - 'injected title' - ); - }); - }); }); diff --git a/static/app/components/core/slot/slot.tsx b/static/app/components/core/slot/slot.tsx index e7ebfb0f36e6..621abc0fcbd7 100644 --- a/static/app/components/core/slot/slot.tsx +++ b/static/app/components/core/slot/slot.tsx @@ -426,15 +426,3 @@ export function slot(names: T): SlotModule return Slot; } - -export function withSlots< - TComponent extends React.ComponentType, - TSlot extends Slot, ->( - Component: TComponent, - slotModule: SlotModule -): TComponent & {Slot: SlotModule} { - const WithSlots = Component as TComponent & {Slot: SlotModule}; - WithSlots.Slot = slotModule; - return WithSlots; -} diff --git a/static/app/components/profiling/profileHeader.tsx b/static/app/components/profiling/profileHeader.tsx index e21147bdbc7d..6b0ff12a9286 100644 --- a/static/app/components/profiling/profileHeader.tsx +++ b/static/app/components/profiling/profileHeader.tsx @@ -112,43 +112,41 @@ export function ProfileHeader({ return ( - + , + items: [ + { + key: 'copy-profile-id', + label: copyIdLabel, + leadingItems: , + onAction: () => copy(profileId), + }, + ...(transactionTarget + ? [ + { + key: 'open-trace', + label: t('Open Trace'), + leadingItems: , + to: transactionTarget, + onAction: handleGoToTransaction, + }, + ] + : []), + ], + }, + }} + > - - , - items: [ - { - key: 'copy-profile-id', - label: copyIdLabel, - leadingItems: , - onAction: () => copy(profileId), - }, - ...(transactionTarget - ? [ - { - key: 'open-trace', - label: t('Open Trace'), - leadingItems: , - to: transactionTarget, - onAction: handleGoToTransaction, - }, - ] - : []), - ], - }, - }} - /> - - - + - - - - - + }, + ]} + /> + ); } diff --git a/static/app/views/automations/detail.tsx b/static/app/views/automations/detail.tsx index 17419c9bd7c7..6e3d1cfc6c6a 100644 --- a/static/app/views/automations/detail.tsx +++ b/static/app/views/automations/detail.tsx @@ -90,7 +90,10 @@ function AutomationDetailContentInner({automation}: {automation: Automation}) { return ( - + - - - diff --git a/static/app/views/detectors/components/details/error/index.tsx b/static/app/views/detectors/components/details/error/index.tsx index fead9516dcc5..4b4c4e1933f7 100644 --- a/static/app/views/detectors/components/details/error/index.tsx +++ b/static/app/views/detectors/components/details/error/index.tsx @@ -83,7 +83,16 @@ export function ErrorDetectorDetails({detector, project}: ErrorDetectorDetailsPr return ( - + + ), + }} + > - - - ), - }} - /> - diff --git a/static/app/views/detectors/components/forms/error/index.tsx b/static/app/views/detectors/components/forms/error/index.tsx index 408ff09885aa..0ed404a10d25 100644 --- a/static/app/views/detectors/components/forms/error/index.tsx +++ b/static/app/views/detectors/components/forms/error/index.tsx @@ -153,7 +153,10 @@ export function EditExistingErrorDetectorForm({ return ( - + - - - diff --git a/static/app/views/detectors/components/uptime/details.tsx b/static/app/views/detectors/components/uptime/details.tsx index c09a71c0eeb8..918c55c063ab 100644 --- a/static/app/views/detectors/components/uptime/details.tsx +++ b/static/app/views/detectors/components/uptime/details.tsx @@ -130,7 +130,16 @@ export default function UptimeAlertDetails() { return ( - + + ), + }} + > - - - ), - }} - /> - - - - - - - - + + + ); } diff --git a/static/app/views/discover/breadcrumb.tsx b/static/app/views/discover/breadcrumb.tsx index 888d77427348..49d8fcdd4fd2 100644 --- a/static/app/views/discover/breadcrumb.tsx +++ b/static/app/views/discover/breadcrumb.tsx @@ -32,9 +32,10 @@ export function DiscoverBreadcrumb({ // no trail above it. if (!eventView?.isValid()) { return ( - - - + ); } diff --git a/static/app/views/discover/landing.tsx b/static/app/views/discover/landing.tsx index a35f199eb544..1d10f0fd9f0e 100644 --- a/static/app/views/discover/landing.tsx +++ b/static/app/views/discover/landing.tsx @@ -188,7 +188,10 @@ function DiscoverLanding() { > - + - - - - - - - - - trackAnalytics('conversations.detail.copy-conversation-id', { - organization, - }), - }, - }} - /> - - + + trackAnalytics('conversations.detail.copy-conversation-id', { + organization, + }), + }, + }} + > + + ); } diff --git a/static/app/views/explore/multiQueryMode/index.tsx b/static/app/views/explore/multiQueryMode/index.tsx index 170bd5304b4c..9c10d19d3ca8 100644 --- a/static/app/views/explore/multiQueryMode/index.tsx +++ b/static/app/views/explore/multiQueryMode/index.tsx @@ -1,5 +1,3 @@ -import {Fragment} from 'react'; - import {BreadcrumbList} from '@sentry/scraps/breadcrumbList'; import {Stack} from '@sentry/scraps/layout'; @@ -38,24 +36,20 @@ export default function MultiQueryMode() { title={title} /> ) : ( - - - - - - - - + + + )} - + + ), + pagination: { + previous: { + ariaLabel: t('Older'), + tooltip: prevReleaseVersion + ? t('Older release') + : t('This is the oldest release'), + to: prevReleaseVersion + ? makeSiblingReleaseTarget(prevReleaseVersion) + : undefined, + onClick: () => trackPaginationClick('older'), + }, + next: { + ariaLabel: t('Newer'), + tooltip: nextReleaseVersion + ? t('Newer release') + : t('This is the newest release'), + to: nextReleaseVersion + ? makeSiblingReleaseTarget(nextReleaseVersion) + : undefined, + onClick: () => trackPaginationClick('newer'), + }, + }, + trailingActions: [ + url + ? { + type: 'button', + element: ( + } + aria-label={t('Open release URL')} + /> + ), + } + : null, + { + type: 'menu', + triggerLabel: t('Release Actions'), + triggerIcon: , + items: menuItems, + }, + ], + }} + > - - - ), - pagination: { - previous: { - ariaLabel: t('Older'), - tooltip: prevReleaseVersion - ? t('Older release') - : t('This is the oldest release'), - to: prevReleaseVersion - ? makeSiblingReleaseTarget(prevReleaseVersion) - : undefined, - onClick: () => trackPaginationClick('older'), - }, - next: { - ariaLabel: t('Newer'), - tooltip: nextReleaseVersion - ? t('Newer release') - : t('This is the newest release'), - to: nextReleaseVersion - ? makeSiblingReleaseTarget(nextReleaseVersion) - : undefined, - onClick: () => trackPaginationClick('newer'), - }, - }, - trailingActions: [ - url - ? { - type: 'button', - element: ( - } - aria-label={t('Open release URL')} - /> - ), - } - : null, - { - type: 'menu', - triggerLabel: t('Release Actions'), - triggerIcon: , - items: menuItems, - }, - ], - }} - /> - @@ -64,115 +64,101 @@ export function ReplayDetailsPageBreadcrumbs({readerResult}: Props) { ); return ( - - - - - - - ) : ( - - ), - // oxlint-disable-next-line react/refs - pagination: { - // oxlint-disable-next-line react/refs - previous: { - ariaLabel: t('Previous replay based on search query'), - tooltip: previousReplay - ? t('Previous replay based on search query') - : undefined, - // oxlint-disable-next-line react/refs - to: previousReplay - ? { - pathname: makeReplaysPathname({ - path: `/${previousReplay.id}/`, - organization, - }), - // oxlint-disable-next-line react/refs - query: initialLocation.current.query, - } - : undefined, - onClick: () => - trackAnalytics('replay.details-playlist-clicked', { - direction: 'previous', + + ) : ( + + ), + pagination: { + previous: { + ariaLabel: t('Previous replay based on search query'), + tooltip: previousReplay + ? t('Previous replay based on search query') + : undefined, + to: previousReplay + ? { + pathname: makeReplaysPathname({ + path: `/${previousReplay.id}/`, organization, }), - }, - // oxlint-disable-next-line react/refs - next: { - ariaLabel: t('Next replay based on search query'), - tooltip: nextReplay ? t('Next replay based on search query') : undefined, - // oxlint-disable-next-line react/refs - to: nextReplay - ? { - pathname: makeReplaysPathname({ - path: `/${nextReplay.id}/`, - organization, - }), - // oxlint-disable-next-line react/refs - query: initialLocation.current.query, - } - : undefined, - onClick: () => - trackAnalytics('replay.details-playlist-clicked', { - direction: 'next', + query: initialLocation.query, + } + : undefined, + onClick: () => + trackAnalytics('replay.details-playlist-clicked', { + direction: 'previous', + organization, + }), + }, + next: { + ariaLabel: t('Next replay based on search query'), + tooltip: nextReplay ? t('Next replay based on search query') : undefined, + to: nextReplay + ? { + pathname: makeReplaysPathname({ + path: `/${nextReplay.id}/`, organization, }), + query: initialLocation.query, + } + : undefined, + onClick: () => + trackAnalytics('replay.details-playlist-clicked', { + direction: 'next', + organization, + }), + }, + }, + trailingActions: [ + hasActionsMenu + ? { + type: 'menu', + triggerLabel: t('Replay Actions'), + triggerIcon: , + items: menuItems, + } + : null, + shouldShowRefreshButton + ? { + type: 'button', + element: ( + + ), + } + : null, + ], + }} + > + , - items: menuItems, - } - : null, - shouldShowRefreshButton - ? { - type: 'button', - element: ( - - ), - } - : null, - ], - }} - /> - - + }, + ]} + /> + ); } diff --git a/static/app/views/issueDetails/header/header.tsx b/static/app/views/issueDetails/header/header.tsx index a36e7b6e61b2..07d4d2f73be7 100644 --- a/static/app/views/issueDetails/header/header.tsx +++ b/static/app/views/issueDetails/header/header.tsx @@ -81,7 +81,7 @@ export function GroupHeader({event, group, project}: GroupHeaderProps) {
- + - - - {hasErrorUpsampling && ( - Page title + ); @@ -55,12 +55,12 @@ describe('TopBar', () => { render( - + - - - , {organization: OrganizationFixture()} ); @@ -69,6 +69,83 @@ describe('TopBar', () => { expect( screen.getByRole('heading', {name: 'Current Issue', level: 1}) ).toBeInTheDocument(); + expect( + within(screen.getByRole('banner')).getAllByRole('heading', {level: 1}) + ).toHaveLength(1); + expect( + within(screen.getByRole('heading', {name: 'Current Issue', level: 1})).queryByRole( + 'link' + ) + ).not.toBeInTheDocument(); + expect(screen.getByRole('link', {name: 'Issues'})).toHaveAttribute( + 'href', + '/issues/' + ); + }); + + it('updates the title and removes it when the page unmounts', () => { + function Page({title}: {title?: string}) { + return ( + + + {title && ( + + )} + + ); + } + + const {rerender} = render(); + expect(screen.getByRole('heading', {name: 'First page'})).toBeInTheDocument(); + + rerender(); + expect(screen.getByRole('heading', {name: 'Second page'})).toBeInTheDocument(); + expect(screen.queryByText('First page')).not.toBeInTheDocument(); + + rerender(); + expect(screen.queryByText('Second page')).not.toBeInTheDocument(); + }); + + it('supports an editable title', async () => { + const onChange = jest.fn(); + render( + + + + + ); + + await userEvent.click(screen.getByText('My dashboard')); + const input = screen.getByRole('textbox', {name: 'Dashboard name'}); + await userEvent.clear(input); + await userEvent.type(input, 'New dashboard{Enter}'); + expect(onChange).toHaveBeenCalledWith('New dashboard'); + }); + + it('supports separate slots while legacy titles migrate', () => { + render( + + + + + + Legacy title + + ); + + expect(screen.getByRole('heading', {name: 'Legacy title'})).toBeInTheDocument(); + expect(screen.getByRole('link', {name: 'Issues'})).toHaveAttribute( + 'href', + '/issues/' + ); }); it('uses icon-only actions below sm', () => { diff --git a/static/app/views/navigation/topBar.tsx b/static/app/views/navigation/topBar.tsx index 407314dfcfe9..0872dca0f485 100644 --- a/static/app/views/navigation/topBar.tsx +++ b/static/app/views/navigation/topBar.tsx @@ -1,10 +1,11 @@ -import {useEffect, useMemo} from 'react'; +import {Fragment, useEffect, useMemo} from 'react'; import {useTheme} from '@emotion/react'; import {mergeProps} from '@react-aria/utils'; +import {BreadcrumbList, type BreadcrumbTitleItem} from '@sentry/scraps/breadcrumbList'; import {Flex} from '@sentry/scraps/layout'; import {SizeProvider} from '@sentry/scraps/sizeContext'; -import {slot, withSlots} from '@sentry/scraps/slot'; +import {slot} from '@sentry/scraps/slot'; import {Heading} from '@sentry/scraps/text'; import {FeedbackButton} from 'sentry/components/feedbackButton/feedbackButton'; @@ -30,6 +31,42 @@ import { const Slot = slot(['breadcrumbs', 'title', 'search', 'actions', 'feedback'] as const); +type TopBarSlotProps = + | { + name: 'breadcrumbs'; + children?: React.ReactNode; + /** The page title. Omit only while using a legacy title slot. */ + title?: BreadcrumbTitleItem; + } + | { + children: React.ReactNode; + name: 'search' | 'actions' | 'feedback'; + title?: never; + } + | { + children: React.ReactNode; + /** @deprecated Pass a title item to the breadcrumbs slot instead. */ + name: 'title'; + title?: never; + }; + +function TopBarSlot(props: TopBarSlotProps) { + if (props.name === 'breadcrumbs') { + return ( + + {props.children !== undefined && {props.children}} + {props.title && ( + + + + )} + + ); + } + + return {props.children}; +} + function TopBarContent() { const theme = useTheme(); const {topBarTop, pageContentTop} = useTopOffset(); @@ -76,7 +113,7 @@ function TopBarContent() { > {/* - * Breadcrumbs and the title are separate slots so the title slot always + * Breadcrumbs and the title use separate internal outlets so the title * owns the page heading. BreadcrumbList.Title renders title content * without a heading, while this outlet supplies the single

. * @@ -149,4 +186,11 @@ function TopBarContent() { ); } -export const TopBar = withSlots(TopBarContent, Slot); +export const TopBar = Object.assign(TopBarContent, { + Slot: Object.assign(TopBarSlot, { + Provider: Slot.Provider, + Outlet: Slot.Outlet, + Fallback: Slot.Fallback, + useSlotOutletRef: Slot.useSlotOutletRef, + }), +}); diff --git a/static/app/views/performance/traceDetails/traceHeader/traceBreadcrumbs.tsx b/static/app/views/performance/traceDetails/traceHeader/traceBreadcrumbs.tsx index eb393ceaf3a9..708ea67ef09d 100644 --- a/static/app/views/performance/traceDetails/traceHeader/traceBreadcrumbs.tsx +++ b/static/app/views/performance/traceDetails/traceHeader/traceBreadcrumbs.tsx @@ -1,5 +1,3 @@ -import {Fragment} from 'react'; - import {BreadcrumbList} from '@sentry/scraps/breadcrumbList'; import ProjectBadge from 'sentry/components/idBadge/projectBadge'; @@ -101,58 +99,54 @@ export function TraceBreadcrumbs({ }); return ( - - - - - - - ) : ( - - ), - pagination, - trailingActions: exploreTarget - ? { - type: 'menu', - triggerLabel: t('Trace Actions'), - triggerIcon: , - items: [ - { - key: 'copy-trace-id', - label: COPY_ID_LABEL, - leadingItems: , - onAction: () => copy(traceSlug), - }, - { - key: 'open-in-explore', - label: t('Open in Explore'), - leadingItems: , - to: exploreTarget.to, - onAction: exploreTarget.onClick, - }, - ], - } - : { - type: 'copy', - text: traceSlug, + + ) : ( + + ), + pagination, + trailingActions: exploreTarget + ? { + type: 'menu', + triggerLabel: t('Trace Actions'), + triggerIcon: , + items: [ + { + key: 'copy-trace-id', label: COPY_ID_LABEL, - tooltip: COPY_ID_LABEL, - icon: , + leadingItems: , + onAction: () => copy(traceSlug), + }, + { + key: 'open-in-explore', + label: t('Open in Explore'), + leadingItems: , + to: exploreTarget.to, + onAction: exploreTarget.onClick, }, - }} - /> - - + ], + } + : { + type: 'copy', + text: traceSlug, + label: COPY_ID_LABEL, + tooltip: COPY_ID_LABEL, + icon: , + }, + }} + > + + ); } diff --git a/static/app/views/performance/transactionSummary/transactionBreadcrumbs.tsx b/static/app/views/performance/transactionSummary/transactionBreadcrumbs.tsx index 7e06b89b544b..a03d6c87c194 100644 --- a/static/app/views/performance/transactionSummary/transactionBreadcrumbs.tsx +++ b/static/app/views/performance/transactionSummary/transactionBreadcrumbs.tsx @@ -1,4 +1,3 @@ -import {Fragment} from 'react'; import type {Location} from 'history'; import {TeamAvatar} from '@sentry/scraps/avatar'; @@ -180,45 +179,41 @@ function TransactionBreadcrumbsContent({ }).map(crumb => ({type: 'link' as const, ...crumb})); return ( - - - - - - - ) : ( - - ), - trailingActions: { - type: 'menu', - triggerLabel: t('Transaction Actions'), - triggerIcon: , - items: [ - starForTeamItem, - { - key: 'set-transaction-threshold', - label: t('Transaction Settings'), - leadingItems: , - disabled: isThresholdLoading, - onAction: openThresholdModal, - }, - ], + + ) : ( + + ), + trailingActions: { + type: 'menu', + triggerLabel: t('Transaction Actions'), + triggerIcon: , + items: [ + starForTeamItem, + { + key: 'set-transaction-threshold', + label: t('Transaction Settings'), + leadingItems: , + disabled: isThresholdLoading, + onAction: openThresholdModal, }, - }} - /> - - + ], + }, + }} + > + + ); } diff --git a/static/app/views/projectDetail/projectDetail.tsx b/static/app/views/projectDetail/projectDetail.tsx index d9ca4b243691..31625a0a7f0f 100644 --- a/static/app/views/projectDetail/projectDetail.tsx +++ b/static/app/views/projectDetail/projectDetail.tsx @@ -194,7 +194,26 @@ export function ProjectDetail() { > - + + ) : ( + + ), + trailingActions: { + type: 'menu', + items: projectActions, + triggerLabel: t('Project Actions'), + triggerIcon: , + }, + }} + > - - - ) : ( - - ), - trailingActions: { - type: 'menu', - items: projectActions, - triggerLabel: t('Project Actions'), - triggerIcon: , - }, - }} - /> - From 94ca48fd1719395de4e4ba25ef202bb1af5bf8d2 Mon Sep 17 00:00:00 2001 From: TkDodo Date: Tue, 6 Oct 2026 10:59:43 +0200 Subject: [PATCH 02/39] ref: unify title slot and breadcrumbs --- .../core/breadcrumbList/breadcrumbList.mdx | 23 ++- .../breadcrumbList/breadcrumbList.spec.tsx | 57 +++++++ .../items/breadcrumbItemPageTitle.tsx | 76 ++++++++- .../items/breadcrumbItemPageTitleEditable.tsx | 2 + static/app/components/editableText.spec.tsx | 28 ++++ static/app/components/editableText.tsx | 38 ++++- static/app/components/layouts/thirds.tsx | 6 - .../workflowEngine/layout/detail.tsx | 3 +- .../components/workflowEngine/layout/edit.tsx | 3 +- .../components/workflowEngine/layout/list.tsx | 13 +- .../components/editableAutomationName.tsx | 14 +- static/app/views/automations/edit.tsx | 31 ++-- static/app/views/automations/new.tsx | 31 ++-- .../dashboards/dashboardBreadcrumbTitle.tsx | 28 +++- static/app/views/dashboards/detail.tsx | 52 +++--- static/app/views/dashboards/manage/index.tsx | 23 +-- static/app/views/dashboards/title.tsx | 34 ++-- .../components/details/common/header.tsx | 28 ++-- .../components/forms/common/breadcrumbs.tsx | 90 ++++------ static/app/views/discover/breadcrumb.tsx | 51 +++--- static/app/views/discover/eventInputName.tsx | 21 ++- .../views/discover/results/resultsHeader.tsx | 32 ++-- .../exploreSavedQueryBreadcrumbs.tsx | 51 +++--- .../views/explore/conversations/layout.tsx | 9 +- static/app/views/explore/errors/content.tsx | 9 +- static/app/views/explore/logs/content.tsx | 25 +-- static/app/views/explore/metrics/content.tsx | 25 +-- .../app/views/explore/profiling/content.tsx | 27 ++- .../app/views/explore/releases/list/index.tsx | 27 ++- static/app/views/explore/replays/list.tsx | 31 ++-- .../app/views/explore/savedQueries/index.tsx | 5 +- static/app/views/explore/spans/content.tsx | 25 +-- .../app/views/feedback/feedbackListPage.tsx | 26 +-- .../crons/components/monitorHeader.tsx | 19 ++- .../views/insights/pages/domainViewHeader.tsx | 12 +- .../views/insights/pages/mobile/layout.tsx | 15 +- .../app/views/investigations/detail/index.tsx | 96 +++-------- static/app/views/investigations/index.tsx | 6 +- .../issueList/editableIssueViewHeader.tsx | 154 ++---------------- .../issueViewsList/issueViewsList.tsx | 5 +- .../app/views/issueList/issueViewsHeader.tsx | 25 ++- static/app/views/issueList/overview.tsx | 2 +- .../app/views/issueList/pages/inbox/index.tsx | 25 +-- static/app/views/navigation/topBar.spec.tsx | 27 ++- static/app/views/navigation/topBar.tsx | 17 +- .../performance/transactionSummary/header.tsx | 30 +--- .../header/buildDetailsHeaderContent.tsx | 19 ++- .../app/views/preprod/components/appIcon.tsx | 11 +- .../preprod/install/buildInstallHeader.tsx | 72 +++----- .../preprod/install/installPage.spec.tsx | 27 ++- .../header/snapshotHeaderContent.tsx | 48 ++---- .../views/projectInstall/createProject.tsx | 7 +- .../views/projectInstall/scmCreateProject.tsx | 7 +- static/app/views/projectsDashboard/index.tsx | 23 +-- .../app/views/projectsDashboard/resources.tsx | 7 +- static/app/views/seerWorkflows/index.tsx | 5 +- .../views/seerWorkflows/overview/index.tsx | 7 +- .../accountSecurityDetails.tsx | 18 +- .../accountSecurity/accountSecurityEnroll.tsx | 12 +- .../components/authenticatorHeader.tsx | 26 --- .../settingsBreadcrumb/breadcrumbDropdown.tsx | 36 ++++ .../breadcrumbTitle.spec.tsx | 62 ++++++- .../settingsBreadcrumb/breadcrumbTitle.tsx | 25 ++- .../components/settingsBreadcrumb/context.tsx | 25 ++- .../components/settingsBreadcrumb/index.tsx | 85 ++++++---- .../integrationCrumb.spec.tsx | 56 +++++-- .../settingsBreadcrumb/integrationCrumb.tsx | 23 ++- .../settingsBreadcrumb/projectCrumb.tsx | 8 +- .../settingsBreadcrumb/teamCrumb.tsx | 8 +- .../components/settingsBreadcrumb/types.tsx | 1 + .../settings/components/settingsLayout.tsx | 5 +- .../components/settingsPageHeader.tsx | 13 +- .../configureIntegration.tsx | 32 +--- .../integrationDetailedView.tsx | 7 +- .../app/views/settings/projectSeer/index.tsx | 6 +- .../components/subscriptionSettingsLayout.tsx | 5 +- 76 files changed, 1097 insertions(+), 966 deletions(-) delete mode 100644 static/app/views/settings/account/accountSecurity/components/authenticatorHeader.tsx diff --git a/static/app/components/core/breadcrumbList/breadcrumbList.mdx b/static/app/components/core/breadcrumbList/breadcrumbList.mdx index 15ab0a377ced..193c950d5cd1 100644 --- a/static/app/components/core/breadcrumbList/breadcrumbList.mdx +++ b/static/app/components/core/breadcrumbList/breadcrumbList.mdx @@ -23,7 +23,7 @@ export const documentation = import('!!type-loader!@sentry/scraps/breadcrumbList `BreadcrumbList` renders the parent portion of a horizontal breadcrumb trail. It does not render a navigation landmark or a page heading. Render the current page -with `BreadcrumbList.Title` in the `TopBar` title slot; `TopBar` supplies the +with the `title` prop of `TopBar.Slot name="breadcrumbs"`; `TopBar` supplies the page's single `

`. ## Usage @@ -38,8 +38,7 @@ TopBar renders `BreadcrumbList.Title` internally and supplies the page's single `

`. The title item supports a leading graphic, a tooltip, pagination, trailing actions, or an editable field. -The separate `name="title"` slot is deprecated. It remains available for legacy -pages while their custom titles migrate to typed title items. +The `title` prop is required. There is no separate `name="title"` slot. ### Index pages @@ -267,6 +266,24 @@ Beyond `label`, the optional props are not shared evenly across the item types. | `labelTooltip` | | ✓ | | | `pagination` | | ✓ | | | `trailingActions` | | ✓ | | +| `help` | | ✓ | | +| `badge` | | ✓ | | +| `status` | | ✓ | | +| `href` | | ✓ | | + +Use `help: {description, docsUrl?, linkLabel?}` for a help tooltip beside the +title. `badge` accepts a feature badge type, such as `'new'` or `'beta'`. +`status: {label, variant}` adds an accessible status indicator. `href` makes +the title an external link while keeping its label a string. + +A trailing action with `type: 'select'` supports a searchable selector. Pass +`triggerLabel`, `options`, `value`, and `onChange`; `search`, `loading`, and +`onOpenChange` are also supported. + +Editable titles accept `editOnDoubleClick` to use a double click or the edit +button to start editing. Use `cancelOnBlur` when leaving the input must discard +the draft. By default, clicking the label starts editing and clicking outside +saves the draft. ### Leading graphics diff --git a/static/app/components/core/breadcrumbList/breadcrumbList.spec.tsx b/static/app/components/core/breadcrumbList/breadcrumbList.spec.tsx index 6cbe78c79365..fb3fba903624 100644 --- a/static/app/components/core/breadcrumbList/breadcrumbList.spec.tsx +++ b/static/app/components/core/breadcrumbList/breadcrumbList.spec.tsx @@ -23,6 +23,63 @@ function hidesBelowSm(element: HTMLElement): boolean { } describe('BreadcrumbList container-query collapse', () => { + it('shows page help, feature status, and an accessible status indicator', async () => { + render( + + ); + + expect(screen.getByText('Security')).toBeInTheDocument(); + expect(screen.getByLabelText('new')).toBeInTheDocument(); + expect( + screen.getByRole('status', {name: 'Authentication active'}) + ).toBeInTheDocument(); + await userEvent.hover(screen.getByRole('img', {name: 'More information'})); + expect(await screen.findByText('Manage authentication.')).toBeInTheDocument(); + expect(screen.getByRole('link', {name: 'Read the Docs'})).toHaveAttribute( + 'href', + 'https://example.com/docs/' + ); + }); + + it('changes the selected item through a title action', async () => { + const onChange = jest.fn(); + render( + + ); + expect(screen.getAllByText('Current project')).toHaveLength(1); + await userEvent.click(screen.getByRole('button', {name: 'Switch project'})); + await userEvent.type(screen.getByRole('textbox'), 'Next'); + await userEvent.click(screen.getByRole('option', {name: 'Next project'})); + expect(onChange).toHaveBeenCalledWith(expect.objectContaining({value: 'next'})); + }); + it('emits an @container display rule for link crumbs, not an always-on @media shadow', () => { render( diff --git a/static/app/components/core/breadcrumbList/items/breadcrumbItemPageTitle.tsx b/static/app/components/core/breadcrumbList/items/breadcrumbItemPageTitle.tsx index 9c717a5fa825..d12e331b2216 100644 --- a/static/app/components/core/breadcrumbList/items/breadcrumbItemPageTitle.tsx +++ b/static/app/components/core/breadcrumbList/items/breadcrumbItemPageTitle.tsx @@ -1,5 +1,6 @@ import {Fragment} from 'react'; +import {FeatureBadge, type FeatureBadgeProps} from '@sentry/scraps/badge/featureBadge'; import {BreadcrumbCopyAction} from '@sentry/scraps/breadcrumbList/actions/breadcrumbCopyAction'; import type {BreadcrumbCopyActionProps} from '@sentry/scraps/breadcrumbList/actions/breadcrumbCopyAction'; import {BreadcrumbMenuAction} from '@sentry/scraps/breadcrumbList/actions/breadcrumbMenuAction'; @@ -10,10 +11,15 @@ import { type LinkButtonProps, LinkButton, } from '@sentry/scraps/button'; -import {InfoText} from '@sentry/scraps/info'; -import {Container, Flex} from '@sentry/scraps/layout'; -import type {LinkProps} from '@sentry/scraps/link'; +import {CompactSelect, type SingleSelectProps} from '@sentry/scraps/compactSelect'; +import {InfoText, InfoTip} from '@sentry/scraps/info'; +import {Container, Flex, Stack} from '@sentry/scraps/layout'; +import {ExternalLink, type LinkProps} from '@sentry/scraps/link'; +import {OverlayTrigger} from '@sentry/scraps/overlayTrigger'; +import {StatusIndicator} from '@sentry/scraps/statusIndicator'; +import {Text} from '@sentry/scraps/text'; import {Tooltip} from '@sentry/scraps/tooltip'; +import {useTranslation} from '@sentry/scraps/translation/useTranslation'; import {IconChevron} from 'sentry/icons'; import {unreachable} from 'sentry/utils/unreachable'; @@ -28,6 +34,10 @@ import {BreadcrumbLeadingSlot} from './breadcrumbLeadingSlot'; type BreadcrumbTitleAction = | ({type: 'copy'} & BreadcrumbCopyActionProps) | ({type: 'menu'} & BreadcrumbMenuActionProps) + | ({triggerLabel: string; type: 'select'} & Pick< + SingleSelectProps, + 'options' | 'value' | 'onChange' | 'onOpenChange' | 'search' | 'loading' + >) | {element: React.ReactElement; type: 'button'}; /** @@ -51,6 +61,23 @@ function renderTrailingAction(action: BreadcrumbTitleAction) { } case 'button': return action.element; + case 'select': { + const {type: _type, triggerLabel, ...props} = action; + return ( + ( + } + /> + )} + /> + ); + } default: unreachable(action); return null; @@ -100,6 +127,12 @@ interface BreadcrumbItemPaginationProps { export interface BreadcrumbItemPageTitleProps { label: string; + /** Feature status shown beside the title. */ + badge?: FeatureBadgeProps['type']; + /** Explanatory tooltip with an optional documentation link. */ + help?: {description: React.ReactNode; docsUrl?: string; linkLabel?: React.ReactNode}; + /** Optional external destination for the title. */ + href?: string; /** * Tooltip shown on the label. renders an always-on custom tooltip (e.g. an issue short-id). */ @@ -111,17 +144,27 @@ export interface BreadcrumbItemPageTitleProps { leadingGraphic?: React.ReactNode; /** Structured prev/next navigation rendered before the label. */ pagination?: BreadcrumbItemPaginationProps; + /** Accessible status shown before the title. */ + status?: { + label: string; + variant: React.ComponentProps['variant']; + }; /** Typed trailing actions rendered after the page title. */ trailingActions?: BreadcrumbTitleActions; } export function BreadcrumbItemPageTitle({ label, + badge, + status, + help, + href, labelTooltip, leadingGraphic, pagination, trailingActions, }: BreadcrumbItemPageTitleProps) { + const {t} = useTranslation(); const actions = renderTrailingActions(trailingActions); return ( @@ -176,6 +219,14 @@ export function BreadcrumbItemPageTitle({ )} {leadingGraphic && {leadingGraphic}} + {status && ( + + )} {/* minWidth={0} lets the title content shrink. The visible-width floor lives on the outer Flex above. */} @@ -187,10 +238,27 @@ export function BreadcrumbItemPageTitle({ variant="inherit" {...containerProps} > - {label} + {href ? {label} : label} )} + {badge && } + {help && ( + + {help.description} + {help.docsUrl && ( + + {help.linkLabel ?? t('Read the Docs')} + + )} + + } + /> + )} {actions} ); diff --git a/static/app/components/core/breadcrumbList/items/breadcrumbItemPageTitleEditable.tsx b/static/app/components/core/breadcrumbList/items/breadcrumbItemPageTitleEditable.tsx index b77e9a34165b..a152ab594ec0 100644 --- a/static/app/components/core/breadcrumbList/items/breadcrumbItemPageTitleEditable.tsx +++ b/static/app/components/core/breadcrumbList/items/breadcrumbItemPageTitleEditable.tsx @@ -13,6 +13,8 @@ export interface BreadcrumbItemPageTitleEditableProps { /** When true, clearing + blurring cancels the edit instead of erroring. */ allowEmpty?: boolean; autoSelect?: boolean; + cancelOnBlur?: boolean; + editOnDoubleClick?: boolean; errorMessage?: React.ReactNode; isDisabled?: boolean; /** diff --git a/static/app/components/editableText.spec.tsx b/static/app/components/editableText.spec.tsx index 93121acc0ba3..2bff9cffdb1a 100644 --- a/static/app/components/editableText.spec.tsx +++ b/static/app/components/editableText.spec.tsx @@ -3,6 +3,34 @@ import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary'; import {EditableText} from 'sentry/components/editableText'; describe('EditableText', () => { + it('supports double-click editing and cancels when focus leaves the input', async () => { + const onChange = jest.fn(); + render( + + ); + + await userEvent.click(screen.getByText('My view')); + expect(screen.queryByRole('textbox')).not.toBeInTheDocument(); + await userEvent.dblClick(screen.getByText('My view')); + await userEvent.clear(screen.getByRole('textbox', {name: 'Edit view name'})); + await userEvent.type(screen.getByRole('textbox'), 'Discarded name'); + await userEvent.tab(); + expect(onChange).not.toHaveBeenCalled(); + expect(screen.getByText('My view')).toBeInTheDocument(); + + await userEvent.click(screen.getByRole('button', {name: 'Edit view name'})); + await userEvent.clear(screen.getByRole('textbox')); + await userEvent.type(screen.getByRole('textbox'), 'New name{Enter}'); + expect(onChange).toHaveBeenCalledWith('New name'); + }); + it('edit value and click outside of the component', async () => { const handleChange = jest.fn(); diff --git a/static/app/components/editableText.tsx b/static/app/components/editableText.tsx index 3ddd701818cb..8df8419a39ee 100644 --- a/static/app/components/editableText.tsx +++ b/static/app/components/editableText.tsx @@ -2,11 +2,13 @@ import {useCallback, useEffect, useRef, useState} from 'react'; import {css} from '@emotion/react'; import styled from '@emotion/styled'; +import {Button} from '@sentry/scraps/button'; import {Input} from '@sentry/scraps/input'; import {addErrorMessage} from 'sentry/actionCreators/indicator'; import {TextOverflow} from 'sentry/components/textOverflow'; import {IconEdit} from 'sentry/icons/iconEdit'; +import {t} from 'sentry/locale'; import {useOnClickOutside} from 'sentry/utils/useOnClickOutside'; type Props = { @@ -19,7 +21,11 @@ type Props = { allowEmpty?: boolean; 'aria-label'?: string; autoSelect?: boolean; + /** Cancel instead of saving when the input loses focus. */ + cancelOnBlur?: boolean; className?: string; + /** Use a double click on the label or the edit button to start editing. */ + editOnDoubleClick?: boolean; errorMessage?: React.ReactNode; isDisabled?: boolean; maxLength?: number; @@ -45,6 +51,8 @@ export function EditableText({ 'aria-label': ariaLabel, placeholder, allowEmpty = false, + cancelOnBlur = false, + editOnDoubleClick = false, variant, }: Props) { const [isEditing, setIsEditing] = useState(false); @@ -150,6 +158,10 @@ export function EditableText({ if (!isEditing) { return; } + if (cancelOnBlur) { + handleCancel(); + return; + } if (isDraftEmpty) { handleEmptyBlur(); @@ -157,7 +169,14 @@ export function EditableText({ } handleCommit(); - }, [handleCommit, handleEmptyBlur, isDraftEmpty, isEditing]); + }, [ + cancelOnBlur, + handleCancel, + handleCommit, + handleEmptyBlur, + isDraftEmpty, + isEditing, + ]); useOnClickOutside(innerWrapperRef, handleClickOutside); @@ -204,6 +223,7 @@ export function EditableText({ value={currentDraft} onChange={handleInputChange} onKeyDown={handleKeyDown} + onBlur={cancelOnBlur ? handleCancel : undefined} onFocus={event => autoSelect && event.target.select()} maxLength={maxLength} placeholder={placeholder} @@ -213,13 +233,25 @@ export function EditableText({ ) : (