traceDrawer.tsx 24 KB

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