traceDrawer.tsx 28 KB

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