overviewTable.tsx 2.3 KB

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