keyRow.tsx 4.2 KB

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