tableView.tsx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import * as Sentry from '@sentry/react';
  4. import type {Location, LocationDescriptorObject} from 'history';
  5. import {openModal} from 'sentry/actionCreators/modal';
  6. import GridEditable, {
  7. COL_WIDTH_MINIMUM,
  8. COL_WIDTH_UNDEFINED,
  9. } from 'sentry/components/gridEditable';
  10. import SortLink from 'sentry/components/gridEditable/sortLink';
  11. import Link from 'sentry/components/links/link';
  12. import {Tooltip} from 'sentry/components/tooltip';
  13. import Truncate from 'sentry/components/truncate';
  14. import {IconStack} from 'sentry/icons';
  15. import {t} from 'sentry/locale';
  16. import type {Organization} from 'sentry/types/organization';
  17. import {trackAnalytics} from 'sentry/utils/analytics';
  18. import {browserHistory} from 'sentry/utils/browserHistory';
  19. import type {CustomMeasurementCollection} from 'sentry/utils/customMeasurements/customMeasurements';
  20. import {getTimeStampFromTableDateField} from 'sentry/utils/dates';
  21. import type {TableData, TableDataRow} from 'sentry/utils/discover/discoverQuery';
  22. import type EventView from 'sentry/utils/discover/eventView';
  23. import {
  24. isFieldSortable,
  25. pickRelevantLocationQueryStrings,
  26. } from 'sentry/utils/discover/eventView';
  27. import {
  28. DURATION_UNITS,
  29. getFieldRenderer,
  30. SIZE_UNITS,
  31. } from 'sentry/utils/discover/fieldRenderers';
  32. import type {Column} from 'sentry/utils/discover/fields';
  33. import {
  34. fieldAlignment,
  35. getEquationAliasIndex,
  36. isEquationAlias,
  37. } from 'sentry/utils/discover/fields';
  38. import {
  39. type DiscoverDatasets,
  40. DisplayModes,
  41. SavedQueryDatasets,
  42. TOP_N,
  43. } from 'sentry/utils/discover/types';
  44. import {generateLinkToEventInTraceView} from 'sentry/utils/discover/urls';
  45. import ViewReplayLink from 'sentry/utils/discover/viewReplayLink';
  46. import {getShortEventId} from 'sentry/utils/events';
  47. import {generateProfileFlamechartRoute} from 'sentry/utils/profiling/routes';
  48. import {decodeList} from 'sentry/utils/queryString';
  49. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  50. import normalizeUrl from 'sentry/utils/url/normalizeUrl';
  51. import {useNavigate} from 'sentry/utils/useNavigate';
  52. import useProjects from 'sentry/utils/useProjects';
  53. import {useRoutes} from 'sentry/utils/useRoutes';
  54. import {appendQueryDatasetParam, hasDatasetSelector} from 'sentry/views/dashboards/utils';
  55. import {TraceViewSources} from 'sentry/views/performance/newTraceDetails/traceHeader/breadcrumbs';
  56. import {getTraceDetailsUrl} from 'sentry/views/performance/traceDetails/utils';
  57. import {generateReplayLink} from 'sentry/views/performance/transactionSummary/utils';
  58. import {makeReleasesPathname} from 'sentry/views/releases/utils/pathnames';
  59. import {
  60. getExpandedResults,
  61. getTargetForTransactionSummaryLink,
  62. pushEventViewToLocation,
  63. } from '../utils';
  64. import {QuickContextHoverWrapper} from './quickContext/quickContextWrapper';
  65. import {ContextType} from './quickContext/utils';
  66. import CellAction, {Actions, updateQuery} from './cellAction';
  67. import ColumnEditModal, {modalCss} from './columnEditModal';
  68. import TableActions from './tableActions';
  69. import TopResultsIndicator from './topResultsIndicator';
  70. import type {TableColumn} from './types';
  71. export type TableViewProps = {
  72. error: string | null;
  73. eventView: EventView;
  74. isFirstPage: boolean;
  75. isLoading: boolean;
  76. location: Location;
  77. measurementKeys: null | string[];
  78. onChangeShowTags: () => void;
  79. organization: Organization;
  80. showTags: boolean;
  81. tableData: TableData | null | undefined;
  82. title: string;
  83. customMeasurements?: CustomMeasurementCollection;
  84. dataset?: DiscoverDatasets;
  85. isHomepage?: boolean;
  86. queryDataset?: SavedQueryDatasets;
  87. spanOperationBreakdownKeys?: string[];
  88. };
  89. /**
  90. * The `TableView` is marked with leading _ in its method names. It consumes
  91. * the EventView object given in its props to generate new EventView objects
  92. * for actions like resizing column.
  93. *
  94. * The entire state of the table view (or event view) is co-located within
  95. * the EventView object. This object is fed from the props.
  96. *
  97. * Attempting to modify the state, and therefore, modifying the given EventView
  98. * object given from its props, will generate new instances of EventView objects.
  99. *
  100. * In most cases, the new EventView object differs from the previous EventView
  101. * object. The new EventView object is pushed to the location object.
  102. */
  103. function TableView(props: TableViewProps) {
  104. const {projects} = useProjects();
  105. const routes = useRoutes();
  106. const navigate = useNavigate();
  107. const replayLinkGenerator = generateReplayLink(routes);
  108. /**
  109. * Updates a column on resizing
  110. */
  111. function _resizeColumn(
  112. columnIndex: number,
  113. nextColumn: TableColumn<keyof TableDataRow>
  114. ) {
  115. const {location, eventView, organization, queryDataset} = props;
  116. const newWidth = nextColumn.width ? Number(nextColumn.width) : COL_WIDTH_UNDEFINED;
  117. const nextEventView = eventView.withResizedColumn(columnIndex, newWidth);
  118. pushEventViewToLocation({
  119. navigate,
  120. location,
  121. nextEventView,
  122. extraQuery: {
  123. ...pickRelevantLocationQueryStrings(location),
  124. ...appendQueryDatasetParam(organization, queryDataset),
  125. },
  126. });
  127. }
  128. function _renderPrependColumns(
  129. isHeader: boolean,
  130. dataRow?: any,
  131. rowIndex?: number
  132. ): React.ReactNode[] {
  133. const {organization, eventView, tableData, location, isHomepage, queryDataset} =
  134. props;
  135. const hasAggregates = eventView.hasAggregateField();
  136. const hasIdField = eventView.hasIdField();
  137. const isTransactionsDataset =
  138. hasDatasetSelector(organization) &&
  139. queryDataset === SavedQueryDatasets.TRANSACTIONS;
  140. if (isHeader) {
  141. if (hasAggregates) {
  142. return [
  143. <PrependHeader key="header-icon">
  144. <IconStack size="sm" />
  145. </PrependHeader>,
  146. ];
  147. }
  148. if (!hasIdField) {
  149. return [
  150. <PrependHeader key="header-event-id">
  151. <SortLink
  152. align="left"
  153. title={t('event id')}
  154. direction={undefined}
  155. canSort={false}
  156. generateSortLink={() => undefined}
  157. />
  158. </PrependHeader>,
  159. ];
  160. }
  161. return [];
  162. }
  163. if (hasAggregates) {
  164. const nextView = getExpandedResults(eventView, {}, dataRow);
  165. const target = {
  166. pathname: location.pathname,
  167. query: {
  168. ...nextView.generateQueryStringObject(),
  169. ...appendQueryDatasetParam(organization, queryDataset),
  170. },
  171. };
  172. return [
  173. <Tooltip key={`eventlink${rowIndex}`} title={t('Open Group')}>
  174. <Link
  175. to={target}
  176. data-test-id="open-group"
  177. onClick={() => {
  178. if (nextView.isEqualTo(eventView)) {
  179. Sentry.captureException(new Error('Failed to drilldown'));
  180. }
  181. }}
  182. >
  183. <StyledIcon size="sm" />
  184. </Link>
  185. </Tooltip>,
  186. ];
  187. }
  188. if (!hasIdField) {
  189. let value = dataRow.id;
  190. if (tableData?.meta) {
  191. const fieldRenderer = getFieldRenderer('id', tableData.meta);
  192. value = fieldRenderer(dataRow, {organization, location});
  193. }
  194. let target: any;
  195. if (dataRow['event.type'] !== 'transaction' && !isTransactionsDataset) {
  196. const project = dataRow.project || dataRow['project.name'];
  197. target = {
  198. // NOTE: This uses a legacy redirect for project event to the issue group event link
  199. // This only works with dev-server or production.
  200. pathname: normalizeUrl(
  201. `/${organization.slug}/${project}/events/${dataRow.id}/`
  202. ),
  203. query: {...location.query, referrer: 'discover-events-table'},
  204. };
  205. } else {
  206. if (!dataRow.trace) {
  207. throw new Error(
  208. 'Transaction event should always have a trace associated with it.'
  209. );
  210. }
  211. target = generateLinkToEventInTraceView({
  212. traceSlug: dataRow.trace,
  213. eventId: dataRow.id,
  214. projectSlug: dataRow.project || dataRow['project.name'],
  215. timestamp: dataRow.timestamp,
  216. organization,
  217. isHomepage,
  218. location,
  219. eventView,
  220. type: 'discover',
  221. source: TraceViewSources.DISCOVER,
  222. });
  223. }
  224. const eventIdLink = (
  225. <StyledLink data-test-id="view-event" to={target}>
  226. {value}
  227. </StyledLink>
  228. );
  229. return [
  230. <QuickContextHoverWrapper
  231. key={`quickContextEventHover${rowIndex}`}
  232. dataRow={dataRow}
  233. contextType={ContextType.EVENT}
  234. organization={organization}
  235. projects={projects}
  236. eventView={eventView}
  237. >
  238. {eventIdLink}
  239. </QuickContextHoverWrapper>,
  240. ];
  241. }
  242. return [];
  243. }
  244. function _renderGridHeaderCell(
  245. column: TableColumn<keyof TableDataRow>
  246. ): React.ReactNode {
  247. const {eventView, location, tableData, organization, queryDataset} = props;
  248. const tableMeta = tableData?.meta;
  249. const align = fieldAlignment(column.name, column.type, tableMeta);
  250. const field = {field: column.key as string, width: column.width};
  251. function generateSortLink(): LocationDescriptorObject | undefined {
  252. if (!tableMeta) {
  253. return undefined;
  254. }
  255. const nextEventView = eventView.sortOnField(field, tableMeta);
  256. const queryStringObject = nextEventView.generateQueryStringObject();
  257. // Need to pull yAxis from location since eventView only stores 1 yAxis field at time
  258. queryStringObject.yAxis = decodeList(location.query.yAxis);
  259. return {
  260. ...location,
  261. query: {
  262. ...queryStringObject,
  263. ...appendQueryDatasetParam(organization, queryDataset),
  264. },
  265. };
  266. }
  267. const currentSort = eventView.sortForField(field, tableMeta);
  268. const canSort = isFieldSortable(field, tableMeta);
  269. let titleText = isEquationAlias(column.name)
  270. ? eventView.getEquations()[getEquationAliasIndex(column.name)]!
  271. : column.name;
  272. if (column.name.toLowerCase() === 'replayid') {
  273. titleText = 'Replay';
  274. }
  275. const title = (
  276. <StyledTooltip title={titleText}>
  277. <Truncate value={titleText} maxLength={60} expandable={false} />
  278. </StyledTooltip>
  279. );
  280. return (
  281. <SortLink
  282. align={align}
  283. title={title}
  284. direction={currentSort ? currentSort.kind : undefined}
  285. canSort={canSort}
  286. generateSortLink={generateSortLink}
  287. />
  288. );
  289. }
  290. function _renderGridBodyCell(
  291. column: TableColumn<keyof TableDataRow>,
  292. dataRow: TableDataRow,
  293. rowIndex: number,
  294. columnIndex: number
  295. ): React.ReactNode {
  296. const {
  297. isFirstPage,
  298. eventView,
  299. location,
  300. organization,
  301. tableData,
  302. isHomepage,
  303. queryDataset,
  304. } = props;
  305. if (!tableData || !tableData.meta) {
  306. return dataRow[column.key];
  307. }
  308. const columnKey = String(column.key);
  309. const fieldRenderer = getFieldRenderer(columnKey, tableData.meta, false);
  310. const display = eventView.getDisplayMode();
  311. const isTopEvents =
  312. display === DisplayModes.TOP5 || display === DisplayModes.DAILYTOP5;
  313. const topEvents = eventView.topEvents ? parseInt(eventView.topEvents, 10) : TOP_N;
  314. const count = Math.min(tableData?.data?.length ?? topEvents, topEvents);
  315. const unit = tableData.meta.units?.[columnKey];
  316. let cell = fieldRenderer(dataRow, {organization, location, unit});
  317. const isTransactionsDataset =
  318. hasDatasetSelector(organization) &&
  319. queryDataset === SavedQueryDatasets.TRANSACTIONS;
  320. if (columnKey === 'id') {
  321. let target: any;
  322. if (dataRow['event.type'] !== 'transaction' && !isTransactionsDataset) {
  323. const project = dataRow.project || dataRow['project.name'];
  324. target = {
  325. // NOTE: This uses a legacy redirect for project event to the issue group event link.
  326. // This only works with dev-server or production.
  327. pathname: normalizeUrl(
  328. `/${organization.slug}/${project}/events/${dataRow.id}/`
  329. ),
  330. query: {...location.query, referrer: 'discover-events-table'},
  331. };
  332. } else {
  333. if (!dataRow.trace) {
  334. throw new Error(
  335. 'Transaction event should always have a trace associated with it.'
  336. );
  337. }
  338. target = generateLinkToEventInTraceView({
  339. traceSlug: dataRow.trace?.toString(),
  340. eventId: dataRow.id,
  341. projectSlug: (dataRow.project || dataRow['project.name']!).toString(),
  342. timestamp: dataRow.timestamp!,
  343. organization,
  344. isHomepage,
  345. location,
  346. eventView,
  347. type: 'discover',
  348. source: TraceViewSources.DISCOVER,
  349. });
  350. }
  351. const idLink = (
  352. <StyledLink data-test-id="view-event" to={target}>
  353. {cell}
  354. </StyledLink>
  355. );
  356. cell = (
  357. <QuickContextHoverWrapper
  358. organization={organization}
  359. dataRow={dataRow}
  360. contextType={ContextType.EVENT}
  361. projects={projects}
  362. eventView={eventView}
  363. >
  364. {idLink}
  365. </QuickContextHoverWrapper>
  366. );
  367. } else if (columnKey === 'transaction' && dataRow.transaction) {
  368. cell = (
  369. <TransactionLink
  370. data-test-id="tableView-transaction-link"
  371. to={getTargetForTransactionSummaryLink(
  372. dataRow,
  373. organization,
  374. projects,
  375. eventView,
  376. location
  377. )}
  378. >
  379. {cell}
  380. </TransactionLink>
  381. );
  382. } else if (columnKey === 'trace') {
  383. const timestamp = getTimeStampFromTableDateField(
  384. dataRow['max(timestamp)'] ?? dataRow.timestamp
  385. );
  386. const dateSelection = eventView.normalizeDateSelection(location);
  387. if (dataRow.trace) {
  388. const target = getTraceDetailsUrl({
  389. organization,
  390. traceSlug: String(dataRow.trace),
  391. dateSelection,
  392. timestamp,
  393. location,
  394. source: TraceViewSources.DISCOVER,
  395. });
  396. cell = (
  397. <Tooltip title={t('View Trace')}>
  398. <StyledLink data-test-id="view-trace" to={target}>
  399. {cell}
  400. </StyledLink>
  401. </Tooltip>
  402. );
  403. }
  404. } else if (columnKey === 'replayId') {
  405. if (dataRow.replayId) {
  406. if (!dataRow['project.name']) {
  407. return getShortEventId(String(dataRow.replayId));
  408. }
  409. const target = replayLinkGenerator(organization, dataRow, undefined);
  410. cell = (
  411. <ViewReplayLink replayId={dataRow.replayId} to={target}>
  412. {cell}
  413. </ViewReplayLink>
  414. );
  415. }
  416. } else if (columnKey === 'profile.id') {
  417. const projectSlug = dataRow.project || dataRow['project.name'];
  418. const profileId = dataRow['profile.id'];
  419. if (projectSlug && profileId) {
  420. const target = generateProfileFlamechartRoute({
  421. organization,
  422. projectSlug: String(projectSlug),
  423. profileId: String(profileId),
  424. });
  425. cell = (
  426. <StyledTooltip title={t('View Profile')}>
  427. <StyledLink
  428. data-test-id="view-profile"
  429. to={target}
  430. onClick={() =>
  431. trackAnalytics('profiling_views.go_to_flamegraph', {
  432. organization,
  433. source: 'discover.table',
  434. })
  435. }
  436. >
  437. {cell}
  438. </StyledLink>
  439. </StyledTooltip>
  440. );
  441. }
  442. }
  443. const topResultsIndicator =
  444. isFirstPage && isTopEvents && rowIndex < topEvents && columnIndex === 0 ? (
  445. // Add one if we need to include Other in the series
  446. <TopResultsIndicator count={count} index={rowIndex} />
  447. ) : null;
  448. const fieldName = columnKey;
  449. const value = dataRow[fieldName];
  450. if (
  451. tableData.meta[fieldName] === 'integer' &&
  452. typeof value === 'number' &&
  453. value > 999
  454. ) {
  455. return (
  456. <Tooltip
  457. title={value.toLocaleString()}
  458. containerDisplayMode="block"
  459. position="right"
  460. >
  461. {topResultsIndicator}
  462. <CellAction
  463. column={column}
  464. dataRow={dataRow}
  465. handleCellAction={handleCellAction(dataRow, column)}
  466. >
  467. {cell}
  468. </CellAction>
  469. </Tooltip>
  470. );
  471. }
  472. return (
  473. <Fragment>
  474. {topResultsIndicator}
  475. <CellAction
  476. column={column}
  477. dataRow={dataRow}
  478. handleCellAction={handleCellAction(dataRow, column)}
  479. >
  480. {cell}
  481. </CellAction>
  482. </Fragment>
  483. );
  484. }
  485. function handleEditColumns() {
  486. const {
  487. organization,
  488. eventView,
  489. measurementKeys,
  490. spanOperationBreakdownKeys,
  491. customMeasurements,
  492. dataset,
  493. } = props;
  494. openModal(
  495. modalProps => (
  496. <ColumnEditModal
  497. {...modalProps}
  498. organization={organization}
  499. measurementKeys={measurementKeys}
  500. spanOperationBreakdownKeys={spanOperationBreakdownKeys}
  501. columns={eventView.getColumns().map(col => col.column)}
  502. onApply={handleUpdateColumns}
  503. customMeasurements={customMeasurements}
  504. dataset={dataset}
  505. />
  506. ),
  507. {modalCss, closeEvents: 'escape-key'}
  508. );
  509. }
  510. function handleCellAction(
  511. dataRow: TableDataRow,
  512. column: TableColumn<keyof TableDataRow>
  513. ) {
  514. return (action: Actions, value: React.ReactText) => {
  515. const {eventView, organization, location, tableData, isHomepage, queryDataset} =
  516. props;
  517. const query = new MutableSearch(eventView.query);
  518. let nextView = eventView.clone();
  519. trackAnalytics('discover_v2.results.cellaction', {
  520. organization,
  521. action,
  522. });
  523. switch (action) {
  524. case Actions.RELEASE: {
  525. const maybeProject = projects.find(project => {
  526. return project.slug === dataRow.project;
  527. });
  528. browserHistory.push(
  529. normalizeUrl({
  530. pathname: makeReleasesPathname({
  531. organization,
  532. path: `/${encodeURIComponent(value)}/`,
  533. }),
  534. query: {
  535. ...nextView.getPageFiltersQuery(),
  536. project: maybeProject ? maybeProject.id : undefined,
  537. },
  538. })
  539. );
  540. return;
  541. }
  542. case Actions.DRILLDOWN: {
  543. // count_unique(column) drilldown
  544. trackAnalytics('discover_v2.results.drilldown', {
  545. organization,
  546. });
  547. // Drilldown into each distinct value and get a count() for each value.
  548. nextView = getExpandedResults(nextView, {}, dataRow).withNewColumn({
  549. kind: 'function',
  550. function: ['count', '', undefined, undefined],
  551. });
  552. browserHistory.push(
  553. normalizeUrl(
  554. nextView.getResultsViewUrlTarget(
  555. organization,
  556. isHomepage,
  557. hasDatasetSelector(organization) ? queryDataset : undefined
  558. )
  559. )
  560. );
  561. return;
  562. }
  563. default: {
  564. // Some custom perf metrics have units.
  565. // These custom perf metrics need to be adjusted to the correct value.
  566. let cellValue = value;
  567. const unit = tableData?.meta?.units?.[column.name];
  568. if (typeof cellValue === 'number' && unit) {
  569. if (Object.keys(SIZE_UNITS).includes(unit)) {
  570. // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
  571. cellValue *= SIZE_UNITS[unit];
  572. } else if (Object.keys(DURATION_UNITS).includes(unit)) {
  573. // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
  574. cellValue *= DURATION_UNITS[unit];
  575. }
  576. }
  577. updateQuery(query, action, column, cellValue);
  578. }
  579. }
  580. nextView.query = query.formatString();
  581. const target = nextView.getResultsViewUrlTarget(
  582. organization,
  583. isHomepage,
  584. hasDatasetSelector(organization) ? queryDataset : undefined
  585. );
  586. // Get yAxis from location
  587. target.query.yAxis = decodeList(location.query.yAxis);
  588. browserHistory.push(normalizeUrl(target));
  589. };
  590. }
  591. function handleUpdateColumns(columns: Column[]): void {
  592. const {organization, eventView, location, isHomepage, queryDataset} = props;
  593. // metrics
  594. trackAnalytics('discover_v2.update_columns', {
  595. organization,
  596. });
  597. const nextView = eventView.withColumns(columns);
  598. const resultsViewUrlTarget = nextView.getResultsViewUrlTarget(
  599. organization,
  600. isHomepage,
  601. hasDatasetSelector(organization) ? queryDataset : undefined
  602. );
  603. // Need to pull yAxis from location since eventView only stores 1 yAxis field at time
  604. const previousYAxis = decodeList(location.query.yAxis);
  605. resultsViewUrlTarget.query.yAxis = previousYAxis.filter(yAxis =>
  606. nextView.getYAxisOptions().find(({value}) => value === yAxis)
  607. );
  608. browserHistory.push(normalizeUrl(resultsViewUrlTarget));
  609. }
  610. function renderHeaderButtons() {
  611. const {
  612. organization,
  613. title,
  614. eventView,
  615. isLoading,
  616. error,
  617. tableData,
  618. location,
  619. onChangeShowTags,
  620. showTags,
  621. queryDataset,
  622. } = props;
  623. return (
  624. <TableActions
  625. title={title}
  626. isLoading={isLoading}
  627. error={error}
  628. organization={organization}
  629. eventView={eventView}
  630. onEdit={handleEditColumns}
  631. tableData={tableData}
  632. location={location}
  633. onChangeShowTags={onChangeShowTags}
  634. showTags={showTags}
  635. supportsInvestigationRule
  636. queryDataset={queryDataset}
  637. />
  638. );
  639. }
  640. const {error, eventView, isLoading, tableData} = props;
  641. const columnOrder = eventView.getColumns();
  642. const columnSortBy = eventView.getSorts();
  643. const prependColumnWidths = eventView.hasAggregateField()
  644. ? ['40px']
  645. : eventView.hasIdField()
  646. ? []
  647. : [`minmax(${COL_WIDTH_MINIMUM}px, max-content)`];
  648. return (
  649. <GridEditable
  650. isLoading={isLoading}
  651. error={error}
  652. data={tableData ? tableData.data : []}
  653. columnOrder={columnOrder}
  654. columnSortBy={columnSortBy}
  655. title={t('Results')}
  656. grid={{
  657. renderHeadCell: _renderGridHeaderCell as any,
  658. renderBodyCell: _renderGridBodyCell as any,
  659. onResizeColumn: _resizeColumn as any,
  660. renderPrependColumns: _renderPrependColumns as any,
  661. prependColumnWidths,
  662. }}
  663. headerButtons={renderHeaderButtons}
  664. />
  665. );
  666. }
  667. const PrependHeader = styled('span')`
  668. color: ${p => p.theme.subText};
  669. `;
  670. const StyledTooltip = styled(Tooltip)`
  671. display: initial;
  672. max-width: max-content;
  673. `;
  674. export const StyledLink = styled(Link)`
  675. & div {
  676. display: inline;
  677. }
  678. `;
  679. export const TransactionLink = styled(Link)`
  680. ${p => p.theme.overflowEllipsis}
  681. `;
  682. const StyledIcon = styled(IconStack)`
  683. vertical-align: middle;
  684. `;
  685. export default TableView;