diff --git a/public/app/features/logs/components/log-context/LogRowContextModal.test.tsx b/public/app/features/logs/components/log-context/LogRowContextModal.test.tsx
index cb5be11c0c6..81a9ed08d0c 100644
--- a/public/app/features/logs/components/log-context/LogRowContextModal.test.tsx
+++ b/public/app/features/logs/components/log-context/LogRowContextModal.test.tsx
@@ -4,6 +4,8 @@ import React from 'react';
import { act } from 'react-dom/test-utils';
import { render } from 'test/redux-rtl';
+import { SplitOpenOptions } from '@grafana/data';
+
import { createLogRow } from '../__mocks__/logRow';
import { LogRowContextModal } from './LogRowContextModal';
@@ -17,10 +19,13 @@ jest.mock('app/types', () => ({
useDispatch: () => dispatchMock,
}));
-const splitOpen = Symbol('splitOpen');
+const splitOpenSym = Symbol('splitOpen');
+const splitOpen = jest.fn().mockReturnValue(splitOpenSym);
jest.mock('app/features/explore/state/main', () => ({
...jest.requireActual('app/features/explore/state/main'),
- splitOpen: () => splitOpen,
+ splitOpen: (arg?: SplitOpenOptions) => {
+ return splitOpen(arg);
+ },
}));
const row = createLogRow({ uid: '1' });
@@ -231,6 +236,42 @@ describe('LogRowContextModal', () => {
expect(onClose).toHaveBeenCalled();
});
+ it('should create correct splitOpen', async () => {
+ const queryObj = { datasource: { uid: 'test-uid' } };
+ const getRowContextQuery = jest.fn().mockResolvedValue(queryObj);
+ const onClose = jest.fn();
+
+ render(
+
+ );
+
+ const splitViewButton = await screen.findByRole('button', {
+ name: /open in split view/i,
+ });
+
+ await userEvent.click(splitViewButton);
+
+ await waitFor(() =>
+ expect(splitOpen).toHaveBeenCalledWith(
+ expect.objectContaining({
+ queries: [queryObj],
+ panelsState: {
+ logs: {
+ id: row.uid,
+ },
+ },
+ })
+ )
+ );
+ });
+
it('should dispatch splitOpen', async () => {
const getRowContextQuery = jest.fn().mockResolvedValue({ datasource: { uid: 'test-uid' } });
const onClose = jest.fn();
@@ -252,6 +293,6 @@ describe('LogRowContextModal', () => {
await userEvent.click(splitViewButton);
- await waitFor(() => expect(dispatchMock).toHaveBeenCalledWith(splitOpen));
+ await waitFor(() => expect(dispatchMock).toHaveBeenCalledWith(splitOpenSym));
});
});
diff --git a/public/app/features/logs/components/log-context/LogRowContextModal.tsx b/public/app/features/logs/components/log-context/LogRowContextModal.tsx
index 5bdd95737d4..237db7b2e45 100644
--- a/public/app/features/logs/components/log-context/LogRowContextModal.tsx
+++ b/public/app/features/logs/components/log-context/LogRowContextModal.tsx
@@ -388,11 +388,22 @@ export const LogRowContextModal: React.FunctionComponent {
+ let rowId = row.uid;
+ if (row.dataFrame.refId) {
+ // the orignal row has the refid from the base query and not the refid from the context query, so we need to replace it.
+ rowId = row.uid.replace(row.dataFrame.refId, contextQuery.refId);
+ }
+
dispatch(
splitOpen({
queries: [contextQuery],
range: getFullTimeRange(),
datasourceUid: contextQuery.datasource!.uid!,
+ panelsState: {
+ logs: {
+ id: rowId,
+ },
+ },
})
);
onClose();