-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
feat(events-v2): Implement tag distribution / heatmaps UI #13478
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
Changes from all commits
6bfe4bb
4ddbe10
ae69f03
6973791
c510ce7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,90 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import styled from 'react-emotion'; | ||
import {isEqual} from 'lodash'; | ||
|
||
import SentryTypes from 'app/sentryTypes'; | ||
import TagDistributionMeter from 'app/components/tagDistributionMeter'; | ||
import withApi from 'app/utils/withApi'; | ||
import withGlobalSelection from 'app/utils/withGlobalSelection'; | ||
import {fetchTags, getEventTagSearchUrl} from './utils'; | ||
|
||
export default class Tags extends React.Component { | ||
class Tags extends React.Component { | ||
static propTypes = { | ||
api: PropTypes.object.isRequired, | ||
organization: SentryTypes.Organization.isRequired, | ||
view: SentryTypes.EventView.isRequired, | ||
selection: SentryTypes.GlobalSelection.isRequired, | ||
location: PropTypes.object.isRequired, | ||
}; | ||
|
||
state = { | ||
isLoading: true, | ||
tags: {}, | ||
}; | ||
|
||
componentDidMount() { | ||
this.fetchData(); | ||
} | ||
|
||
componentDidUpdate(prevProps) { | ||
if ( | ||
this.props.view.id !== prevProps.view.id || | ||
!isEqual(this.props.selection, prevProps.selection) | ||
) { | ||
this.fetchData(); | ||
} | ||
} | ||
|
||
fetchData = async () => { | ||
const {api, organization, view} = this.props; | ||
|
||
try { | ||
const tags = await fetchTags(api, organization.slug, view.tags); | ||
this.setState({tags, isLoading: false}); | ||
} catch (err) { | ||
this.setState({tags: {}, isLoading: false}); | ||
} | ||
}; | ||
|
||
renderTag(tag) { | ||
return <TagDistributionMeter key={tag} title={tag} segments={[]} />; | ||
const {location} = this.props; | ||
const {isLoading, tags} = this.state; | ||
let segments = []; | ||
let totalValues = 0; | ||
if (!isLoading && tags[tag]) { | ||
totalValues = tags[tag].totalValues; | ||
segments = tags[tag].topValues; | ||
} | ||
|
||
segments.forEach(segment => { | ||
segment.url = getEventTagSearchUrl(tag, segment.value, location); | ||
}); | ||
|
||
return ( | ||
<TagDistributionMeter | ||
key={tag} | ||
title={tag} | ||
segments={segments} | ||
totalValues={totalValues} | ||
isLoading={isLoading} | ||
renderLoading={() => <Placeholder />} | ||
/> | ||
); | ||
} | ||
|
||
render() { | ||
return <div>{this.props.view.tags.map(tag => this.renderTag(tag))}</div>; | ||
} | ||
} | ||
|
||
const Placeholder = styled('div')` | ||
height: 16px; | ||
width: 100%; | ||
display: inline-block; | ||
border-radius: ${p => p.theme.borderRadius}; | ||
background-color: #dad9ed; | ||
`; | ||
|
||
export {Tags}; | ||
export default withApi(withGlobalSelection(Tags)); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,17 +58,18 @@ export function getQuery(view, location) { | |
* Return a location object for the current pathname | ||
* with a query string reflected the provided tag. | ||
* | ||
* @param {Object} tag containing key/value properties | ||
* @param {String} tagKey | ||
* @param {String} tagValue | ||
* @param {Object} browser location object. | ||
* @return {Object} router target | ||
*/ | ||
export function eventTagSearchUrl(tag, location) { | ||
export function getEventTagSearchUrl(tagKey, tagValue, location) { | ||
const query = {...location.query}; | ||
// Add tag key/value to search | ||
if (query.query) { | ||
query.query += ` ${tag.key}:"${tag.value}"`; | ||
query.query += ` ${tagKey}:"${tagValue}"`; | ||
} else { | ||
query.query = `${tag.key}:"${tag.value}"`; | ||
query.query = `${tagKey}:"${tagValue}"`; | ||
} | ||
// Remove the event slug so the user sees new search results. | ||
delete query.eventSlug; | ||
|
@@ -78,3 +79,25 @@ export function eventTagSearchUrl(tag, location) { | |
query, | ||
}; | ||
} | ||
|
||
/** | ||
* Fetches tag distributions for heatmaps for an array of tag keys | ||
* | ||
* @param {Object} api | ||
* @param {String} orgSlug | ||
* @param {Array} tagList | ||
* @returns {Promise<Object>} | ||
*/ | ||
export function fetchTags(api, orgSlug, tagList) { | ||
return api | ||
.requestPromise(`/organizations/${orgSlug}/events-heatmap/`, { | ||
query: {keys: tagList}, | ||
}) | ||
.then(resp => { | ||
const tags = {}; | ||
resp.forEach(tag => { | ||
tags[tag.key] = tag; | ||
}); | ||
return tags; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could use return resp.reduce((result, item) => {
result[tag.key] = tag;
return result;
}, {}); Might not be worth it though ⛳ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
⛳️ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lol :). Subjectively, I find forEach to be more readable and more performant (at least compared to the 2nd solution) for building an object |
||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React from 'react'; | ||
import {mount} from 'enzyme'; | ||
|
||
import {Client} from 'app/api'; | ||
import {Tags} from 'app/views/organizationEventsV2/tags'; | ||
|
||
describe('Tags', function() { | ||
const org = TestStubs.Organization(); | ||
beforeEach(function() { | ||
Client.addMockResponse({ | ||
url: `/organizations/${org.slug}/events-heatmap/`, | ||
body: [ | ||
{ | ||
key: 'release', | ||
name: 'Release', | ||
totalValues: 2, | ||
topValues: [{count: 2, value: 'abcd123', name: 'abcd123'}], | ||
}, | ||
{ | ||
key: 'environment', | ||
name: 'Environment', | ||
totalValues: 1, | ||
topValues: [{count: 1, value: 'production', name: 'production'}], | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
afterEach(function() { | ||
Client.clearMockResponses(); | ||
}); | ||
|
||
it('renders', async function() { | ||
const api = new Client(); | ||
const view = { | ||
id: 'test', | ||
name: 'Test', | ||
data: {}, | ||
tags: ['release', 'environment'], | ||
}; | ||
const wrapper = mount( | ||
<Tags | ||
view={view} | ||
api={api} | ||
organization={org} | ||
selection={{projects: [], environments: [], datetime: {}}} | ||
location={{}} | ||
/> | ||
); | ||
|
||
expect(wrapper.find('Placeholder')).toHaveLength(2); | ||
await tick(); | ||
wrapper.update(); | ||
expect(wrapper.find('Placeholder')).toHaveLength(0); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we show a component level error in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, will follow up with error states