releasesPromo.tsx 13 KB

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