organizationApiKeysList.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import {Fragment} from 'react';
  2. import {css} from '@emotion/react';
  3. import styled from '@emotion/styled';
  4. import AlertLink from 'sentry/components/alertLink';
  5. import {Button} from 'sentry/components/button';
  6. import ExternalLink from 'sentry/components/links/externalLink';
  7. import Link from 'sentry/components/links/link';
  8. import LinkWithConfirmation from 'sentry/components/links/linkWithConfirmation';
  9. import {PanelTable} from 'sentry/components/panels/panelTable';
  10. import TextCopyInput from 'sentry/components/textCopyInput';
  11. import {IconAdd, IconDelete} from 'sentry/icons';
  12. import {t, tct} from 'sentry/locale';
  13. import type {Organization} from 'sentry/types/organization';
  14. import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader';
  15. import TextBlock from 'sentry/views/settings/components/text/textBlock';
  16. import type {DeprecatedApiKey} from './types';
  17. type Props = {
  18. /**
  19. * Busy differs from loading in that busy is a result of an action like removing
  20. */
  21. busy: boolean;
  22. keys: DeprecatedApiKey[];
  23. /**
  24. * Loading refers to fetching the API Keys
  25. */
  26. loading: boolean;
  27. onAddApiKey: () => void;
  28. onRemove: (id: DeprecatedApiKey['id']) => void;
  29. organization: Organization;
  30. };
  31. function OrganizationApiKeysList({
  32. organization,
  33. keys,
  34. busy,
  35. loading,
  36. onAddApiKey,
  37. onRemove,
  38. }: Props) {
  39. const hasKeys = Boolean(keys?.length);
  40. const action = (
  41. <Button
  42. priority="primary"
  43. size="sm"
  44. icon={<IconAdd isCircled />}
  45. busy={busy}
  46. disabled={busy}
  47. onClick={onAddApiKey}
  48. >
  49. {t('New API Key')}
  50. </Button>
  51. );
  52. return (
  53. <div>
  54. <SettingsPageHeader title={t('API Keys')} action={action} />
  55. <TextBlock>
  56. {tct(
  57. `API keys grant access to the [api:developer web API].
  58. If you're looking to configure a Sentry client, you'll need a
  59. client key which is available in your project settings.`,
  60. {
  61. api: <ExternalLink href="https://docs.sentry.io/api/" />,
  62. }
  63. )}
  64. </TextBlock>
  65. <AlertLink to="/settings/account/api/auth-tokens/" priority="info">
  66. {tct(
  67. 'Until Sentry supports OAuth, you might want to switch to using [tokens:User Auth Tokens] instead.',
  68. {
  69. tokens: <u />,
  70. }
  71. )}
  72. </AlertLink>
  73. <PanelTable
  74. isLoading={loading}
  75. isEmpty={!hasKeys}
  76. emptyMessage={t('No API keys for this organization')}
  77. headers={[t('Name'), t('Key'), t('Actions')]}
  78. >
  79. {keys?.map(({id, key, label}) => {
  80. return (
  81. <Fragment key={key}>
  82. <Cell>
  83. <Link to={`/settings/${organization.slug}/api-keys/${id}/`}>{label}</Link>
  84. </Cell>
  85. <TextCopyInput size="md" monospace>
  86. {key}
  87. </TextCopyInput>
  88. <Cell>
  89. <LinkWithConfirmation
  90. aria-label={t('Remove API Key')}
  91. className="btn btn-default btn-sm"
  92. onConfirm={() => onRemove(id)}
  93. message={t('Are you sure you want to remove this API key?')}
  94. title={t('Remove API Key?')}
  95. >
  96. <IconDelete
  97. size="xs"
  98. css={css`
  99. position: relative;
  100. top: 2px;
  101. `}
  102. />
  103. </LinkWithConfirmation>
  104. </Cell>
  105. </Fragment>
  106. );
  107. })}
  108. </PanelTable>
  109. </div>
  110. );
  111. }
  112. const Cell = styled('div')`
  113. display: flex;
  114. align-items: center;
  115. `;
  116. export default OrganizationApiKeysList;