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

[Logs UI] Refactor log entry data fetching to hooks #51526

Merged
merged 25 commits into from
Dec 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
80b892d
Get initialinitial log fetch working with v2 store
Zacqary Nov 20, 2019
79bd94f
Replicate shouldLoadAroundPosition logic within hooks
Zacqary Nov 20, 2019
3d2ecae
Reload entries on filter change
Zacqary Nov 20, 2019
12ea512
Add scroll to load additional entries functionality
Zacqary Nov 21, 2019
1bbd8c1
Cleanup types types and remove state/remote folder
Zacqary Nov 22, 2019
97e6496
Typescript cleanup
Zacqary Nov 22, 2019
9b203b7
Merge remote-tracking branch 'upstream/master' into 50395-refactor-lo…
Zacqary Nov 22, 2019
ccee4f2
Remove extraneous console.log
Zacqary Nov 25, 2019
1017ae5
Fix typecheck
Zacqary Nov 25, 2019
8c597a2
Add action to load new entries manually
Zacqary Nov 25, 2019
388120d
Typecheck fix
Zacqary Nov 26, 2019
d61e53e
Merge remote-tracking branch 'upstream/master' into 50395-refactor-lo…
Zacqary Nov 26, 2019
3b5227d
Move v2 store stuff into logs containers
Zacqary Dec 2, 2019
49134a2
Typecheck fix
Zacqary Dec 3, 2019
756fc64
Merge remote-tracking branch 'upstream/master' into 50395-refactor-lo…
Zacqary Dec 3, 2019
4b6bb64
More typecheck fix
Zacqary Dec 3, 2019
24bfe9e
Remove filterQuery from log highlights redux bridge
Zacqary Dec 3, 2019
1c3e0c7
Rename LogEntriesDependencies to LogEntriesFetchParams
Zacqary Dec 3, 2019
ce1b88f
Fix endless reloading bug
Zacqary Dec 3, 2019
9a84a8d
Fix duplicate entry rendering
Zacqary Dec 3, 2019
8e9d9ee
Make sourceId into a dynamic parameter
Zacqary Dec 4, 2019
6e544f3
Fix bug in pagesAfterEnd not being reported causing endless reload
Zacqary Dec 5, 2019
34e8afa
Merge remote-tracking branch 'upstream/master' into 50395-refactor-lo…
Zacqary Dec 9, 2019
030cd5f
Fix bugs with live streaming
Zacqary Dec 9, 2019
550e485
Merge remote-tracking branch 'upstream/master' into 50395-refactor-lo…
Zacqary Dec 9, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions x-pack/legacy/plugins/infra/public/apps/start_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { InfraFrontendLibs } from '../lib/lib';
import { PageRouter } from '../routes';
import { createStore } from '../store';
import { ApolloClientContext } from '../utils/apollo_context';
import { ReduxStateContextProvider } from '../utils/redux_context';
import { HistoryContext } from '../utils/history_context';
import {
useUiSetting$,
Expand All @@ -46,15 +47,17 @@ export async function startApp(libs: InfraFrontendLibs) {
<UICapabilitiesProvider>
<EuiErrorBoundary>
<ReduxStoreProvider store={store}>
<ApolloProvider client={libs.apolloClient}>
<ApolloClientContext.Provider value={libs.apolloClient}>
<EuiThemeProvider darkMode={darkMode}>
<HistoryContext.Provider value={history}>
<PageRouter history={history} />
</HistoryContext.Provider>
</EuiThemeProvider>
</ApolloClientContext.Provider>
</ApolloProvider>
<ReduxStateContextProvider>
<ApolloProvider client={libs.apolloClient}>
<ApolloClientContext.Provider value={libs.apolloClient}>
<EuiThemeProvider darkMode={darkMode}>
<HistoryContext.Provider value={history}>
<PageRouter history={history} />
</HistoryContext.Provider>
</EuiThemeProvider>
</ApolloClientContext.Provider>
</ApolloProvider>
</ReduxStateContextProvider>
</ReduxStoreProvider>
</EuiErrorBoundary>
</UICapabilitiesProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface LogTextStreamLoadingItemViewProps {
hasMore: boolean;
isLoading: boolean;
isStreaming: boolean;
lastStreamingUpdate: number | null;
lastStreamingUpdate: Date | null;
onLoadMore?: () => void;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ interface ScrollableLogTextStreamViewProps {
hasMoreBeforeStart: boolean;
hasMoreAfterEnd: boolean;
isStreaming: boolean;
lastLoadedTime: number | null;
lastLoadedTime: Date | null;
target: TimeKey | null;
jumpToTarget: (target: TimeKey) => any;
reportVisibleInterval: (params: {
Expand Down Expand Up @@ -143,7 +143,7 @@ export class ScrollableLogTextStreamView extends React.PureComponent<
const hasItems = items.length > 0;
return (
<ScrollableLogTextStreamViewWrapper>
{isReloading && !hasItems ? (
{isReloading && (!isStreaming || !hasItems) ? (
<InfraLoadingPanel
width="100%"
height="100%"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,10 @@ export class VerticalScrollPanel<Child> extends React.PureComponent<
// Flag the scrollTop change that's about to happen as programmatic, as
// opposed to being in direct response to user input
this.nextScrollEventFromCenterTarget = true;
scrollRef.current.scrollTop = targetDimensions.top + targetOffset - scrollViewHeight / 2;
return true;
const currentScrollTop = scrollRef.current.scrollTop;
const newScrollTop = targetDimensions.top + targetOffset - scrollViewHeight / 2;
scrollRef.current.scrollTop = newScrollTop;
return currentScrollTop !== newScrollTop;
}
return false;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { ApolloClient } from 'apollo-client';
import { TimeKey } from '../../../../common/time';
import { logEntriesQuery } from '../../../graphql/log_entries.gql_query';
import { useApolloClient } from '../../../utils/apollo_context';
import { LogEntriesResponse } from '.';

const LOAD_CHUNK_SIZE = 200;

type LogEntriesGetter = (
client: ApolloClient<{}>,
countBefore: number,
countAfter: number
) => (params: {
sourceId: string;
timeKey: TimeKey | null;
filterQuery: string | null;
}) => Promise<LogEntriesResponse>;

const getLogEntries: LogEntriesGetter = (client, countBefore, countAfter) => async ({
sourceId,
timeKey,
filterQuery,
}) => {
if (!timeKey) throw new Error('TimeKey is null');
const result = await client.query({
query: logEntriesQuery,
variables: {
sourceId,
timeKey: { time: timeKey.time, tiebreaker: timeKey.tiebreaker },
countBefore,
countAfter,
filterQuery,
},
fetchPolicy: 'no-cache',
});
// Workaround for Typescript. Since we're removing the GraphQL API in another PR or two
// 7.6 goes out I don't think it's worth the effort to actually make this
// typecheck pass
const { source } = result.data as any;
const { logEntriesAround } = source;
return {
entries: logEntriesAround.entries,
entriesStart: logEntriesAround.start,
entriesEnd: logEntriesAround.end,
hasMoreAfterEnd: logEntriesAround.hasMoreAfter,
hasMoreBeforeStart: logEntriesAround.hasMoreBefore,
lastLoadedTime: new Date(),
};
};

export const useGraphQLQueries = () => {
const client = useApolloClient();
if (!client) throw new Error('Unable to get Apollo Client from context');
return {
getLogEntriesAround: getLogEntries(client, LOAD_CHUNK_SIZE, LOAD_CHUNK_SIZE),
getLogEntriesBefore: getLogEntries(client, LOAD_CHUNK_SIZE, 0),
getLogEntriesAfter: getLogEntries(client, 0, LOAD_CHUNK_SIZE),
};
};
Loading