newIssueExperienceButton.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import {useCallback} from 'react';
  2. import styled from '@emotion/styled';
  3. import {Button} from 'sentry/components/button';
  4. import DropdownButton from 'sentry/components/dropdownButton';
  5. import {DropdownMenu} from 'sentry/components/dropdownMenu';
  6. import {IconLab} from 'sentry/icons';
  7. import {t} from 'sentry/locale';
  8. import {trackAnalytics} from 'sentry/utils/analytics';
  9. import {useFeedbackForm} from 'sentry/utils/useFeedbackForm';
  10. import useMutateUserOptions from 'sentry/utils/useMutateUserOptions';
  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 hasStreamlinedUIFlag = organization.features.includes('issue-details-streamline');
  16. const hasStreamlinedUI = useHasStreamlinedUI();
  17. const openForm = useFeedbackForm();
  18. const {mutate} = useMutateUserOptions();
  19. const handleToggle = useCallback(() => {
  20. mutate({['prefersIssueDetailsStreamlinedUI']: !hasStreamlinedUI});
  21. trackAnalytics('issue_details.streamline_ui_toggle', {
  22. isEnabled: !hasStreamlinedUI,
  23. organization: organization,
  24. });
  25. }, [mutate, organization, hasStreamlinedUI]);
  26. if (!hasStreamlinedUIFlag) {
  27. return null;
  28. }
  29. if (!openForm || !hasStreamlinedUI) {
  30. const label = hasStreamlinedUI
  31. ? t('Switch to the old issue experience')
  32. : t('Switch to the new issue experience');
  33. return (
  34. <StyledButton
  35. enabled={hasStreamlinedUI}
  36. size={hasStreamlinedUI ? 'xs' : 'sm'}
  37. icon={<IconLab isSolid={hasStreamlinedUI} />}
  38. title={label}
  39. aria-label={label}
  40. onClick={handleToggle}
  41. />
  42. );
  43. }
  44. return (
  45. <DropdownMenu
  46. trigger={triggerProps => (
  47. <StyledDropdownButton
  48. {...triggerProps}
  49. enabled={hasStreamlinedUI}
  50. size={hasStreamlinedUI ? 'xs' : 'sm'}
  51. aria-label={t('Switch issue experience')}
  52. >
  53. {/* Passing icon as child to avoid extra icon margin */}
  54. <IconLab isSolid={hasStreamlinedUI} />
  55. </StyledDropdownButton>
  56. )}
  57. items={[
  58. {
  59. key: 'switch-to-old-ui',
  60. label: t('Switch to the old issue experience'),
  61. onAction: handleToggle,
  62. },
  63. {
  64. key: 'give-feedback',
  65. label: t('Give feedback on new UI'),
  66. hidden: !openForm,
  67. onAction: () => {
  68. openForm({
  69. messagePlaceholder: t(
  70. 'Excluding bribes, what can we do to have you willing to use the new UI?'
  71. ),
  72. });
  73. },
  74. },
  75. ]}
  76. position="bottom-end"
  77. />
  78. );
  79. }
  80. const StyledDropdownButton = styled(DropdownButton)<{enabled: boolean}>`
  81. color: ${p => (p.enabled ? p.theme.button.primary.background : 'inherit')};
  82. :hover {
  83. color: ${p => (p.enabled ? p.theme.button.primary.background : 'inherit')};
  84. }
  85. `;
  86. const StyledButton = styled(Button)<{enabled: boolean}>`
  87. color: ${p => (p.enabled ? p.theme.button.primary.background : 'inherit')};
  88. :hover {
  89. color: ${p => (p.enabled ? p.theme.button.primary.background : 'inherit')};
  90. }
  91. `;