noThresholdCard.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import {useState} from 'react';
  2. import styled from '@emotion/styled';
  3. import {Button} from 'sentry/components/button';
  4. import ProjectBadge from 'sentry/components/idBadge/projectBadge';
  5. import {PanelTable} from 'sentry/components/panels/panelTable';
  6. import {IconAdd} from 'sentry/icons';
  7. import {t} from 'sentry/locale';
  8. import {space} from 'sentry/styles/space';
  9. import type {Project} from 'sentry/types';
  10. import {ThresholdGroupRows} from './thresholdGroupRows';
  11. type Props = {
  12. allEnvironmentNames: string[];
  13. project: Project;
  14. refetch: () => void;
  15. setTempError: (msg: string) => void;
  16. };
  17. export default function NoThresholdCard({
  18. project,
  19. allEnvironmentNames,
  20. refetch,
  21. setTempError,
  22. }: Props) {
  23. const [createNew, setCreateNew] = useState(false);
  24. return createNew ? (
  25. <StyledPanelTable isEmpty={false} headers={[]}>
  26. <ThresholdGroupRows
  27. allEnvironmentNames={allEnvironmentNames}
  28. isLastRow
  29. refetch={refetch}
  30. setTempError={setTempError}
  31. project={project}
  32. newGroup
  33. onFormClose={() => setCreateNew(false)}
  34. />
  35. </StyledPanelTable>
  36. ) : (
  37. <StyledPanel>
  38. <StyledStrong>
  39. <ProjectBadge project={project} avatarSize={16} hideOverflow />
  40. </StyledStrong>
  41. <Button
  42. aria-label={t('Create Threshold')}
  43. icon={<IconAdd color="activeText" isCircled />}
  44. onClick={() => setCreateNew(true)}
  45. size="xs"
  46. >
  47. Create Threshold
  48. </Button>
  49. </StyledPanel>
  50. );
  51. }
  52. const StyledStrong = styled('strong')`
  53. font-size: ${p => p.theme.fontSizeMedium};
  54. `;
  55. const StyledPanel = styled('div')`
  56. display: flex;
  57. align-items: center;
  58. justify-content: space-between;
  59. padding: ${space(2)};
  60. border: 1px solid ${p => p.theme.border};
  61. border-radius: ${p => p.theme.panelBorderRadius};
  62. margin-top: ${space(1)};
  63. `;
  64. const StyledPanelTable = styled(PanelTable)`
  65. @media (min-width: ${p => p.theme.breakpoints.small}) {
  66. overflow: initial;
  67. }
  68. grid-template-columns:
  69. minmax(100px, 1fr) minmax(250px, 1fr) minmax(200px, 4fr)
  70. minmax(150px, auto);
  71. white-space: nowrap;
  72. font-size: ${p => p.theme.fontSizeMedium};
  73. > * {
  74. border-bottom: inherit;
  75. }
  76. > *:last-child {
  77. > *:last-child {
  78. border-radius: 0 0 ${p => p.theme.borderRadius} 0;
  79. border-bottom: 0;
  80. }
  81. }
  82. `;