index.tsx 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. import {Fragment} from 'react';
  2. import {RouteComponentProps} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import {addErrorMessage} from 'sentry/actionCreators/indicator';
  5. import ProjectActions from 'sentry/actions/projectActions';
  6. import Checkbox from 'sentry/components/checkbox';
  7. import Pagination from 'sentry/components/pagination';
  8. import {PanelTable} from 'sentry/components/panels';
  9. import SearchBar from 'sentry/components/searchBar';
  10. import {t} from 'sentry/locale';
  11. import space from 'sentry/styles/space';
  12. import {Organization, Project} from 'sentry/types';
  13. import {BuiltinSymbolSource, CustomRepo, DebugFile} from 'sentry/types/debugFiles';
  14. import routeTitleGen from 'sentry/utils/routeTitle';
  15. import AsyncView from 'sentry/views/asyncView';
  16. import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader';
  17. import TextBlock from 'sentry/views/settings/components/text/textBlock';
  18. import PermissionAlert from 'sentry/views/settings/project/permissionAlert';
  19. import DebugFileRow from './debugFileRow';
  20. import Sources from './sources';
  21. type Props = RouteComponentProps<{orgId: string; projectId: string}, {}> & {
  22. organization: Organization;
  23. project: Project;
  24. };
  25. type State = AsyncView['state'] & {
  26. debugFiles: DebugFile[] | null;
  27. project: Project;
  28. showDetails: boolean;
  29. builtinSymbolSources?: BuiltinSymbolSource[] | null;
  30. };
  31. class ProjectDebugSymbols extends AsyncView<Props, State> {
  32. getTitle() {
  33. const {projectId} = this.props.params;
  34. return routeTitleGen(t('Debug Files'), projectId, false);
  35. }
  36. getDefaultState() {
  37. return {
  38. ...super.getDefaultState(),
  39. project: this.props.project,
  40. showDetails: false,
  41. };
  42. }
  43. getEndpoints(): ReturnType<AsyncView['getEndpoints']> {
  44. const {organization, params, location} = this.props;
  45. const {builtinSymbolSources} = this.state || {};
  46. const {orgId, projectId} = params;
  47. const {query} = location.query;
  48. const endpoints: ReturnType<AsyncView['getEndpoints']> = [
  49. [
  50. 'debugFiles',
  51. `/projects/${orgId}/${projectId}/files/dsyms/`,
  52. {
  53. query: {
  54. query,
  55. file_formats: [
  56. 'breakpad',
  57. 'macho',
  58. 'elf',
  59. 'pe',
  60. 'pdb',
  61. 'sourcebundle',
  62. 'wasm',
  63. 'bcsymbolmap',
  64. 'uuidmap',
  65. 'il2cpp',
  66. ],
  67. },
  68. },
  69. ],
  70. ];
  71. if (!builtinSymbolSources && organization.features.includes('symbol-sources')) {
  72. endpoints.push(['builtinSymbolSources', '/builtin-symbol-sources/', {}]);
  73. }
  74. return endpoints;
  75. }
  76. handleDelete = (id: string) => {
  77. const {orgId, projectId} = this.props.params;
  78. this.setState({
  79. loading: true,
  80. });
  81. this.api.request(`/projects/${orgId}/${projectId}/files/dsyms/?id=${id}`, {
  82. method: 'DELETE',
  83. complete: () => this.fetchData(),
  84. });
  85. };
  86. handleSearch = (query: string) => {
  87. const {location, router} = this.props;
  88. router.push({
  89. ...location,
  90. query: {...location.query, cursor: undefined, query},
  91. });
  92. };
  93. async fetchProject() {
  94. const {params} = this.props;
  95. const {orgId, projectId} = params;
  96. try {
  97. const updatedProject = await this.api.requestPromise(
  98. `/projects/${orgId}/${projectId}/`
  99. );
  100. ProjectActions.updateSuccess(updatedProject);
  101. } catch {
  102. addErrorMessage(t('An error occurred while fetching project data'));
  103. }
  104. }
  105. getQuery() {
  106. const {query} = this.props.location.query;
  107. return typeof query === 'string' ? query : undefined;
  108. }
  109. getEmptyMessage() {
  110. if (this.getQuery()) {
  111. return t('There are no debug symbols that match your search.');
  112. }
  113. return t('There are no debug symbols for this project.');
  114. }
  115. renderLoading() {
  116. return this.renderBody();
  117. }
  118. renderDebugFiles() {
  119. const {debugFiles, showDetails} = this.state;
  120. const {organization, params} = this.props;
  121. const {orgId, projectId} = params;
  122. if (!debugFiles?.length) {
  123. return null;
  124. }
  125. return debugFiles.map(debugFile => {
  126. const downloadUrl = `${this.api.baseUrl}/projects/${orgId}/${projectId}/files/dsyms/?id=${debugFile.id}`;
  127. return (
  128. <DebugFileRow
  129. debugFile={debugFile}
  130. showDetails={showDetails}
  131. downloadUrl={downloadUrl}
  132. downloadRole={organization.debugFilesRole}
  133. onDelete={this.handleDelete}
  134. key={debugFile.id}
  135. orgSlug={organization.slug}
  136. />
  137. );
  138. });
  139. }
  140. renderBody() {
  141. const {organization, project, router, location} = this.props;
  142. const {loading, showDetails, builtinSymbolSources, debugFiles, debugFilesPageLinks} =
  143. this.state;
  144. return (
  145. <Fragment>
  146. <SettingsPageHeader title={t('Debug Information Files')} />
  147. <TextBlock>
  148. {t(`
  149. Debug information files are used to convert addresses and minified
  150. function names from native crash reports into function names and
  151. locations.
  152. `)}
  153. </TextBlock>
  154. {organization.features.includes('symbol-sources') && (
  155. <Fragment>
  156. <PermissionAlert />
  157. <Sources
  158. api={this.api}
  159. location={location}
  160. router={router}
  161. projSlug={project.slug}
  162. organization={organization}
  163. customRepositories={
  164. (project.symbolSources
  165. ? JSON.parse(project.symbolSources)
  166. : []) as CustomRepo[]
  167. }
  168. builtinSymbolSources={project.builtinSymbolSources ?? []}
  169. builtinSymbolSourceOptions={builtinSymbolSources ?? []}
  170. isLoading={loading}
  171. />
  172. </Fragment>
  173. )}
  174. <Wrapper>
  175. <TextBlock noMargin>{t('Uploaded debug information files')}</TextBlock>
  176. <Filters>
  177. <Label>
  178. <Checkbox
  179. checked={showDetails}
  180. onChange={e => {
  181. this.setState({showDetails: (e.target as HTMLInputElement).checked});
  182. }}
  183. />
  184. {t('show details')}
  185. </Label>
  186. <SearchBar
  187. placeholder={t('Search DIFs')}
  188. onSearch={this.handleSearch}
  189. query={this.getQuery()}
  190. />
  191. </Filters>
  192. </Wrapper>
  193. <StyledPanelTable
  194. headers={[
  195. t('Debug ID'),
  196. t('Information'),
  197. <Actions key="actions">{t('Actions')}</Actions>,
  198. ]}
  199. emptyMessage={this.getEmptyMessage()}
  200. isEmpty={debugFiles?.length === 0}
  201. isLoading={loading}
  202. >
  203. {this.renderDebugFiles()}
  204. </StyledPanelTable>
  205. <Pagination pageLinks={debugFilesPageLinks} />
  206. </Fragment>
  207. );
  208. }
  209. }
  210. const StyledPanelTable = styled(PanelTable)`
  211. grid-template-columns: 37% 1fr auto;
  212. `;
  213. const Actions = styled('div')`
  214. text-align: right;
  215. `;
  216. const Wrapper = styled('div')`
  217. display: grid;
  218. grid-template-columns: auto 1fr;
  219. gap: ${space(4)};
  220. align-items: center;
  221. margin-top: ${space(4)};
  222. margin-bottom: ${space(1)};
  223. @media (max-width: ${p => p.theme.breakpoints.small}) {
  224. display: block;
  225. }
  226. `;
  227. const Filters = styled('div')`
  228. display: grid;
  229. grid-template-columns: min-content minmax(200px, 400px);
  230. align-items: center;
  231. justify-content: flex-end;
  232. gap: ${space(2)};
  233. @media (max-width: ${p => p.theme.breakpoints.small}) {
  234. grid-template-columns: min-content 1fr;
  235. }
  236. `;
  237. const Label = styled('label')`
  238. font-weight: normal;
  239. display: flex;
  240. margin-bottom: 0;
  241. white-space: nowrap;
  242. input {
  243. margin-top: 0;
  244. margin-right: ${space(1)};
  245. }
  246. `;
  247. export default ProjectDebugSymbols;