monitors.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. import {Fragment} from 'react';
  2. import {withRouter, WithRouterProps} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import * as qs from 'query-string';
  5. import Button from 'sentry/components/button';
  6. import FeatureBadge from 'sentry/components/featureBadge';
  7. import Link from 'sentry/components/links/link';
  8. import {normalizeDateTimeParams} from 'sentry/components/organizations/pageFilters/parse';
  9. import PageHeading from 'sentry/components/pageHeading';
  10. import Pagination from 'sentry/components/pagination';
  11. import {Panel, PanelBody, PanelItem} from 'sentry/components/panels';
  12. import ProjectPageFilter from 'sentry/components/projectPageFilter';
  13. import SearchBar from 'sentry/components/searchBar';
  14. import TimeSince from 'sentry/components/timeSince';
  15. import {t} from 'sentry/locale';
  16. import {PageHeader} from 'sentry/styles/organization';
  17. import space from 'sentry/styles/space';
  18. import {Organization} from 'sentry/types';
  19. import {decodeScalar} from 'sentry/utils/queryString';
  20. import withOrganization from 'sentry/utils/withOrganization';
  21. import AsyncView from 'sentry/views/asyncView';
  22. import MonitorIcon from './monitorIcon';
  23. import {Monitor} from './types';
  24. type Props = AsyncView['props'] &
  25. WithRouterProps<{orgId: string}> & {
  26. organization: Organization;
  27. };
  28. type State = AsyncView['state'] & {
  29. monitorList: Monitor[] | null;
  30. };
  31. class Monitors extends AsyncView<Props, State> {
  32. getEndpoints(): ReturnType<AsyncView['getEndpoints']> {
  33. const {params, location} = this.props;
  34. return [
  35. [
  36. 'monitorList',
  37. `/organizations/${params.orgId}/monitors/`,
  38. {
  39. query: location.query,
  40. },
  41. ],
  42. ];
  43. }
  44. getTitle() {
  45. return `Monitors - ${this.props.params.orgId}`;
  46. }
  47. handleSearch = (query: string) => {
  48. const {location, router} = this.props;
  49. router.push({
  50. pathname: location.pathname,
  51. query: normalizeDateTimeParams({
  52. ...(location.query || {}),
  53. query,
  54. }),
  55. });
  56. };
  57. renderBody() {
  58. const {monitorList, monitorListPageLinks} = this.state;
  59. const {organization} = this.props;
  60. return (
  61. <Fragment>
  62. <PageHeader>
  63. <HeaderTitle>
  64. <div>
  65. {t('Monitors')} <FeatureBadge type="beta" />
  66. </div>
  67. <Button
  68. to={`/organizations/${organization.slug}/monitors/create/`}
  69. priority="primary"
  70. >
  71. {t('New Monitor')}
  72. </Button>
  73. </HeaderTitle>
  74. </PageHeader>
  75. <Filters>
  76. <ProjectPageFilter resetParamsOnChange={['cursor']} />
  77. <SearchBar
  78. query={decodeScalar(qs.parse(location.search)?.query, '')}
  79. placeholder={t('Search for monitors.')}
  80. onSearch={this.handleSearch}
  81. />
  82. </Filters>
  83. <Panel>
  84. <PanelBody>
  85. {monitorList?.map(monitor => (
  86. <PanelItemCentered key={monitor.id}>
  87. <MonitorIcon status={monitor.status} size={16} />
  88. <StyledLink
  89. to={`/organizations/${organization.slug}/monitors/${monitor.id}/`}
  90. >
  91. {monitor.name}
  92. </StyledLink>
  93. {monitor.nextCheckIn ? (
  94. <StyledTimeSince date={monitor.lastCheckIn} />
  95. ) : (
  96. t('n/a')
  97. )}
  98. </PanelItemCentered>
  99. ))}
  100. </PanelBody>
  101. </Panel>
  102. {monitorListPageLinks && (
  103. <Pagination pageLinks={monitorListPageLinks} {...this.props} />
  104. )}
  105. </Fragment>
  106. );
  107. }
  108. }
  109. const HeaderTitle = styled(PageHeading)`
  110. display: flex;
  111. align-items: center;
  112. justify-content: space-between;
  113. flex: 1;
  114. `;
  115. const PanelItemCentered = styled(PanelItem)`
  116. align-items: center;
  117. padding: 0;
  118. padding-left: ${space(2)};
  119. padding-right: ${space(2)};
  120. `;
  121. const StyledLink = styled(Link)`
  122. flex: 1;
  123. padding: ${space(2)};
  124. `;
  125. const StyledTimeSince = styled(TimeSince)`
  126. font-variant-numeric: tabular-nums;
  127. `;
  128. const Filters = styled('div')`
  129. display: grid;
  130. grid-template-columns: minmax(auto, 300px) 1fr;
  131. gap: ${space(1.5)};
  132. margin-bottom: ${space(2)};
  133. `;
  134. export default withRouter(withOrganization(Monitors));