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. (#102980)

* Use better loading indicator for `useLogSource`

* Use clearer name for the loading entries flag

* Reuse query object if its value persists
  • Loading branch information
Alejandro Fernández Gómez authored and kibanamachine committed Jun 24, 2021
1 parent 697f8ba commit 2ed850a
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 2ed850a

Please sign in to comment.