cardHeader.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import styled from '@emotion/styled';
  2. import Button from 'sentry/components/button';
  3. import ButtonBar from 'sentry/components/buttonBar';
  4. import Clipboard from 'sentry/components/clipboard';
  5. import ConfirmDelete from 'sentry/components/confirmDelete';
  6. import DateTime from 'sentry/components/dateTime';
  7. import QuestionTooltip from 'sentry/components/questionTooltip';
  8. import {IconCopy, IconDelete, IconEdit} from 'sentry/icons';
  9. import {t, tct} from 'sentry/locale';
  10. import space from 'sentry/styles/space';
  11. import {Relay} from 'sentry/types';
  12. type Props = Relay & {
  13. disabled: boolean;
  14. onDelete: (publicKey: Relay['publicKey']) => () => void;
  15. onEdit: (publicKey: Relay['publicKey']) => () => void;
  16. };
  17. const CardHeader = ({
  18. publicKey,
  19. name,
  20. description,
  21. created,
  22. disabled,
  23. onEdit,
  24. onDelete,
  25. }: Props) => {
  26. const deleteButton = (
  27. <Button
  28. size="sm"
  29. icon={<IconDelete />}
  30. aria-label={t('Delete Key')}
  31. disabled={disabled}
  32. title={disabled ? t('You do not have permission to delete keys') : undefined}
  33. />
  34. );
  35. return (
  36. <Header>
  37. <KeyName>
  38. {name}
  39. {description && <QuestionTooltip position="top" size="sm" title={description} />}
  40. </KeyName>
  41. <DateCreated>
  42. {tct('Created on [date]', {date: <DateTime date={created} />})}
  43. </DateCreated>
  44. <StyledButtonBar gap={1}>
  45. <Clipboard value={publicKey}>
  46. <Button size="sm" icon={<IconCopy />}>
  47. {t('Copy Key')}
  48. </Button>
  49. </Clipboard>
  50. <Button
  51. size="sm"
  52. onClick={onEdit(publicKey)}
  53. icon={<IconEdit />}
  54. aria-label={t('Edit Key')}
  55. disabled={disabled}
  56. title={disabled ? t('You do not have permission to edit keys') : undefined}
  57. />
  58. {disabled ? (
  59. deleteButton
  60. ) : (
  61. <ConfirmDelete
  62. message={t(
  63. 'After removing this Public Key, your Relay will no longer be able to communicate with Sentry and events will be dropped.'
  64. )}
  65. onConfirm={onDelete(publicKey)}
  66. confirmInput={name}
  67. >
  68. {deleteButton}
  69. </ConfirmDelete>
  70. )}
  71. </StyledButtonBar>
  72. </Header>
  73. );
  74. };
  75. export default CardHeader;
  76. const KeyName = styled('div')`
  77. grid-row: 1/2;
  78. display: grid;
  79. grid-template-columns: repeat(2, max-content);
  80. grid-column-gap: ${space(0.5)};
  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(1)};
  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. `;