Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"dependencies": {
"@floating-ui/react": "^0.26.24",
"@sentry/types": "^8.30.0",
"@spotlightjs/overlay": "^2.9.0",
"@tanstack/react-query": "^5.56.2",
"@tanstack/react-virtual": "^3.10.8",
"cva": "npm:class-variance-authority@^0.7.0",
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/lib/components/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import IconSettings from 'toolbar/components/icon/IconSettings';
import {useApiProxyInstance} from 'toolbar/context/ApiProxyContext';
import ConfigContext from 'toolbar/context/ConfigContext';
import useNavigationExpansion from 'toolbar/hooks/useNavigationExpansion';
import useSpotlightOverlay from 'toolbar/hooks/useSpotlightOverlay';
import {DebugTarget} from 'toolbar/types/config';

const navClassName = cx(['flex', 'flex-col', 'gap-1', 'p-1', 'items-center']);
Expand Down Expand Up @@ -50,6 +51,8 @@ export default function Navigation() {
const navigate = useNavigate();
const apiProxy = useApiProxyInstance();

const {showSpotlight, hideSpotlight} = useSpotlightOverlay();

const toPathOrHome = (to: To) => ({
to,
onClick: (e: MouseEvent) => {
Expand Down Expand Up @@ -106,6 +109,9 @@ export default function Navigation() {
<NavLink {...toPathOrHome('/featureFlags')} title="Feature Flags" className={navItemClassName}>
<IconFlag size="sm" />
</NavLink>
<button onClick={showSpotlight()} className={navItemClassName}>
<IconFlag size="sm" />
</button>
</Fragment>
) : null}
</motion.div>
Expand Down
54 changes: 54 additions & 0 deletions src/lib/hooks/useSpotlightOverlay.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import * as SpotlightJs from '@spotlightjs/overlay';
import type {WindowWithSpotlight} from '@spotlightjs/overlay';
import {useCallback, useMemo} from 'react';

export default function useSpotlightOverlay() {
const showSpotlight = useCallback(() => {
if (isSpotlightInjected()) {
SpotlightJs.openSpotlight();
} else {
SpotlightJs.init({
fullPage: true,
injectImmediately: false,
showTriggerButton: false,
integrations: [
SpotlightJs.sentry({
injectIntoSDK: false,
// @ts-expect-error Copied from https://github.com/getsentry/sentry-sdk-browser-extension/blob/main/src/pages/spotlight.tsx
sidecarUrl: document.location.origin,
}),
],
showClearEventsButton: false,
sidecarUrl: document.location.origin,
// @ts-expect-error Copied from https://github.com/getsentry/sentry-sdk-browser-extension/blob/main/src/pages/spotlight.tsx
skipSidecar: true,
});
}
}, []);

const hideSpotlight = useCallback(() => {
SpotlightJs.closeSpotlight();
}, []);

// TODO: Spotlight should have an API for cleaning up
// useEffect(() => {
// if (isSpotlightInjected()) {}
// }, []);

return useMemo(
() => ({
showSpotlight,
hideSpotlight,
}),
[showSpotlight, hideSpotlight]
);
}

// TODO: Spotlight should export this function itself
function isSpotlightInjected() {
const windowWithSpotlight = window as WindowWithSpotlight;
if (windowWithSpotlight.__spotlight && window.document.getElementById('sentry-spotlight-root')) {
return true;
}
return false;
}