diff --git a/static/app/components/devtoolbar/components/app.tsx b/static/app/components/devtoolbar/components/app.tsx index 47c8bb7ad8d86e..2696a86a23a0b4 100644 --- a/static/app/components/devtoolbar/components/app.tsx +++ b/static/app/components/devtoolbar/components/app.tsx @@ -5,6 +5,7 @@ import LoadingTriangle from 'sentry/components/loadingTriangle'; import {useSessionStorage} from 'sentry/utils/useSessionStorage'; import usePlacementCss from '../hooks/usePlacementCss'; +import useVisibility from '../hooks/useVisibility'; import {fixedContainerBaseCss} from '../styles/fixedContainer'; import {avatarCss, globalCss, loadingIndicatorCss} from '../styles/global'; import {resetFlexColumnCss} from '../styles/reset'; @@ -15,8 +16,12 @@ import PanelRouter from './panelRouter'; export default function App() { const placement = usePlacementCss(); - const [isHidden, setIsHidden] = useSessionStorage('hide_employee_devtoolbar', false); - if (isHidden) { + const [visibility] = useVisibility(); + const [isDisabled, setIsDisabled] = useSessionStorage( + 'hide_employee_devtoolbar', + false + ); + if (isDisabled) { return null; } @@ -25,10 +30,10 @@ export default function App() { -
- {isHidden ? null : ( +
+ {isDisabled ? null : ( - + }> diff --git a/static/app/components/devtoolbar/components/feedback/feedbackPanel.tsx b/static/app/components/devtoolbar/components/feedback/feedbackPanel.tsx index 08aa45f01383a3..ba33b85d0b6ca9 100644 --- a/static/app/components/devtoolbar/components/feedback/feedbackPanel.tsx +++ b/static/app/components/devtoolbar/components/feedback/feedbackPanel.tsx @@ -12,6 +12,7 @@ import useReplayCount from 'sentry/utils/replayCount/useReplayCount'; import useConfiguration from '../../hooks/useConfiguration'; import useCurrentTransactionName from '../../hooks/useCurrentTransactionName'; import {useSDKFeedbackButton} from '../../hooks/useSDKFeedbackButton'; +import useVisibility from '../../hooks/useVisibility'; import { badgeWithLabelCss, gridFlexEndCss, @@ -34,7 +35,17 @@ import SentryAppLink from '../sentryAppLink'; import useInfiniteFeedbackList from './useInfiniteFeedbackList'; export default function FeedbackPanel() { - const buttonRef = useSDKFeedbackButton(); + const [, setVisible] = useVisibility(); + + const buttonRef = useSDKFeedbackButton( + useMemo( + () => ({ + onFormOpen: () => setVisible('hidden'), + onFormClose: () => setVisible('visible'), + }), + [setVisible] + ) + ); const transactionName = useCurrentTransactionName(); const queryResult = useInfiniteFeedbackList({ query: `url:*${transactionName}`, diff --git a/static/app/components/devtoolbar/components/navigation.tsx b/static/app/components/devtoolbar/components/navigation.tsx index e05c418e745894..5fd892e86238a7 100644 --- a/static/app/components/devtoolbar/components/navigation.tsx +++ b/static/app/components/devtoolbar/components/navigation.tsx @@ -9,7 +9,11 @@ import useToolbarRoute from '../hooks/useToolbarRoute'; import {navigationButtonCss, navigationCss} from '../styles/navigation'; import {resetButtonCss, resetDialogCss} from '../styles/reset'; -export default function Navigation({setIsHidden}: {setIsHidden: (val: boolean) => void}) { +export default function Navigation({ + setIsDisabled, +}: { + setIsDisabled: (val: boolean) => void; +}) { const {trackAnalytics} = useConfiguration(); const placement = usePlacementCss(); @@ -26,7 +30,7 @@ export default function Navigation({setIsHidden}: {setIsHidden: (val: boolean) = } /> { - setIsHidden(true); + setIsDisabled(true); trackAnalytics?.({ eventKey: `devtoolbar.nav.hide.click`, eventName: `devtoolbar: Hide devtoolbar`, diff --git a/static/app/components/devtoolbar/components/providers.tsx b/static/app/components/devtoolbar/components/providers.tsx index 74556468e9cd42..9b24802bd55bc0 100644 --- a/static/app/components/devtoolbar/components/providers.tsx +++ b/static/app/components/devtoolbar/components/providers.tsx @@ -7,6 +7,7 @@ import {lightTheme} from 'sentry/utils/theme'; import {ConfigurationContextProvider} from '../hooks/useConfiguration'; import {ToolbarRouterContextProvider} from '../hooks/useToolbarRoute'; +import {VisibilityContextProvider} from '../hooks/useVisibility'; import type {Configuration} from '../types'; interface Props { @@ -35,7 +36,9 @@ export default function Providers({children, config, container}: Props) { - {children} + + {children} + diff --git a/static/app/components/devtoolbar/hooks/useSDKFeedbackButton.tsx b/static/app/components/devtoolbar/hooks/useSDKFeedbackButton.tsx index 1024f5826be957..314e840e9cc724 100644 --- a/static/app/components/devtoolbar/hooks/useSDKFeedbackButton.tsx +++ b/static/app/components/devtoolbar/hooks/useSDKFeedbackButton.tsx @@ -2,17 +2,23 @@ import {useEffect, useRef} from 'react'; import useConfiguration from './useConfiguration'; -export function useSDKFeedbackButton() { +export function useSDKFeedbackButton({ + onFormClose, + onFormOpen, +}: { + onFormClose?: () => void; + onFormOpen?: () => void; +}) { const buttonRef = useRef(null); const {SentrySDK} = useConfiguration(); const feedback = SentrySDK && 'getFeedback' in SentrySDK && SentrySDK.getFeedback(); useEffect(() => { if (feedback && buttonRef.current) { - return feedback.attachTo(buttonRef.current, {}); + return feedback.attachTo(buttonRef.current, {onFormOpen, onFormClose}); } return () => {}; - }, [feedback]); + }, [feedback, onFormOpen, onFormClose]); return feedback ? buttonRef : undefined; } diff --git a/static/app/components/devtoolbar/hooks/useVisibility.tsx b/static/app/components/devtoolbar/hooks/useVisibility.tsx new file mode 100644 index 00000000000000..5f9a31f809beff --- /dev/null +++ b/static/app/components/devtoolbar/hooks/useVisibility.tsx @@ -0,0 +1,20 @@ +import type {CSSProperties, Dispatch, ReactNode, SetStateAction} from 'react'; +import {createContext, useContext, useState} from 'react'; + +type State = CSSProperties['visibility']; + +const VisibilityContext = createContext<[State, Dispatch>]>([ + 'visible', + () => {}, +]); + +export function VisibilityContextProvider({children}: {children: ReactNode}) { + const state = useState('visible'); + return ( + {children} + ); +} + +export default function useVisibility() { + return useContext(VisibilityContext); +}