-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Get initialinitial log fetch working with v2 store * Replicate shouldLoadAroundPosition logic within hooks * Reload entries on filter change * Add scroll to load additional entries functionality * Cleanup types types and remove state/remote folder * Typescript cleanup * Remove extraneous console.log * Fix typecheck * Add action to load new entries manually * Typecheck fix * Move v2 store stuff into logs containers * Typecheck fix * More typecheck fix * Remove filterQuery from log highlights redux bridge * Rename LogEntriesDependencies to LogEntriesFetchParams * Fix endless reloading bug * Fix duplicate entry rendering * Make sourceId into a dynamic parameter * Fix bug in pagesAfterEnd not being reported causing endless reload * Fix bugs with live streaming
- Loading branch information
Showing
40 changed files
with
620 additions
and
941 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
x-pack/legacy/plugins/infra/public/containers/logs/log_entries/gql_queries.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
}; | ||
}; |
Oops, something went wrong.