-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
feat(app-platform): Open in stacktrace button #12401
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1208fba
display button and link
MeredithAnya d4185be
refactor getUrl
MeredithAnya 4943b65
dont need react.fragments
MeredithAnya a1413de
theme.zIndex
MeredithAnya 09a7907
add tests
MeredithAnya a08ddb1
translation
MeredithAnya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
96 changes: 96 additions & 0 deletions
96
src/sentry/static/sentry/app/components/events/interfaces/openInButton.jsx
This file contains hidden or 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,96 @@ | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import SentryTypes from 'app/sentryTypes'; | ||
import Button from 'app/components/button'; | ||
import qs from 'query-string'; | ||
import styled from 'react-emotion'; | ||
import {t} from 'app/locale'; | ||
|
||
import withApi from 'app/utils/withApi'; | ||
import withLatestContext from 'app/utils/withLatestContext'; | ||
|
||
class OpenInButton extends React.Component { | ||
static propTypes = { | ||
api: PropTypes.object, | ||
organization: SentryTypes.Organization, | ||
project: SentryTypes.Project, | ||
lineNo: PropTypes.number, | ||
filename: PropTypes.string, | ||
}; | ||
|
||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
loading: false, | ||
error: false, | ||
components: [], | ||
}; | ||
} | ||
|
||
componentWillMount() { | ||
this.fetchIssueLinkComponents(); | ||
} | ||
|
||
fetchIssueLinkComponents() { | ||
const {api, organization, project} = this.props; | ||
api | ||
.requestPromise( | ||
`/organizations/${organization.slug}/sentry-app-components/?filter=stacktrace-link&projectId=${project.id}` | ||
) | ||
.then(data => { | ||
if (data.length) { | ||
this.setState({components: data}); | ||
} | ||
}) | ||
.catch(error => { | ||
return; | ||
}); | ||
} | ||
|
||
getUrl() { | ||
const {components} = this.state; | ||
const {filename, lineNo} = this.props; | ||
|
||
const queryParams = { | ||
lineNo, | ||
filename, | ||
}; | ||
const query = qs.stringify(queryParams); | ||
return components[0].schema.url + '&' + query; | ||
} | ||
|
||
render() { | ||
const {components} = this.state; | ||
if (!components.length) { | ||
return null; | ||
} | ||
|
||
const url = this.getUrl(); | ||
return ( | ||
<StyledButtonContainer> | ||
<StyledButton href={url} size="small" priority="primary"> | ||
{t(`Debug In ${components[0].sentryApp.name}`)} | ||
</StyledButton> | ||
</StyledButtonContainer> | ||
); | ||
} | ||
} | ||
|
||
export {OpenInButton}; | ||
const OpenInButtonComponent = withLatestContext(OpenInButton); | ||
export default withApi(OpenInButtonComponent); | ||
|
||
const StyledButtonContainer = styled('div')` | ||
height: 0; | ||
position: relative; | ||
`; | ||
|
||
const StyledButton = styled(Button)` | ||
position: absolute; | ||
z-index: ${p => p.theme.zIndex.header}; | ||
height: 36px; | ||
line-height: 1.5; | ||
padding: 0px 5px; | ||
top: -31px; | ||
right: 30px; | ||
`; |
This file contains hidden or 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
90 changes: 90 additions & 0 deletions
90
tests/js/spec/components/events/interfaces/openInButton.spec.jsx
This file contains hidden or 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,90 @@ | ||
import React from 'react'; | ||
import {Client} from 'app/api'; | ||
import {mount} from 'enzyme'; | ||
import qs from 'query-string'; | ||
|
||
import {OpenInButton} from 'app/components/events/interfaces/openInButton'; | ||
|
||
describe('OpenInButton', function() { | ||
const api = new Client(); | ||
const filename = '/sentry/app.py'; | ||
const lineNo = 123; | ||
const org = TestStubs.Organization(); | ||
const project = TestStubs.Project(); | ||
const install = TestStubs.SentryAppInstallation(); | ||
|
||
beforeEach(() => { | ||
Client.clearMockResponses(); | ||
}); | ||
|
||
describe('with stacktrace-link component', function() { | ||
it('renders button', async function() { | ||
Client.addMockResponse({ | ||
method: 'GET', | ||
url: `/organizations/${org.slug}/sentry-app-components/?filter=stacktrace-link&projectId=${project.id}`, | ||
body: [ | ||
{ | ||
uuid: 'ed517da4-a324-44c0-aeea-1894cd9923fb', | ||
type: 'stacktrace-link', | ||
schema: { | ||
uri: '/redirection', | ||
url: `http://localhost:5000/redirection?installationId=${install.uuid}&projectSlug=${project.slug}`, | ||
}, | ||
sentryApp: { | ||
uuid: 'b468fed3-afba-4917-80d6-bdac99c1ec05', | ||
slug: 'foo', | ||
name: 'Foo', | ||
}, | ||
}, | ||
], | ||
}); | ||
const wrapper = mount( | ||
<OpenInButton | ||
api={api} | ||
organization={org} | ||
project={project} | ||
filename={filename} | ||
lineNo={lineNo} | ||
/>, | ||
TestStubs.routerContext() | ||
); | ||
await tick(); | ||
wrapper.update(); | ||
expect(wrapper.state().components[0].schema.url).toEqual( | ||
`http://localhost:5000/redirection?installationId=${install.uuid}&projectSlug=${project.slug}` | ||
); | ||
const base = `http://localhost:5000/redirection?installationId=${install.uuid}&projectSlug=${project.slug}`; | ||
const queryParams = { | ||
lineNo, | ||
filename, | ||
}; | ||
const query = qs.stringify(queryParams); | ||
expect(wrapper.find('Button').prop('href')).toEqual(base + '&' + query); | ||
expect(wrapper.find('Button').text()).toEqual('Debug In Foo'); | ||
}); | ||
}); | ||
|
||
describe('without stacktrace-link component', function() { | ||
it('renders button', async function() { | ||
Client.addMockResponse({ | ||
method: 'GET', | ||
url: `/organizations/${org.slug}/sentry-app-components/?filter=stacktrace-link&projectId=${project.id}`, | ||
body: [], | ||
}); | ||
const wrapper = mount( | ||
<OpenInButton | ||
api={api} | ||
organization={org} | ||
project={project} | ||
filename={filename} | ||
lineNo={lineNo} | ||
/>, | ||
TestStubs.routerContext() | ||
); | ||
await tick(); | ||
wrapper.update(); | ||
expect(wrapper.state().components).toEqual([]); | ||
expect(wrapper.find('Button').exists()).toEqual(false); | ||
}); | ||
}); | ||
}); |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Does this cause issues? Do you need to
return ''
?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.
I think you have to return
null