-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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] Remove apollo deps from log link-to routes #74502
Merged
weltenwort
merged 11 commits into
elastic:master
from
weltenwort:logs-ui-remove-apollo-deps
Aug 14, 2020
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a541efe
Replace old source hook with new hook in link-to
weltenwort a070acb
Fix loading page rendering
weltenwort be35a08
Guard log source setState against unmounting
weltenwort 0238ed1
Fix and enhance log link-to unit tests
weltenwort fa51b27
Merge branch 'master' into logs-ui-remove-apollo-deps
weltenwort 031c6b8
Merge branch 'master' into logs-ui-remove-apollo-deps
elasticmachine ea92e03
Remove commented-out code
weltenwort 0f4f9a8
Add sourceId test case
weltenwort c2b6a1c
Reintroduce unambigious link-to logs route
weltenwort c114735
Add more tests
weltenwort 781bf99
Merge branch 'master' into logs-ui-remove-apollo-deps
elasticmachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
78 changes: 78 additions & 0 deletions
78
x-pack/plugins/infra/public/containers/logs/log_source/log_source.mock.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,78 @@ | ||
/* | ||
* 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 { LogSourceConfiguration, LogSourceStatus, useLogSource } from './log_source'; | ||
|
||
type CreateUseLogSource = (sourceConfiguration?: { sourceId?: string }) => typeof useLogSource; | ||
|
||
const defaultSourceId = 'default'; | ||
|
||
export const createUninitializedUseLogSourceMock: CreateUseLogSource = ({ | ||
sourceId = defaultSourceId, | ||
} = {}) => () => ({ | ||
derivedIndexPattern: { | ||
fields: [], | ||
title: 'unknown', | ||
}, | ||
hasFailedLoadingSource: false, | ||
hasFailedLoadingSourceStatus: false, | ||
initialize: jest.fn(), | ||
isLoading: false, | ||
isLoadingSourceConfiguration: false, | ||
isLoadingSourceStatus: false, | ||
isUninitialized: true, | ||
loadSource: jest.fn(), | ||
loadSourceConfiguration: jest.fn(), | ||
loadSourceFailureMessage: undefined, | ||
loadSourceStatus: jest.fn(), | ||
sourceConfiguration: undefined, | ||
sourceId, | ||
sourceStatus: undefined, | ||
updateSourceConfiguration: jest.fn(), | ||
}); | ||
|
||
export const createLoadingUseLogSourceMock: CreateUseLogSource = ({ | ||
sourceId = defaultSourceId, | ||
} = {}) => (args) => ({ | ||
...createUninitializedUseLogSourceMock({ sourceId })(args), | ||
isLoading: true, | ||
isLoadingSourceConfiguration: true, | ||
isLoadingSourceStatus: true, | ||
}); | ||
|
||
export const createLoadedUseLogSourceMock: CreateUseLogSource = ({ | ||
sourceId = defaultSourceId, | ||
} = {}) => (args) => ({ | ||
...createUninitializedUseLogSourceMock({ sourceId })(args), | ||
sourceConfiguration: createBasicSourceConfiguration(sourceId), | ||
sourceStatus: { | ||
logIndexFields: [], | ||
logIndexStatus: 'available', | ||
}, | ||
}); | ||
|
||
export const createBasicSourceConfiguration = (sourceId: string): LogSourceConfiguration => ({ | ||
id: sourceId, | ||
origin: 'stored', | ||
configuration: { | ||
description: `description for ${sourceId}`, | ||
logAlias: 'LOG_INDICES', | ||
logColumns: [], | ||
fields: { | ||
container: 'CONTAINER_FIELD', | ||
host: 'HOST_FIELD', | ||
pod: 'POD_FIELD', | ||
tiebreaker: 'TIEBREAKER_FIELD', | ||
timestamp: 'TIMESTAMP_FIELD', | ||
}, | ||
name: sourceId, | ||
}, | ||
}); | ||
|
||
export const createAvailableSourceStatus = (logIndexFields = []): LogSourceStatus => ({ | ||
logIndexFields, | ||
logIndexStatus: 'available', | ||
}); |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this fixes the race condition you mentioned in the description.
Could you help me understand what was the problem? I see that
useMountedState
is a wrapper arounduseEffect
. I looked for usages of these promise creators and I couldn't find uses that weren't wrapped inuseEffect
already.I worry that this might introduce a "gotcha" if consumers of this API need to call the promises before their component is mounted (i.e. in
useLayoutEffect
). If I understand this correctly, calling the promise will do nothing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useMountedState
returns a predicate that indicates whether the component is mounted. This becomes important when the component unmounts while the promise is pending. Then, when the promise is resolved, the subsequentsetState
will cause an exception. Therefore all asynchronously calledsetState
s should be guarded by such a check. I'm still trying to catch up with all the occurrences of that mistake in this plugin, so this is a small step.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As described above, the promise itself is not the problem. It resolving and thereby causing a
setState
call before mounting or after unmounting is.