Skip to content
Merged
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
3 changes: 3 additions & 0 deletions static/app/components/events/autofix/v3/nextStep.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,17 @@ describe('SeerDrawerNextStep', () => {
jest
.mocked(useSeerExplorerContext)
.mockReturnValue({
autoOpenSeerExplorer: jest.fn(),
closeSeerExplorer: jest.fn(),
hideSidebar: jest.fn(),
isOpen: false,
openChatPrompt,
openSeerExplorer: jest.fn(),
sessionState: 'inactive',
sidebarContainerRef: {current: null},
setSidebarPosition: jest.fn(),
sidebarAppendInitialQuery: false,
sidebarAutoFocus: true,
sidebarInitialQuery: undefined,
sidebarKey: 0,
sidebarPosition: 'auto',
Expand Down
2 changes: 2 additions & 0 deletions static/app/utils/analytics/seerAnalyticsEvents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ export type SeerAnalyticsEventsParameters = {
run_id: SeerExplorerRunId | undefined;
type: 'positive' | 'negative';
};
'seer.explorer.global_panel.auto_opened': Record<string, unknown>;
'seer.explorer.global_panel.opened': {referrer: string; isDrawer?: boolean};
'seer.explorer.global_panel.tool_link_navigation': {
referrer: string;
Expand Down Expand Up @@ -288,6 +289,7 @@ export const seerAnalyticsEventsMap: Record<SeerAnalyticsEventKey, string | null
'seer.explorer.block_copied': 'Seer Explorer: Block Content Copied',
'seer.explorer.connect_scm_modal.opened': 'Seer Explorer: Connect SCM Modal Opened',
'seer.explorer.feedback_submitted': 'Seer Explorer: Feedback Submitted',
'seer.explorer.global_panel.auto_opened': 'Seer Explorer: Global Panel Auto Opened',
'seer.explorer.global_panel.opened': 'Seer Explorer: Global Panel Opened',
'seer.explorer.global_panel.tool_link_navigation': 'Seer Explorer: Tool Link Visited',
'seer.explorer.message_sent': 'Seer Explorer: Message Sent',
Expand Down
2 changes: 2 additions & 0 deletions static/app/views/automations/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
useLLMContext,
} from 'sentry/views/seerExplorer/contexts/llmContext';
import {registerLLMContext} from 'sentry/views/seerExplorer/contexts/registerLLMContext';
import {useAutoOpenSeerExplorer} from 'sentry/views/seerExplorer/hooks/useAutoOpenSeerExplorer';
import {
toLLMContextProjectFields,
useSelectedProjectsForLLMContext,
Expand Down Expand Up @@ -73,6 +74,7 @@ function formatAutomationRows(automations: Automation[]): string {

function AutomationsListInner() {
const getPaginationCaption = useGetPaginationCaption();
useAutoOpenSeerExplorer();
const [, setCursor] = useQueryState('cursor', {history: 'push'});

const {queryOptions, enabled, cursor, sort, query} = useAutomationListQueryOptions();
Expand Down
2 changes: 2 additions & 0 deletions static/app/views/dashboards/manage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
} from 'sentry/views/dashboards/utils/prebuiltConfigs';
import {TopBar} from 'sentry/views/navigation/topBar';
import {RouteError} from 'sentry/views/routeError';
import {useAutoOpenSeerExplorer} from 'sentry/views/seerExplorer/hooks/useAutoOpenSeerExplorer';

import {getIsOnlyPrebuilt} from './utils/getIsOnlyPrebuilt';
import {DashboardTable} from './dashboardTable';
Expand Down Expand Up @@ -75,6 +76,7 @@ function getSortOptions({isOnlyPrebuilt}: {isOnlyPrebuilt: boolean}) {

function ManageDashboards() {
const organization = useOrganization();
useAutoOpenSeerExplorer();
const queryClient = useQueryClient();
const navigate = useNavigate();
const location = useLocation();
Expand Down
2 changes: 2 additions & 0 deletions static/app/views/detectors/list/allMonitors.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {SentryDocumentTitle} from 'sentry/components/sentryDocumentTitle';
import {WorkflowEngineListLayout} from 'sentry/components/workflowEngine/layout/list';
import {t} from 'sentry/locale';
import {useAutoOpenSeerExplorer} from 'sentry/views/seerExplorer/hooks/useAutoOpenSeerExplorer';

import {DetectorListActions} from './common/detectorListActions';
import {DetectorListContent} from './common/detectorListContent';
Expand All @@ -15,6 +16,7 @@ const DOCS_URL = 'https://docs.sentry.io/product/new-monitors-and-alerts/monitor

export default function AllMonitors() {
const detectorListQuery = useDetectorListQuery();
useAutoOpenSeerExplorer();

return (
<SentryDocumentTitle title={TITLE}>
Expand Down
3 changes: 3 additions & 0 deletions static/app/views/navigation/topBar.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,17 @@ describe('TopBar', () => {

describe('feedback slot', () => {
const seerExplorerOpen: SeerExplorerContextValue = {
autoOpenSeerExplorer: jest.fn(),
closeSeerExplorer: jest.fn(),
hideSidebar: jest.fn(),
isOpen: true,
openChatPrompt: jest.fn(),
openSeerExplorer: jest.fn(),
sessionState: 'inactive',
sidebarContainerRef: {current: null},
setSidebarPosition: jest.fn(),
sidebarAppendInitialQuery: false,
sidebarAutoFocus: true,
sidebarInitialQuery: undefined,
sidebarKey: 0,
sidebarPosition: 'auto',
Expand Down
2 changes: 2 additions & 0 deletions static/app/views/performance/traceDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {isLogsEnabled} from 'sentry/views/explore/logs/isLogsEnabled';
import {canUseMetricsUI} from 'sentry/views/explore/metrics/metricsFlags';
import {useLLMContext} from 'sentry/views/seerExplorer/contexts/llmContext';
import {registerLLMContext} from 'sentry/views/seerExplorer/contexts/registerLLMContext';
import {useAutoOpenSeerExplorer} from 'sentry/views/seerExplorer/hooks/useAutoOpenSeerExplorer';

import {useTrace} from './traceApi/useTrace';
import {useTraceMeta} from './traceApi/useTraceMeta';
Expand Down Expand Up @@ -63,6 +64,7 @@ const TRACE_VIEW_PREFERENCES_KEY = 'trace-waterfall-preferences';

export default function TraceView() {
const params = useParams<{traceSlug?: string}>();
useAutoOpenSeerExplorer();
const traceSlug = useMemo(() => decodeTraceSlug(params.traceSlug), [params.traceSlug]);

const preferences = useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ export function SeerExplorerContent({
getPageReferrer,
initialQuery,
appendInitialQuery,
autoFocusComposer = true,
onClose,
onPopOut,
renderHeader,
sidebarPosition,
onSidebarPositionChange,
Expand All @@ -146,7 +148,14 @@ export function SeerExplorerContent({
onClose: () => void;
/** Submit `initialQuery` into the open run rather than only an empty one. */
appendInitialQuery?: boolean;
/** Focus the composer on mount. Off when Seer opened without a user action. */
autoFocusComposer?: boolean;
initialQuery?: string;
/**
* Hides the current surface once its content moves to the popped-out window.
* Defaults to `onClose`.
*/
onPopOut?: () => void;
onSidebarPositionChange?: (position: SeerExplorerSidebarPosition) => void;
/** Surface chrome for the header. Defaults to the sidebar shell. */
renderHeader?: RenderHeader;
Expand Down Expand Up @@ -191,7 +200,7 @@ export function SeerExplorerContent({
// happened to be left last time.
preferInitialWindowPlacement: true,
})
.then(() => onClose())
.then(() => (onPopOut ?? onClose)())
.catch(() => {
// Failed to open the PiP window — keep the current surface open.
});
Expand Down Expand Up @@ -734,13 +743,17 @@ export function SeerExplorerContent({

// - Scroll effects ---------------------------------------------------------

// Only the value at mount matters: it describes how this surface was opened.
const autoFocusOnMountRef = useRef(autoFocusComposer);
useEffect(() => {
// Scroll to bottom and focus input when drawer opens
setTimeout(() => {
if (scrollContainerRef.current) {
scrollContainerRef.current.scrollTop = scrollContainerRef.current.scrollHeight;
}
composerRef.current?.focus();
if (autoFocusOnMountRef.current) {
composerRef.current?.focus();
}
}, 100);
}, []);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export function SeerExplorerPanel() {
const {getPageReferrer} = usePageReferrer();
const {
closeSeerExplorer,
hideSidebar,
sidebarAutoFocus,
sidebarPosition,
setSidebarPosition,
sidebarInitialQuery,
Expand All @@ -30,7 +32,9 @@ export function SeerExplorerPanel() {
getPageReferrer={getPageReferrer}
initialQuery={sidebarInitialQuery}
appendInitialQuery={sidebarAppendInitialQuery}
autoFocusComposer={sidebarAutoFocus}
onClose={closeSeerExplorer}
onPopOut={hideSidebar}
sidebarPosition={sidebarPosition}
onSidebarPositionChange={setSidebarPosition}
/>
Expand Down
155 changes: 155 additions & 0 deletions static/app/views/seerExplorer/hooks/useAutoOpenSeerExplorer.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import {Fragment} from 'react';
import {OrganizationFixture} from 'sentry-fixture/organization';

import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';

import {PictureInPictureProvider} from '@sentry/scraps/pictureInPicture';

import {SeerExplorerChatStateProvider} from 'sentry/views/seerExplorer/seerExplorerChatStateContext';
import {SeerExplorerContextProvider} from 'sentry/views/seerExplorer/seerExplorerContextProvider';
import {SeerExplorerSessionsProvider} from 'sentry/views/seerExplorer/seerExplorerSessionContext';
import {useSeerExplorerContext} from 'sentry/views/seerExplorer/useSeerExplorerContext';

import {useAutoOpenSeerExplorer} from './useAutoOpenSeerExplorer';

function mockViewportWidth(width: number) {
window.matchMedia = jest.fn().mockImplementation((query: string) => {
const minWidth = /min-width:\s*(\d+)px/.exec(query)?.[1];
return {
matches: minWidth === undefined ? false : width >= Number(minWidth),
media: query,
onchange: null,
addListener: jest.fn(),
removeListener: jest.fn(),
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
};
});
}

function SeerProviders({children}: {children?: React.ReactNode}) {
return (
<SeerExplorerSessionsProvider>
<SeerExplorerChatStateProvider>
<PictureInPictureProvider>
<SeerExplorerContextProvider>{children}</SeerExplorerContextProvider>
</PictureInPictureProvider>
</SeerExplorerChatStateProvider>
</SeerExplorerSessionsProvider>
);
}

function AutoOpenPage() {
useAutoOpenSeerExplorer();
return null;
}

function SeerState() {
const {isOpen, hideSidebar, toggleSeerExplorer} = useSeerExplorerContext();
return (
<Fragment>
<button type="button" onClick={toggleSeerExplorer}>
{isOpen ? 'seer open' : 'seer closed'}
</button>
<button type="button" onClick={hideSidebar}>
pop out
</button>
</Fragment>
);
}

function TestPage({showPage = true}: {showPage?: boolean}) {
return (
<Fragment>
{showPage ? <AutoOpenPage /> : null}
<SeerState />
</Fragment>
);
}

describe('useAutoOpenSeerExplorer', () => {
const organization = OrganizationFixture({
openMembership: true,
hideAiFeatures: false,
features: ['seer-explorer', 'seer-explorer-auto-open'],
});

beforeEach(() => {
sessionStorage.clear();
localStorage.clear();
mockViewportWidth(1440);
MockApiClient.addMockResponse({
url: `/organizations/${organization.slug}/seer/runs/`,
body: [],
});
});

it('opens the sidebar on a wide viewport', async () => {
render(<TestPage />, {organization, additionalWrapper: SeerProviders});

expect(await screen.findByRole('button', {name: 'seer open'})).toBeInTheDocument();
});

it('does not open on a narrow viewport', async () => {
mockViewportWidth(390);
render(<TestPage />, {organization, additionalWrapper: SeerProviders});

expect(await screen.findByRole('button', {name: 'seer closed'})).toBeInTheDocument();
});

it('does not open without the feature flag', async () => {
render(<TestPage />, {
organization: OrganizationFixture({
openMembership: true,
hideAiFeatures: false,
features: ['seer-explorer'],
}),
additionalWrapper: SeerProviders,
});

expect(await screen.findByRole('button', {name: 'seer closed'})).toBeInTheDocument();
});

it('stays closed on later pages after the user closes it', async () => {
const {rerender} = render(<TestPage />, {
organization,
additionalWrapper: SeerProviders,
});

await userEvent.click(await screen.findByRole('button', {name: 'seer open'}));
expect(screen.getByRole('button', {name: 'seer closed'})).toBeInTheDocument();

// Leave the page and come back: the dismissal outlives the page.
rerender(<TestPage showPage={false} />);
rerender(<TestPage />);

expect(screen.getByRole('button', {name: 'seer closed'})).toBeInTheDocument();
});

it('does not count popping the panel out as a dismissal', async () => {
const {rerender} = render(<TestPage />, {
organization,
additionalWrapper: SeerProviders,
});

expect(await screen.findByRole('button', {name: 'seer open'})).toBeInTheDocument();
await userEvent.click(screen.getByRole('button', {name: 'pop out'}));
expect(screen.getByRole('button', {name: 'seer closed'})).toBeInTheDocument();

rerender(<TestPage showPage={false} />);
rerender(<TestPage />);

expect(await screen.findByRole('button', {name: 'seer open'})).toBeInTheDocument();
});

it('clears the dismissal when the user opens the panel again', async () => {
localStorage.setItem('seer-explorer-sidebar-auto-open-dismissed', 'true');
render(<TestPage />, {organization, additionalWrapper: SeerProviders});

await userEvent.click(await screen.findByRole('button', {name: 'seer closed'}));

expect(screen.getByRole('button', {name: 'seer open'})).toBeInTheDocument();
expect(localStorage.getItem('seer-explorer-sidebar-auto-open-dismissed')).toBeNull();
});
});
Loading
Loading