Skip to content
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

Conversation

weltenwort
Copy link
Member

@weltenwort weltenwort commented Nov 18, 2019

Summary

This removes the two eslint exceptions specific to the infra plugin introduced in #49244.

fixes #49563

Notes

The changes fall into one of several categories:

  • Those that fix incorrect dependency lists by adding or removing values. This class of errors was mostly auto-fixable.
  • Those that avoid the hook with the incorrect dependency list altogether by refactoring the code. This mostly applies to useEffects and might have changed the semantics.
  • Those that fix violations of the hook call order invariant by moving the condition either to a parent component or beneath the hook calls.
  • Those that selectively disable the linter check because the situation can not be statically checked.
  • Those that temporarily disable the linter check until the corresponding hook has been refactored to correctly model the dataflow.

Checklist

@weltenwort weltenwort added Feature:Metrics UI Metrics UI feature v8.0.0 Feature:Logs UI Logs UI feature Team:Infra Monitoring UI - DEPRECATED DEPRECATED - Label for the Infra Monitoring UI team. Use Team:obs-ux-infra_services release_note:skip Skip the PR/issue when compiling release notes v7.6.0 labels Nov 18, 2019
@weltenwort weltenwort self-assigned this Nov 18, 2019
@elasticmachine
Copy link
Contributor

Pinging @elastic/logs-metrics-ui (Team:logs-metrics-ui)

@elasticmachine
Copy link
Contributor

💔 Build Failed

Instead of requiring separate `useEffect` usages to populate the URL
with the initial state, enhance `useUrlState` with the ability to
write back the default state to the URL if the `writeDefaultState`
option is true.
@weltenwort weltenwort force-pushed the logs-metrics-ui-remove-eslint-exceptions branch from 7daf5b4 to c366a36 Compare December 2, 2019 23:52
@elasticmachine
Copy link
Contributor

💔 Build Failed

@@ -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,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ The initialization is now handled by the useUrlState hook itself.

@@ -23,29 +23,25 @@ export const SubSection: FunctionComponent<SubSectionProps> = ({
isLiveStreaming,
stopLiveStreaming,
}) => {
if (!children || !metrics) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ This condition violated the hook call order invariant so it was moved further down below the hook calls.

}
return null;
}),
[children, metric, id, onChangeRangeTime, isLiveStreaming, stopLiveStreaming]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ Memoizing on children had no effect in this case because the parent always supplies a new list of React elements.

@@ -42,19 +42,15 @@ export const useMetricsTime = () => {
interval: '>=1m',
});

const parsedFrom = dateMath.parse(timeRange.from);
const parsedTo = dateMath.parse(timeRange.to, { roundUp: true });
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ This always produced a new Moment and thereby caused the memoization below to have no effect. It was therefore moved into the memoization function's body so the original value could be used as the memoization key.

}
}, [inputRef]);
// the EuiCombobox forwards the ref to an input element
const handleInputRef = useCallback(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ Since the stored Ref was not used anywhere the imperative action can just be performed in the already imperative ref callback.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rename it then to something on the line of focusInput()

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@weltenwort weltenwort marked this pull request as ready for review December 3, 2019 14:56
@weltenwort weltenwort requested a review from a team as a code owner December 3, 2019 14:56
@weltenwort
Copy link
Member Author

I would appreciate a look at the metric explorer fixes by someone more familiar with the intended semantics. Some of the required fixes were a bit more extensive, especially those were the calls were conditionally called.

addNavItem(item: NavItem): void;
setRefreshInterval(refreshInterval: number): void;
setAutoReload(isAutoReloading: boolean): void;
triggerRefresh(): void;
setTimeRange(timeRange: MetricsTimeInput): void;
}
export const NodeDetailsPage = (props: Props) => {
if (!props.metadata) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ This condition broke the hook call order invariant so it was moved to the parent component.

triggerRefresh={triggerRefresh}
setTimeRange={setTimeRange}
/>
{metadata ? (
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ This was moved up from the NodeDetailsPage component to fix the conditional hook usage. There's probably a better way of handling this than not rendering anything, but that's what the component itself did (@simianhacker @phillipb).

@afgomez afgomez self-requested a review December 10, 2019 08:42
Copy link
Contributor

@afgomez afgomez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logs changes LGTM

}
}, [inputRef]);
// the EuiCombobox forwards the ref to an input element
const handleInputRef = useCallback(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rename it then to something on the line of focusInput()

Copy link
Contributor

@phillipb phillipb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all looks really good. Not totally sure how I feel about useEffect needing to specify all of its deps, but it appears there's already a rich thread of folks talking through this facebook/create-react-app#6880. It'll probably just take me a bit to wrap my head around it.

if (!metric) {
if (!id) {
return null;
} else if (!metric) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♂looks right to me

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@weltenwort weltenwort merged commit 0cd62ca into elastic:master Dec 11, 2019
@weltenwort weltenwort deleted the logs-metrics-ui-remove-eslint-exceptions branch December 11, 2019 12:48
jloleysens added a commit to jloleysens/kibana that referenced this pull request Dec 11, 2019
…le-sql-highlighting

* 'master' of github.com:elastic/kibana: (56 commits)
  Migrate url shortener service (elastic#50896)
  Re-enable datemath in from/to canvas timelion args (elastic#52159)
  [Logs + Metrics UI] Remove eslint exceptions (elastic#50979)
  [Logs + Metrics UI] Add missing headers in Logs & metrics (elastic#52405)
  [ML] API integration tests - initial tests for bucket span estimator (elastic#52636)
  [Watcher] New Platform (NP) Migration (elastic#50908)
  Decouple Authorization subsystem from Legacy API. (elastic#52638)
  [APM] Fix some warnings logged in APM tests (elastic#52487)
  [ui/public/utils] Delete unused base_object & find_by_param (elastic#52500)
  [ui/public/utils] Move items into ui/vis (elastic#52615)
  fix newlines in kbn-analytics build script
  Add top level examples folder and command to run, `--run-examples`. (elastic#52027)
  feat(NA): add trap for SIGINT in the git precommit hook (elastic#52662)
  [DOCS] Updtes description of elasticsearch.requestHeadersWhitelist (elastic#52675)
  [Telemetry/Pulse] Updates advanced settings text for usage data (elastic#52657)
  [SIEM][Detection Engine] Adds the default name space to the end of the signals index
  [Logs UI] Generalize ML module management (elastic#50662)
  Removing stateful saved object finder (elastic#52166)
  Shim oss telemetry (elastic#51168)
  [Reporting/Screenshots] Do not fail the report if request is aborted (elastic#52344)
  ...

# Conflicts:
#	src/legacy/core_plugins/console/public/legacy.ts
#	src/legacy/core_plugins/console/public/np_ready/application/models/legacy_core_editor/mode/elasticsearch_sql_highlight_rules.ts
#	src/legacy/core_plugins/console/public/np_ready/lib/autocomplete/components/full_request_component.ts
#	src/legacy/core_plugins/console/public/quarantined/src/sense_editor/row_parser.js
@weltenwort
Copy link
Member Author

weltenwort commented Dec 12, 2019

backport to 7.x blocked by #52582 (not anymore)

weltenwort added a commit to weltenwort/kibana that referenced this pull request Dec 12, 2019
This removes the two eslint exceptions specific to the `infra` plugin introduced in elastic#49244.

fixes elastic#49563
weltenwort added a commit that referenced this pull request Dec 12, 2019
Backports the following commits to 7.x:
 - [Logs + Metrics UI] Remove eslint exceptions (#50979)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Logs UI Logs UI feature Feature:Metrics UI Metrics UI feature release_note:skip Skip the PR/issue when compiling release notes Team:Infra Monitoring UI - DEPRECATED DEPRECATED - Label for the Infra Monitoring UI team. Use Team:obs-ux-infra_services v7.6.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove temporary x-pack/legacy/plugins/infra eslint overrides
4 participants