keyRow.tsx 3.7 KB

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