index.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. import {Fragment} from 'react';
  2. import {RouteComponentProps} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import {Location} from 'history';
  5. import EmptyMessage from 'sentry/components/emptyMessage';
  6. import LoadingIndicator from 'sentry/components/loadingIndicator';
  7. import Pagination from 'sentry/components/pagination';
  8. import Panel from 'sentry/components/panels/panel';
  9. import PanelBody from 'sentry/components/panels/panelBody';
  10. import PanelHeader from 'sentry/components/panels/panelHeader';
  11. import PanelItem from 'sentry/components/panels/panelItem';
  12. import Placeholder from 'sentry/components/placeholder';
  13. import {t} from 'sentry/locale';
  14. import {space} from 'sentry/styles/space';
  15. import {Organization, Project} from 'sentry/types';
  16. import {sortProjects} from 'sentry/utils';
  17. import {decodeScalar} from 'sentry/utils/queryString';
  18. import routeTitleGen from 'sentry/utils/routeTitle';
  19. import withOrganization from 'sentry/utils/withOrganization';
  20. import DeprecatedAsyncView, {AsyncViewState} from 'sentry/views/deprecatedAsyncView';
  21. import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader';
  22. import ProjectListItem from 'sentry/views/settings/components/settingsProjectItem';
  23. import CreateProjectButton from 'sentry/views/settings/organizationProjects/createProjectButton';
  24. import ProjectStatsGraph from './projectStatsGraph';
  25. const ITEMS_PER_PAGE = 50;
  26. interface Props extends RouteComponentProps<{}, {}> {
  27. location: Location;
  28. organization: Organization;
  29. }
  30. type ProjectStats = Record<string, Required<Project['stats']>>;
  31. interface State extends AsyncViewState {
  32. projectList: Project[] | null;
  33. projectListPageLinks: string | null;
  34. projectStats: ProjectStats | null;
  35. }
  36. class OrganizationProjects extends DeprecatedAsyncView<Props, State> {
  37. getEndpoints(): ReturnType<DeprecatedAsyncView['getEndpoints']> {
  38. const {location, organization} = this.props;
  39. const query = decodeScalar(location.query.query);
  40. return [
  41. [
  42. 'projectList',
  43. `/organizations/${organization.slug}/projects/`,
  44. {
  45. query: {
  46. query,
  47. per_page: ITEMS_PER_PAGE,
  48. },
  49. },
  50. ],
  51. [
  52. 'projectStats',
  53. `/organizations/${organization.slug}/stats/`,
  54. {
  55. query: {
  56. since: new Date().getTime() / 1000 - 3600 * 24,
  57. stat: 'generated',
  58. group: 'project',
  59. per_page: ITEMS_PER_PAGE,
  60. },
  61. },
  62. ],
  63. ];
  64. }
  65. getTitle(): string {
  66. const {organization} = this.props;
  67. return routeTitleGen(t('Projects'), organization.slug, false);
  68. }
  69. renderLoading(): React.ReactNode {
  70. return this.renderBody();
  71. }
  72. renderBody(): React.ReactNode {
  73. const {projectList, projectListPageLinks, projectStats} = this.state;
  74. const {organization} = this.props;
  75. const action = <CreateProjectButton />;
  76. return (
  77. <Fragment>
  78. <SettingsPageHeader title="Projects" action={action} />
  79. <SearchWrapper>
  80. {this.renderSearchInput({
  81. updateRoute: true,
  82. placeholder: t('Search Projects'),
  83. className: 'search',
  84. })}
  85. </SearchWrapper>
  86. <Panel>
  87. <PanelHeader>{t('Projects')}</PanelHeader>
  88. <PanelBody>
  89. {projectList ? (
  90. sortProjects(projectList).map(project => (
  91. <GridPanelItem key={project.id}>
  92. <ProjectListItemWrapper>
  93. <ProjectListItem project={project} organization={organization} />
  94. </ProjectListItemWrapper>
  95. <ProjectStatsGraphWrapper>
  96. {projectStats ? (
  97. <ProjectStatsGraph
  98. key={project.id}
  99. project={project}
  100. stats={projectStats[project.id]}
  101. />
  102. ) : (
  103. <Placeholder height="25px" />
  104. )}
  105. </ProjectStatsGraphWrapper>
  106. </GridPanelItem>
  107. ))
  108. ) : (
  109. <LoadingIndicator />
  110. )}
  111. {projectList && projectList.length === 0 && (
  112. <EmptyMessage>{t('No projects found.')}</EmptyMessage>
  113. )}
  114. </PanelBody>
  115. </Panel>
  116. {projectListPageLinks && (
  117. <Pagination pageLinks={projectListPageLinks} {...this.props} />
  118. )}
  119. </Fragment>
  120. );
  121. }
  122. }
  123. export default withOrganization(OrganizationProjects);
  124. const SearchWrapper = styled('div')`
  125. margin-bottom: ${space(2)};
  126. `;
  127. const GridPanelItem = styled(PanelItem)`
  128. display: flex;
  129. align-items: center;
  130. padding: 0;
  131. `;
  132. const ProjectListItemWrapper = styled('div')`
  133. padding: ${space(2)};
  134. flex: 1;
  135. `;
  136. const ProjectStatsGraphWrapper = styled('div')`
  137. padding: ${space(2)};
  138. width: 25%;
  139. margin-left: ${space(2)};
  140. `;