From 75c10c12f52afeafccc521595f87d0d71ac170b1 Mon Sep 17 00:00:00 2001 From: Laetitia Fesselier Date: Tue, 1 Jun 2021 14:21:23 -0400 Subject: [PATCH] Flow -> TypeScript conversion --- babel.config.js | 1 - .../jsx/react-series-data-viewer/.flowconfig | 15 ----- .../jsx/react-series-data-viewer/README.md | 2 +- .../jsx/react-series-data-viewer/package.json | 9 +-- .../src/ajax/index.js | 23 ------- .../src/ajax/index.tsx | 23 +++++++ .../src/chunks/{index.js => index.tsx} | 1 - .../src/color/{index.js => index.tsx} | 2 - ...esProvider.js => EEGLabSeriesProvider.tsx} | 30 ++++++--- .../{AnnotationForm.js => AnnotationForm.tsx} | 44 ++++++++----- .../series/components/{Axis.js => Axis.tsx} | 10 ++- .../{EEGMontage.js => EEGMontage.tsx} | 26 ++++---- .../series/components/{Epoch.js => Epoch.tsx} | 9 ++- .../{EventManager.js => EventManager.tsx} | 23 ++++--- .../{IntervalSelect.js => IntervalSelect.tsx} | 35 +++++----- .../{LineChunk.js => LineChunk.tsx} | 14 ++-- ...sponsiveViewer.js => ResponsiveViewer.tsx} | 28 ++++---- .../{SeriesCursor.js => SeriesCursor.tsx} | 14 ++-- .../{SeriesRenderer.js => SeriesRenderer.tsx} | 66 +++++++++---------- .../{components.js => components.tsx} | 0 .../src/series/store/{index.js => index.tsx} | 4 +- .../logic/{dragBounds.js => dragBounds.tsx} | 8 +-- .../logic/{fetchChunks.js => fetchChunks.tsx} | 25 ++++--- .../{filterEpochs.js => filterEpochs.tsx} | 10 ++- .../logic/{highLowPass.js => highLowPass.tsx} | 12 ++-- .../logic/{pagination.js => pagination.tsx} | 10 ++- ...scaleAmplitudes.js => scaleAmplitudes.tsx} | 9 ++- .../{timeSelection.js => timeSelection.tsx} | 10 +-- .../store/state/{bounds.js => bounds.tsx} | 12 ++-- .../store/state/{channel.js => channel.tsx} | 6 +- .../store/state/{cursor.js => cursor.tsx} | 8 +-- .../store/state/{dataset.js => dataset.tsx} | 14 ++-- .../store/state/{filters.js => filters.tsx} | 16 ++--- .../store/state/{montage.js => montage.tsx} | 6 +- .../state/{rightPanel.js => rightPanel.tsx} | 6 +- .../{timeSelection.js => timeSelection.tsx} | 8 +-- .../src/series/store/{types.js => types.tsx} | 8 +-- .../src/vector/{index.js => index.tsx} | 4 +- .../php/models/electrophysiofile.class.inc | 60 +++++++++++------ .../php/sessions.class.inc | 32 +++++---- .../php/split_data.class.inc | 12 ++-- package.json | 3 +- tsconfig.json | 20 ++++++ webpack.config.js | 9 ++- 44 files changed, 349 insertions(+), 338 deletions(-) delete mode 100644 modules/electrophysiology_browser/jsx/react-series-data-viewer/.flowconfig delete mode 100644 modules/electrophysiology_browser/jsx/react-series-data-viewer/src/ajax/index.js create mode 100644 modules/electrophysiology_browser/jsx/react-series-data-viewer/src/ajax/index.tsx rename modules/electrophysiology_browser/jsx/react-series-data-viewer/src/chunks/{index.js => index.tsx} (98%) rename modules/electrophysiology_browser/jsx/react-series-data-viewer/src/color/{index.js => index.tsx} (98%) rename modules/electrophysiology_browser/jsx/react-series-data-viewer/src/eeglab/{EEGLabSeriesProvider.js => EEGLabSeriesProvider.tsx} (89%) rename modules/electrophysiology_browser/jsx/react-series-data-viewer/src/series/components/{AnnotationForm.js => AnnotationForm.tsx} (83%) rename modules/electrophysiology_browser/jsx/react-series-data-viewer/src/series/components/{Axis.js => Axis.tsx} (90%) rename modules/electrophysiology_browser/jsx/react-series-data-viewer/src/series/components/{EEGMontage.js => EEGMontage.tsx} (94%) rename modules/electrophysiology_browser/jsx/react-series-data-viewer/src/series/components/{Epoch.js => Epoch.tsx} (84%) rename modules/electrophysiology_browser/jsx/react-series-data-viewer/src/series/components/{EventManager.js => EventManager.tsx} (89%) rename modules/electrophysiology_browser/jsx/react-series-data-viewer/src/series/components/{IntervalSelect.js => IntervalSelect.tsx} (85%) rename modules/electrophysiology_browser/jsx/react-series-data-viewer/src/series/components/{LineChunk.js => LineChunk.tsx} (90%) rename modules/electrophysiology_browser/jsx/react-series-data-viewer/src/series/components/{ResponsiveViewer.js => ResponsiveViewer.tsx} (82%) rename modules/electrophysiology_browser/jsx/react-series-data-viewer/src/series/components/{SeriesCursor.js => SeriesCursor.tsx} (96%) rename modules/electrophysiology_browser/jsx/react-series-data-viewer/src/series/components/{SeriesRenderer.js => SeriesRenderer.tsx} (93%) rename modules/electrophysiology_browser/jsx/react-series-data-viewer/src/series/components/{components.js => components.tsx} (100%) rename modules/electrophysiology_browser/jsx/react-series-data-viewer/src/series/store/{index.js => index.tsx} (97%) rename modules/electrophysiology_browser/jsx/react-series-data-viewer/src/series/store/logic/{dragBounds.js => dragBounds.tsx} (91%) rename modules/electrophysiology_browser/jsx/react-series-data-viewer/src/series/store/logic/{fetchChunks.js => fetchChunks.tsx} (90%) rename modules/electrophysiology_browser/jsx/react-series-data-viewer/src/series/store/logic/{filterEpochs.js => filterEpochs.tsx} (90%) rename modules/electrophysiology_browser/jsx/react-series-data-viewer/src/series/store/logic/{highLowPass.js => highLowPass.tsx} (92%) rename modules/electrophysiology_browser/jsx/react-series-data-viewer/src/series/store/logic/{pagination.js => pagination.tsx} (87%) rename modules/electrophysiology_browser/jsx/react-series-data-viewer/src/series/store/logic/{scaleAmplitudes.js => scaleAmplitudes.tsx} (85%) rename modules/electrophysiology_browser/jsx/react-series-data-viewer/src/series/store/logic/{timeSelection.js => timeSelection.tsx} (94%) rename modules/electrophysiology_browser/jsx/react-series-data-viewer/src/series/store/state/{bounds.js => bounds.tsx} (84%) rename modules/electrophysiology_browser/jsx/react-series-data-viewer/src/series/store/state/{channel.js => channel.tsx} (89%) rename modules/electrophysiology_browser/jsx/react-series-data-viewer/src/series/store/state/{cursor.js => cursor.tsx} (77%) rename modules/electrophysiology_browser/jsx/react-series-data-viewer/src/series/store/state/{dataset.js => dataset.tsx} (92%) rename modules/electrophysiology_browser/jsx/react-series-data-viewer/src/series/store/state/{filters.js => filters.tsx} (78%) rename modules/electrophysiology_browser/jsx/react-series-data-viewer/src/series/store/state/{montage.js => montage.tsx} (88%) rename modules/electrophysiology_browser/jsx/react-series-data-viewer/src/series/store/state/{rightPanel.js => rightPanel.tsx} (80%) rename modules/electrophysiology_browser/jsx/react-series-data-viewer/src/series/store/state/{timeSelection.js => timeSelection.tsx} (77%) rename modules/electrophysiology_browser/jsx/react-series-data-viewer/src/series/store/{types.js => types.tsx} (84%) rename modules/electrophysiology_browser/jsx/react-series-data-viewer/src/vector/{index.js => index.tsx} (82%) create mode 100644 tsconfig.json diff --git a/babel.config.js b/babel.config.js index 3df220b14a5..6e76911457a 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,7 +1,6 @@ module.exports = function(api) { api.cache(true); const presets = [ - "@babel/preset-flow", "@babel/preset-react", "@babel/preset-env" ]; diff --git a/modules/electrophysiology_browser/jsx/react-series-data-viewer/.flowconfig b/modules/electrophysiology_browser/jsx/react-series-data-viewer/.flowconfig deleted file mode 100644 index ca078320be1..00000000000 --- a/modules/electrophysiology_browser/jsx/react-series-data-viewer/.flowconfig +++ /dev/null @@ -1,15 +0,0 @@ -[ignore] -/node_modules/npm/ - -[include] -../../../../jsx - -[libs] - -[lints] - -[options] -react.runtime=automatic -module.name_mapper='^jsx' -> '/../../../../jsx/' - -[strict] diff --git a/modules/electrophysiology_browser/jsx/react-series-data-viewer/README.md b/modules/electrophysiology_browser/jsx/react-series-data-viewer/README.md index 3736f710e73..3fdb76869e6 100644 --- a/modules/electrophysiology_browser/jsx/react-series-data-viewer/README.md +++ b/modules/electrophysiology_browser/jsx/react-series-data-viewer/README.md @@ -13,7 +13,7 @@ A collection of expressive, low-level visualization primitives for React. RxJS is a library for composing asynchronous and event-based programs by using observable sequences. It provides one core type, the Observable, satellite types (Observer, Schedulers, Subjects) and operators to allow handling asynchronous events as collections. -### flow (https://flow.org) +### TypeScript (https://www.typescriptlang.org) A static type checker for javascript. ### Protocol Buffers (https://developers.google.com/protocol-buffers) diff --git a/modules/electrophysiology_browser/jsx/react-series-data-viewer/package.json b/modules/electrophysiology_browser/jsx/react-series-data-viewer/package.json index c5428d87369..ce869505d17 100644 --- a/modules/electrophysiology_browser/jsx/react-series-data-viewer/package.json +++ b/modules/electrophysiology_browser/jsx/react-series-data-viewer/package.json @@ -27,14 +27,15 @@ "redux-observable": "^1.0.0", "redux-thunk": "^2.3.0", "resize-observer-polyfill": "^1.5.0", - "rxjs": "^6.6.3" + "rxjs": "^6.6.3", + "tslib": "^1.9.3" }, "devDependencies": { - "babel-plugin-flow-react-proptypes": "^24.1.2", - "flow-bin": "^0.123.0" + "@types/react": "^16.12.0", + "@types/react-dom": "^16.9.9", + "@types/react-redux": "7.1.16" }, "scripts": { - "flow": "./node_modules/flow-bin/cli.js", "postinstall": "protoc protocol-buffers/chunk.proto --js_out=import_style=commonjs,binary:./src/" }, "license": "MIT", diff --git a/modules/electrophysiology_browser/jsx/react-series-data-viewer/src/ajax/index.js b/modules/electrophysiology_browser/jsx/react-series-data-viewer/src/ajax/index.js deleted file mode 100644 index 35ba2acde27..00000000000 --- a/modules/electrophysiology_browser/jsx/react-series-data-viewer/src/ajax/index.js +++ /dev/null @@ -1,23 +0,0 @@ -export const fetchBlob = (...args) => - fetch(...args).then((response) => { - if (!response.ok) { - return new Promise(() => {}); - } - return response.blob().then((data) => data); - }); - -export const fetchJSON = (...args) => - fetch(...args).then((response) => { - if (!response.ok) { - return new Promise(() => {}); - } - return response.json().then((data) => data); - }); - -export const fetchText = (...args) => - fetch(...args).then((response) => { - if (!response.ok) { - return new Promise(() => {}); - } - return response.text().then((data) => data); - }); diff --git a/modules/electrophysiology_browser/jsx/react-series-data-viewer/src/ajax/index.tsx b/modules/electrophysiology_browser/jsx/react-series-data-viewer/src/ajax/index.tsx new file mode 100644 index 00000000000..021f6a76f5d --- /dev/null +++ b/modules/electrophysiology_browser/jsx/react-series-data-viewer/src/ajax/index.tsx @@ -0,0 +1,23 @@ +export const fetchBlob = (url: string, params?: {}) => + fetch(url, params).then((response) => { + if (!response.ok) { + return Promise.resolve(null) as Promise; + } + return response.blob().then((data) => data); + }); + +export const fetchJSON = (url: string, params?: {}) => + fetch(url, params).then((response) => { + if (!response.ok) { + return Promise.resolve(null) as Promise; + } + return response.json().then((data) => data); + }); + +export const fetchText = (url: string, params?: {}) => + fetch(url, params).then((response) => { + if (!response.ok) { + return Promise.resolve(null) as Promise; + } + return response.text().then((data) => data); + }); diff --git a/modules/electrophysiology_browser/jsx/react-series-data-viewer/src/chunks/index.js b/modules/electrophysiology_browser/jsx/react-series-data-viewer/src/chunks/index.tsx similarity index 98% rename from modules/electrophysiology_browser/jsx/react-series-data-viewer/src/chunks/index.js rename to modules/electrophysiology_browser/jsx/react-series-data-viewer/src/chunks/index.tsx index 9005ebd88e2..465b6dd3976 100644 --- a/modules/electrophysiology_browser/jsx/react-series-data-viewer/src/chunks/index.js +++ b/modules/electrophysiology_browser/jsx/react-series-data-viewer/src/chunks/index.tsx @@ -1,4 +1,3 @@ -// @flow import {FloatChunk} from '../protocol-buffers/chunk_pb'; import {fetchBlob} from '../ajax'; diff --git a/modules/electrophysiology_browser/jsx/react-series-data-viewer/src/color/index.js b/modules/electrophysiology_browser/jsx/react-series-data-viewer/src/color/index.tsx similarity index 98% rename from modules/electrophysiology_browser/jsx/react-series-data-viewer/src/color/index.js rename to modules/electrophysiology_browser/jsx/react-series-data-viewer/src/color/index.tsx index c0d7ee7f4c3..1f2027139d8 100644 --- a/modules/electrophysiology_browser/jsx/react-series-data-viewer/src/color/index.js +++ b/modules/electrophysiology_browser/jsx/react-series-data-viewer/src/color/index.tsx @@ -1,5 +1,3 @@ -// @flow - import {scaleOrdinal} from 'd3-scale'; // import * as R from 'ramda'; // import {schemeCategory10, schemeSet3} from 'd3-scale-chromatic'; diff --git a/modules/electrophysiology_browser/jsx/react-series-data-viewer/src/eeglab/EEGLabSeriesProvider.js b/modules/electrophysiology_browser/jsx/react-series-data-viewer/src/eeglab/EEGLabSeriesProvider.tsx similarity index 89% rename from modules/electrophysiology_browser/jsx/react-series-data-viewer/src/eeglab/EEGLabSeriesProvider.js rename to modules/electrophysiology_browser/jsx/react-series-data-viewer/src/eeglab/EEGLabSeriesProvider.tsx index bff25a0c5f6..a8316b47419 100644 --- a/modules/electrophysiology_browser/jsx/react-series-data-viewer/src/eeglab/EEGLabSeriesProvider.js +++ b/modules/electrophysiology_browser/jsx/react-series-data-viewer/src/eeglab/EEGLabSeriesProvider.tsx @@ -1,6 +1,6 @@ +import React, {Component} from 'react'; import {tsvParse} from 'd3-dsv'; -import {Component} from 'react'; -import {createStore, applyMiddleware} from 'redux'; +import {createStore, applyMiddleware, Store} from 'redux'; import {Provider} from 'react-redux'; import {createEpicMiddleware} from 'redux-observable'; import thunk from 'redux-thunk'; @@ -16,8 +16,15 @@ import { import {setDomain, setInterval} from '../series/store/state/bounds'; import {updateFilteredEpochs} from '../series/store/logic/filterEpochs'; import {setElectrodes} from '../series/store/state/montage'; +import {Channel} from '../series/store/types'; -type Props = { +declare global { + interface Window { + EEGLabSeriesProviderStore: Store; + } +} + +type CProps = { chunksURL: string, epochsURL: string, electrodesURL: string, @@ -27,12 +34,17 @@ type Props = { /** * EEGLabSeriesProvider component */ -class EEGLabSeriesProvider extends Component { +class EEGLabSeriesProvider extends Component { + private store: Store; + public state: { + channels: Channel[] + }; + /** * @constructor * @param {object} props - React Component properties */ - constructor(props: Props) { + constructor(props: CProps) { super(props); const epicMiddleware = createEpicMiddleware(); @@ -154,10 +166,10 @@ class EEGLabSeriesProvider extends Component { ); } -} -EEGLabSeriesProvider.defaultProps = { - limit: MAX_CHANNELS, -}; + static defaultProps = { + limit: MAX_CHANNELS, + }; +} export default EEGLabSeriesProvider; diff --git a/modules/electrophysiology_browser/jsx/react-series-data-viewer/src/series/components/AnnotationForm.js b/modules/electrophysiology_browser/jsx/react-series-data-viewer/src/series/components/AnnotationForm.tsx similarity index 83% rename from modules/electrophysiology_browser/jsx/react-series-data-viewer/src/series/components/AnnotationForm.js rename to modules/electrophysiology_browser/jsx/react-series-data-viewer/src/series/components/AnnotationForm.tsx index 8bb432663ec..cce1762d5b1 100644 --- a/modules/electrophysiology_browser/jsx/react-series-data-viewer/src/series/components/AnnotationForm.js +++ b/modules/electrophysiology_browser/jsx/react-series-data-viewer/src/series/components/AnnotationForm.tsx @@ -1,21 +1,20 @@ -// @flow - import React, {useEffect, useState} from 'react'; -import type {Epoch as EpochType, RightPanel} from '../store/types'; -import {connect} from 'react-redux'; +import {Epoch as EpochType, RightPanel} from '../store/types'; +import {connect, DefaultRootState} from 'react-redux'; import {setTimeSelection} from '../store/state/timeSelection'; import {setRightPanel} from '../store/state/rightPanel'; import * as R from 'ramda'; import {toggleEpoch, updateActiveEpoch} from '../store/logic/filterEpochs'; +import {RootState} from '../store'; -type Props = { - timeSelection: ?[number, number], +type CProps = { + timeSelection?: [number, number], epochs: EpochType[], filteredEpochs: number[], - setTimeSelection: [?number, ?number] => void, - setRightPanel: RightPanel => void, - toggleEpoch: number => void, - updateActiveEpoch: ?number => void, + setTimeSelection: (_: [number, number]) => void, + setRightPanel: (_: RightPanel) => void, + toggleEpoch: (_: number) => void, + updateActiveEpoch: (_: number) => void, interval: [number, number], }; @@ -28,7 +27,7 @@ const AnnotationForm = ({ toggleEpoch, updateActiveEpoch, interval, -}: Props) => { +}: CProps) => { const [startEvent = '', endEvent = ''] = timeSelection || []; let [event, setEvent] = useState([startEvent, endEvent]); @@ -81,10 +80,14 @@ const AnnotationForm = ({ setEvent([value, event[1]]); if (validate([value, event[1]])) { + let endTime = event[1]; + if (typeof endTime === 'string'){ + endTime = parseInt(endTime); + } setTimeSelection( [ - parseInt(value) || null, - parseInt(event[1]) || null, + value || null, + endTime || null, ] ); } @@ -104,7 +107,16 @@ const AnnotationForm = ({ setEvent([event[0], value]); if (validate([event[0], value])) { - setTimeSelection([parseInt(event[0]) || null, value]); + let startTime = event[0]; + if (typeof startTime === 'string'){ + startTime = parseInt(startTime); + } + setTimeSelection( + [ + startTime || null, + value + ] + ); } }} value={event[1]} @@ -145,7 +157,7 @@ const AnnotationForm = ({