-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(events-v2): Implement tag distribution / heatmaps UI (#13478)
SEN-672
- Loading branch information
Showing
7 changed files
with
169 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 74 additions & 2 deletions
76
src/sentry/static/sentry/app/views/organizationEventsV2/tags.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters