cardHeader.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import styled from '@emotion/styled';
  2. import {Button} from 'sentry/components/button';
  3. import ButtonBar from 'sentry/components/buttonBar';
  4. import ConfirmDelete from 'sentry/components/confirmDelete';
  5. import {DateTime} from 'sentry/components/dateTime';
  6. import QuestionTooltip from 'sentry/components/questionTooltip';
  7. import {IconCopy, IconDelete, IconEdit} from 'sentry/icons';
  8. import {t, tct} from 'sentry/locale';
  9. import {space} from 'sentry/styles/space';
  10. import type {Relay} from 'sentry/types/relay';
  11. import useCopyToClipboard from 'sentry/utils/useCopyToClipboard';
  12. type Props = Relay & {
  13. disabled: boolean;
  14. onDelete: (publicKey: Relay['publicKey']) => () => void;
  15. onEdit: (publicKey: Relay['publicKey']) => () => void;
  16. };
  17. function CardHeader({
  18. publicKey,
  19. name,
  20. description,
  21. created,
  22. disabled,
  23. onEdit,
  24. onDelete,
  25. }: Props) {
  26. const {onClick} = useCopyToClipboard({text: publicKey});
  27. const deleteButton = (
  28. <Button
  29. size="sm"
  30. icon={<IconDelete />}
  31. aria-label={t('Delete Key')}
  32. disabled={disabled}
  33. title={disabled ? t('You do not have permission to delete keys') : undefined}
  34. />
  35. );
  36. return (
  37. <Header>
  38. <KeyName>
  39. {name}
  40. {description && <QuestionTooltip position="top" size="sm" title={description} />}
  41. </KeyName>
  42. <DateCreated>
  43. {tct('Created on [date]', {date: <DateTime date={created} />})}
  44. </DateCreated>
  45. <StyledButtonBar gap={1}>
  46. <Button size="sm" icon={<IconCopy />} onClick={onClick}>
  47. {t('Copy Key')}
  48. </Button>
  49. <Button
  50. size="sm"
  51. onClick={onEdit(publicKey)}
  52. icon={<IconEdit />}
  53. aria-label={t('Edit Key')}
  54. disabled={disabled}
  55. title={disabled ? t('You do not have permission to edit keys') : undefined}
  56. />
  57. {disabled ? (
  58. deleteButton
  59. ) : (
  60. <ConfirmDelete
  61. message={t(
  62. 'After removing this Public Key, your Relay will no longer be able to communicate with Sentry and events will be dropped.'
  63. )}
  64. onConfirm={onDelete(publicKey)}
  65. confirmInput={name}
  66. >
  67. {deleteButton}
  68. </ConfirmDelete>
  69. )}
  70. </StyledButtonBar>
  71. </Header>
  72. );
  73. }
  74. export default CardHeader;
  75. const KeyName = styled('div')`
  76. grid-row: 1/2;
  77. grid-template-columns: repeat(2, max-content);
  78. display: flex;
  79. gap: ${space(1)};
  80. align-items: center;
  81. `;
  82. const DateCreated = styled('div')`
  83. grid-row: 2/3;
  84. color: ${p => p.theme.gray300};
  85. font-size: ${p => p.theme.fontSizeMedium};
  86. `;
  87. const StyledButtonBar = styled(ButtonBar)`
  88. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  89. grid-row: 1/3;
  90. }
  91. `;
  92. const Header = styled('div')`
  93. display: grid;
  94. grid-row-gap: ${space(0.25)};
  95. margin-bottom: ${space(1)};
  96. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  97. grid-template-columns: 1fr max-content;
  98. grid-template-rows: repeat(2, max-content);
  99. }
  100. `;