releasesPromo.tsx 14 KB

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