traceDrawer.tsx 26 KB

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