apiTokenRow.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. size="sm"
  26. onClick={() => onRemove(token)}
  27. icon={<IconSubtract isCircled size="xs" />}
  28. >
  29. {t('Remove')}
  30. </Button>
  31. </Controls>
  32. <Details>
  33. <ScopesWrapper>
  34. <Heading>{t('Scopes')}</Heading>
  35. <ScopeList>{token.scopes.join(', ')}</ScopeList>
  36. </ScopesWrapper>
  37. <div>
  38. <Heading>{t('Created')}</Heading>
  39. <Time>
  40. <DateTime
  41. date={getDynamicText({
  42. value: token.dateCreated,
  43. fixed: new Date(1508208080000), // National Pasta Day
  44. })}
  45. />
  46. </Time>
  47. </div>
  48. </Details>
  49. </StyledPanelItem>
  50. );
  51. }
  52. const StyledPanelItem = styled(PanelItem)`
  53. flex-direction: column;
  54. padding: ${space(2)};
  55. `;
  56. const Controls = styled('div')`
  57. display: flex;
  58. align-items: center;
  59. margin-bottom: ${space(1)};
  60. `;
  61. const InputWrapper = styled('div')`
  62. font-size: ${p => p.theme.fontSizeRelativeSmall};
  63. flex: 1;
  64. margin-right: ${space(1)};
  65. `;
  66. const Details = styled('div')`
  67. display: flex;
  68. margin-top: ${space(1)};
  69. `;
  70. const ScopesWrapper = styled('div')`
  71. flex: 1;
  72. `;
  73. const ScopeList = styled('div')`
  74. font-size: ${p => p.theme.fontSizeRelativeSmall};
  75. line-height: 1.4;
  76. `;
  77. const Time = styled('time')`
  78. font-size: ${p => p.theme.fontSizeRelativeSmall};
  79. line-height: 1.4;
  80. `;
  81. const Heading = styled('div')`
  82. font-size: ${p => p.theme.fontSizeMedium};
  83. text-transform: uppercase;
  84. color: ${p => p.theme.subText};
  85. margin-bottom: ${space(1)};
  86. `;
  87. export default ApiTokenRow;