Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v10.0.x] Log Context: Fix split view button using the wrong query #69416

Merged
merged 1 commit into from
Jun 1, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { createLogRow } from '../__mocks__/logRow';
import { LogRowContextModal } from './LogRowContextModal';

const getRowContext = jest.fn().mockResolvedValue({ data: { fields: [], rows: [] } });
const getRowContextQuery = jest.fn().mockResolvedValue({ datasource: { uid: 'test-uid' } });

const dispatchMock = jest.fn();
jest.mock('app/types', () => ({
Expand Down Expand Up @@ -127,6 +128,35 @@ describe('LogRowContextModal', () => {
await waitFor(() => expect(getRowContext).toHaveBeenCalledTimes(4));
});

it('should call getRowContextQuery when limit changes', async () => {
render(
<LogRowContextModal
row={row}
open={true}
onClose={() => {}}
getRowContext={getRowContext}
getRowContextQuery={getRowContextQuery}
timeZone={timeZone}
/>
);

// this will call it initially and in the first fetchResults
await waitFor(() => expect(getRowContextQuery).toHaveBeenCalledTimes(2));

const tenLinesButton = screen.getByRole('button', {
name: /50 lines/i,
});
await userEvent.click(tenLinesButton);
const twentyLinesButton = screen.getByRole('menuitemradio', {
name: /20 lines/i,
});
act(() => {
userEvent.click(twentyLinesButton);
});

await waitFor(() => expect(getRowContextQuery).toHaveBeenCalledTimes(3));
});

it('should show a split view button', async () => {
const getRowContextQuery = jest.fn().mockResolvedValue({ datasource: { uid: 'test-uid' } });

Expand Down Expand Up @@ -175,7 +205,7 @@ describe('LogRowContextModal', () => {
/>
);

await waitFor(() => expect(getRowContextQuery).toHaveBeenCalledTimes(1));
await waitFor(() => expect(getRowContextQuery).toHaveBeenCalledTimes(2));
});

it('should close modal', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,14 @@ export const LogRowContextModal: React.FunctionComponent<LogRowContextModalProps
}
};

const updateContextQuery = async () => {
const contextQuery = getRowContextQuery ? await getRowContextQuery(row) : null;
setContextQuery(contextQuery);
};

const [{ loading }, fetchResults] = useAsyncFn(async () => {
if (open && row && limit) {
await updateContextQuery();
const rawResults = await Promise.all([
getRowContext(row, {
limit: logsSortOrder === LogsSortOrder.Descending ? limit + 1 : limit,
Expand Down Expand Up @@ -268,10 +274,7 @@ export const LogRowContextModal: React.FunctionComponent<LogRowContextModalProps
}
}, [scrollElement]);

useAsync(async () => {
const contextQuery = getRowContextQuery ? await getRowContextQuery(row) : null;
setContextQuery(contextQuery);
}, [getRowContextQuery, row]);
useAsync(updateContextQuery, [getRowContextQuery, row]);

return (
<Modal
Expand Down