-
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 + Metrics UI] Remove eslint exceptions #50979
Merged
weltenwort
merged 23 commits into
elastic:master
from
weltenwort:logs-metrics-ui-remove-eslint-exceptions
Dec 11, 2019
Merged
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
214c285
Remove infra eslint exception
weltenwort 9aa42ed
Enhance useUrlState to write default to URL
weltenwort 6a660d4
Refactor autoFocus ref handler to avoid useEffect
weltenwort 4e0f0db
Refactor onChange callback to avoid useEffect
weltenwort c366a36
Fix incorrect dependency lists
weltenwort db84a98
Fix conditional hook usage and ineffective memoization
weltenwort 8a58208
Fix dangerous array mutation of useMemo closure
weltenwort 3ffbfdf
Fix incorrect memoization dependencies
weltenwort fadb8ba
Whitelist externally managed dependency lists
weltenwort c53a133
Fix incomplete dependency lists
weltenwort 873031a
Fix conditional hook usage
weltenwort af5d428
Fix conditional hook usage
weltenwort 35a0902
Whitelist external dependencies
weltenwort 8a85124
Fix incomplete dependency lists
weltenwort 5e523b6
Temporarily whitelist complex effect dependency list
weltenwort 61d7095
Avoid useEffect for initialization
weltenwort 35bf164
Fix incomplete dependency lists
weltenwort 8f7f34b
Wrap all imperative calls into useEffect
weltenwort 24270c8
Merge branch 'master' into logs-metrics-ui-remove-eslint-exceptions
weltenwort 13b7e90
Fix conditional hook usage
weltenwort 8e4fa68
Merge branch 'master' into logs-metrics-ui-remove-eslint-exceptions
weltenwort 1efb711
Name function more specifically
weltenwort c4dd7d4
Merge branch 'master' into logs-metrics-ui-remove-eslint-exceptions
weltenwort 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,28 +17,33 @@ import { | |
} from '../../graphql/types'; | ||
import { findInventoryModel } from '../../../common/inventory_models'; | ||
|
||
interface Props { | ||
interface WaffleInventorySwitcherProps { | ||
nodeType: InfraNodeType; | ||
changeNodeType: (nodeType: InfraNodeType) => void; | ||
changeGroupBy: (groupBy: InfraSnapshotGroupbyInput[]) => void; | ||
changeMetric: (metric: InfraSnapshotMetricInput) => void; | ||
} | ||
|
||
export const WaffleInventorySwitcher = (props: Props) => { | ||
export const WaffleInventorySwitcher: React.FC<WaffleInventorySwitcherProps> = ({ | ||
changeNodeType, | ||
changeGroupBy, | ||
changeMetric, | ||
nodeType, | ||
}) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ℹ️ This destructuring just allows for correct dependency declaration below. |
||
const [isOpen, setIsOpen] = useState(false); | ||
const closePopover = useCallback(() => setIsOpen(false), []); | ||
const openPopover = useCallback(() => setIsOpen(true), []); | ||
const goToNodeType = useCallback( | ||
(nodeType: InfraNodeType) => { | ||
(targetNodeType: InfraNodeType) => { | ||
closePopover(); | ||
props.changeNodeType(nodeType); | ||
props.changeGroupBy([]); | ||
const inventoryModel = findInventoryModel(nodeType); | ||
props.changeMetric({ | ||
changeNodeType(targetNodeType); | ||
changeGroupBy([]); | ||
const inventoryModel = findInventoryModel(targetNodeType); | ||
changeMetric({ | ||
type: inventoryModel.metrics.defaultSnapshot as InfraSnapshotMetricType, | ||
}); | ||
}, | ||
[props.changeGroupBy, props.changeNodeType, props.changeMetric] | ||
[closePopover, changeNodeType, changeGroupBy, changeMetric] | ||
); | ||
const goToHost = useCallback(() => goToNodeType('host' as InfraNodeType), [goToNodeType]); | ||
const goToK8 = useCallback(() => goToNodeType('pod' as InfraNodeType), [goToNodeType]); | ||
|
@@ -68,10 +73,10 @@ export const WaffleInventorySwitcher = (props: Props) => { | |
], | ||
}, | ||
], | ||
[] | ||
[goToDocker, goToHost, goToK8] | ||
); | ||
const selectedText = useMemo(() => { | ||
switch (props.nodeType) { | ||
switch (nodeType) { | ||
case InfraNodeType.host: | ||
return i18n.translate('xpack.infra.waffle.nodeTypeSwitcher.hostsLabel', { | ||
defaultMessage: 'Hosts', | ||
|
@@ -81,7 +86,7 @@ export const WaffleInventorySwitcher = (props: Props) => { | |
case InfraNodeType.container: | ||
return 'Docker'; | ||
} | ||
}, [props.nodeType]); | ||
}, [nodeType]); | ||
|
||
return ( | ||
<EuiFilterGroup> | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,11 +4,11 @@ | |
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { useEffect } from 'react'; | ||
import * as rt from 'io-ts'; | ||
import { identity, constant } from 'fp-ts/lib/function'; | ||
import { fold } from 'fp-ts/lib/Either'; | ||
import { constant, identity } from 'fp-ts/lib/function'; | ||
import { pipe } from 'fp-ts/lib/pipeable'; | ||
import * as rt from 'io-ts'; | ||
|
||
import { useUrlState } from '../../../utils/use_url_state'; | ||
|
||
const autoRefreshRT = rt.union([ | ||
|
@@ -40,12 +40,9 @@ export const useLogAnalysisResultsUrlState = () => { | |
pipe(urlTimeRangeRT.decode(value), fold(constant(undefined), identity)), | ||
encodeUrlState: urlTimeRangeRT.encode, | ||
urlStateKey: TIME_RANGE_URL_STATE_KEY, | ||
writeDefaultState: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ℹ️ The initialization is now handled by the |
||
}); | ||
|
||
useEffect(() => { | ||
setTimeRange(timeRange); | ||
}, []); | ||
|
||
const [autoRefresh, setAutoRefresh] = useUrlState({ | ||
defaultState: { | ||
isPaused: false, | ||
|
@@ -55,12 +52,9 @@ export const useLogAnalysisResultsUrlState = () => { | |
pipe(autoRefreshRT.decode(value), fold(constant(undefined), identity)), | ||
encodeUrlState: autoRefreshRT.encode, | ||
urlStateKey: AUTOREFRESH_URL_STATE_KEY, | ||
writeDefaultState: true, | ||
}); | ||
|
||
useEffect(() => { | ||
setAutoRefresh(autoRefresh); | ||
}, []); | ||
|
||
return { | ||
timeRange, | ||
setTimeRange, | ||
|
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
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.
ℹ️ This makes
useEffect
unnecessary by moving theonChange
call into the setter.