thresholdGroupTable.tsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 &&
  47. sortedThreshold.map((threshold, idx) => {
  48. return (
  49. <ThresholdGroupRows
  50. key={threshold.id}
  51. project={project}
  52. allEnvironmentNames={allEnvironmentNames}
  53. threshold={threshold}
  54. refetch={refetch}
  55. setTempError={setTempError}
  56. isLastRow={idx === sortedThreshold.length - 1}
  57. />
  58. );
  59. })}
  60. </StyledPanelTable>
  61. </div>
  62. );
  63. }
  64. const StyledStrong = styled('div')`
  65. font-weight: 600;
  66. font-size: ${p => p.theme.fontSizeMedium};
  67. margin: ${space(2)} 0;
  68. `;
  69. const StyledPanelTable = styled(PanelTable)`
  70. @media (min-width: ${p => p.theme.breakpoints.small}) {
  71. overflow: initial;
  72. }
  73. grid-template-columns:
  74. minmax(100px, 1fr) minmax(250px, 1fr) minmax(200px, 4fr)
  75. minmax(150px, auto);
  76. white-space: nowrap;
  77. font-size: ${p => p.theme.fontSizeMedium};
  78. > * {
  79. border-bottom: inherit;
  80. }
  81. > *:last-child {
  82. > *:last-child {
  83. border-radius: 0 0 ${p => p.theme.borderRadius} 0;
  84. border-bottom: 0;
  85. }
  86. }
  87. `;