thresholdGroupTable.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import {useMemo} from 'react';
  2. import styled from '@emotion/styled';
  3. import ProjectBadge from 'sentry/components/idBadge/projectBadge';
  4. import {PanelTable} from 'sentry/components/panels/panelTable';
  5. import {t} from 'sentry/locale';
  6. import {space} from 'sentry/styles/space';
  7. import type {Project} from 'sentry/types';
  8. import type {Threshold} from '../utils/types';
  9. import {ThresholdGroupRows} from './thresholdGroupRows';
  10. type Props = {
  11. allEnvironmentNames: string[];
  12. isError: boolean;
  13. isLoading: boolean;
  14. project: Project;
  15. refetch: () => void;
  16. setTempError: (msg: string) => void;
  17. thresholds: Threshold[];
  18. };
  19. export default function ThresholdGroupTable({
  20. allEnvironmentNames,
  21. isError,
  22. isLoading,
  23. project,
  24. refetch,
  25. setTempError,
  26. thresholds,
  27. }: Props) {
  28. const sortedThreshold: Threshold[] = useMemo(() => {
  29. return thresholds.sort((a, b) => {
  30. const keyA: string = a.environment ? a.environment.name : '';
  31. const keyB: string = b.environment ? b.environment.name : '';
  32. return keyA.localeCompare(keyB);
  33. });
  34. }, [thresholds]);
  35. return (
  36. <div>
  37. <StyledStrong>
  38. <ProjectBadge project={project} avatarSize={16} hideOverflow />
  39. </StyledStrong>
  40. <StyledPanelTable
  41. isLoading={isLoading}
  42. isEmpty={thresholds.length === 0 && !isError}
  43. emptyMessage={t('No thresholds found.')}
  44. headers={[t('Environment'), t('Window'), t('Condition'), t(' ')]}
  45. >
  46. {sortedThreshold?.map((threshold, idx) => {
  47. return (
  48. <ThresholdGroupRows
  49. key={threshold.id}
  50. project={project}
  51. allEnvironmentNames={allEnvironmentNames}
  52. threshold={threshold}
  53. refetch={refetch}
  54. setTempError={setTempError}
  55. isLastRow={idx === sortedThreshold.length - 1}
  56. />
  57. );
  58. })}
  59. </StyledPanelTable>
  60. </div>
  61. );
  62. }
  63. const StyledStrong = styled('div')`
  64. font-weight: 600;
  65. font-size: ${p => p.theme.fontSizeMedium};
  66. margin: ${space(2)} 0;
  67. `;
  68. const StyledPanelTable = styled(PanelTable)`
  69. @media (min-width: ${p => p.theme.breakpoints.small}) {
  70. overflow: initial;
  71. }
  72. grid-template-columns:
  73. minmax(100px, 1fr) minmax(250px, 1fr) minmax(200px, 4fr)
  74. minmax(150px, auto);
  75. white-space: nowrap;
  76. font-size: ${p => p.theme.fontSizeMedium};
  77. > * {
  78. border-bottom: inherit;
  79. }
  80. > *:last-child {
  81. > *:last-child {
  82. border-radius: 0 0 ${p => p.theme.borderRadius} 0;
  83. border-bottom: 0;
  84. }
  85. }
  86. `;