traceDrawer.tsx 27 KB

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