addViewPage.tsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. import {useContext} from 'react';
  2. import styled from '@emotion/styled';
  3. import bannerStar from 'sentry-images/spot/banner-star.svg';
  4. import {usePrompt} from 'sentry/actionCreators/prompts';
  5. import {Button, LinkButton} from 'sentry/components/button';
  6. import {openConfirmModal} from 'sentry/components/confirm';
  7. import InteractionStateLayer from 'sentry/components/interactionStateLayer';
  8. import ExternalLink from 'sentry/components/links/externalLink';
  9. import QuestionTooltip from 'sentry/components/questionTooltip';
  10. import {FormattedQuery} from 'sentry/components/searchQueryBuilder/formattedQuery';
  11. import {IconClose} from 'sentry/icons';
  12. import {t, tn} from 'sentry/locale';
  13. import {space} from 'sentry/styles/space';
  14. import type {SavedSearch} from 'sentry/types/group';
  15. import {trackAnalytics} from 'sentry/utils/analytics';
  16. import useOrganization from 'sentry/utils/useOrganization';
  17. import {OverflowEllipsisTextContainer} from 'sentry/views/insights/common/components/textAlign';
  18. import {NewTabContext} from 'sentry/views/issueList/utils/newTabContext';
  19. type SearchSuggestion = {
  20. label: string;
  21. query: string;
  22. scope?: 'personal' | 'organization';
  23. };
  24. interface SearchSuggestionListProps {
  25. searchSuggestions: SearchSuggestion[];
  26. title: React.ReactNode;
  27. type: 'recommended' | 'saved_searches';
  28. }
  29. const RECOMMENDED_SEARCHES: SearchSuggestion[] = [
  30. {label: 'Prioritized', query: 'is:unresolved issue.priority:[high, medium]'},
  31. {label: 'Assigned to Me', query: 'is:unresolved assigned_or_suggested:me'},
  32. {
  33. label: 'For Review',
  34. query: 'is:unresolved is:for_review assigned_or_suggested:[me, my_teams, none]',
  35. },
  36. {label: 'Request Errors', query: 'is:unresolved http.status_code:5*'},
  37. {label: 'High Volume Issues', query: 'is:unresolved timesSeen:>100'},
  38. {label: 'Recent Errors', query: 'is:unresolved issue.category:error firstSeen:-24h'},
  39. {label: 'Function Regressions', query: 'issue.type:profile_function_regression'},
  40. ];
  41. function AddViewPage({
  42. personalSavedSearches = [],
  43. organizationSavedSearches = [],
  44. }: {
  45. organizationSavedSearches?: SavedSearch[];
  46. personalSavedSearches?: SavedSearch[];
  47. }) {
  48. const toolTipContents = (
  49. <Container>
  50. {t(
  51. 'Saved searches will be deprecated soon. For any you wish to return to, please save them as views.'
  52. )}
  53. <ExternalLink href={'https://docs.sentry.io/product/issues/issue-views'}>
  54. {t('Learn More')}
  55. </ExternalLink>
  56. </Container>
  57. );
  58. const savedSearchTitle = (
  59. <SavedSearchesTitle>
  60. {t('Saved Searches (will be removed)')}
  61. <QuestionTooltip
  62. icon="info"
  63. title={toolTipContents}
  64. size="sm"
  65. position="top"
  66. skipWrapper
  67. isHoverable
  68. />
  69. </SavedSearchesTitle>
  70. );
  71. const savedSearchSuggestions: SearchSuggestion[] = [
  72. ...(personalSavedSearches.map(search => ({
  73. label: search.name,
  74. query: search.query,
  75. scope: 'personal',
  76. })) as SearchSuggestion[]),
  77. ...(organizationSavedSearches.map(search => ({
  78. label: search.name,
  79. query: search.query,
  80. scope: 'organization',
  81. })) as SearchSuggestion[]),
  82. ];
  83. return (
  84. <AddViewWrapper>
  85. <AddViewBanner
  86. hasSavedSearches={savedSearchSuggestions && savedSearchSuggestions.length !== 0}
  87. />
  88. <SearchSuggestionList
  89. title={'Recommended Searches'}
  90. searchSuggestions={RECOMMENDED_SEARCHES}
  91. type="recommended"
  92. />
  93. {savedSearchSuggestions.length !== 0 && (
  94. <SearchSuggestionList
  95. title={savedSearchTitle}
  96. searchSuggestions={savedSearchSuggestions}
  97. type="saved_searches"
  98. />
  99. )}
  100. </AddViewWrapper>
  101. );
  102. }
  103. function AddViewBanner({hasSavedSearches}: {hasSavedSearches: boolean}) {
  104. const organization = useOrganization();
  105. const {isPromptDismissed, dismissPrompt} = usePrompt({
  106. feature: 'issue_views_add_view_banner',
  107. organization,
  108. });
  109. return !isPromptDismissed ? (
  110. <Banner>
  111. <BannerStar1 src={bannerStar} />
  112. <BannerStar2 src={bannerStar} />
  113. <BannerStar3 src={bannerStar} />
  114. <Title>
  115. {t('Welcome to the new Issue Views experience (Early Adopter only)')}
  116. <DismissButton
  117. analyticsEventKey="issue_views.add_view.banner_dismissed"
  118. analyticsEventName="'Issue Views: Add View Banner Dismissed"
  119. size="zero"
  120. borderless
  121. icon={<IconClose size="xs" />}
  122. aria-label={t('Dismiss')}
  123. onClick={() => dismissPrompt()}
  124. />
  125. </Title>
  126. <SubTitle>
  127. <div>
  128. {t(
  129. 'Issues just got a lot more personalized. Save your frequent issue searches for quick access.'
  130. )}
  131. </div>
  132. <div>{t('A few notes before you get started:')}</div>
  133. <AFewNotesList>
  134. <li>
  135. <BannerNoteBold>{t('Views are for your eyes only. ')}</BannerNoteBold>
  136. {t("No need to worry about messing up other team members' views")}
  137. </li>
  138. <li>
  139. <BannerNoteBold>{t('Drag your views to reorder. ')}</BannerNoteBold>{' '}
  140. {t('The leftmost view is your “default” experience')}
  141. </li>
  142. {hasSavedSearches && (
  143. <li>
  144. <BannerNoteBold>
  145. {t('Saved searches will be deprecated in the future. ')}
  146. </BannerNoteBold>{' '}
  147. {t(
  148. 'You can save them as views from the list below (only appears if you have saved searches)'
  149. )}
  150. </li>
  151. )}
  152. </AFewNotesList>
  153. </SubTitle>
  154. <FittedLinkButton
  155. size="sm"
  156. href="https://docs.sentry.io/product/issues/issue-views"
  157. external
  158. >
  159. {t('Read Docs')}
  160. </FittedLinkButton>
  161. </Banner>
  162. ) : null;
  163. }
  164. function SearchSuggestionList({
  165. title,
  166. searchSuggestions,
  167. type,
  168. }: SearchSuggestionListProps) {
  169. const {onNewViewsSaved} = useContext(NewTabContext);
  170. const organization = useOrganization();
  171. const analyticsKey =
  172. type === 'recommended'
  173. ? 'issue_views.add_view.recommended_view_saved'
  174. : 'issue_views.add_view.saved_search_saved';
  175. const analyticsEventName =
  176. type === 'recommended'
  177. ? 'Issue Views: Recommended View Saved'
  178. : 'Issue Views: Saved Search Saved';
  179. return (
  180. <Suggestions>
  181. <TitleWrapper>
  182. {title}
  183. {type === 'saved_searches' && (
  184. <StyledButton
  185. size="zero"
  186. onClick={e => {
  187. e.stopPropagation();
  188. openConfirmModal({
  189. message: (
  190. <ConfirmModalMessage>
  191. {tn(
  192. 'Save %s saved search as a view?',
  193. 'Save %s saved searches as views?',
  194. searchSuggestions.length
  195. )}
  196. </ConfirmModalMessage>
  197. ),
  198. onConfirm: () => {
  199. onNewViewsSaved?.(
  200. searchSuggestions.map(suggestion => ({
  201. ...suggestion,
  202. saveQueryToView: true,
  203. }))
  204. );
  205. },
  206. });
  207. }}
  208. analyticsEventKey="issue_views.add_view.all_saved_searches_saved"
  209. analyticsEventName="Issue Views: All Saved Searches Saved"
  210. borderless
  211. >
  212. {t('Save all')}
  213. </StyledButton>
  214. )}
  215. </TitleWrapper>
  216. <SuggestionList>
  217. {searchSuggestions.map((suggestion, index) => (
  218. <Suggestion
  219. key={index}
  220. onClick={() => {
  221. onNewViewsSaved?.([
  222. {
  223. ...suggestion,
  224. saveQueryToView: false,
  225. },
  226. ]);
  227. trackAnalytics(analyticsKey, {
  228. organization,
  229. persisted: false,
  230. label: suggestion.label,
  231. query: suggestion.query,
  232. });
  233. }}
  234. >
  235. {/*
  236. Saved search labels have an average length of approximately 16 characters
  237. This container fits 16 'a's comfortably, and 20 'a's before overflowing.
  238. */}
  239. <OverflowEllipsisTextContainer>
  240. {suggestion.label}
  241. </OverflowEllipsisTextContainer>
  242. <ScopeTagContainer>
  243. {suggestion.scope === 'personal' ? (
  244. <Scope>{t('Private')}</Scope>
  245. ) : suggestion.scope === 'organization' ? (
  246. <Scope>{t('Public')}</Scope>
  247. ) : null}
  248. </ScopeTagContainer>
  249. <QueryWrapper>
  250. <FormattedQuery query={suggestion.query} />
  251. <ActionsWrapper className="data-actions-wrapper">
  252. <StyledButton
  253. size="zero"
  254. onClick={e => {
  255. e.stopPropagation();
  256. onNewViewsSaved?.([
  257. {
  258. ...suggestion,
  259. saveQueryToView: true,
  260. },
  261. ]);
  262. }}
  263. analyticsEventKey={analyticsKey}
  264. analyticsEventName={analyticsEventName}
  265. analyticsParams={{
  266. persisted: true,
  267. label: suggestion.label,
  268. query: suggestion.query,
  269. }}
  270. borderless
  271. >
  272. {t('Save as new view')}
  273. </StyledButton>
  274. </ActionsWrapper>
  275. </QueryWrapper>
  276. <StyledInteractionStateLayer />
  277. </Suggestion>
  278. ))}
  279. </SuggestionList>
  280. </Suggestions>
  281. );
  282. }
  283. export default AddViewPage;
  284. const Scope = styled('div')`
  285. color: ${p => p.theme.subText};
  286. `;
  287. const ScopeTagContainer = styled('div')`
  288. display: flex;
  289. `;
  290. const Suggestions = styled('section')`
  291. width: 100%;
  292. `;
  293. const SavedSearchesTitle = styled('div')`
  294. align-items: center;
  295. display: flex;
  296. gap: ${space(1)};
  297. `;
  298. const StyledInteractionStateLayer = styled(InteractionStateLayer)`
  299. border-radius: 4px;
  300. width: 100.8%;
  301. `;
  302. const TitleWrapper = styled('div')`
  303. display: flex;
  304. justify-content: space-between;
  305. color: ${p => p.theme.subText};
  306. font-weight: 550;
  307. font-size: ${p => p.theme.fontSizeMedium};
  308. margin-bottom: ${space(0.75)};
  309. `;
  310. const ActionsWrapper = styled('div')`
  311. display: flex;
  312. align-items: center;
  313. gap: ${space(0.75)};
  314. visibility: hidden;
  315. `;
  316. const StyledButton = styled(Button)`
  317. font-size: ${p => p.theme.fontSizeMedium};
  318. color: ${p => p.theme.subText};
  319. font-weight: ${p => p.theme.fontWeightNormal};
  320. padding: ${space(0.5)};
  321. border: none;
  322. &:hover {
  323. color: ${p => p.theme.subText};
  324. }
  325. `;
  326. const QueryWrapper = styled('div')`
  327. display: flex;
  328. justify-content: space-between;
  329. align-items: center;
  330. width: 100%;
  331. overflow: hidden;
  332. `;
  333. const SuggestionList = styled('ul')`
  334. display: flex;
  335. flex-direction: column;
  336. padding: 0;
  337. li:has(+ li:hover) {
  338. border-bottom: 1px solid transparent;
  339. }
  340. li:hover {
  341. border-bottom: 1px solid transparent;
  342. }
  343. li:last-child {
  344. border-bottom: 1px solid transparent;
  345. }
  346. `;
  347. const Suggestion = styled('li')`
  348. position: relative;
  349. display: inline-grid;
  350. grid-template-columns: 170px 60px auto;
  351. align-items: center;
  352. padding: ${space(1)} 0;
  353. border-bottom: 1px solid ${p => p.theme.innerBorder};
  354. gap: ${space(1)};
  355. &:hover {
  356. cursor: pointer;
  357. }
  358. &:hover .data-actions-wrapper {
  359. visibility: visible;
  360. }
  361. `;
  362. const Banner = styled('div')`
  363. position: relative;
  364. display: flex;
  365. flex-direction: column;
  366. margin-bottom: 0;
  367. padding: 12px;
  368. gap: ${space(0.5)};
  369. border: 1px solid ${p => p.theme.border};
  370. border-radius: ${p => p.theme.panelBorderRadius};
  371. background: linear-gradient(
  372. 269.35deg,
  373. ${p => p.theme.backgroundTertiary} 0.32%,
  374. rgba(245, 243, 247, 0) 99.69%
  375. );
  376. `;
  377. const Title = styled('div')`
  378. font-size: ${p => p.theme.fontSizeMedium};
  379. font-weight: ${p => p.theme.fontWeightBold};
  380. `;
  381. const BannerNoteBold = styled('div')`
  382. display: inline;
  383. font-weight: ${p => p.theme.fontWeightBold};
  384. `;
  385. const SubTitle = styled('div')`
  386. display: flex;
  387. flex-direction: column;
  388. font-weight: ${p => p.theme.fontWeightNormal};
  389. font-size: ${p => p.theme.fontSizeMedium};
  390. gap: ${space(0.5)};
  391. `;
  392. const AddViewWrapper = styled('div')`
  393. display: flex;
  394. flex-direction: column;
  395. gap: ${space(2)};
  396. @media (max-width: ${p => p.theme.breakpoints.small}) {
  397. flex-direction: column;
  398. align-items: center;
  399. }
  400. `;
  401. const BannerStar1 = styled('img')`
  402. position: absolute;
  403. bottom: 10px;
  404. right: 150px;
  405. transform: scale(0.9);
  406. @media (max-width: ${p => p.theme.breakpoints.large}) {
  407. display: none;
  408. }
  409. `;
  410. const BannerStar2 = styled('img')`
  411. position: absolute;
  412. top: 10px;
  413. right: 120px;
  414. transform: rotate(-30deg) scale(0.7);
  415. @media (max-width: ${p => p.theme.breakpoints.large}) {
  416. display: none;
  417. }
  418. `;
  419. const BannerStar3 = styled('img')`
  420. position: absolute;
  421. bottom: 30px;
  422. right: 80px;
  423. transform: rotate(80deg) scale(0.6);
  424. @media (max-width: ${p => p.theme.breakpoints.large}) {
  425. display: none;
  426. }
  427. `;
  428. const ConfirmModalMessage = styled('div')`
  429. display: flex;
  430. justify-content: center;
  431. font-weight: ${p => p.theme.fontWeightBold};
  432. `;
  433. const Container = styled('div')`
  434. display: inline-flex;
  435. flex-direction: column;
  436. align-items: flex-start;
  437. text-align: left;
  438. gap: ${space(1)};
  439. `;
  440. const AFewNotesList = styled('ul')`
  441. margin-bottom: ${space(0.5)};
  442. `;
  443. const FittedLinkButton = styled(LinkButton)`
  444. width: fit-content;
  445. `;
  446. const DismissButton = styled(Button)`
  447. position: absolute;
  448. top: ${space(1)};
  449. right: ${space(1)};
  450. color: ${p => p.theme.subText};
  451. `;