From d3a8f6d0269f6dd9a55cd6c8f6841147d63d9d87 Mon Sep 17 00:00:00 2001 From: Lukas Siatka Date: Thu, 14 May 2020 18:55:30 +0200 Subject: [PATCH] Explore: fixes loading more logs in logs context view (#24135) --- ...test.ts => LogRowContextProvider.test.tsx} | 84 ++++++++++++++++++- .../components/Logs/LogRowContextProvider.tsx | 14 +++- 2 files changed, 95 insertions(+), 3 deletions(-) rename packages/grafana-ui/src/components/Logs/{LogRowContextProvider.test.ts => LogRowContextProvider.test.tsx} (51%) diff --git a/packages/grafana-ui/src/components/Logs/LogRowContextProvider.test.ts b/packages/grafana-ui/src/components/Logs/LogRowContextProvider.test.tsx similarity index 51% rename from packages/grafana-ui/src/components/Logs/LogRowContextProvider.test.ts rename to packages/grafana-ui/src/components/Logs/LogRowContextProvider.test.tsx index 07fbbfefbf5..57052cc015c 100644 --- a/packages/grafana-ui/src/components/Logs/LogRowContextProvider.test.ts +++ b/packages/grafana-ui/src/components/Logs/LogRowContextProvider.test.tsx @@ -1,5 +1,8 @@ +import React from 'react'; import { FieldType, LogRowModel, MutableDataFrame, Labels, LogLevel, DataQueryResponse } from '@grafana/data'; -import { getRowContexts } from './LogRowContextProvider'; +import { getRowContexts, LogRowContextProvider } from './LogRowContextProvider'; +import { mount } from 'enzyme'; +import { act } from 'react-dom/test-utils'; describe('getRowContexts', () => { describe('when called with a DataFrame and results are returned', () => { @@ -84,6 +87,85 @@ describe('getRowContexts', () => { }); }); +describe('LogRowContextProvider', () => { + describe('when requesting longer context', () => { + it('can request more log lines', async () => { + const firstResult = new MutableDataFrame({ + refId: 'B', + fields: [ + { name: 'ts', type: FieldType.time, values: [10, 9, 8, 7, 6, 5, 4, 3, 2, 1] }, + { + name: 'line', + type: FieldType.string, + values: ['10', '9', '8', '7', '6', '5', '4', '3', '2', '1'], + labels: {}, + }, + { + name: 'id', + type: FieldType.string, + values: ['10', '9', '8', '7', '6', '5', '4', '3', '2', '1'], + labels: {}, + }, + ], + }); + + const secondResult = new MutableDataFrame({ + refId: 'B', + fields: [ + { name: 'ts', type: FieldType.time, values: [14, 13, 12] }, + { name: 'line', type: FieldType.string, values: ['14', '13', '12'], labels: {} }, + { name: 'id', type: FieldType.string, values: ['14', '13', '12'], labels: {} }, + ], + }); + + let called = false; + const getRowContextMock = (row: LogRowModel, options?: any): Promise => { + if (!called) { + called = true; + return Promise.resolve({ data: [firstResult] }); + } + return Promise.resolve({ data: [secondResult] }); + }; + let wrapper: any; + await act(async () => { + wrapper = await mount( + + {({ result, errors, hasMoreContextRows, updateLimit, limit }) => { + return ( +
+
+

{result.before?.toString()}

+

{result.after?.toString()}

+
+
+

{errors.before}

+

{errors.after}

+
+
+

{String(hasMoreContextRows.before)}

+

{String(hasMoreContextRows.after)}

+
+
{limit}
+ +
+ ); + }} +
+ ); + }); + expect(wrapper.find('.hasMoreContextRows-before').text()).toBe('true'); + expect(wrapper.find('.hasMoreContextRows-after').text()).toBe('true'); + expect(wrapper.find('.limit').text()).toBe('10'); + await act(async () => wrapper.find('.updateLimit').simulate('click')); + expect(wrapper.find('.limit').text()).toBe('20'); + expect(wrapper.find('.hasMoreContextRows-before').text()).toBe('true'); + expect(wrapper.find('.hasMoreContextRows-after').text()).toBe('false'); + }); + }); +}); + const row: LogRowModel = { entryFieldIndex: 0, rowIndex: 0, diff --git a/packages/grafana-ui/src/components/Logs/LogRowContextProvider.tsx b/packages/grafana-ui/src/components/Logs/LogRowContextProvider.tsx index 9acb05be487..8991a9cbd74 100644 --- a/packages/grafana-ui/src/components/Logs/LogRowContextProvider.tsx +++ b/packages/grafana-ui/src/components/Logs/LogRowContextProvider.tsx @@ -37,6 +37,7 @@ interface LogRowContextProviderProps { errors: LogRowContextQueryErrors; hasMoreContextRows: HasMoreContextRows; updateLimit: () => void; + limit: number; }) => JSX.Element; } @@ -160,11 +161,19 @@ export const LogRowContextProvider: React.FunctionComponent setLimit(limit + 10), + limit, }); };