newIssueExperienceButton.tsx 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import styled from '@emotion/styled';
  2. import {Button} from 'sentry/components/button';
  3. import ButtonBar from 'sentry/components/buttonBar';
  4. import {IconLab} from 'sentry/icons';
  5. import {t} from 'sentry/locale';
  6. import {trackAnalytics} from 'sentry/utils/analytics';
  7. import {useFeedbackForm} from 'sentry/utils/useFeedbackForm';
  8. import {useLocation} from 'sentry/utils/useLocation';
  9. import useMutateUserOptions from 'sentry/utils/useMutateUserOptions';
  10. import {useNavigate} from 'sentry/utils/useNavigate';
  11. import useOrganization from 'sentry/utils/useOrganization';
  12. import {useHasStreamlinedUI} from 'sentry/views/issueDetails/utils';
  13. export function NewIssueExperienceButton() {
  14. const organization = useOrganization();
  15. const location = useLocation();
  16. const navigate = useNavigate();
  17. const hasStreamlinedUIFlag = organization.features.includes('issue-details-streamline');
  18. const hasStreamlinedUI = useHasStreamlinedUI();
  19. const openForm = useFeedbackForm();
  20. const {mutate} = useMutateUserOptions();
  21. if (!hasStreamlinedUIFlag) {
  22. return null;
  23. }
  24. const feedbackButton = openForm ? (
  25. <Button
  26. size="sm"
  27. aria-label={t('Give feedback on new UI')}
  28. onClick={() =>
  29. openForm({
  30. messagePlaceholder: t('How can we make this new UI work for you?'),
  31. tags: {
  32. ['feedback.source']: 'issue_details_streamline_ui',
  33. ['feedback.owner']: 'issues',
  34. },
  35. })
  36. }
  37. >
  38. {t('Give Feedback')}
  39. </Button>
  40. ) : null;
  41. const label = hasStreamlinedUI
  42. ? t('Switch to the old issue experience')
  43. : t('Switch to the new issue experience');
  44. return (
  45. <ButtonBar merged>
  46. <StyledButton
  47. enabled={hasStreamlinedUI}
  48. size="sm"
  49. icon={<IconLab isSolid={hasStreamlinedUI} />}
  50. title={label}
  51. aria-label={label}
  52. onClick={() => {
  53. mutate({['prefersIssueDetailsStreamlinedUI']: !hasStreamlinedUI});
  54. trackAnalytics('issue_details.streamline_ui_toggle', {
  55. isEnabled: !hasStreamlinedUI,
  56. organization: organization,
  57. });
  58. navigate({
  59. ...location,
  60. query: {...location.query, streamline: hasStreamlinedUI ? '0' : '1'},
  61. });
  62. }}
  63. />
  64. {hasStreamlinedUI && feedbackButton}
  65. </ButtonBar>
  66. );
  67. }
  68. const StyledButton = styled(Button)<{enabled: boolean}>`
  69. color: ${p => (p.enabled ? p.theme.button.primary.background : 'inherit')};
  70. :hover {
  71. color: ${p => (p.enabled ? p.theme.button.primary.background : 'inherit')};
  72. }
  73. `;