From a5d577eca19f2b0b7ad6b2aa588a67118abf6cd4 Mon Sep 17 00:00:00 2001 From: Sven Grossmann Date: Wed, 18 Jan 2023 09:52:18 +0100 Subject: [PATCH] Logs: Make `no logs found` text more visible in Explore (#61651) * move scan buttons up * update test --- public/app/features/explore/Logs.test.tsx | 132 +++++++++++++++++++++- public/app/features/explore/Logs.tsx | 32 +++--- 2 files changed, 146 insertions(+), 18 deletions(-) diff --git a/public/app/features/explore/Logs.test.tsx b/public/app/features/explore/Logs.test.tsx index 59f2120253e..11f7c553415 100644 --- a/public/app/features/explore/Logs.test.tsx +++ b/public/app/features/explore/Logs.test.tsx @@ -7,7 +7,7 @@ import { ExploreId } from 'app/types'; import { Logs } from './Logs'; describe('Logs', () => { - const setup = (propOverrides?: object) => { + const setup = (logs?: LogRowModel[]) => { const rows = [ makeLog({ uid: '1', timeEpochMs: 1 }), makeLog({ uid: '2', timeEpochMs: 2 }), @@ -24,7 +24,7 @@ describe('Logs', () => { onClickFilterOutLabel={() => null} logsVolumeData={undefined} loadLogsVolumeData={() => undefined} - logRows={rows} + logRows={logs ?? rows} timeZone={'utc'} width={50} loading={false} @@ -61,6 +61,134 @@ describe('Logs', () => { expect(logRows[2].textContent).toContain('log message 1'); }); + it('should render no logs found', () => { + setup([]); + + expect(screen.getByText(/no logs found\./i)).toBeInTheDocument(); + expect( + screen.getByRole('button', { + name: /scan for older logs/i, + }) + ).toBeInTheDocument(); + }); + + it('should render a load more button', () => { + const scanningStarted = jest.fn(); + render( + undefined} + logsVolumeEnabled={true} + onSetLogsVolumeEnabled={() => null} + onClickFilterLabel={() => null} + onClickFilterOutLabel={() => null} + logsVolumeData={undefined} + loadLogsVolumeData={() => undefined} + logRows={[]} + onStartScanning={scanningStarted} + timeZone={'utc'} + width={50} + loading={false} + loadingState={LoadingState.Done} + absoluteRange={{ + from: toUtc('2019-01-01 10:00:00').valueOf(), + to: toUtc('2019-01-01 16:00:00').valueOf(), + }} + addResultsToCache={() => {}} + onChangeTime={() => {}} + clearCache={() => {}} + getFieldLinks={() => { + return []; + }} + eventBus={new EventBusSrv()} + /> + ); + const button = screen.getByRole('button', { + name: /scan for older logs/i, + }); + button.click(); + expect(scanningStarted).toHaveBeenCalled(); + }); + + it('should render a stop scanning button', () => { + render( + undefined} + logsVolumeEnabled={true} + onSetLogsVolumeEnabled={() => null} + onClickFilterLabel={() => null} + onClickFilterOutLabel={() => null} + logsVolumeData={undefined} + loadLogsVolumeData={() => undefined} + logRows={[]} + scanning={true} + timeZone={'utc'} + width={50} + loading={false} + loadingState={LoadingState.Done} + absoluteRange={{ + from: toUtc('2019-01-01 10:00:00').valueOf(), + to: toUtc('2019-01-01 16:00:00').valueOf(), + }} + addResultsToCache={() => {}} + onChangeTime={() => {}} + clearCache={() => {}} + getFieldLinks={() => { + return []; + }} + eventBus={new EventBusSrv()} + /> + ); + + expect( + screen.getByRole('button', { + name: /stop scan/i, + }) + ).toBeInTheDocument(); + }); + + it('should render a stop scanning button', () => { + const scanningStopped = jest.fn(); + + render( + undefined} + logsVolumeEnabled={true} + onSetLogsVolumeEnabled={() => null} + onClickFilterLabel={() => null} + onClickFilterOutLabel={() => null} + logsVolumeData={undefined} + loadLogsVolumeData={() => undefined} + logRows={[]} + scanning={true} + onStopScanning={scanningStopped} + timeZone={'utc'} + width={50} + loading={false} + loadingState={LoadingState.Done} + absoluteRange={{ + from: toUtc('2019-01-01 10:00:00').valueOf(), + to: toUtc('2019-01-01 16:00:00').valueOf(), + }} + addResultsToCache={() => {}} + onChangeTime={() => {}} + clearCache={() => {}} + getFieldLinks={() => { + return []; + }} + eventBus={new EventBusSrv()} + /> + ); + + const button = screen.getByRole('button', { + name: /stop scan/i, + }); + button.click(); + expect(scanningStopped).toHaveBeenCalled(); + }); + it('should flip the order', () => { setup(); const oldestFirstSelection = screen.getByLabelText('Oldest first'); diff --git a/public/app/features/explore/Logs.tsx b/public/app/features/explore/Logs.tsx index 0bcdf60f5ca..ce9c1266d5e 100644 --- a/public/app/features/explore/Logs.tsx +++ b/public/app/features/explore/Logs.tsx @@ -507,6 +507,22 @@ class UnthemedLogs extends PureComponent { scrollElement={scrollElement} onLogRowHover={this.onLogRowHover} /> + {!loading && !hasData && !scanning && ( +
+ No logs found. + +
+ )} + {scanning && ( +
+ {scanText} + +
+ )} { clearCache={clearCache} /> - {!loading && !hasData && !scanning && ( -
- No logs found. - -
- )} - {scanning && ( -
- {scanText} - -
- )} );