apiTokenRow.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import styled from '@emotion/styled';
  2. import {Button} from 'sentry/components/button';
  3. import DateTime from 'sentry/components/dateTime';
  4. import {PanelItem} from 'sentry/components/panels';
  5. import TextCopyInput from 'sentry/components/textCopyInput';
  6. import {IconSubtract} from 'sentry/icons';
  7. import {t} from 'sentry/locale';
  8. import {space} from 'sentry/styles/space';
  9. import {InternalAppApiToken} from 'sentry/types';
  10. import getDynamicText from 'sentry/utils/getDynamicText';
  11. type Props = {
  12. onRemove: (token: InternalAppApiToken) => void;
  13. token: InternalAppApiToken;
  14. };
  15. function ApiTokenRow({token, onRemove}: Props) {
  16. return (
  17. <StyledPanelItem>
  18. <Controls>
  19. <InputWrapper>
  20. <TextCopyInput>
  21. {getDynamicText({value: token.token, fixed: 'CI_AUTH_TOKEN'})}
  22. </TextCopyInput>
  23. </InputWrapper>
  24. <Button
  25. onClick={() => onRemove(token)}
  26. icon={<IconSubtract isCircled size="xs" />}
  27. >
  28. {t('Remove')}
  29. </Button>
  30. </Controls>
  31. <Details>
  32. <ScopesWrapper>
  33. <Heading>{t('Scopes')}</Heading>
  34. <ScopeList>{token.scopes.join(', ')}</ScopeList>
  35. </ScopesWrapper>
  36. <div>
  37. <Heading>{t('Created')}</Heading>
  38. <Time>
  39. <DateTime
  40. date={getDynamicText({
  41. value: token.dateCreated,
  42. fixed: new Date(1508208080000), // National Pasta Day
  43. })}
  44. />
  45. </Time>
  46. </div>
  47. </Details>
  48. </StyledPanelItem>
  49. );
  50. }
  51. const StyledPanelItem = styled(PanelItem)`
  52. flex-direction: column;
  53. padding: ${space(2)};
  54. `;
  55. const Controls = styled('div')`
  56. display: flex;
  57. align-items: center;
  58. margin-bottom: ${space(1)};
  59. `;
  60. const InputWrapper = styled('div')`
  61. font-size: ${p => p.theme.fontSizeRelativeSmall};
  62. flex: 1;
  63. margin-right: ${space(1)};
  64. `;
  65. const Details = styled('div')`
  66. display: flex;
  67. margin-top: ${space(1)};
  68. `;
  69. const ScopesWrapper = styled('div')`
  70. flex: 1;
  71. `;
  72. const ScopeList = styled('div')`
  73. font-size: ${p => p.theme.fontSizeRelativeSmall};
  74. line-height: 1.4;
  75. `;
  76. const Time = styled('time')`
  77. font-size: ${p => p.theme.fontSizeRelativeSmall};
  78. line-height: 1.4;
  79. `;
  80. const Heading = styled('div')`
  81. font-size: ${p => p.theme.fontSizeMedium};
  82. text-transform: uppercase;
  83. color: ${p => p.theme.subText};
  84. margin-bottom: ${space(1)};
  85. `;
  86. export default ApiTokenRow;