index.tsx 7.7 KB

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