overviewTable.tsx 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import Pagination from 'sentry/components/pagination';
  4. import {PanelTable} from 'sentry/components/panels';
  5. import {t} from 'sentry/locale';
  6. import {setApiQueryData, useQueryClient} from 'sentry/utils/queryClient';
  7. import {useLocation} from 'sentry/utils/useLocation';
  8. import useOrganization from 'sentry/utils/useOrganization';
  9. import {Monitor, MonitorEnvironment} from '../types';
  10. import {makeMonitorListQueryKey} from '../utils';
  11. import {MonitorRow} from './row';
  12. interface Props {
  13. monitorList: Monitor[];
  14. monitorListPageLinks?: string | null;
  15. }
  16. export function OverviewTable({monitorList, monitorListPageLinks}: Props) {
  17. const location = useLocation();
  18. const organization = useOrganization();
  19. const queryClient = useQueryClient();
  20. const queryKey = makeMonitorListQueryKey(organization, location);
  21. const renderMonitorRow = (monitor: Monitor, monitorEnv?: MonitorEnvironment) => (
  22. <MonitorRow
  23. key={`${monitor.slug}-${monitorEnv?.name ?? 'no-env'}`}
  24. monitor={monitor}
  25. monitorEnv={monitorEnv}
  26. onDelete={deletedEnv => {
  27. if (deletedEnv) {
  28. if (!monitorList) {
  29. return;
  30. }
  31. const deletedEnvMonitor = monitorList.find(m => m.slug === monitor.slug);
  32. if (!deletedEnvMonitor) {
  33. return;
  34. }
  35. deletedEnvMonitor.environments = deletedEnvMonitor.environments.filter(
  36. e => e.name !== deletedEnv.name
  37. );
  38. setApiQueryData(queryClient, queryKey, monitorList);
  39. } else {
  40. setApiQueryData(
  41. queryClient,
  42. queryKey,
  43. monitorList?.filter(m => m.slug !== monitor.slug)
  44. );
  45. }
  46. }}
  47. organization={organization}
  48. />
  49. );
  50. return (
  51. <Fragment>
  52. <StyledPanelTable
  53. headers={[
  54. t('Monitor Name'),
  55. t('Status'),
  56. t('Schedule'),
  57. t('Next Checkin'),
  58. t('Project'),
  59. t('Environment'),
  60. t('Actions'),
  61. ]}
  62. >
  63. {monitorList
  64. ?.map(monitor =>
  65. monitor.environments.length > 0
  66. ? monitor.environments.map(monitorEnv =>
  67. renderMonitorRow(monitor, monitorEnv)
  68. )
  69. : renderMonitorRow(monitor)
  70. )
  71. .flat()}
  72. </StyledPanelTable>
  73. {monitorListPageLinks && <Pagination pageLinks={monitorListPageLinks} />}
  74. </Fragment>
  75. );
  76. }
  77. const StyledPanelTable = styled(PanelTable)`
  78. grid-template-columns: 1fr max-content 1fr max-content max-content max-content max-content;
  79. `;