index.tsx 7.4 KB

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