Skip to content

Commit 9297555

Browse files
authored
refactor: Replace Flow with Typescript (prestodb#26573)
## Description <!---Describe your changes in detail--> This removes flow, and replaces it with typescript, and is the next step in the plan laid out in prestodb#25716 (comment) ## Motivation and Context <!---Why is this change required? What problem does it solve?--> <!---If it fixes an open issue, please link to the issue here.--> Typescript has better tooling, and has a bigger community around it so this will be another QOL improvement for developers. Big # line changes is mostly yarn-lock changes, the code diff relatively small ## Impact <!---Describe any public API or user-facing feature change or any performance impact--> ## Test Plan <!---Please fill in how you tested your change--> CI passes, there should be no user facing changes ## Contributor checklist - [ ] 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). - [ ] PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced. - [ ] Documented new properties (with its default value), SQL syntax, functions, or other functionality. - [ ] If release notes are required, they follow the [release notes guidelines](https://github.com/prestodb/presto/wiki/Release-Notes-Guidelines). - [ ] Adequate tests were added if applicable. - [ ] CI passed. - [ ] If adding new dependencies, verified they have an [OpenSSF Scorecard](https://securityscorecards.dev/#the-checks) score of 5.0 or higher (or obtained explicit TSC approval for lower scores). ## Release Notes Please follow [release notes guidelines](https://github.com/prestodb/presto/wiki/Release-Notes-Guidelines) and fill in the release notes below. ``` == NO RELEASE NOTE == ```
1 parent a070982 commit 9297555

20 files changed

+1306
-1059
lines changed

presto-ui/bin/check_webui.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ fi
2929

3030
popd
3131

32-
# Fail on flow warnings
32+
# Fail on typescript warnings
3333

34-
if ! yarn --cwd ${WEBUI_ROOT}/ run flow; then
35-
echo "ERROR: Flow found type errors while performing static analysis"
34+
if ! yarn --cwd ${WEBUI_ROOT}/ run typecheck; then
35+
echo "ERROR: Typescript type errors found"
3636
exit 1
3737
fi
3838

presto-ui/src/components/LivePlan.jsx renamed to presto-ui/src/components/LivePlan.tsx

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
* See the License for the specific language governing permissions and
1212
* limitations under the License.
1313
*/
14-
//@flow
1514

1615
import React, { useState, useEffect, useRef, useCallback } from "react";
1716
import ReactDOMServer from "react-dom/server";
@@ -23,27 +22,27 @@ import { initializeGraph, initializeSvg } from "../d3utils";
2322
import { QueryHeader } from "./QueryHeader";
2423

2524
type StageStatisticsProps = {
26-
stage: any,
25+
stage: any;
2726
};
2827
export type StageNodeInfo = {
29-
stageId: string,
30-
id: string,
31-
root: string,
32-
distribution: any,
33-
stageStats: any,
34-
state: string,
35-
nodes: Map<string, any>,
28+
stageId: string;
29+
id: string;
30+
root: string;
31+
distribution: any;
32+
stageStats: any;
33+
state: string;
34+
nodes: Map<string, any>;
3635
};
3736

3837
type OutputStage = {
39-
subStages: any,
40-
stageId: string,
41-
latestAttemptExecutionInfo: any,
42-
plan: any,
38+
subStages: any;
39+
stageId: string;
40+
latestAttemptExecutionInfo: any;
41+
plan: any;
4342
};
4443

4544
type QueryInfo = {
46-
outputStage: OutputStage,
45+
outputStage: OutputStage;
4746
};
4847

4948
function getStages(queryInfo: QueryInfo): Map<string, StageNodeInfo> {
@@ -86,7 +85,7 @@ function flattenNode(stages: any, rootNodeInfo: any, node: any, result: Map<any,
8685
});
8786
}
8887

89-
export const StageStatistics = (props: StageStatisticsProps): React.Node => {
88+
export const StageStatistics = (props: StageStatisticsProps): React.ReactElement => {
9089
const { stage } = props;
9190
const stats = stage.stageStats;
9291
return (
@@ -121,15 +120,15 @@ export const StageStatistics = (props: StageStatisticsProps): React.Node => {
121120
StageStatistics.getStages = getStages;
122121

123122
type PlanNodeProps = {
124-
id: string,
125-
name: string,
126-
identifier: string,
127-
details: string,
128-
sources: string[],
129-
remoteSources: string[],
123+
id: string;
124+
name: string;
125+
identifier: string;
126+
details: string;
127+
sources: string[];
128+
remoteSources: string[];
130129
};
131130

132-
export const PlanNode = (props: PlanNodeProps): React.Node => {
131+
export const PlanNode = (props: PlanNodeProps): React.ReactElement => {
133132
return (
134133
<div
135134
style={{ color: "#000" }}
@@ -146,28 +145,27 @@ export const PlanNode = (props: PlanNodeProps): React.Node => {
146145
};
147146

148147
type LivePlanProps = {
149-
queryId: string,
150-
isEmbedded: boolean,
148+
queryId: string;
149+
isEmbedded: boolean;
151150
};
152151

153152
type LivePlanState = {
154-
initialized: boolean,
155-
ended: boolean,
156-
query: ?any,
153+
initialized: boolean;
154+
ended: boolean;
155+
query: any | null | undefined;
157156
};
158157

159-
export const LivePlan = (props: LivePlanProps): React.Node => {
158+
export const LivePlan = (props: LivePlanProps): React.ReactElement => {
160159
const [state, setState] = useState<LivePlanState>({
161160
initialized: false,
162161
ended: false,
163162
query: null,
164163
});
165164

166-
const timeoutId = useRef<TimeoutID | null>(null);
165+
const timeoutId = useRef<number | null>(null);
167166
const graphRef = useRef(initializeGraph());
168-
// $FlowFixMe: Flow is not recognizing the SVGSVGElement type
169167
const svgRef = useRef<any>(null);
170-
const renderRef = useRef(new dagreD3.render());
168+
const renderRef = useRef(dagreD3.render());
171169

172170
const refreshLoop: () => void = useCallback(() => {
173171
clearTimeout(timeoutId.current); // to stop multiple series of refreshLoop from going on simultaneously
@@ -179,7 +177,7 @@ export const LivePlan = (props: LivePlanProps): React.Node => {
179177
if (ended) {
180178
clearTimeout(timeoutId.current);
181179
} else {
182-
timeoutId.current = setTimeout(refreshLoop, 1000);
180+
timeoutId.current = window.setTimeout(refreshLoop, 1000);
183181
}
184182
return {
185183
...prevState,
@@ -194,7 +192,7 @@ export const LivePlan = (props: LivePlanProps): React.Node => {
194192
...prevState,
195193
initialized: true,
196194
}));
197-
timeoutId.current = setTimeout(refreshLoop, 1000);
195+
timeoutId.current = window.setTimeout(refreshLoop, 1000);
198196
});
199197
}, [props.queryId]);
200198

@@ -322,7 +320,7 @@ export const LivePlan = (props: LivePlanProps): React.Node => {
322320

323321
useEffect(() => {
324322
updateD3Graph();
325-
//$FlowFixMe
323+
// @ts-expect-error - Bootstrap tooltip plugin not in jQuery types
326324
$('[data-bs-toggle="tooltip"]')?.tooltip?.();
327325
}, [state.query, state.ended]);
328326

presto-ui/src/components/PageTitle.jsx renamed to presto-ui/src/components/PageTitle.tsx

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,22 @@
1111
* See the License for the specific language governing permissions and
1212
* limitations under the License.
1313
*/
14-
//@flow
1514
import React, { useState, useEffect, useRef } from "react";
1615

1716
type Props = {
18-
titles: string[],
19-
urls?: string[],
20-
current?: number,
21-
path?: string,
17+
titles: string[];
18+
urls?: string[];
19+
current?: number;
20+
path?: string;
2221
};
2322

2423
type State = {
25-
noConnection: boolean,
26-
lightShown: boolean,
27-
info: ?any,
28-
lastSuccess: number,
29-
modalShown: boolean,
30-
errorText: ?string,
24+
noConnection: boolean;
25+
lightShown: boolean;
26+
info: any | null | undefined;
27+
lastSuccess: number;
28+
modalShown: boolean;
29+
errorText: string | null | undefined;
3130
};
3231

3332
const ClusterResourceGroupNavBar = ({ titles, urls, current = 0 }: Props) => {
@@ -50,7 +49,7 @@ const isOffline = () => {
5049
return window.location.protocol === "file:";
5150
};
5251

53-
export const PageTitle = (props: Props): React.Node => {
52+
export const PageTitle = (props: Props): React.ReactElement => {
5453
const [state, setState] = useState<State>({
5554
noConnection: false,
5655
lightShown: false,
@@ -60,7 +59,7 @@ export const PageTitle = (props: Props): React.Node => {
6059
errorText: null,
6160
});
6261

63-
const timeoutId = useRef<TimeoutID | null>(null);
62+
const timeoutId = useRef<number | null>(null);
6463

6564
const refreshLoop = () => {
6665
clearTimeout(timeoutId.current);
@@ -74,9 +73,8 @@ export const PageTitle = (props: Props): React.Node => {
7473
lastSuccess: Date.now(),
7574
modalShown: false,
7675
}));
77-
//$FlowFixMe$ Bootstrap 5 plugin
7876
$("#no-connection-modal").hide();
79-
timeoutId.current = setTimeout(refreshLoop, 1000);
77+
timeoutId.current = window.setTimeout(refreshLoop, 1000);
8078
})
8179
.catch((error) => {
8280
setState((prevState) => {
@@ -87,11 +85,11 @@ export const PageTitle = (props: Props): React.Node => {
8785
!prevState.modalShown && (error || Date.now() - prevState.lastSuccess > 30 * 1000);
8886

8987
if (shouldShowModal) {
90-
//$FlowFixMe$ Bootstrap 5 plugin
88+
// @ts-expect-error - Bootstrap modal plugin not in jQuery types
9189
$("#no-connection-modal").modal("show");
9290
}
9391

94-
timeoutId.current = setTimeout(refreshLoop, 1000);
92+
timeoutId.current = window.setTimeout(refreshLoop, 1000);
9593

9694
return {
9795
...prevState,
@@ -207,7 +205,7 @@ export const PageTitle = (props: Props): React.Node => {
207205
</div>
208206
</div>
209207
</nav>
210-
<div id="no-connection-modal" className="modal" tabIndex="-1" role="dialog">
208+
<div id="no-connection-modal" className="modal" tabIndex={-1} role="dialog">
211209
<div className="modal-dialog modal-sm" role="document">
212210
<div className="modal-content">
213211
<div className="row error-message">

presto-ui/src/components/QueryDetail.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* limitations under the License.
1313
*/
1414

15-
import React, { useState, useEffect, useRef } from "react";
15+
import { useState, useEffect, useRef } from "react";
1616
import DataTable, { createTheme } from "react-data-table-component";
1717

1818
import {

0 commit comments

Comments
 (0)