traceDrawer.tsx 27 KB

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