traceDrawer.tsx 28 KB

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