traceDrawer.tsx 28 KB

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