Skip to content

Commit

Permalink
[Fleet][Logs UI] Prevent double loading of entries in <LogStream />
Browse files Browse the repository at this point in the history
… component. (elastic#102980) (elastic#103269)

* Use better loading indicator for `useLogSource`

* Use clearer name for the loading entries flag

* Reuse query object if its value persists

Co-authored-by: Alejandro Fernández Gómez <alejandro.fernandez@elastic.co>
  • Loading branch information
kibanamachine and Alejandro Fernández Gómez authored Jun 24, 2021
1 parent 4b546bf commit 5cb6643
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Read more at https://github.com/elastic/kibana/blob/master/src/plugins/kibana_re

const {
derivedIndexPattern,
isLoadingSourceConfiguration,
isLoading: isLoadingSource,
loadSource,
sourceConfiguration,
} = useLogSource({
Expand All @@ -138,7 +138,7 @@ Read more at https://github.com/elastic/kibana/blob/master/src/plugins/kibana_re
hasMoreAfter,
hasMoreBefore,
isLoadingMore,
isReloading,
isReloading: isLoadingEntries,
} = useLogStream({
sourceId,
startTimestamp,
Expand Down Expand Up @@ -198,7 +198,7 @@ Read more at https://github.com/elastic/kibana/blob/master/src/plugins/kibana_re
items={streamItems}
scale="medium"
wrap={true}
isReloading={isLoadingSourceConfiguration || isReloading}
isReloading={isLoadingSource || isLoadingEntries}
isLoadingMore={isLoadingMore}
hasMoreBeforeStart={hasMoreBefore}
hasMoreAfterEnd={hasMoreAfter}
Expand Down
13 changes: 10 additions & 3 deletions x-pack/plugins/infra/public/containers/logs/log_stream/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
* 2.0.
*/

import { isEqual } from 'lodash';
import createContainer from 'constate';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { useCallback, useEffect, useMemo, useState, useRef } from 'react';
import usePrevious from 'react-use/lib/usePrevious';
import useSetState from 'react-use/lib/useSetState';
import { esQuery } from '../../../../../../../src/plugins/data/public';
Expand Down Expand Up @@ -65,6 +66,12 @@ export function useLogStream({
const prevStartTimestamp = usePrevious(startTimestamp);
const prevEndTimestamp = usePrevious(endTimestamp);

const cachedQuery = useRef(query);

if (!isEqual(query, cachedQuery)) {
cachedQuery.current = query;
}

useEffect(() => {
if (prevStartTimestamp && prevStartTimestamp > startTimestamp) {
setState({ hasMoreBefore: true });
Expand All @@ -82,10 +89,10 @@ export function useLogStream({
sourceId,
startTimestamp,
endTimestamp,
query,
query: cachedQuery.current,
columnOverrides: columns,
}),
[columns, endTimestamp, query, sourceId, startTimestamp]
[columns, endTimestamp, cachedQuery, sourceId, startTimestamp]
);

const {
Expand Down

0 comments on commit 5cb6643

Please sign in to comment.