Просмотр исходного кода

fix(discover): Link txn dataset events to trace view correctly (#75247)

We use event.type to determine where to link events to. Transactions
dataset does not have event type, so use dataset selection if
available to make decision
Shruthi 7 месяцев назад
Родитель
Сommit
e9c883e0e1

+ 68 - 0
static/app/views/discover/table/tableView.spec.tsx

@@ -8,6 +8,7 @@ import ProjectsStore from 'sentry/stores/projectsStore';
 import TagStore from 'sentry/stores/tagStore';
 import {browserHistory} from 'sentry/utils/browserHistory';
 import EventView from 'sentry/utils/discover/eventView';
+import {SavedQueryDatasets} from 'sentry/utils/discover/types';
 import TableView from 'sentry/views/discover/table/tableView';
 
 describe('TableView > CellActions', function () {
@@ -50,6 +51,7 @@ describe('TableView > CellActions', function () {
         measurementKeys={null}
         showTags={false}
         title=""
+        queryDataset={SavedQueryDatasets.TRANSACTIONS}
       />,
       {router: context.router}
     );
@@ -326,6 +328,72 @@ describe('TableView > CellActions', function () {
     );
   });
 
+  it('renders trace view link', function () {
+    const org = OrganizationFixture({
+      features: [
+        'discover-basic',
+        'performance-discover-dataset-selector',
+        'trace-view-v1',
+      ],
+    });
+
+    rows = {
+      meta: {
+        trace: 'string',
+        id: 'string',
+        transaction: 'string',
+        timestamp: 'date',
+        project: 'string',
+        'event.type': 'string',
+      },
+      data: [
+        {
+          trace: '7fdf8efed85a4f9092507063ced1995b',
+          id: '509663014077465b8981b65225bdec0f',
+          transaction: '/organizations/',
+          timestamp: '2019-05-23T22:12:48+00:00',
+          project: 'project-slug',
+          'event.type': '',
+        },
+      ],
+    };
+
+    const loc = LocationFixture({
+      pathname: '/organizations/org-slug/discover/results/',
+      query: {
+        id: '42',
+        name: 'best query',
+        field: ['id', 'transaction', 'timestamp'],
+        queryDataset: 'transaction-like',
+        sort: ['transaction'],
+        query: '',
+        project: ['123'],
+        statsPeriod: '14d',
+        environment: ['staging'],
+        yAxis: 'p95',
+      },
+    });
+
+    initialData = initializeOrg({
+      organization: org,
+      router: {location: loc},
+    });
+
+    renderComponent(initialData, rows, EventView.fromLocation(loc));
+
+    const firstRow = screen.getAllByRole('row')[1];
+    const link = within(firstRow).getByTestId('view-event');
+
+    expect(link).toHaveAttribute(
+      'href',
+      expect.stringMatching(
+        RegExp(
+          '/organizations/org-slug/performance/trace/7fdf8efed85a4f9092507063ced1995b/?.*'
+        )
+      )
+    );
+  });
+
   it('handles go to release', async function () {
     renderComponent(initialData, rows, eventView);
     await openContextMenu(5);

+ 22 - 5
static/app/views/discover/table/tableView.tsx

@@ -39,7 +39,7 @@ import {
 import {
   type DiscoverDatasets,
   DisplayModes,
-  type SavedQueryDatasets,
+  SavedQueryDatasets,
   TOP_N,
 } from 'sentry/utils/discover/types';
 import {generateLinkToEventInTraceView} from 'sentry/utils/discover/urls';
@@ -135,10 +135,15 @@ function TableView(props: TableViewProps) {
     dataRow?: any,
     rowIndex?: number
   ): React.ReactNode[] {
-    const {organization, eventView, tableData, location, isHomepage} = props;
+    const {organization, eventView, tableData, location, isHomepage, queryDataset} =
+      props;
     const hasAggregates = eventView.hasAggregateField();
     const hasIdField = eventView.hasIdField();
 
+    const isTransactionsDataset =
+      hasDatasetSelector(organization) &&
+      queryDataset === SavedQueryDatasets.TRANSACTIONS;
+
     if (isHeader) {
       if (hasAggregates) {
         return [
@@ -197,7 +202,7 @@ function TableView(props: TableViewProps) {
 
       let target;
 
-      if (dataRow['event.type'] !== 'transaction') {
+      if (dataRow['event.type'] !== 'transaction' && !isTransactionsDataset) {
         const project = dataRow.project || dataRow['project.name'];
         target = {
           // NOTE: This uses a legacy redirect for project event to the issue group event link
@@ -306,7 +311,15 @@ function TableView(props: TableViewProps) {
     rowIndex: number,
     columnIndex: number
   ): React.ReactNode {
-    const {isFirstPage, eventView, location, organization, tableData, isHomepage} = props;
+    const {
+      isFirstPage,
+      eventView,
+      location,
+      organization,
+      tableData,
+      isHomepage,
+      queryDataset,
+    } = props;
 
     if (!tableData || !tableData.meta) {
       return dataRow[column.key];
@@ -325,10 +338,14 @@ function TableView(props: TableViewProps) {
     const unit = tableData.meta.units?.[columnKey];
     let cell = fieldRenderer(dataRow, {organization, location, unit});
 
+    const isTransactionsDataset =
+      hasDatasetSelector(organization) &&
+      queryDataset === SavedQueryDatasets.TRANSACTIONS;
+
     if (columnKey === 'id') {
       let target;
 
-      if (dataRow['event.type'] !== 'transaction') {
+      if (dataRow['event.type'] !== 'transaction' && !isTransactionsDataset) {
         const project = dataRow.project || dataRow['project.name'];
 
         target = {