You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor(ui): Convert components from class to function components, pt 1 (#25759)
## Description
Second batch of the component conversion started in #25666 (please see
PR for background details). This focuses on the components in the
`components/` folder; due to the amount of components there and large
diffs, we will break up into a few separate PRs.
In addition, I also fixed what I assume is a bug related to displaying
the `LivePlan` component - previously, the function that sets up the D3
graph (`updateD3Graph`), was only called from `componentDidUpdate`, and
had a check on it:
```
componentDidUpdate(prevProps: LivePlanProps, prevState: LivePlanState) {
if (this.state.query !== prevState.query) {
this.updateD3Graph();
}
//$FlowFixMe
$('[data-bs-toggle="tooltip"]')?.tooltip?.()
}
```
However, after the first render, `this.state.query` and
`prevState.query` are both identical, causing `updateD3Graph` to only
run once. The problem is, that function has a condition where it sets up
the `svg` and then shorts out:
```
updateD3Graph() {
if (!this.state.svg) {
this.setState({
svg: initializeSvg("#plan-canvas"),
});
return;
}
...
```
Thus, it will only run once, only setting up `this.state.svg`, and then
shorting out, preventing the graph from being displayed. However, this
might be situational, as I have only tested this on finished queries -
maybe this is only supposed to show for running queries? I'm not sure,
but I have tested on master, and if you go into Query Details -> Live
Plan for a finished query, you will not see the chart. My refactoring
has resolved this, but please let me know if this is intended
functionality.
## Motivation and Context
Resolves item 12 in
[#21062](#21062); function
components are the new de-facto standard in react, and benefit from
ongoing optimizations in current and future react versions.
## Impact
UI
## Test Plan
Tested the UI interface extensively, checking all refactored components
and their interactions.
Components/interactions tested:
- ClusterHUD - including sparkline charts
- LivePlan - including bug fix for finished queries
- PageTitle
- SQLClientView, including running queries and other interactions
- StaticQueryHeader
- WorkerStatus, including sparkline charts
- WorkerThreadList
## Contributor checklist
- [x] Please make sure your submission complies with our [contributing
guide](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md),
in particular [code
style](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md#code-style)
and [commit
standards](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md#commit-standards).
- [x] PR description addresses the issue accurately and concisely. If
the change is non-trivial, a GitHub Issue is referenced.
- [x] Documented new properties (with its default value), SQL syntax,
functions, or other functionality.
- [x] If release notes are required, they follow the [release notes
guidelines](https://github.com/prestodb/presto/wiki/Release-Notes-Guidelines).
- [x] Adequate tests were added if applicable.
- [x] CI passed.
## Release Notes
```
== NO RELEASE NOTE ==
```
## Summary by Sourcery
Convert multiple React class components to function components using
hooks, consolidate helper logic into standalone functions, and fix
LivePlan D3 graph rendering for completed queries.
Bug Fixes:
- Fix LivePlan D3 graph initialization so the chart displays correctly
for finished queries.
Enhancements:
- Refactor WorkerStatus, WorkerThreadList, LivePlan (including
StageStatistics and PlanNode), PageTitle, ClusterHUD, SQLInput,
StaticQueryHeader, and SQLClientView into function components with
useState, useEffect, useRef, and useCallback hooks.
- Convert static methods and class utilities (e.g., status/thread
queries, thread processing, stage flattening) into standalone helper
functions for improved code clarity and modularity.
0 commit comments