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

React 18 #6902

Closed
wants to merge 40 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
b6c50ae
Update babel dependencies and configuration
steve9164 May 28, 2023
5c17326
Upgrade React to v18
steve9164 May 28, 2023
68b9c7e
Convert type assertions to "as" syntax
steve9164 May 28, 2023
7ed527a
Convert some type assertions that failed jscodeshift
steve9164 May 28, 2023
6f9a936
Convert type assertions to "as" syntax in tests
steve9164 May 28, 2023
25ca4f2
Update yarn lockfile
steve9164 May 28, 2023
1f5f618
Typescript fixes
steve9164 Sep 22, 2023
3d062f9
Run react-codemod update-react-imports
steve9164 Sep 22, 2023
ed09de2
Fix collision on global declaration between @types/dompurify dependen…
steve9164 Sep 22, 2023
04a3d1b
Fix other Typescript problems
steve9164 Sep 22, 2023
8d40587
Ensure that typescript is looking for types in node_modules
steve9164 Sep 22, 2023
ced3cf1
Extend tsconfig-node from default tsconfig so that typeRoots (and oth…
steve9164 Sep 22, 2023
ec350bb
Revert before merging; use react-18 TerriaMap branch
steve9164 Sep 27, 2023
c59eeb0
Fix eslint for React 17 and remove some instances of using unknown pr…
steve9164 Sep 27, 2023
17b873c
Remove some console logs from tests
steve9164 Sep 27, 2023
50e8575
Upgrade testing packages
steve9164 Sep 28, 2023
b3fa111
Allow rendering DragWrapper without DOM in test environment
steve9164 Sep 28, 2023
fc628b3
The ReactNode type already includes arrays, so make it also support s…
steve9164 Sep 28, 2023
70806c5
Ensure consistency when panel mounts before terria.pickedFeatures cha…
steve9164 Sep 28, 2023
d9b561e
Fix tests
steve9164 Sep 28, 2023
aa5a8bc
Update yarn lockfile
steve9164 Sep 28, 2023
1908915
Pass lint
steve9164 Sep 28, 2023
a86852a
Switch tests from release build to dev build
steve9164 Sep 28, 2023
e7f1706
Remove dodgy test
steve9164 Sep 28, 2023
d63f001
Use proper syled components, and add simple render regression tests
steve9164 Oct 13, 2023
ca90f20
Merge remote-tracking branch 'origin/main' into react18-sd
steve9164 Oct 16, 2023
f06d278
Remove React import
steve9164 Oct 16, 2023
2452ce4
Add typescript out directory to ignore files
steve9164 Oct 17, 2023
0cb7446
Type errors have fixed themselves?
steve9164 Oct 17, 2023
a0accef
Remove ViewState from component that doesn't use it
steve9164 Oct 30, 2023
629e0db
Merge remote-tracking branch 'origin/main' into react18-sd
steve9164 Nov 2, 2023
5d92e92
Remove uses of import * as React and uses of React.FC
steve9164 Nov 15, 2023
e6d5549
Update terriajs-server gulp task
steve9164 Nov 15, 2023
68d7d65
Organise imports
steve9164 Nov 15, 2023
b3f42ff
Fix React import for React 18
steve9164 Nov 15, 2023
9c2fb34
Wrap in ViewState context
steve9164 Nov 15, 2023
b41eb61
Upgrade mobx-react and update MomentPointsChart
steve9164 Nov 22, 2023
b3c8160
Convert Chart files from jsx + mobx to React functional tsx
steve9164 Dec 1, 2023
cee9235
Remove unnecessary condition and match conditionals
steve9164 Dec 3, 2023
d497b3e
Add function name
steve9164 Dec 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"useBuiltIns": "usage"
}
],
"@babel/preset-react",
["@babel/preset-react", { "runtime": "automatic" }],
["@babel/typescript", { "allowNamespaces": true }]
],
"plugins": [
Expand Down
9 changes: 8 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"extends": ["eslint:recommended", "plugin:react/recommended"],
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:react/jsx-runtime"
],
"parser": "@babel/eslint-parser",
"parserOptions": {
"requireConfigFile": false,
Expand Down Expand Up @@ -27,6 +31,9 @@
"rules": {
"react/jsx-no-undef": 0,

/* Ignore styled-components css property */
"react/no-unknown-property": ["error", { "ignore": ["css"] }],

/*Possible Errors */
"no-cond-assign": [1, "except-parens"],
"no-console": 0,
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ jobs:
run: yarn prettier-check

- name: Build TerriaJS tests
run: yarn gulp lint release -- --continue
id: lint_build_spec
run: yarn gulp lint build -- --continue
env:
NODE_OPTIONS: --max_old_space_size=4096

# Run on failure of gulp lint build, in case it's a lint failure
- name: Run tests using xvfb
uses: GabrielBB/xvfb-action@v1
if: ${{success() || steps.lint_build_spec.outcome == 'failure'}}
with:
run: yarn gulp test-firefox
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Update .prettierignore whenever this file changes
docs/
node_modules/
.idea/
Expand All @@ -17,6 +18,7 @@ package-lock.json
*.swp
dist
.history/
ts-out/

# Catalog index generation files
catalog-index*.json
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package-lock.json
*.swp
dist
.history/
ts-out/

# Catalog index generation files
catalog-index*.json
Expand Down
2 changes: 1 addition & 1 deletion buildprocess/ci-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ npm install -g yarn@^1.19.0

# Clone and build TerriaMap, using this version of TerriaJS
TERRIAJS_COMMIT_HASH=$(git rev-parse HEAD)
git clone -b main https://github.com/TerriaJS/TerriaMap.git
git clone -b react-18 https://github.com/TerriaJS/TerriaMap.git
cd TerriaMap
TERRIAMAP_COMMIT_HASH=$(git rev-parse HEAD)
sed -i -e 's@"terriajs": ".*"@"terriajs": "'$GITHUB_REPOSITORY'#'${GITHUB_BRANCH}'"@g' package.json
Expand Down
2 changes: 1 addition & 1 deletion buildprocess/configureWebpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function configureWebpack(
useBuiltIns: "usage"
}
],
"@babel/preset-react",
["@babel/preset-react", { runtime: "automatic" }],
["@babel/typescript", { allowNamespaces: true }]
],
plugins: [
Expand Down
72 changes: 72 additions & 0 deletions buildprocess/terriajsServerGulpTask.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//@ts-check
/**
* terriajs-server gulp task. Runs terriajs-server.
* Used in terriajs & TerriaMap gulpfiles.
* @param {number | undefined} defaultPort - the default port that terriajs-server should run on
* @returns {(done: (error?: Error) => void) => void} A gulp task
*/
const terriajsServerGulpTask = (defaultPort = undefined) => {
return (done) => {
// E.g. gulp terriajs-server --terriajsServerArg port=4000 --terriajsServerArg verbose=true
// or gulp dev --terriajsServerArg port=3000
const { spawn } = require("child_process");
const fs = require("fs");
const minimist = require("minimist");
// Arguments written in skewer-case can cause problems (unsure why), so stick to camelCase
const options = minimist(process.argv.slice(2), {
string: ["terriajsServerArg"],
default: { terriajsServerArg: [] }
});

const logFile = fs.openSync("./terriajs-server.log", "w");
const serverArgs = Array.isArray(options.terriajsServerArg)
? options.terriajsServerArg
: [options.terriajsServerArg];
if (defaultPort !== undefined) {
serverArgs.splice(0, 0, `port=${defaultPort}`);
}
const child = spawn(
"node",
[
require.resolve("terriajs-server/terriajs-server.js"),
...serverArgs.map((arg) => `--${arg}`)
],
{ detached: true, stdio: ["ignore", logFile, logFile] }
);
child.on("exit", (exitCode, signal) => {
done(
new Error(
"terriajs-server quit" +
(exitCode !== null ? ` with exit code: ${exitCode}` : "") +
(signal ? ` from signal: ${signal}` : "") +
"\nCheck terriajs-server.log for more information."
)
);
});
child.on("spawn", () => {
console.log("terriajs-server started - see terriajs-server.log for logs");
});
// Intercept SIGINT, SIGTERM and SIGHUP, cleanup terriajs-server and re-send signal
// May fail to catch some relevant signals on Windows
// SIGINT: ctrl+c
// SIGTERM: kill <pid>
// SIGHUP: terminal closed
process.once("SIGINT", () => {
child.kill("SIGTERM");
process.kill(process.pid, "SIGINT");
});
process.once("SIGTERM", () => {
child.kill("SIGTERM");
process.kill(process.pid, "SIGTERM");
});
process.once("SIGHUP", () => {
child.kill("SIGTERM");
process.kill(process.pid, "SIGHUP");
});
process.on("exit", () => {
child.kill("SIGTERM");
});
};
};

module.exports = terriajsServerGulpTask;
3 changes: 0 additions & 3 deletions doc/contributing/translation-guide-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ It gets the `t` function and `i18n` instance inside your **functional components
**Usage**

```js
import React from "react";
import { useTranslation } from "react-i18next";

export function MyComponent() {
Expand All @@ -33,7 +32,6 @@ The `withTranslation` is a classic HOC (higher order component) and gets the `t`
**Usage**

```js
import React from "react";
import { withTranslation } from "react-i18next";

function MyComponent({ t, i18n }) {
Expand All @@ -52,7 +50,6 @@ While the Trans component gives you a lot of power by letting you interpolate or
As long you have no react nodes you like to be integrated into a translated text (text formatting, like strong, i, ...) or adding some link component - you won't need it - most can be done by using the good old t function.

```js
import React from "react";
import { Trans, useTranslation } from "react-i18next";

function MyComponent() {
Expand Down
4 changes: 1 addition & 3 deletions doc/customizing/skinning.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ This file creates the main user interface, using [React](https://facebook.github
For example, here's a version that includes an extra menu that links to terria.io, and adds the measure tool to the navigation area:

```javascript
import React from "react";

import version from "../../version";

import StandardUserInterface from "terriajs/lib/ReactViews/StandardUserInterface/StandardUserInterface.jsx";
import StandardUserInterface from "terriajs/lib/ReactViews/StandardUserInterface/StandardUserInterface";
import MenuItem from "terriajs/lib/ReactViews/StandardUserInterface/customizable/MenuItem";
import RelatedMaps from "./RelatedMaps";
import {
Expand Down
60 changes: 2 additions & 58 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// the devDependencies available. Individual tasks, other than `post-npm-install` and any tasks it
// calls, may require in `devDependency` modules locally.
var gulp = require("gulp");
var terriajsServerGulpTask = require("./buildprocess/terriajsServerGulpTask");

gulp.task("build-specs", function (done) {
var runWebpack = require("./buildprocess/runWebpack.js");
Expand Down Expand Up @@ -227,64 +228,7 @@ gulp.task(
)
);

gulp.task("terriajs-server", function (done) {
// E.g. gulp terriajs-server --terriajsServerArg port=4000 --terriajsServerArg verbose=true
// or gulp dev --terriajsServerArg port=3000
const { spawn } = require("child_process");
const fs = require("fs");
const minimist = require("minimist");

const knownOptions = {
string: ["terriajsServerArg"],
default: {
terriajsServerArg: []
}
};
const options = minimist(process.argv.slice(2), knownOptions);

const logFile = fs.openSync("./terriajs-server.log", "a");
const serverArgs = Array.isArray(options.terriajsServerArg)
? options.terriajsServerArg
: [options.terriajsServerArg];
// Spawn detached - attached does not make terriajs-server
// quit when the gulp task is stopped
const child = spawn(
"node",
[
"./node_modules/.bin/terriajs-server",
"--port=3002",
...serverArgs.map((arg) => `--${arg}`)
],
{ detached: true, stdio: ["ignore", logFile, logFile] }
);
child.on("exit", (exitCode, signal) => {
done(
new Error(
"terriajs-server quit" +
(exitCode !== null ? ` with exit code: ${exitCode}` : "") +
(signal ? ` from signal: ${signal}` : "") +
"\nCheck terriajs-server.log for more information."
)
);
});
// Intercept SIGINT, SIGTERM and SIGHUP, cleanup terriajs-server and re-send signal
// May fail to catch some relevant signals on Windows
// SIGINT: ctrl+c
// SIGTERM: kill <pid>
// SIGHUP: terminal closed
process.once("SIGINT", () => {
child.kill("SIGTERM");
process.kill(process.pid, "SIGINT");
});
process.once("SIGTERM", () => {
child.kill("SIGTERM");
process.kill(process.pid, "SIGTERM");
});
process.once("SIGHUP", () => {
child.kill("SIGTERM");
process.kill(process.pid, "SIGHUP");
});
});
gulp.task("terriajs-server", terriajsServerGulpTask(3002));

gulp.task("build", gulp.series("copy-cesium-assets", "build-specs"));
gulp.task("release", gulp.series("copy-cesium-assets", "release-specs"));
Expand Down
10 changes: 4 additions & 6 deletions lib/Charts/ChartView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ export default class ChartView {

@computed
get chartableItems(): ChartableMixin.Instance[] {
return <any>(
this.terria.workbench.items.filter(
(item) => ChartableMixin.isMixedInto(item) && item.chartItems.length > 0
)
);
return this.terria.workbench.items.filter(
(item) => ChartableMixin.isMixedInto(item) && item.chartItems.length > 0
) as any;
}

/**
Expand All @@ -32,7 +30,7 @@ export default class ChartView {
for (let i = 0; i < this.chartableItems.length; i++) {
for (let j = 0; j < this.chartableItems[i].chartItems.length; j++) {
const chartItem = this.chartableItems[i].chartItems[j];
if (chartItem.isSelectedInWorkbench && chartItem.showInChartPanel) {
if (chartItem.showInChartPanel) {
return chartItem.xAxis;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Core/instanceOf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ export default function instanceOf<T>(
type: Class<T>,
instance: any
): instance is T {
return instance instanceof <any>type;
return instance instanceof (type as any);
}
2 changes: 1 addition & 1 deletion lib/Core/markdownToHtml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function markdownToHtml(
// (typeof string === 'string'). So if this isn't a string primitive, call toString
// on it in order to make it one.
if (markdownString && typeof markdownString !== "string") {
stringToParse = (<any>markdownString).toString();
stringToParse = (markdownString as any).toString();
}
if (markdownOptions.injectTermsAsTooltips && markdownOptions.tooltipTerms) {
stringToParse = injectTerms(stringToParse, markdownOptions.tooltipTerms);
Expand Down
4 changes: 2 additions & 2 deletions lib/Map/Cesium/CesiumRenderLoopPauser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,14 +305,14 @@ export default class CesiumRenderLoopPauser {

const cameraMovedInLastSecond = now - this._lastCameraMoveTime < 1000;

const surface = (<any>scene.globe)._surface;
const surface = (scene.globe as any)._surface;
const terrainTilesWaiting =
!surface._tileProvider.ready ||
surface._tileLoadQueueHigh.length > 0 ||
surface._tileLoadQueueMedium.length > 0 ||
surface._tileLoadQueueLow.length > 0 ||
surface._debug.tilesWaitingForChildren > 0;
const tweens = (<any>scene).tweens;
const tweens = (scene as any).tweens;

if (
!cameraMovedInLastSecond &&
Expand Down
20 changes: 10 additions & 10 deletions lib/Map/ImageryProvider/MapboxVectorTileImageryProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,35 +185,35 @@ export default class MapboxVectorTileImageryProvider
get credit(): Credit {
let credit = this._credit;
if (credit === undefined) {
return <any>undefined;
return undefined as any;
} else if (typeof credit === "string") {
credit = new Credit(credit);
}
return credit;
}

get defaultAlpha(): number {
return <any>undefined;
return undefined as any;
}

get defaultBrightness(): number {
return <any>undefined;
return undefined as any;
}

get defaultContrast(): number {
return <any>undefined;
return undefined as any;
}

get defaultGamma(): number {
return <any>undefined;
return undefined as any;
}

get defaultHue(): number {
return <any>undefined;
return undefined as any;
}

get defaultSaturation(): number {
return <any>undefined;
return undefined as any;
}

get defaultMagnificationFilter(): any {
Expand All @@ -225,15 +225,15 @@ export default class MapboxVectorTileImageryProvider
}

get proxy(): DefaultProxy {
return <any>undefined;
return undefined as any;
}

get readyPromise(): Promise<boolean> {
return Promise.resolve(true);
}

get tileDiscardPolicy(): TileDiscardPolicy {
return <any>undefined;
return undefined as any;
}

getTileCredits(x: number, y: number, level: number): Credit[] {
Expand Down Expand Up @@ -326,7 +326,7 @@ export default class MapboxVectorTileImageryProvider

let pos;

let extentFactor = canvas.width / (<any>layer).extent; // Vector tile works with extent [0, 4095], but canvas is only [0,255]
let extentFactor = canvas.width / (layer as any).extent; // Vector tile works with extent [0, 4095], but canvas is only [0,255]

// Features
for (let i = 0; i < layer.length; i++) {
Expand Down
Loading
Loading