-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
Changes from 20 commits
214c285
9aa42ed
6a660d4
4e0f0db
c366a36
db84a98
8a58208
3ffbfdf
fadb8ba
c53a133
873031a
af5d428
35a0902
8a85124
5e523b6
61d7095
35bf164
8f7f34b
24270c8
13b7e90
8e4fa68
1efb711
c4dd7d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
import { EuiComboBox } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
|
||
import React, { useCallback, useState, useEffect } from 'react'; | ||
import React, { useCallback, useState } from 'react'; | ||
import { FieldType } from 'ui/index_patterns'; | ||
import { colorTransformer, MetricsExplorerColor } from '../../../common/color_palette'; | ||
import { | ||
|
@@ -31,24 +31,19 @@ interface SelectedOption { | |
|
||
export const MetricsExplorerMetrics = ({ options, onChange, fields, autoFocus = false }: Props) => { | ||
const colors = Object.keys(MetricsExplorerColor) as MetricsExplorerColor[]; | ||
const [inputRef, setInputRef] = useState<HTMLInputElement | null>(null); | ||
const [focusOnce, setFocusState] = useState<boolean>(false); | ||
const [shouldFocus, setShouldFocus] = useState(autoFocus); | ||
|
||
useEffect(() => { | ||
if (inputRef && autoFocus && !focusOnce) { | ||
inputRef.focus(); | ||
setFocusState(true); | ||
} | ||
}, [inputRef]); | ||
// the EuiCombobox forwards the ref to an input element | ||
const handleInputRef = useCallback( | ||
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. ℹ️ Since the stored 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. I would rename it then to something on the line of |
||
(ref: HTMLInputElement | null) => { | ||
if (ref && shouldFocus) { | ||
ref.focus(); | ||
setShouldFocus(false); | ||
} | ||
}, | ||
[shouldFocus] | ||
); | ||
|
||
// I tried to use useRef originally but the EUIComboBox component's type definition | ||
// would only accept an actual input element or a callback function (with the same type). | ||
// This effectivly does the same thing but is compatible with EuiComboBox. | ||
const handleInputRef = (ref: HTMLInputElement) => { | ||
if (ref) { | ||
setInputRef(ref); | ||
} | ||
}; | ||
const handleChange = useCallback( | ||
selectedOptions => { | ||
onChange( | ||
|
@@ -59,7 +54,7 @@ export const MetricsExplorerMetrics = ({ options, onChange, fields, autoFocus = | |
})) | ||
); | ||
}, | ||
[options, onChange] | ||
[onChange, options.aggregation, colors] | ||
); | ||
|
||
const comboOptions = fields | ||
|
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> | ||
|
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, | ||
|
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.