releasesPromo.tsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. import {useCallback, useEffect, useState} from 'react';
  2. import styled from '@emotion/styled';
  3. import commitImage from 'sentry-images/spot/releases-tour-commits.svg';
  4. import emailImage from 'sentry-images/spot/releases-tour-email.svg';
  5. import resolutionImage from 'sentry-images/spot/releases-tour-resolution.svg';
  6. import statsImage from 'sentry-images/spot/releases-tour-stats.svg';
  7. import {addErrorMessage, addSuccessMessage} from 'sentry/actionCreators/indicator';
  8. import {openCreateReleaseIntegration} from 'sentry/actionCreators/modal';
  9. import Access from 'sentry/components/acl/access';
  10. import {Button} from 'sentry/components/button';
  11. import DropdownAutoComplete from 'sentry/components/dropdownAutoComplete';
  12. import {Item} from 'sentry/components/dropdownAutoComplete/types';
  13. import Link from 'sentry/components/links/link';
  14. import {TourImage, TourStep, TourText} from 'sentry/components/modals/featureTourModal';
  15. import {Panel} from 'sentry/components/panels';
  16. import TextOverflow from 'sentry/components/textOverflow';
  17. import Tooltip from 'sentry/components/tooltip';
  18. import {IconAdd, IconCopy} from 'sentry/icons';
  19. import {t} from 'sentry/locale';
  20. import space from 'sentry/styles/space';
  21. import {Organization, Project, SentryApp} from 'sentry/types';
  22. import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
  23. import useApi from 'sentry/utils/useApi';
  24. import useApiRequests from 'sentry/utils/useApiRequests';
  25. const releasesSetupUrl = 'https://docs.sentry.io/product/releases/';
  26. const docsLink = (
  27. <Button external href={releasesSetupUrl}>
  28. {t('Setup')}
  29. </Button>
  30. );
  31. export const RELEASES_TOUR_STEPS: TourStep[] = [
  32. {
  33. title: t('Suspect Commits'),
  34. image: <TourImage src={commitImage} />,
  35. body: (
  36. <TourText>
  37. {t(
  38. 'Sentry suggests which commit caused an issue and who is likely responsible so you can triage.'
  39. )}
  40. </TourText>
  41. ),
  42. actions: docsLink,
  43. },
  44. {
  45. title: t('Release Stats'),
  46. image: <TourImage src={statsImage} />,
  47. body: (
  48. <TourText>
  49. {t(
  50. 'Get an overview of the commits in each release, and which issues were introduced or fixed.'
  51. )}
  52. </TourText>
  53. ),
  54. actions: docsLink,
  55. },
  56. {
  57. title: t('Easily Resolve'),
  58. image: <TourImage src={resolutionImage} />,
  59. body: (
  60. <TourText>
  61. {t(
  62. 'Automatically resolve issues by including the issue number in your commit message.'
  63. )}
  64. </TourText>
  65. ),
  66. actions: docsLink,
  67. },
  68. {
  69. title: t('Deploy Emails'),
  70. image: <TourImage src={emailImage} />,
  71. body: (
  72. <TourText>
  73. {t(
  74. 'Receive email notifications about when your code gets deployed. This can be customized in settings.'
  75. )}
  76. </TourText>
  77. ),
  78. },
  79. ];
  80. type Props = {
  81. organization: Organization;
  82. project: Project;
  83. };
  84. const ReleasesPromo = ({organization, project}: Props) => {
  85. const {data, renderComponent, isLoading} = useApiRequests<{
  86. internalIntegrations: SentryApp[];
  87. }>({
  88. endpoints: [
  89. [
  90. 'internalIntegrations',
  91. `/organizations/${organization.slug}/sentry-apps/`,
  92. {query: {status: 'internal'}},
  93. ],
  94. ],
  95. });
  96. const api = useApi();
  97. const [token, setToken] = useState(null);
  98. const [integrations, setIntegrations] = useState<SentryApp[]>([]);
  99. const [selectedItem, selectItem] = useState<Pick<Item, 'label' | 'value'> | null>(null);
  100. useEffect(() => {
  101. if (!isLoading && data.internalIntegrations) {
  102. setIntegrations(data.internalIntegrations);
  103. }
  104. }, [isLoading, data.internalIntegrations]);
  105. useEffect(() => {
  106. trackAdvancedAnalyticsEvent('releases.quickstart_viewed', {
  107. organization,
  108. project_id: project.id,
  109. });
  110. // eslint-disable-next-line react-hooks/exhaustive-deps
  111. }, []);
  112. const trackQuickstartCopy = useCallback(() => {
  113. trackAdvancedAnalyticsEvent('releases.quickstart_copied', {
  114. organization,
  115. project_id: project.id,
  116. });
  117. }, [organization, project]);
  118. const trackQuickstartCreatedIntegration = useCallback(
  119. (integration: SentryApp) => {
  120. trackAdvancedAnalyticsEvent('releases.quickstart_create_integration.success', {
  121. organization,
  122. project_id: project.id,
  123. integration_uuid: integration.uuid,
  124. });
  125. },
  126. [organization, project]
  127. );
  128. const trackCreateIntegrationModalClose = useCallback(() => {
  129. trackAdvancedAnalyticsEvent('releases.quickstart_create_integration_modal.close', {
  130. organization,
  131. project_id: project.id,
  132. });
  133. }, [organization, project.id]);
  134. const fetchToken = async sentryAppSlug => {
  135. const tokens = await api.requestPromise(`/sentry-apps/${sentryAppSlug}/api-tokens/`);
  136. if (!tokens.length) {
  137. const newToken = await generateToken(sentryAppSlug);
  138. return setToken(newToken);
  139. }
  140. return setToken(tokens[0].token);
  141. };
  142. const generateToken = async (sentryAppSlug: string) => {
  143. const newToken = await api.requestPromise(
  144. `/sentry-apps/${sentryAppSlug}/api-tokens/`,
  145. {
  146. method: 'POST',
  147. }
  148. );
  149. return newToken.token;
  150. };
  151. const handleCopy = async () => {
  152. if (!token || !selectedItem) {
  153. addErrorMessage(t('Select an integration for your auth token!'));
  154. return;
  155. }
  156. const current_text = `
  157. # Install the cli
  158. curl -sL https://sentry.io/get-cli/ | SENTRY_CLI_VERSION="2.2.0" bash
  159. # Setup configuration values
  160. SENTRY_AUTH_TOKEN=${token} # From internal integration: ${selectedItem.value.name}
  161. SENTRY_ORG=${organization.slug}
  162. SENTRY_PROJECT=${project.slug}
  163. VERSION=\`sentry-cli releases propose-version\`
  164. # Workflow to create releases
  165. sentry-cli releases new "$VERSION"
  166. sentry-cli releases set-commits "$VERSION" --auto
  167. sentry-cli releases finalize "$VERSION"
  168. `;
  169. await navigator.clipboard.writeText(current_text);
  170. addSuccessMessage(t('Copied to clipboard!'));
  171. trackQuickstartCopy();
  172. };
  173. const renderIntegrationNode = (integration: SentryApp) => {
  174. return {
  175. value: {slug: integration.slug, name: integration.name},
  176. searchKey: `${integration.name}`,
  177. label: (
  178. <MenuItemWrapper data-test-id="integration-option" key={integration.uuid}>
  179. <Label>{integration.name}</Label>
  180. </MenuItemWrapper>
  181. ),
  182. };
  183. };
  184. return renderComponent(
  185. <Panel>
  186. <Container>
  187. <ContainerHeader>
  188. <h3>{t('Set up Releases')}</h3>
  189. <Button priority="default" size="sm" href={releasesSetupUrl} external>
  190. {t('Full Documentation')}
  191. </Button>
  192. </ContainerHeader>
  193. <p>
  194. {t(
  195. 'Find which release caused an issue, apply source maps, and get notified about your deploys.'
  196. )}
  197. </p>
  198. <p>
  199. {t(
  200. 'Add the following commands to your CI config when you deploy your application.'
  201. )}
  202. </p>
  203. <CodeBlock>
  204. <CopyButton onClick={handleCopy}>
  205. <IconCopy />
  206. </CopyButton>
  207. <Comment># Install the cli</Comment>
  208. <Bash>
  209. curl -sL https://sentry.io/get-cli/ | SENTRY_CLI_VERSION="2.2.0" bash
  210. </Bash>
  211. <Bash>{'\n'}</Bash>
  212. <Comment># Setup configuration values</Comment>
  213. <Bash>
  214. SENTRY_AUTH_TOKEN=
  215. <StyledDropdownAutoComplete
  216. minWidth={300}
  217. maxHeight={400}
  218. onOpen={e => {
  219. // This can be called multiple times and does not always have `event`
  220. e?.stopPropagation();
  221. }}
  222. items={[
  223. {
  224. label: <GroupHeader>{t('Available Integrations')}</GroupHeader>,
  225. id: 'available-integrations',
  226. items: (integrations || []).map(renderIntegrationNode),
  227. },
  228. ]}
  229. alignMenu="left"
  230. onSelect={({label, value}) => {
  231. selectItem({label, value});
  232. fetchToken(value.slug);
  233. }}
  234. itemSize="small"
  235. searchPlaceholder={t('Select Internal Integration')}
  236. menuFooter={
  237. <Access access={['org:integrations']}>
  238. {({hasAccess}) => (
  239. <Tooltip
  240. title={t(
  241. 'You must be an organization owner, manager or admin to create an integration.'
  242. )}
  243. disabled={hasAccess}
  244. >
  245. <CreateIntegrationLink
  246. to=""
  247. data-test-id="create-release-integration"
  248. disabled={!hasAccess}
  249. onClick={() =>
  250. openCreateReleaseIntegration({
  251. organization,
  252. project,
  253. onCreateSuccess: (integration: SentryApp) => {
  254. setIntegrations([integration, ...integrations]);
  255. const {label, value} = renderIntegrationNode(integration);
  256. selectItem({
  257. label,
  258. value,
  259. });
  260. fetchToken(value.slug);
  261. trackQuickstartCreatedIntegration(integration);
  262. },
  263. onCancel: () => {
  264. trackCreateIntegrationModalClose();
  265. },
  266. })
  267. }
  268. >
  269. <MenuItemFooterWrapper>
  270. <IconContainer>
  271. <IconAdd color="activeText" isCircled legacySize="14px" />
  272. </IconContainer>
  273. <Label>{t('Create New Integration')}</Label>
  274. </MenuItemFooterWrapper>
  275. </CreateIntegrationLink>
  276. </Tooltip>
  277. )}
  278. </Access>
  279. }
  280. disableLabelPadding
  281. emptyHidesInput
  282. >
  283. {() => {
  284. return token && selectedItem ? (
  285. <span style={{display: 'flex'}}>
  286. <Bash>{token}</Bash>
  287. <Comment>{` # From internal integration: ${selectedItem.value.name} `}</Comment>
  288. </span>
  289. ) : (
  290. <Bash style={{color: '#7cc5c4'}}>{'<click-here-for-your-token>'}</Bash>
  291. );
  292. }}
  293. </StyledDropdownAutoComplete>
  294. </Bash>
  295. <Bash>{`SENTRY_ORG=${organization.slug}`}</Bash>
  296. <Bash>{`SENTRY_PROJECT=${project.slug}`}</Bash>
  297. <Bash>VERSION=`sentry-cli releases propose-version`</Bash>
  298. <Bash>{'\n'}</Bash>
  299. <Comment># Workflow to create releases</Comment>
  300. <Bash>sentry-cli releases new "$VERSION"</Bash>
  301. <Bash>sentry-cli releases set-commits "$VERSION" --auto</Bash>
  302. <Bash>sentry-cli releases finalize "$VERSION"</Bash>
  303. </CodeBlock>
  304. </Container>
  305. </Panel>
  306. );
  307. };
  308. const ContainerHeader = styled('div')`
  309. display: flex;
  310. justify-content: space-between;
  311. align-items: center;
  312. margin-bottom: ${space(3)};
  313. min-height: 32px;
  314. h3 {
  315. margin: 0;
  316. }
  317. @media (max-width: ${p => p.theme.breakpoints.small}) {
  318. flex-direction: column;
  319. align-items: flex-start;
  320. h3 {
  321. margin-bottom: ${space(2)};
  322. }
  323. }
  324. `;
  325. const CodeBlock = styled('pre')`
  326. background: #251f3d;
  327. display: flex;
  328. flex-direction: column;
  329. padding: ${space(2)};
  330. overflow: initial;
  331. position: relative;
  332. `;
  333. const CopyButton = styled(Button)`
  334. position: absolute;
  335. right: 20px;
  336. `;
  337. const Language = styled('code')`
  338. font-size: 15px;
  339. text-shadow: none;
  340. direction: ltr;
  341. text-align: left;
  342. white-space: pre;
  343. word-spacing: normal;
  344. word-break: normal;
  345. line-height: 1.5;
  346. display: flex;
  347. align-items: center;
  348. `;
  349. const Bash = styled(Language)`
  350. color: #f2edf6;
  351. `;
  352. const Comment = styled(Language)`
  353. color: #77658b;
  354. `;
  355. const Container = styled('div')`
  356. padding: ${space(3)};
  357. `;
  358. const StyledDropdownAutoComplete = styled(DropdownAutoComplete)`
  359. font-family: ${p => p.theme.text.family};
  360. border: none;
  361. border-radius: 4px;
  362. width: 300px;
  363. `;
  364. const GroupHeader = styled('div')`
  365. font-size: ${p => p.theme.fontSizeSmall};
  366. font-family: ${p => p.theme.text.family};
  367. font-weight: 600;
  368. margin: ${space(1)} 0;
  369. color: ${p => p.theme.subText};
  370. line-height: ${p => p.theme.fontSizeSmall};
  371. text-align: left;
  372. `;
  373. const CreateIntegrationLink = styled(Link)`
  374. color: ${p => (p.disabled ? p.theme.disabled : p.theme.textColor)};
  375. `;
  376. const MenuItemWrapper = styled('div')<{
  377. disabled?: boolean;
  378. py?: number;
  379. }>`
  380. cursor: ${p => (p.disabled ? 'not-allowed' : 'pointer')};
  381. display: flex;
  382. align-items: center;
  383. font-family: ${p => p.theme.text.family};
  384. font-size: 13px;
  385. ${p =>
  386. typeof p.py !== 'undefined' &&
  387. `
  388. padding-top: ${p.py};
  389. padding-bottom: ${p.py};
  390. `};
  391. `;
  392. const MenuItemFooterWrapper = styled(MenuItemWrapper)`
  393. padding: ${space(0.25)} ${space(1)};
  394. border-top: 1px solid ${p => p.theme.innerBorder};
  395. background-color: ${p => p.theme.tag.highlight.background};
  396. color: ${p => p.theme.active};
  397. :hover {
  398. color: ${p => p.theme.activeHover};
  399. svg {
  400. fill: ${p => p.theme.activeHover};
  401. }
  402. }
  403. `;
  404. const IconContainer = styled('div')`
  405. display: flex;
  406. align-items: center;
  407. justify-content: center;
  408. width: 24px;
  409. height: 24px;
  410. flex-shrink: 0;
  411. `;
  412. const Label = styled(TextOverflow)`
  413. margin-left: 6px;
  414. `;
  415. export default ReleasesPromo;