traceDrawer.tsx 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925
  1. import {useCallback, useLayoutEffect, useMemo, useRef, useState} from 'react';
  2. import {type Theme, useTheme} from '@emotion/react';
  3. import styled from '@emotion/styled';
  4. import pick from 'lodash/pick';
  5. import type {Tag} from 'sentry/actionCreators/events';
  6. import {Button} from 'sentry/components/button';
  7. import {IconChevron, IconCircleFill, IconClose, IconPanel, IconPin} from 'sentry/icons';
  8. import {t} from 'sentry/locale';
  9. import {space} from 'sentry/styles/space';
  10. import type {EventTransaction} from 'sentry/types/event';
  11. import type EventView from 'sentry/utils/discover/eventView';
  12. import {PERFORMANCE_URL_PARAM} from 'sentry/utils/performance/constants';
  13. import {
  14. cancelAnimationTimeout,
  15. requestAnimationTimeout,
  16. } from 'sentry/utils/profiling/hooks/useVirtualizedTree/virtualizedTreeUtils';
  17. import type {UseApiQueryResult} from 'sentry/utils/queryClient';
  18. import {useInfiniteApiQuery} from 'sentry/utils/queryClient';
  19. import type RequestError from 'sentry/utils/requestError/requestError';
  20. import type {Color} from 'sentry/utils/theme';
  21. import {useLocation} from 'sentry/utils/useLocation';
  22. import useOrganization from 'sentry/utils/useOrganization';
  23. import type {ReplayRecord} from 'sentry/views/replays/types';
  24. import {traceAnalytics} from '../traceAnalytics';
  25. import {getTraceQueryParams} from '../traceApi/useTrace';
  26. import type {TraceMetaQueryResults} from '../traceApi/useTraceMeta';
  27. import {DrawerContainerRefContext} from '../traceDrawer/details/drawerContainerRefContext';
  28. import {TraceProfiles} from '../traceDrawer/tabs/traceProfiles';
  29. import {TraceVitals} from '../traceDrawer/tabs/traceVitals';
  30. import {
  31. usePassiveResizableDrawer,
  32. type UsePassiveResizableDrawerOptions,
  33. } from '../traceDrawer/usePassiveResizeableDrawer';
  34. import type {TraceShape, TraceTree} from '../traceModels/traceTree';
  35. import type {TraceTreeNode} from '../traceModels/traceTreeNode';
  36. import type {TraceScheduler} from '../traceRenderers/traceScheduler';
  37. import type {VirtualizedViewManager} from '../traceRenderers/virtualizedViewManager';
  38. import {makeTraceNodeBarColor} from '../traceRow/traceBar';
  39. import type {TraceReducerAction, TraceReducerState} from '../traceState';
  40. import {TRACE_DRAWER_DEFAULT_SIZES} from '../traceState/tracePreferences';
  41. import {useTraceState, useTraceStateDispatch} from '../traceState/traceStateProvider';
  42. import {getTraceTabTitle, type TraceTabsReducerState} from '../traceState/traceTabs';
  43. import {useHasTraceNewUi} from '../useHasTraceNewUi';
  44. import {TraceDetails} from './tabs/trace';
  45. import {TraceTreeNodeDetails} from './tabs/traceTreeNodeDetails';
  46. type TraceDrawerProps = {
  47. manager: VirtualizedViewManager;
  48. meta: TraceMetaQueryResults;
  49. onScrollToNode: (node: TraceTreeNode<TraceTree.NodeValue>) => void;
  50. onTabScrollToNode: (node: TraceTreeNode<TraceTree.NodeValue>) => void;
  51. replay: ReplayRecord | null;
  52. rootEventResults: UseApiQueryResult<EventTransaction, RequestError>;
  53. scheduler: TraceScheduler;
  54. trace: TraceTree;
  55. traceEventView: EventView;
  56. traceGridRef: HTMLElement | null;
  57. traceType: TraceShape;
  58. };
  59. export function TraceDrawer(props: TraceDrawerProps) {
  60. const theme = useTheme();
  61. const location = useLocation();
  62. const organization = useOrganization();
  63. const traceState = useTraceState();
  64. const traceDispatch = useTraceStateDispatch();
  65. const contentContainerRef = useRef<HTMLDivElement>(null);
  66. const hasNewTraceUi = useHasTraceNewUi();
  67. // The /events-facets/ endpoint used to fetch tags for the trace tab is slow. Therefore,
  68. // we try to prefetch the tags as soon as the drawer loads, hoping that the tags will be loaded
  69. // by the time the user clicks on the trace tab. Also prevents the tags from being refetched.
  70. const urlParams = useMemo(() => {
  71. const {timestamp} = getTraceQueryParams(location.query, undefined);
  72. const params = pick(location.query, [
  73. ...Object.values(PERFORMANCE_URL_PARAM),
  74. 'cursor',
  75. ]);
  76. if (timestamp) {
  77. params.traceTimestamp = timestamp;
  78. }
  79. return params;
  80. // eslint-disable-next-line react-hooks/exhaustive-deps
  81. }, []);
  82. const tagsInfiniteQueryResults = useInfiniteApiQuery<Tag[]>({
  83. queryKey: [
  84. `/organizations/${organization.slug}/events-facets/`,
  85. {
  86. query: {
  87. ...urlParams,
  88. ...props.traceEventView.getFacetsAPIPayload(location),
  89. cursor: undefined,
  90. },
  91. },
  92. ],
  93. });
  94. const traceStateRef = useRef(traceState);
  95. traceStateRef.current = traceState;
  96. const isDrawerMinimized =
  97. traceStateRef.current.preferences.drawer.minimized ||
  98. (hasNewTraceUi && !traceStateRef.current.tabs.current_tab?.node);
  99. const minimizedBottomDrawerSize = hasNewTraceUi ? 0 : 27;
  100. const initialSizeRef = useRef<Record<string, number> | null>(null);
  101. if (!initialSizeRef.current) {
  102. initialSizeRef.current = {};
  103. }
  104. const resizeEndRef = useRef<{id: number} | null>(null);
  105. const onResize = useCallback(
  106. (size: number, min: number, user?: boolean, minimized?: boolean) => {
  107. if (!props.traceGridRef) {
  108. return;
  109. }
  110. // When we resize the layout in x axis, we need to update the physical space
  111. // of the virtualized view manager to make sure a redrawing is correctly triggered.
  112. // If we dont do this, then the virtualized view manager will only trigger a redraw
  113. // whenver ResizeObserver detects a change. Since resize observers have "debounced"
  114. // callbacks, relying only on them to redraw the screen causes visual jank.
  115. if (
  116. (traceStateRef.current.preferences.layout === 'drawer left' ||
  117. traceStateRef.current.preferences.layout === 'drawer right') &&
  118. props.manager.container
  119. ) {
  120. const {width, height} = props.manager.container.getBoundingClientRect();
  121. props.scheduler.dispatch('set container physical space', [0, 0, width, height]);
  122. }
  123. minimized = minimized ?? isDrawerMinimized;
  124. if (traceStateRef.current.preferences.layout === 'drawer bottom' && user) {
  125. if (size <= min && !minimized && !hasNewTraceUi) {
  126. traceDispatch({
  127. type: 'minimize drawer',
  128. payload: true,
  129. });
  130. } else if (size > min && minimized) {
  131. traceDispatch({
  132. type: 'minimize drawer',
  133. payload: false,
  134. });
  135. }
  136. }
  137. const {width, height} = props.traceGridRef.getBoundingClientRect();
  138. const drawerWidth = size / width;
  139. const drawerHeight = size / height;
  140. if (resizeEndRef.current) {
  141. cancelAnimationTimeout(resizeEndRef.current);
  142. }
  143. resizeEndRef.current = requestAnimationTimeout(() => {
  144. if (isDrawerMinimized) {
  145. return;
  146. }
  147. const drawer_size =
  148. traceStateRef.current.preferences.layout === 'drawer bottom'
  149. ? drawerHeight
  150. : drawerWidth;
  151. traceDispatch({
  152. type: 'set drawer dimension',
  153. payload: drawer_size,
  154. });
  155. }, 1000);
  156. if (traceStateRef.current.preferences.layout === 'drawer bottom') {
  157. min = minimized ? minimizedBottomDrawerSize : size;
  158. } else {
  159. min = minimized ? 0 : size;
  160. }
  161. if (traceStateRef.current.preferences.layout === 'drawer bottom') {
  162. props.traceGridRef.style.gridTemplateColumns = `1fr`;
  163. props.traceGridRef.style.gridTemplateRows = `1fr minmax(${min}px, ${drawerHeight * 100}%)`;
  164. } else if (traceStateRef.current.preferences.layout === 'drawer left') {
  165. props.traceGridRef.style.gridTemplateColumns = `minmax(${min}px, ${drawerWidth * 100}%) 1fr`;
  166. props.traceGridRef.style.gridTemplateRows = '1fr auto';
  167. } else {
  168. props.traceGridRef.style.gridTemplateColumns = `1fr minmax(${min}px, ${drawerWidth * 100}%)`;
  169. props.traceGridRef.style.gridTemplateRows = '1fr auto';
  170. }
  171. },
  172. [
  173. props.traceGridRef,
  174. props.manager,
  175. props.scheduler,
  176. traceDispatch,
  177. isDrawerMinimized,
  178. hasNewTraceUi,
  179. minimizedBottomDrawerSize,
  180. ]
  181. );
  182. const [drawerRef, setDrawerRef] = useState<HTMLDivElement | null>(null);
  183. const drawerOptions: Pick<UsePassiveResizableDrawerOptions, 'min' | 'initialSize'> =
  184. useMemo(() => {
  185. const initialSizeInPercentage =
  186. traceState.preferences.drawer.sizes[traceState.preferences.layout];
  187. // We have a stored user preference for the drawer size
  188. const {width, height} = props.traceGridRef?.getBoundingClientRect() ?? {
  189. width: 0,
  190. height: 0,
  191. };
  192. const initialSize = isDrawerMinimized
  193. ? 0
  194. : traceState.preferences.layout === 'drawer bottom'
  195. ? height * initialSizeInPercentage
  196. : width * initialSizeInPercentage;
  197. return {
  198. min: traceState.preferences.layout === 'drawer bottom' ? 27 : 350,
  199. initialSize,
  200. ref: drawerRef,
  201. };
  202. // eslint-disable-next-line react-hooks/exhaustive-deps
  203. }, [props.traceGridRef, traceState.preferences.layout, drawerRef, isDrawerMinimized]);
  204. const resizableDrawerOptions: UsePassiveResizableDrawerOptions = useMemo(() => {
  205. return {
  206. ...drawerOptions,
  207. onResize,
  208. direction:
  209. traceState.preferences.layout === 'drawer left'
  210. ? 'left'
  211. : traceState.preferences.layout === 'drawer right'
  212. ? 'right'
  213. : 'up',
  214. };
  215. }, [onResize, drawerOptions, traceState.preferences.layout]);
  216. const {onMouseDown, size} = usePassiveResizableDrawer(resizableDrawerOptions);
  217. const onParentClick = useCallback(
  218. (node: TraceTreeNode<TraceTree.NodeValue>) => {
  219. props.onTabScrollToNode(node);
  220. traceDispatch({
  221. type: 'activate tab',
  222. payload: node,
  223. pin_previous: true,
  224. });
  225. },
  226. [props, traceDispatch]
  227. );
  228. const onMinimizeClick = useCallback(() => {
  229. traceAnalytics.trackDrawerMinimize(organization);
  230. traceDispatch({
  231. type: 'minimize drawer',
  232. payload: !isDrawerMinimized,
  233. });
  234. if (!isDrawerMinimized) {
  235. onResize(0, 0, true, true);
  236. size.current = drawerOptions.min;
  237. } else {
  238. if (drawerOptions.initialSize === 0) {
  239. const userPreference =
  240. traceStateRef.current.preferences.drawer.sizes[
  241. traceStateRef.current.preferences.layout
  242. ];
  243. const {width, height} = props.traceGridRef?.getBoundingClientRect() ?? {
  244. width: 0,
  245. height: 0,
  246. };
  247. const containerSize =
  248. traceStateRef.current.preferences.layout === 'drawer bottom' ? height : width;
  249. const drawer_size = containerSize * userPreference;
  250. onResize(drawer_size, drawerOptions.min, true, false);
  251. size.current = userPreference;
  252. return;
  253. }
  254. onResize(drawerOptions.initialSize, drawerOptions.min, true, false);
  255. size.current = drawerOptions.initialSize;
  256. }
  257. }, [
  258. size,
  259. onResize,
  260. traceDispatch,
  261. props.traceGridRef,
  262. isDrawerMinimized,
  263. organization,
  264. drawerOptions,
  265. ]);
  266. const onDoubleClickResetToDefault = useCallback(() => {
  267. if (!isDrawerMinimized) {
  268. onMinimizeClick();
  269. return;
  270. }
  271. traceDispatch({type: 'minimize drawer', payload: false});
  272. const initialSize = TRACE_DRAWER_DEFAULT_SIZES[traceState.preferences.layout];
  273. const {width, height} = props.traceGridRef?.getBoundingClientRect() ?? {
  274. width: 0,
  275. height: 0,
  276. };
  277. const containerSize =
  278. traceState.preferences.layout === 'drawer bottom' ? height : width;
  279. const drawer_size = containerSize * initialSize;
  280. onResize(drawer_size, drawerOptions.min, true, false);
  281. size.current = drawer_size;
  282. }, [
  283. size,
  284. onMinimizeClick,
  285. onResize,
  286. drawerOptions.min,
  287. traceState.preferences.layout,
  288. props.traceGridRef,
  289. isDrawerMinimized,
  290. traceDispatch,
  291. ]);
  292. const initializedRef = useRef(false);
  293. useLayoutEffect(() => {
  294. if (initializedRef.current) {
  295. return;
  296. }
  297. if (isDrawerMinimized && props.traceGridRef) {
  298. if (traceStateRef.current.preferences.layout === 'drawer bottom') {
  299. props.traceGridRef.style.gridTemplateColumns = `1fr`;
  300. props.traceGridRef.style.gridTemplateRows = `1fr minmax(${minimizedBottomDrawerSize}px, 0%)`;
  301. size.current = minimizedBottomDrawerSize;
  302. } else if (traceStateRef.current.preferences.layout === 'drawer left') {
  303. props.traceGridRef.style.gridTemplateColumns = `minmax(${0}px, 0%) 1fr`;
  304. props.traceGridRef.style.gridTemplateRows = '1fr auto';
  305. size.current = 0;
  306. } else {
  307. props.traceGridRef.style.gridTemplateColumns = `1fr minmax(${0}px, 0%)`;
  308. props.traceGridRef.style.gridTemplateRows = '1fr auto';
  309. size.current = 0;
  310. }
  311. initializedRef.current = true;
  312. }
  313. // eslint-disable-next-line react-hooks/exhaustive-deps
  314. }, [props.traceGridRef, minimizedBottomDrawerSize]);
  315. // Syncs the height of the tabs with the trace indicators
  316. const hasIndicators =
  317. props.trace.indicators.length > 0 &&
  318. traceState.preferences.layout !== 'drawer bottom';
  319. if (
  320. isDrawerMinimized &&
  321. (traceState.preferences.layout !== 'drawer bottom' || hasNewTraceUi)
  322. ) {
  323. return hasNewTraceUi ? null : (
  324. <TabsHeightContainer
  325. absolute
  326. layout={traceState.preferences.layout}
  327. hasIndicators={hasIndicators}
  328. >
  329. <TabLayoutControlItem>
  330. <TraceLayoutMinimizeButton onClick={onMinimizeClick} trace_state={traceState} />
  331. </TabLayoutControlItem>
  332. </TabsHeightContainer>
  333. );
  334. }
  335. return (
  336. <PanelWrapper ref={setDrawerRef} layout={traceState.preferences.layout}>
  337. <ResizeableHandle
  338. layout={traceState.preferences.layout}
  339. onMouseDown={onMouseDown}
  340. onDoubleClick={onDoubleClickResetToDefault}
  341. />
  342. <TabsHeightContainer
  343. layout={traceState.preferences.layout}
  344. onDoubleClick={onDoubleClickResetToDefault}
  345. hasIndicators={hasIndicators}
  346. >
  347. <TabsLayout data-test-id="trace-drawer-tabs">
  348. <TabActions>
  349. <TabLayoutControlItem>
  350. <TraceLayoutMinimizeButton
  351. onClick={onMinimizeClick}
  352. trace_state={traceState}
  353. />
  354. <TabSeparator />
  355. </TabLayoutControlItem>
  356. </TabActions>
  357. <TabsContainer
  358. style={{
  359. gridTemplateColumns: `repeat(${traceState.tabs.tabs.length + (traceState.tabs.last_clicked_tab ? 1 : 0)}, minmax(0, min-content))`,
  360. }}
  361. >
  362. {/* Renders all open tabs */}
  363. {traceState.tabs.tabs.map((n, i) => {
  364. return (
  365. <TraceDrawerTab
  366. key={i}
  367. tab={n}
  368. index={i}
  369. theme={theme}
  370. trace={props.trace}
  371. trace_state={traceState}
  372. traceDispatch={traceDispatch}
  373. onTabScrollToNode={props.onTabScrollToNode}
  374. pinned
  375. />
  376. );
  377. })}
  378. {/* Renders the last tab the user clicked on - this one is ephemeral and might change */}
  379. {traceState.tabs.last_clicked_tab ? (
  380. <TraceDrawerTab
  381. pinned={false}
  382. key="last-clicked"
  383. tab={traceState.tabs.last_clicked_tab}
  384. index={traceState.tabs.tabs.length}
  385. theme={theme}
  386. trace_state={traceState}
  387. traceDispatch={traceDispatch}
  388. onTabScrollToNode={props.onTabScrollToNode}
  389. trace={props.trace}
  390. />
  391. ) : null}
  392. </TabsContainer>
  393. {traceState.preferences.drawer.layoutOptions.length > 0 && !hasNewTraceUi ? (
  394. <TraceLayoutButtons traceDispatch={traceDispatch} trace_state={traceState} />
  395. ) : null}
  396. </TabsLayout>
  397. </TabsHeightContainer>
  398. {isDrawerMinimized ? null : (
  399. <DrawerContainerRefContext.Provider value={contentContainerRef}>
  400. <Content
  401. ref={contentContainerRef}
  402. layout={traceState.preferences.layout}
  403. data-test-id="trace-drawer"
  404. >
  405. <ContentWrapper>
  406. {traceState.tabs.current_tab ? (
  407. traceState.tabs.current_tab.node === 'trace' ? (
  408. <TraceDetails
  409. meta={props.meta}
  410. traceType={props.traceType}
  411. tree={props.trace}
  412. node={props.trace.root.children[0]!}
  413. rootEventResults={props.rootEventResults}
  414. tagsInfiniteQueryResults={tagsInfiniteQueryResults}
  415. traceEventView={props.traceEventView}
  416. />
  417. ) : traceState.tabs.current_tab.node === 'vitals' ? (
  418. <TraceVitals trace={props.trace} />
  419. ) : traceState.tabs.current_tab.node === 'profiles' ? (
  420. <TraceProfiles
  421. tree={props.trace}
  422. onScrollToNode={props.onScrollToNode}
  423. />
  424. ) : (
  425. <TraceTreeNodeDetails
  426. replay={props.replay}
  427. manager={props.manager}
  428. organization={organization}
  429. onParentClick={onParentClick}
  430. node={traceState.tabs.current_tab.node}
  431. onTabScrollToNode={props.onTabScrollToNode}
  432. />
  433. )
  434. ) : null}
  435. </ContentWrapper>
  436. </Content>
  437. </DrawerContainerRefContext.Provider>
  438. )}
  439. </PanelWrapper>
  440. );
  441. }
  442. interface TraceDrawerTabProps {
  443. index: number;
  444. onTabScrollToNode: (node: TraceTreeNode<TraceTree.NodeValue>) => void;
  445. pinned: boolean;
  446. tab: TraceTabsReducerState['tabs'][number];
  447. theme: Theme;
  448. trace: TraceTree;
  449. traceDispatch: React.Dispatch<TraceReducerAction>;
  450. trace_state: TraceReducerState;
  451. }
  452. function TraceDrawerTab(props: TraceDrawerTabProps) {
  453. const organization = useOrganization();
  454. const node = props.tab.node;
  455. const hasNewTraceUi = useHasTraceNewUi();
  456. if (typeof node === 'string') {
  457. const root = props.trace.root.children[0];
  458. return (
  459. <Tab
  460. data-test-id="trace-drawer-tab"
  461. className={typeof props.tab.node === 'string' ? 'Static' : ''}
  462. aria-selected={
  463. props.tab === props.trace_state.tabs.current_tab ? 'true' : 'false'
  464. }
  465. onClick={() => {
  466. if (props.tab.node !== 'vitals' && props.tab.node !== 'profiles') {
  467. traceAnalytics.trackTabView(node, organization);
  468. props.onTabScrollToNode(root!);
  469. }
  470. props.traceDispatch({type: 'activate tab', payload: props.index});
  471. }}
  472. >
  473. {/* A trace is technically an entry in the list, so it has a color */}
  474. {props.tab.node === 'trace' ||
  475. props.tab.node === 'vitals' ||
  476. props.tab.node === 'profiles' ? null : (
  477. <TabButtonIndicator
  478. backgroundColor={makeTraceNodeBarColor(props.theme, root!)}
  479. />
  480. )}
  481. <TabButton>{props.tab.label ?? node}</TabButton>
  482. </Tab>
  483. );
  484. }
  485. return (
  486. <Tab
  487. data-test-id="trace-drawer-tab"
  488. aria-selected={props.tab === props.trace_state.tabs.current_tab ? 'true' : 'false'}
  489. onClick={() => {
  490. traceAnalytics.trackTabView('event', organization);
  491. props.onTabScrollToNode(node);
  492. props.traceDispatch({type: 'activate tab', payload: props.index});
  493. }}
  494. >
  495. {hasNewTraceUi ? (
  496. <StyledIconCircleFilled
  497. size="xs"
  498. color={makeTraceNodeBarColor(props.theme, node) as Color}
  499. />
  500. ) : (
  501. <TabButtonIndicator backgroundColor={makeTraceNodeBarColor(props.theme, node)} />
  502. )}
  503. <TabButton>{getTraceTabTitle(node)}</TabButton>
  504. <TabPinButton
  505. pinned={props.pinned}
  506. onClick={e => {
  507. e.stopPropagation();
  508. traceAnalytics.trackTabPin(organization);
  509. props.pinned
  510. ? props.traceDispatch({type: 'unpin tab', payload: props.index})
  511. : props.traceDispatch({type: 'pin tab'});
  512. }}
  513. />
  514. </Tab>
  515. );
  516. }
  517. function TraceLayoutButtons(props: {
  518. traceDispatch: React.Dispatch<TraceReducerAction>;
  519. trace_state: TraceReducerState;
  520. }) {
  521. const organization = useOrganization();
  522. return (
  523. <TabActions>
  524. {props.trace_state.preferences.drawer.layoutOptions.includes('drawer left') ? (
  525. <TabLayoutControlItem>
  526. <TabIconButton
  527. active={props.trace_state.preferences.layout === 'drawer left'}
  528. onClick={() => {
  529. traceAnalytics.trackLayoutChange('drawer left', organization);
  530. props.traceDispatch({type: 'set layout', payload: 'drawer left'});
  531. }}
  532. size="xs"
  533. aria-label={t('Drawer left')}
  534. icon={<IconPanel size="xs" direction="left" />}
  535. />
  536. </TabLayoutControlItem>
  537. ) : null}
  538. {props.trace_state.preferences.drawer.layoutOptions.includes('drawer bottom') ? (
  539. <TabLayoutControlItem>
  540. <TabIconButton
  541. active={props.trace_state.preferences.layout === 'drawer bottom'}
  542. onClick={() => {
  543. traceAnalytics.trackLayoutChange('drawer bottom', organization);
  544. props.traceDispatch({type: 'set layout', payload: 'drawer bottom'});
  545. }}
  546. size="xs"
  547. aria-label={t('Drawer bottom')}
  548. icon={<IconPanel size="xs" direction="down" />}
  549. />
  550. </TabLayoutControlItem>
  551. ) : null}
  552. {props.trace_state.preferences.drawer.layoutOptions.includes('drawer right') ? (
  553. <TabLayoutControlItem>
  554. <TabIconButton
  555. active={props.trace_state.preferences.layout === 'drawer right'}
  556. onClick={() => {
  557. traceAnalytics.trackLayoutChange('drawer right', organization);
  558. props.traceDispatch({type: 'set layout', payload: 'drawer right'});
  559. }}
  560. size="xs"
  561. aria-label={t('Drawer right')}
  562. icon={<IconPanel size="xs" direction="right" />}
  563. />
  564. </TabLayoutControlItem>
  565. ) : null}
  566. </TabActions>
  567. );
  568. }
  569. function TraceLayoutMinimizeButton(props: {
  570. onClick: () => void;
  571. trace_state: TraceReducerState;
  572. }) {
  573. const hasNewTraceUi = useHasTraceNewUi();
  574. if (!hasNewTraceUi) {
  575. return <LegacyTraceLayoutMinimizeButton {...props} />;
  576. }
  577. return (
  578. <CloseButton
  579. priority="link"
  580. size="xs"
  581. borderless
  582. aria-label={t('Close Drawer')}
  583. icon={<StyledIconClose />}
  584. onClick={props.onClick}
  585. >
  586. {t('Close')}
  587. </CloseButton>
  588. );
  589. }
  590. const StyledIconClose = styled(IconClose)`
  591. width: 10px;
  592. height: 10px;
  593. `;
  594. const CloseButton = styled(Button)`
  595. font-size: ${p => p.theme.fontSizeSmall};
  596. color: ${p => p.theme.subText};
  597. height: 100%;
  598. border-bottom: 2px solid transparent;
  599. &:hover {
  600. color: ${p => p.theme.textColor};
  601. }
  602. `;
  603. function LegacyTraceLayoutMinimizeButton(props: {
  604. onClick: () => void;
  605. trace_state: TraceReducerState;
  606. }) {
  607. return (
  608. <TabIconButton
  609. size="xs"
  610. active={props.trace_state.preferences.drawer.minimized}
  611. onClick={props.onClick}
  612. aria-label={t('Minimize')}
  613. icon={
  614. <SmallerChevronIcon
  615. size="sm"
  616. isCircled
  617. direction={
  618. props.trace_state.preferences.layout === 'drawer bottom'
  619. ? props.trace_state.preferences.drawer.minimized
  620. ? 'up'
  621. : 'down'
  622. : props.trace_state.preferences.layout === 'drawer left'
  623. ? props.trace_state.preferences.drawer.minimized
  624. ? 'right'
  625. : 'left'
  626. : props.trace_state.preferences.drawer.minimized
  627. ? 'left'
  628. : 'right'
  629. }
  630. />
  631. }
  632. />
  633. );
  634. }
  635. const StyledIconCircleFilled = styled(IconCircleFill)`
  636. margin-right: ${space(0.25)};
  637. `;
  638. const ResizeableHandle = styled('div')<{
  639. layout: 'drawer bottom' | 'drawer left' | 'drawer right';
  640. }>`
  641. width: ${p => (p.layout === 'drawer bottom' ? '100%' : '12px')};
  642. height: ${p => (p.layout === 'drawer bottom' ? '12px' : '100%')};
  643. cursor: ${p => (p.layout === 'drawer bottom' ? 'ns-resize' : 'ew-resize')};
  644. position: absolute;
  645. top: ${p => (p.layout === 'drawer bottom' ? '-6px' : 0)};
  646. left: ${p =>
  647. p.layout === 'drawer bottom' ? 0 : p.layout === 'drawer right' ? '-6px' : 'initial'};
  648. right: ${p => (p.layout === 'drawer left' ? '-6px' : 0)};
  649. z-index: 1;
  650. `;
  651. const PanelWrapper = styled('div')<{
  652. layout: 'drawer bottom' | 'drawer left' | 'drawer right';
  653. }>`
  654. grid-area: drawer;
  655. display: flex;
  656. flex-direction: column;
  657. overflow: hidden;
  658. width: 100%;
  659. border-top: ${p =>
  660. p.layout === 'drawer bottom' ? `1px solid ${p.theme.border}` : 'none'};
  661. border-left: ${p =>
  662. p.layout === 'drawer right' ? `1px solid ${p.theme.border}` : 'none'};
  663. border-right: ${p =>
  664. p.layout === 'drawer left' ? `1px solid ${p.theme.border}` : 'none'};
  665. bottom: 0;
  666. right: 0;
  667. position: relative;
  668. background: ${p => p.theme.background};
  669. color: ${p => p.theme.textColor};
  670. text-align: left;
  671. z-index: 10;
  672. `;
  673. const SmallerChevronIcon = styled(IconChevron)`
  674. width: 13px;
  675. height: 13px;
  676. transition: none;
  677. `;
  678. const TabsHeightContainer = styled('div')<{
  679. hasIndicators: boolean;
  680. layout: 'drawer bottom' | 'drawer left' | 'drawer right';
  681. absolute?: boolean;
  682. }>`
  683. background: ${p => p.theme.background};
  684. left: ${p => (p.layout === 'drawer left' ? '0' : 'initial')};
  685. right: ${p => (p.layout === 'drawer right' ? '0' : 'initial')};
  686. position: ${p => (p.absolute ? 'absolute' : 'relative')};
  687. height: ${p => (p.hasIndicators ? '44px' : '26px')};
  688. border-bottom: 1px solid ${p => p.theme.border};
  689. display: flex;
  690. flex-direction: column;
  691. justify-content: end;
  692. `;
  693. const TabsLayout = styled('div')`
  694. display: grid;
  695. grid-template-columns: auto 1fr auto;
  696. padding-left: ${space(1)};
  697. padding-right: ${space(0.5)};
  698. `;
  699. const TabsContainer = styled('ul')`
  700. display: grid;
  701. list-style-type: none;
  702. width: 100%;
  703. align-items: center;
  704. justify-content: left;
  705. gap: ${space(0.5)};
  706. padding-left: 0;
  707. margin-bottom: 0;
  708. `;
  709. const TabActions = styled('ul')`
  710. display: flex;
  711. align-items: center;
  712. list-style-type: none;
  713. padding-left: 0;
  714. margin-bottom: 0;
  715. flex: none;
  716. button {
  717. padding: 0 ${space(0.25)};
  718. }
  719. `;
  720. const TabSeparator = styled('span')`
  721. display: inline-block;
  722. margin-left: ${space(0.5)};
  723. margin-right: ${space(0.5)};
  724. height: 16px;
  725. width: 1px;
  726. background-color: ${p => p.theme.border};
  727. transform: translateY(3px);
  728. `;
  729. const TabLayoutControlItem = styled('li')`
  730. display: inline-block;
  731. margin: 0;
  732. position: relative;
  733. z-index: 10;
  734. background-color: ${p => p.theme.background};
  735. height: 100%;
  736. `;
  737. const Tab = styled('li')`
  738. height: 100%;
  739. border-top: 2px solid transparent;
  740. display: flex;
  741. align-items: center;
  742. border-bottom: 2px solid transparent;
  743. padding: 0 ${space(0.25)};
  744. position: relative;
  745. &.Static + li:not(.Static) {
  746. margin-left: 10px;
  747. &:after {
  748. display: block;
  749. content: '';
  750. position: absolute;
  751. left: -10px;
  752. top: 50%;
  753. transform: translateY(-50%);
  754. height: 16px;
  755. width: 1px;
  756. background-color: ${p => p.theme.border};
  757. }
  758. }
  759. &:hover {
  760. border-bottom: 2px solid ${p => p.theme.blue200};
  761. button:last-child {
  762. transition: all 0.3s ease-in-out 500ms;
  763. transform: scale(1);
  764. opacity: 1;
  765. }
  766. }
  767. &[aria-selected='true'] {
  768. border-bottom: 2px solid ${p => p.theme.blue400};
  769. }
  770. `;
  771. const TabButtonIndicator = styled('div')<{backgroundColor: string}>`
  772. width: 12px;
  773. height: 12px;
  774. min-width: 12px;
  775. border-radius: 2px;
  776. margin-right: ${space(0.25)};
  777. background-color: ${p => p.backgroundColor};
  778. `;
  779. const TabButton = styled('button')`
  780. height: 100%;
  781. border: none;
  782. max-width: 28ch;
  783. overflow: hidden;
  784. text-overflow: ellipsis;
  785. white-space: nowrap;
  786. border-radius: 0;
  787. margin: 0;
  788. padding: 0 ${space(0.25)};
  789. font-size: ${p => p.theme.fontSizeSmall};
  790. color: ${p => p.theme.textColor};
  791. background: transparent;
  792. `;
  793. const Content = styled('div')<{layout: 'drawer bottom' | 'drawer left' | 'drawer right'}>`
  794. position: relative;
  795. overflow: auto;
  796. flex: 1;
  797. td {
  798. max-width: 100% !important;
  799. }
  800. `;
  801. const TabIconButton = styled(Button)<{active: boolean}>`
  802. border: none;
  803. background-color: transparent;
  804. box-shadow: none;
  805. transition: none !important;
  806. opacity: ${p => (p.active ? 0.7 : 0.5)};
  807. height: 24px;
  808. max-height: 24px;
  809. &:hover {
  810. border: none;
  811. background-color: transparent;
  812. box-shadow: none;
  813. opacity: ${p => (p.active ? 0.6 : 0.5)};
  814. }
  815. `;
  816. function TabPinButton(props: {
  817. pinned: boolean;
  818. onClick?: (e: React.MouseEvent<HTMLElement>) => void;
  819. }) {
  820. return (
  821. <PinButton
  822. size="zero"
  823. data-test-id="trace-drawer-tab-pin-button"
  824. onClick={props.onClick}
  825. >
  826. <StyledIconPin size="xs" isSolid={props.pinned} />
  827. </PinButton>
  828. );
  829. }
  830. const PinButton = styled(Button)`
  831. padding: ${space(0.5)};
  832. margin: 0;
  833. background-color: transparent;
  834. border: none;
  835. &:hover {
  836. background-color: transparent;
  837. }
  838. `;
  839. const StyledIconPin = styled(IconPin)`
  840. background-color: transparent;
  841. border: none;
  842. `;
  843. const ContentWrapper = styled('div')`
  844. inset: ${space(1)};
  845. position: absolute;
  846. `;