Skip to content

feat(events-v2) Make tag values interactive in event modal #13470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {getCurrentView} from './utils';
export default class OrganizationEventsV2 extends React.Component {
static propTypes = {
organization: SentryTypes.Organization.isRequired,
location: PropTypes.object,
location: PropTypes.object.isRequired,
};

renderTabs() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import React from 'react';
import styled from 'react-emotion';
import PropTypes from 'prop-types';
import {withRouter} from 'react-router';

import Link from 'app/components/links/link';
import {t} from 'app/locale';
import space from 'app/styles/space';
import {eventTagSearchUrl} from './utils';

const TagsTable = props => {
return (
Expand All @@ -13,7 +17,9 @@ const TagsTable = props => {
{props.tags.map(tag => (
<StyledTr key={tag.key}>
<TagKey>{tag.key}</TagKey>
<TagValue>{tag.value}</TagValue>
<TagValue>
<Link to={eventTagSearchUrl(tag, props.location)}>{tag.value}</Link>
</TagValue>
</StyledTr>
))}
</tbody>
Expand All @@ -23,6 +29,7 @@ const TagsTable = props => {
};
TagsTable.propTypes = {
tags: PropTypes.array.isRequired,
location: PropTypes.object,
};

const TagHeading = styled('h5')`
Expand All @@ -48,4 +55,4 @@ const TagValue = styled(TagKey)`
text-align: right;
`;

export default TagsTable;
export default withRouter(TagsTable);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would avoid using withRouter - it's caused with weird behavior for me before. I think what happens is that it will cause an additional render. When the routes change, we get an update due to the router and then withRouter will also update.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was trying to avoid snaking the location down the render tree and also not using window.location.

If this re-renders when the URLs change I think that's ok here as this component is pretty lightweight.

25 changes: 25 additions & 0 deletions src/sentry/static/sentry/app/views/organizationEventsV2/utils.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,28 @@ export function getQuery(view) {

return data;
}

/**
* Return a location object for the current pathname
* with a query string reflected the provided tag.
*
* @param {Object} tag containing key/value properties
* @param {Object} browser location object.
* @return {Object} router target
*/
export function eventTagSearchUrl(tag, location) {
const query = {...location.query};
// Add tag key/value to search
if (query.query) {
query.query += ` ${tag.key}:"${tag.value}"`;
} else {
query.query = `${tag.key}:"${tag.value}"`;
}
// Remove the event slug so the user sees new search results.
delete query.eventSlug;

return {
pathname: location.pathname,
query,
};
}
71 changes: 71 additions & 0 deletions tests/js/spec/views/organizationEventsV2/index.spec.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import {mount} from 'enzyme';
import {initializeOrg} from 'app-test/helpers/initializeOrg';

import OrganizationEventsV2 from 'app/views/organizationEventsV2';

Expand All @@ -18,6 +19,7 @@ describe('OrganizationEventsV2', function() {
});
MockApiClient.addMockResponse({
url: '/projects/org-slug/project-slug/events/deadbeef/',
method: 'GET',
body: {
id: '1234',
size: 1200,
Expand Down Expand Up @@ -89,4 +91,73 @@ describe('OrganizationEventsV2', function() {
const modal = wrapper.find('EventDetails');
expect(modal).toHaveLength(1);
});

it('navigates when tag values are clicked', async function() {
const {organization, routerContext} = initializeOrg({
organization: TestStubs.Organization({projects: [TestStubs.Project()]}),
router: {
location: {
pathname: '/organizations/org-slug/events/',
query: {
eventSlug: 'project-slug:deadbeef',
},
},
},
});
const wrapper = mount(
<OrganizationEventsV2
organization={organization}
params={{orgId: organization.slug}}
location={routerContext.context.location}
/>,
routerContext
);
await tick();
await wrapper.update();

// Get the first link as we wrap react-router's link
const tagLink = wrapper.find('EventDetails TagsTable TagValue Link').first();

// Should remove eventSlug and append new tag value causing
// the view to re-render
expect(tagLink.props().to).toEqual({
pathname: '/organizations/org-slug/events/',
query: {query: 'browser:"Firefox"'},
});
});

it('appends tag value to existing query when clicked', async function() {
const {organization, routerContext} = initializeOrg({
organization: TestStubs.Organization({projects: [TestStubs.Project()]}),
router: {
location: {
pathname: '/organizations/org-slug/events/',
query: {
query: 'Dumpster',
eventSlug: 'project-slug:deadbeef',
},
},
},
});
const wrapper = mount(
<OrganizationEventsV2
organization={organization}
params={{orgId: organization.slug}}
location={routerContext.context.location}
/>,
routerContext
);
await tick();
await wrapper.update();

// Get the first link as we wrap react-router's link
const tagLink = wrapper.find('EventDetails TagsTable TagValue Link').first();

// Should remove eventSlug and append new tag value causing
// the view to re-render
expect(tagLink.props().to).toEqual({
pathname: '/organizations/org-slug/events/',
query: {query: 'Dumpster browser:"Firefox"'},
});
});
});
39 changes: 38 additions & 1 deletion tests/js/spec/views/organizationEventsV2/utils.spec.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import {getCurrentView, getQuery} from 'app/views/organizationEventsV2/utils';
import {
getCurrentView,
getQuery,
eventTagSearchUrl,
} from 'app/views/organizationEventsV2/utils';
import {ALL_VIEWS} from 'app/views/organizationEventsV2/data';

describe('getCurrentView()', function() {
Expand Down Expand Up @@ -38,3 +42,36 @@ describe('getQuery()', function() {
]);
});
});

describe('eventTagSearchUrl()', function() {
let location;
beforeEach(function() {
location = {
pathname: '/organization/org-slug/events/',
query: {},
};
});

it('adds a query', function() {
expect(eventTagSearchUrl({key: 'browser', value: 'firefox'}, location)).toEqual({
pathname: location.pathname,
query: {query: 'browser:"firefox"'},
});
});

it('removes eventSlug', function() {
location.query.eventSlug = 'project-slug:deadbeef';
expect(eventTagSearchUrl({key: 'browser', value: 'firefox'}, location)).toEqual({
pathname: location.pathname,
query: {query: 'browser:"firefox"'},
});
});

it('appends to an existing query', function() {
location.query.query = 'failure';
expect(eventTagSearchUrl({key: 'browser', value: 'firefox'}, location)).toEqual({
pathname: location.pathname,
query: {query: 'failure browser:"firefox"'},
});
});
});