traceDrawer.tsx 25 KB

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