keyRow.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import type {RouteComponentProps} from 'react-router';
  2. import styled from '@emotion/styled';
  3. import {Button} from 'sentry/components/button';
  4. import ClippedBox from 'sentry/components/clippedBox';
  5. import Confirm from 'sentry/components/confirm';
  6. import Link from 'sentry/components/links/link';
  7. import Panel from 'sentry/components/panels/panel';
  8. import PanelBody from 'sentry/components/panels/panelBody';
  9. import PanelHeader from 'sentry/components/panels/panelHeader';
  10. import {IconDelete} from 'sentry/icons';
  11. import {t} from 'sentry/locale';
  12. import {space} from 'sentry/styles/space';
  13. import type {Project, ProjectKey} from 'sentry/types';
  14. import recreateRoute from 'sentry/utils/recreateRoute';
  15. import {LoaderScript} from 'sentry/views/settings/project/projectKeys/list/loaderScript';
  16. import ProjectKeyCredentials from 'sentry/views/settings/project/projectKeys/projectKeyCredentials';
  17. type Props = {
  18. data: ProjectKey;
  19. hasWriteAccess: boolean;
  20. onRemove: (data: ProjectKey) => void;
  21. onToggle: (isActive: boolean, data: ProjectKey) => void;
  22. orgId: string;
  23. project: Project;
  24. projectId: string;
  25. } & Pick<RouteComponentProps<{}, {}>, 'routes' | 'location' | 'params'>;
  26. function KeyRow({
  27. data,
  28. onRemove,
  29. onToggle,
  30. hasWriteAccess,
  31. routes,
  32. location,
  33. params,
  34. project,
  35. }: Props) {
  36. const handleEnable = () => onToggle(true, data);
  37. const handleDisable = () => onToggle(false, data);
  38. const editUrl = recreateRoute(`${data.id}/`, {routes, params, location});
  39. const platform = project.platform || 'other';
  40. const isBrowserJavaScript = platform === 'javascript';
  41. const isJsPlatform = platform.startsWith('javascript');
  42. return (
  43. <Panel>
  44. <PanelHeader hasButtons>
  45. <Title disabled={!data.isActive}>
  46. <PanelHeaderLink to={editUrl}>{data.label}</PanelHeaderLink>
  47. {!data.isActive && (
  48. <small>
  49. {' \u2014 '}
  50. {t('Disabled')}
  51. </small>
  52. )}
  53. </Title>
  54. <Controls>
  55. <Button to={editUrl} size="xs">
  56. {t('Configure')}
  57. </Button>
  58. <Confirm
  59. disabled={!hasWriteAccess}
  60. onConfirm={data.isActive ? handleDisable : handleEnable}
  61. confirmText={data.isActive ? t('Disable Key') : t('Enable Key')}
  62. message={
  63. data.isActive
  64. ? t('Are you sure you want to disable this key?')
  65. : t('Are you sure you want to enable this key?')
  66. }
  67. >
  68. <Button size="xs">{data.isActive ? t('Disable') : t('Enable')}</Button>
  69. </Confirm>
  70. <Confirm
  71. disabled={!hasWriteAccess}
  72. priority="danger"
  73. onConfirm={() => onRemove(data)}
  74. confirmText={t('Remove Key')}
  75. message={t(
  76. 'Are you sure you want to remove this key? This action is irreversible.'
  77. )}
  78. >
  79. <Button size="xs" icon={<IconDelete />} aria-label={t('Delete')} />
  80. </Confirm>
  81. </Controls>
  82. </PanelHeader>
  83. <StyledClippedBox
  84. clipHeight={300}
  85. defaultClipped={!isJsPlatform}
  86. btnText={t('Expand')}
  87. >
  88. <StyledPanelBody disabled={!data.isActive}>
  89. <ProjectKeyCredentials
  90. projectId={`${data.projectId}`}
  91. data={data}
  92. showMinidump={!isJsPlatform}
  93. showUnreal={!isJsPlatform}
  94. showSecurityEndpoint={!isJsPlatform}
  95. />
  96. {isBrowserJavaScript && (
  97. <LoaderScript
  98. projectKey={data}
  99. routes={routes}
  100. location={location}
  101. params={params}
  102. />
  103. )}
  104. </StyledPanelBody>
  105. </StyledClippedBox>
  106. </Panel>
  107. );
  108. }
  109. export default KeyRow;
  110. const StyledClippedBox = styled(ClippedBox)`
  111. padding: 0;
  112. margin: 0;
  113. > *:last-child {
  114. padding-bottom: ${space(3)};
  115. }
  116. `;
  117. const PanelHeaderLink = styled(Link)`
  118. color: ${p => p.theme.subText};
  119. `;
  120. const Title = styled('div')<{disabled: boolean}>`
  121. flex: 1;
  122. ${p => (p.disabled ? 'opacity: 0.5;' : '')};
  123. margin-right: ${space(1)};
  124. `;
  125. const Controls = styled('div')`
  126. display: grid;
  127. align-items: center;
  128. gap: ${space(1)};
  129. grid-auto-flow: column;
  130. `;
  131. const StyledPanelBody = styled(PanelBody)<{disabled: boolean}>`
  132. ${p => (p.disabled ? 'opacity: 0.5;' : '')};
  133. `;