index.tsx 4.6 KB

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