monitors.tsx 4.2 KB

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