keyRow.tsx 4.3 KB

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