Skip to content

Commit a0a749e

Browse files
authored
[7.x] [Logs + Metrics UI] Remove eslint exceptions (#50979) (#52933)
Backports the following commits to 7.x: - [Logs + Metrics UI] Remove eslint exceptions (#50979)
1 parent 064968e commit a0a749e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+269
-231
lines changed

.eslintrc.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,6 @@ module.exports = {
170170
'react-hooks/rules-of-hooks': 'off',
171171
},
172172
},
173-
{
174-
files: ['x-pack/legacy/plugins/infra/**/*.{js,ts,tsx}'],
175-
rules: {
176-
'react-hooks/exhaustive-deps': 'off',
177-
'react-hooks/rules-of-hooks': 'off',
178-
},
179-
},
180173
{
181174
files: ['x-pack/legacy/plugins/lens/**/*.{js,ts,tsx}'],
182175
rules: {

x-pack/legacy/plugins/infra/public/components/formatted_time.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export const useFormattedTime = (
3737

3838
const dateFormat = formatMap[format];
3939
const formattedTime = useMemo(() => getFormattedTime(time, dateFormat, fallbackFormat), [
40-
getFormattedTime,
4140
time,
4241
dateFormat,
4342
fallbackFormat,

x-pack/legacy/plugins/infra/public/components/logging/log_entry_flyout/log_entry_actions_menu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const LogEntryActionsMenu: React.FunctionComponent<{
5151
/>
5252
</EuiContextMenuItem>,
5353
],
54-
[uptimeLink]
54+
[apmLink, uptimeLink]
5555
);
5656

5757
const hasMenuItems = useMemo(() => menuItems.length > 0, [menuItems]);

x-pack/legacy/plugins/infra/public/components/logging/log_highlights_menu.tsx

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
import { i18n } from '@kbn/i18n';
1717
import { FormattedMessage } from '@kbn/i18n/react';
1818
import { debounce } from 'lodash';
19-
import React, { useCallback, useEffect, useMemo, useState } from 'react';
19+
import React, { useCallback, useMemo, useState } from 'react';
2020

2121
import euiStyled from '../../../../../common/eui_styled_components';
2222
import { useVisibilityState } from '../../utils/use_visibility_state';
@@ -47,8 +47,25 @@ export const LogHighlightsMenu: React.FC<LogHighlightsMenuProps> = ({
4747
} = useVisibilityState(false);
4848

4949
// Input field state
50-
const [highlightTerm, setHighlightTerm] = useState('');
50+
const [highlightTerm, _setHighlightTerm] = useState('');
51+
5152
const debouncedOnChange = useMemo(() => debounce(onChange, 275), [onChange]);
53+
const setHighlightTerm = useCallback<typeof _setHighlightTerm>(
54+
valueOrUpdater =>
55+
_setHighlightTerm(previousHighlightTerm => {
56+
const newHighlightTerm =
57+
typeof valueOrUpdater === 'function'
58+
? valueOrUpdater(previousHighlightTerm)
59+
: valueOrUpdater;
60+
61+
if (newHighlightTerm !== previousHighlightTerm) {
62+
debouncedOnChange([newHighlightTerm]);
63+
}
64+
65+
return newHighlightTerm;
66+
}),
67+
[debouncedOnChange]
68+
);
5269
const changeHighlightTerm = useCallback(
5370
e => {
5471
const value = e.target.value;
@@ -57,9 +74,6 @@ export const LogHighlightsMenu: React.FC<LogHighlightsMenuProps> = ({
5774
[setHighlightTerm]
5875
);
5976
const clearHighlightTerm = useCallback(() => setHighlightTerm(''), [setHighlightTerm]);
60-
useEffect(() => {
61-
debouncedOnChange([highlightTerm]);
62-
}, [highlightTerm]);
6377

6478
const button = (
6579
<EuiButtonEmpty color="text" size="xs" iconType="brush" onClick={togglePopover}>

x-pack/legacy/plugins/infra/public/components/logging/log_text_stream/text_styles.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export const useMeasuredCharacterDimensions = (scale: TextScale) => {
6363
X
6464
</MonospaceCharacterDimensionsProbe>
6565
),
66-
[scale]
66+
[measureElement, scale]
6767
);
6868

6969
return {

x-pack/legacy/plugins/infra/public/components/metrics_explorer/metrics.tsx

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import { EuiComboBox } from '@elastic/eui';
88
import { i18n } from '@kbn/i18n';
99

10-
import React, { useCallback, useState, useEffect } from 'react';
10+
import React, { useCallback, useState } from 'react';
1111
import { FieldType } from 'ui/index_patterns';
1212
import { colorTransformer, MetricsExplorerColor } from '../../../common/color_palette';
1313
import {
@@ -31,24 +31,19 @@ interface SelectedOption {
3131

3232
export const MetricsExplorerMetrics = ({ options, onChange, fields, autoFocus = false }: Props) => {
3333
const colors = Object.keys(MetricsExplorerColor) as MetricsExplorerColor[];
34-
const [inputRef, setInputRef] = useState<HTMLInputElement | null>(null);
35-
const [focusOnce, setFocusState] = useState<boolean>(false);
34+
const [shouldFocus, setShouldFocus] = useState(autoFocus);
3635

37-
useEffect(() => {
38-
if (inputRef && autoFocus && !focusOnce) {
39-
inputRef.focus();
40-
setFocusState(true);
41-
}
42-
}, [inputRef]);
36+
// the EuiCombobox forwards the ref to an input element
37+
const autoFocusInputElement = useCallback(
38+
(inputElement: HTMLInputElement | null) => {
39+
if (inputElement && shouldFocus) {
40+
inputElement.focus();
41+
setShouldFocus(false);
42+
}
43+
},
44+
[shouldFocus]
45+
);
4346

44-
// I tried to use useRef originally but the EUIComboBox component's type definition
45-
// would only accept an actual input element or a callback function (with the same type).
46-
// This effectivly does the same thing but is compatible with EuiComboBox.
47-
const handleInputRef = (ref: HTMLInputElement) => {
48-
if (ref) {
49-
setInputRef(ref);
50-
}
51-
};
5247
const handleChange = useCallback(
5348
selectedOptions => {
5449
onChange(
@@ -59,7 +54,7 @@ export const MetricsExplorerMetrics = ({ options, onChange, fields, autoFocus =
5954
}))
6055
);
6156
},
62-
[options, onChange]
57+
[onChange, options.aggregation, colors]
6358
);
6459

6560
const comboOptions = fields
@@ -86,7 +81,7 @@ export const MetricsExplorerMetrics = ({ options, onChange, fields, autoFocus =
8681
selectedOptions={selectedOptions}
8782
onChange={handleChange}
8883
isClearable={true}
89-
inputRef={handleInputRef}
84+
inputRef={autoFocusInputElement}
9085
/>
9186
);
9287
};

x-pack/legacy/plugins/infra/public/components/saved_views/create_modal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const SavedViewCreateModal = ({ close, save, isInvalid }: Props) => {
3636

3737
const saveView = useCallback(() => {
3838
save(viewName, includeTime);
39-
}, [viewName, includeTime]);
39+
}, [includeTime, save, viewName]);
4040

4141
return (
4242
<EuiOverlayMask>

x-pack/legacy/plugins/infra/public/components/source_configuration/add_log_column_popover.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export const AddLogColumnButtonAndPopover: React.FunctionComponent<{
9494

9595
addLogColumn(selectedOption.columnConfiguration);
9696
},
97-
[addLogColumn, availableColumnOptions]
97+
[addLogColumn, availableColumnOptions, closePopover]
9898
);
9999

100100
return (

x-pack/legacy/plugins/infra/public/components/source_configuration/source_configuration_form_state.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const useSourceConfigurationFormState = (configuration?: SourceConfigurat
5252
const resetForm = useCallback(() => {
5353
indicesConfigurationFormState.resetForm();
5454
logColumnsConfigurationFormState.resetForm();
55-
}, [indicesConfigurationFormState.resetForm, logColumnsConfigurationFormState.formState]);
55+
}, [indicesConfigurationFormState, logColumnsConfigurationFormState]);
5656

5757
const isFormDirty = useMemo(
5858
() => indicesConfigurationFormState.isFormDirty || logColumnsConfigurationFormState.isFormDirty,

x-pack/legacy/plugins/infra/public/components/waffle/waffle_inventory_switcher.tsx

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,33 @@ import {
1717
} from '../../graphql/types';
1818
import { findInventoryModel } from '../../../common/inventory_models';
1919

20-
interface Props {
20+
interface WaffleInventorySwitcherProps {
2121
nodeType: InfraNodeType;
2222
changeNodeType: (nodeType: InfraNodeType) => void;
2323
changeGroupBy: (groupBy: InfraSnapshotGroupbyInput[]) => void;
2424
changeMetric: (metric: InfraSnapshotMetricInput) => void;
2525
}
2626

27-
export const WaffleInventorySwitcher = (props: Props) => {
27+
export const WaffleInventorySwitcher: React.FC<WaffleInventorySwitcherProps> = ({
28+
changeNodeType,
29+
changeGroupBy,
30+
changeMetric,
31+
nodeType,
32+
}) => {
2833
const [isOpen, setIsOpen] = useState(false);
2934
const closePopover = useCallback(() => setIsOpen(false), []);
3035
const openPopover = useCallback(() => setIsOpen(true), []);
3136
const goToNodeType = useCallback(
32-
(nodeType: InfraNodeType) => {
37+
(targetNodeType: InfraNodeType) => {
3338
closePopover();
34-
props.changeNodeType(nodeType);
35-
props.changeGroupBy([]);
36-
const inventoryModel = findInventoryModel(nodeType);
37-
props.changeMetric({
39+
changeNodeType(targetNodeType);
40+
changeGroupBy([]);
41+
const inventoryModel = findInventoryModel(targetNodeType);
42+
changeMetric({
3843
type: inventoryModel.metrics.defaultSnapshot as InfraSnapshotMetricType,
3944
});
4045
},
41-
[props.changeGroupBy, props.changeNodeType, props.changeMetric]
46+
[closePopover, changeNodeType, changeGroupBy, changeMetric]
4247
);
4348
const goToHost = useCallback(() => goToNodeType('host' as InfraNodeType), [goToNodeType]);
4449
const goToK8 = useCallback(() => goToNodeType('pod' as InfraNodeType), [goToNodeType]);
@@ -68,10 +73,10 @@ export const WaffleInventorySwitcher = (props: Props) => {
6873
],
6974
},
7075
],
71-
[]
76+
[goToDocker, goToHost, goToK8]
7277
);
7378
const selectedText = useMemo(() => {
74-
switch (props.nodeType) {
79+
switch (nodeType) {
7580
case InfraNodeType.host:
7681
return i18n.translate('xpack.infra.waffle.nodeTypeSwitcher.hostsLabel', {
7782
defaultMessage: 'Hosts',
@@ -81,7 +86,7 @@ export const WaffleInventorySwitcher = (props: Props) => {
8186
case InfraNodeType.container:
8287
return 'Docker';
8388
}
84-
}, [props.nodeType]);
89+
}, [nodeType]);
8590

8691
return (
8792
<EuiFilterGroup>

0 commit comments

Comments
 (0)