Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
[Chore]: Technical: Translate components/common final part (#1750)
dariaterekhovaaec0f7534110f9
diff --git a/package.json b/package.jsonindex b28685f93..dd0ea7a17 100644--- a/package.json+++ b/package.json@@ -108,9 +108,13 @@"@types/d3-selection": "^3.0.2","@types/exenv": "^1.2.0","@types/keymirror": "^0.1.1",+ "@types/lodash.get": "^4.4.6",+ "@types/lodash.isequal": "^4.5.5","@types/lodash.pick": "^4.4.6","@types/react-lifecycles-compat": "^3.0.1","@types/react-modal": "^3.13.1",+ "@types/react-onclickoutside": "^6.7.4",+ "@types/react-virtualized": "^9.21.20","@types/react-vis": "^1.8.0","classnames": "^2.2.1","colorbrewer": "^1.5.0",diff --git a/src/components/common/animation-control/animation-control.js b/src/components/common/animation-control/animation-control.tsxsimilarity index 96%rename from src/components/common/animation-control/animation-control.jsrename to src/components/common/animation-control/animation-control.tsxindex d8ebc4ce9..88eacbf2b 100644--- a/src/components/common/animation-control/animation-control.js+++ b/src/components/common/animation-control/animation-control.tsx@@ -58,7 +58,7 @@ const StyledDomain = styled.div.attrs({AnimationControlFactory.deps = [PlaybackControlsFactory, FloatingTimeDisplayFactory];-function AnimationControlFactory(PlaybackControls, FloatingTimeDisplay) {+function AnimationControlFactory(PlaybackControls: ReturnType<typeof PlaybackControlsFactory>, FloatingTimeDisplay: ReturnType<typeof FloatingTimeDisplayFactory>) {const AnimationControl = ({isAnimatable,isAnimating,@@ -104,7 +104,6 @@ function AnimationControlFactory(PlaybackControls, FloatingTimeDisplay) {<BottomWidgetInner className="bottom-widget--inner"><AnimationWidgetInner className="animation-widget--inner"><PlaybackControls- className="animation-control-playpause"startAnimation={toggleAnimation}isAnimating={isAnimating}pauseAnimation={toggleAnimation}diff --git a/src/components/common/animation-control/animation-controller.js b/src/components/common/animation-control/animation-controller.tssimilarity index 90%rename from src/components/common/animation-control/animation-controller.jsrename to src/components/common/animation-control/animation-controller.tsindex a408cccc8..e26724ea4 100644--- a/src/components/common/animation-control/animation-controller.js+++ b/src/components/common/animation-control/animation-controller.ts@@ -24,6 +24,17 @@ import {requestAnimationFrame, cancelAnimationFrame} from 'global/window';import Console from 'global/console';import {BASE_SPEED, FPS, ANIMATION_WINDOW} from 'constants/default-settings';+type AnimationControllerProps = {+ isAnimating?: boolean;+ speed?: number;+ updateAnimation: Function;+ animationWindow?: string;+ steps?: number[] | null;+ domain: number[];+ value: number[];+ baseSpeed?: number;+}+function AnimationControllerFactory() {/*** 4 Animation Window Types@@ -47,15 +58,15 @@ function AnimationControllerFactory() {* Current time is a point. An array of sorted time steps are provided,* animate a moving point jumps to the next step*/- class AnimationController extends Component {- // TODO: convert the entire component to use hooks in the next PR+ class AnimationController extends Component<AnimationControllerProps> {+static defaultProps = {baseSpeed: BASE_SPEED,speed: 1,steps: null,animationWindow: ANIMATION_WINDOW.free};-+state = {isAnimating: false};@@ -75,9 +86,10 @@ function AnimationControllerFactory() {}_timer = null;+ _startTime: number | undefined;_startOrPauseAnimation() {- const {isAnimating, speed} = this.props;+ const {isAnimating, speed = 1} = this.props;if (!this._timer && isAnimating && speed > 0) {this._startAnimation();} else if (this._timer && !isAnimating) {@@ -118,8 +130,10 @@ function AnimationControllerFactory() {};_resetAnimtionByTimeStep = () => {+ const {steps = null} = this.props+ if (!steps) return;// go to the first steps- this.props.updateAnimation([this.props.steps[0], 0]);+ this.props.updateAnimation([steps[0], 0]);};_resetAnimation = () => {@@ -131,7 +145,7 @@ function AnimationControllerFactory() {};_startAnimation = () => {- const {speed} = this.props;+ const {speed = 1} = this.props;this._clearTimer();if (speed > 0) {if (this.props.animationWindow === ANIMATION_WINDOW.interval) {@@ -176,7 +190,7 @@ function AnimationControllerFactory() {};_nextFrameByDomain() {- const {domain, value, speed, baseSpeed, animationWindow} = this.props;+ const {domain, value, speed = 1, baseSpeed = 600, animationWindow} = this.props;const delta = ((domain[1] - domain[0]) / baseSpeed) * speed;// loop when reaches the end@@ -200,7 +214,8 @@ function AnimationControllerFactory() {}_nextFrameByTimeStep() {- const {steps, value} = this.props;+ const {steps = null, value} = this.props;+ if (!steps) return;const val = Array.isArray(value) ? value[0] : value;const index = bisectLeft(steps, val);const nextIdx = index >= steps.length - 1 ? 0 : index + 1;diff --git a/src/components/common/animation-control/animation-speed-slider.js b/src/components/common/animation-control/animation-speed-slider.tsxsimilarity index 89%rename from src/components/common/animation-control/animation-speed-slider.jsrename to src/components/common/animation-control/animation-speed-slider.tsxindex 75f80fabb..8db83aee5 100644--- a/src/components/common/animation-control/animation-speed-slider.js+++ b/src/components/common/animation-control/animation-speed-slider.tsx@@ -45,8 +45,14 @@ const SpeedSliderContainer = styled.div`AnimationSpeedSliderFactory.deps = [RangeSliderFactory];-export default function AnimationSpeedSliderFactory(RangeSlider) {- class AnimationSpeedSlider extends Component {+interface AnimationSpeedSliderProps {+ onHide: () => void;+ speed: number;+ updateAnimationSpeed: (val: number) => void+}++export default function AnimationSpeedSliderFactory(RangeSlider: ReturnType<typeof RangeSliderFactory>) {+ class AnimationSpeedSlider extends Component<AnimationSpeedSliderProps> {handleClickOutside = e => {this.props.onHide();};@@ -64,7 +70,6 @@ export default function AnimationSpeedSliderFactory(RangeSlider) {value1={this.props.speed}onChange={this._onChange}isRanged={false}- showTooltipshowInputinputTheme="secondary"inputSize="tiny"diff --git a/src/components/common/animation-control/floating-time-display.js b/src/components/common/animation-control/floating-time-display.tsxsimilarity index 94%rename from src/components/common/animation-control/floating-time-display.jsrename to src/components/common/animation-control/floating-time-display.tsxindex 9bc6bde67..eed85ec48 100644--- a/src/components/common/animation-control/floating-time-display.js+++ b/src/components/common/animation-control/floating-time-display.tsx@@ -106,7 +106,11 @@ const TimeDivider = () => (</StyledHorizontalBar>);-const TimeDisplayRow = ({timeValues = []}) => (+interface TimeDisplayRowProps{+ timeValues?: string[]+}++const TimeDisplayRow = ({timeValues = []}: TimeDisplayRowProps) => (<CenterFlexbox><div className="time-value">{timeValues[0]}</div>{timeValues[1] ? <TimeDivider /> : null}@@ -114,8 +118,15 @@ const TimeDisplayRow = ({timeValues = []}) => (</CenterFlexbox>);+interface FloatingTimeDisplayProps {+ currentTime: number | number[],+ defaultTimeFormat?: string,+ timeFormat?: string,+ timezone?: string+}+export default function FloatingTimeDisplayFactory() {- const FloatingTimeDisplay = ({currentTime, defaultTimeFormat, timeFormat, timezone}) => {+ const FloatingTimeDisplay = ({currentTime, defaultTimeFormat, timeFormat, timezone}: FloatingTimeDisplayProps) => {const {displayDate, displayTime} = useMemo(() => {const groupTime = Array.isArray(currentTime) ? currentTime : [currentTime];const hasUserFormat = typeof timeFormat === 'string';@@ -129,7 +140,7 @@ export default function FloatingTimeDisplayFactory() {displayTime: []};}- return groupTime.reduce(+ return groupTime.reduce<{displayDate: string[], displayTime: string[]}>((accu, curr) => {const [dateFormat, datetimeFormat] = currentFormat.split(' ');const dateString = dateFunc(dateFormat)(curr);diff --git a/src/components/common/animation-control/playback-controls.js b/src/components/common/animation-control/playback-controls.tsxsimilarity index 89%rename from src/components/common/animation-control/playback-controls.jsrename to src/components/common/animation-control/playback-controls.tsxindex e3fc4482f..dd5d2d901 100644--- a/src/components/common/animation-control/playback-controls.js+++ b/src/components/common/animation-control/playback-controls.tsx@@ -27,6 +27,7 @@ import AnimationSpeedSliderFactory from './animation-speed-slider';import {Reset, Play, Pause, Rocket, AnchorWindow, FreeWindow} from 'components/common/icons';import {ANIMATION_WINDOW} from 'constants/default-settings';import {preciseRound} from 'utils/data-utils';+import { ReactComponentLike } from 'prop-types';const DELAY_SHOW = 500;const DEFAULT_BUTTON_HEIGHT = '20px';@@ -50,7 +51,11 @@ const StyledSpeedControl = styled.div`}`;-export const IconButton = styled(Button)`+interface IconButtonProps {+ collapsed?: boolean;+}++export const IconButton = styled(Button)<IconButtonProps>`width: ${props => (props.collapsed ? 0 : 32)}px;height: 32px;color: ${props => props.theme.playbackButtonColor};@@ -96,6 +101,21 @@ const DEFAULT_ANIMATE_ITEMS = {}};+interface AnimationItem {+ id: string,+ icon: ReactComponentLike,+ tooltip: string+}++interface AnimationWindowControlProps {+ onClick?: (id: string) => void,+ selected?: string,+ onHide: ()=>void,+ height?: string,+ animationItems: {[key: string]: AnimationItem};+ btnStyle+}+export const AnimationWindowControl = ({onClick,selected,@@ -103,7 +123,7 @@ export const AnimationWindowControl = ({height,animationItems,btnStyle = {}-}) => (+}: AnimationWindowControlProps) => (<div>{Object.values(animationItems).filter(item => item.id !== selected)@@ -114,7 +134,7 @@ export const AnimationWindowControl = ({data-for={`${item.id}-tooltip`}className="playback-control-button"onClick={() => {- onClick(item.id);+ onClick&&onClick(item.id);onHide();}}{...btnStyle}@@ -130,8 +150,25 @@ export const AnimationWindowControl = ({</div>);+interface PlaybackControls {+ isAnimatable?: boolean;+ isAnimating?: boolean,+ width?: number | string,+ speed: number,+ animationWindow?: string+ setFilterAnimationWindow?: (id: string) => void,+ updateAnimationSpeed,+ pauseAnimation?: () => void;+ resetAnimation: () => void;+ startAnimation: () => void;+ playbackIcons?: typeof DEFAULT_ICONS;+ animationItems?: {[key: string]: AnimationItem};+ buttonStyle?: string;+ buttonHeight?: string;+}+PlaybackControlsFactory.deps = [AnimationSpeedSliderFactory];-function PlaybackControlsFactory(AnimationSpeedSlider) {+function PlaybackControlsFactory(AnimationSpeedSlider: ReturnType<typeof AnimationSpeedSliderFactory>) {// eslint-disable-next-line complexityconst PlaybackControls = ({isAnimatable = true,@@ -148,7 +185,7 @@ function PlaybackControlsFactory(AnimationSpeedSlider) {animationItems = DEFAULT_ANIMATE_ITEMS,buttonStyle = 'secondary',buttonHeight = DEFAULT_BUTTON_HEIGHT- }) => {+ }: PlaybackControls) => {const [isSpeedControlVisible, toggleSpeedControl] = useState(false);const [showAnimationWindowControl, setShowAnimationWindowControl] = useState(false);@@ -256,7 +293,6 @@ function PlaybackControlsFactory(AnimationSpeedSlider) {data-for="animate-play-pause"className={classnames('playback-control-button', {active: isAnimating})}onClick={isAnimating ? pauseAnimation : startAnimation}- hide={isSpeedControlVisible}{...btnStyle}>{isAnimating ? (diff --git a/src/components/common/animation-control/speed-control.js b/src/components/common/animation-control/speed-control.tsxsimilarity index 96%rename from src/components/common/animation-control/speed-control.jsrename to src/components/common/animation-control/speed-control.tsxindex 1e05bb075..66ff7d920 100644--- a/src/components/common/animation-control/speed-control.js+++ b/src/components/common/animation-control/speed-control.tsx@@ -40,7 +40,7 @@ const StyledSpeedText = styled.div`SpeedControlFactory.deps = [AnimationSpeedSliderFactory];-function SpeedControlFactory(AnimationSpeedSlider) {+function SpeedControlFactory(AnimationSpeedSlider: ReturnType<typeof AnimationSpeedSliderFactory>) {const SpeedControl = ({onClick,updateAnimationSpeed,diff --git a/src/components/common/data-table/button.js b/src/components/common/data-table/button.tsxsimilarity index 82%rename from src/components/common/data-table/button.jsrename to src/components/common/data-table/button.tsxindex 2cb4f7265..c61ec5b9d 100644--- a/src/components/common/data-table/button.js+++ b/src/components/common/data-table/button.tsx@@ -18,7 +18,7 @@// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN// THE SOFTWARE.-import React from 'react';+import React, { MouseEventHandler, ReactNode } from 'react';import styled from 'styled-components';const StyledButton = styled.button`@@ -37,9 +37,17 @@ const StyledButton = styled.button`opacity: 0.8;}`;++type ButtonProps = {+ onClick?: MouseEventHandler<HTMLButtonElement>,+ disabled?: boolean,+ text?: string,+ children?: ReactNode+} & React.ButtonHTMLAttributes<HTMLButtonElement>+const noop = () => {};-const Button = ({onClick = noop, disabled = false, text = '', children, ...props}) => (- <StyledButton {...props} onClick={disabled ? null : onClick}>+const Button = ({onClick = noop, disabled = false, text = '', children, ...props}: ButtonProps) => (+ <StyledButton {...props} onClick={disabled ? undefined : onClick}>{text || children}</StyledButton>);diff --git a/src/components/common/data-table/canvas.js b/src/components/common/data-table/canvas.tsxsimilarity index 100%rename from src/components/common/data-table/canvas.jsrename to src/components/common/data-table/canvas.tsxdiff --git a/src/components/common/data-table/cell-size.js b/src/components/common/data-table/cell-size.tssimilarity index 93%rename from src/components/common/data-table/cell-size.jsrename to src/components/common/data-table/cell-size.tsindex a7f4883b1..6a45d373a 100644--- a/src/components/common/data-table/cell-size.js+++ b/src/components/common/data-table/cell-size.ts@@ -90,7 +90,7 @@ function clamp(min, max, value) {return Math.max(Math.min(max, value), min);}-function getColumnOrder(pinnedColumns = [], unpinnedColumns = []) {+function getColumnOrder(pinnedColumns: string[] = [], unpinnedColumns: string[] = []) {return [...pinnedColumns, ...unpinnedColumns];}@@ -119,7 +119,7 @@ function getSizeSum(sizeCache, key) {* @param {number} containerWidth* @param {number} roomToFill*/-function expandCellSize(cellSizeCache, columnOrder, containerWidth, roomToFill) {+function expandCellSize(cellSizeCache: object, columnOrder: string[], containerWidth: number, roomToFill: number) {let remaining = roomToFill;const expandedCellSize = columnOrder.reduce((accu, col) => {@@ -139,7 +139,7 @@ function expandCellSize(cellSizeCache, columnOrder, containerWidth, roomToFill)};}, {});- let ghost = null;+ let ghost: number | null = null;if (remaining > 0 && remaining < MIN_GHOST_CELL_SIZE) {// expand last cellconst lastCell = columnOrder[columnOrder.length - 1];@@ -163,10 +163,10 @@ function expandCellSize(cellSizeCache, columnOrder, containerWidth, roomToFill)* @param {string[]} unpinnedColumns*/export function adjustCellsToContainer(- containerWidth,- cellSizeCache,- pinnedColumns,- unpinnedColumns+ containerWidth: number,+ cellSizeCache: object,+ pinnedColumns: string[],+ unpinnedColumns: string[]) {const minRowSum = getSizeSum(cellSizeCache, 'row');if (minRowSum >= containerWidth) {diff --git a/src/components/common/data-table/grid.js b/src/components/common/data-table/grid.tsxsimilarity index 91%rename from src/components/common/data-table/grid.jsrename to src/components/common/data-table/grid.tsxindex 0976f269b..7f6aff403 100644--- a/src/components/common/data-table/grid.js+++ b/src/components/common/data-table/grid.tsx@@ -19,10 +19,13 @@// THE SOFTWARE.import React, {PureComponent} from 'react';-import {Grid} from 'react-virtualized';+import {Grid, GridProps} from 'react-virtualized';import isEqual from 'lodash.isequal';-export default class GridHack extends PureComponent {+export default class GridHack extends PureComponent<GridProps> {++ grid: Grid | null = null+componentDidUpdate(preProps) {/** This hack exists because in react-virtualized the@@ -35,7 +38,7 @@ export default class GridHack extends PureComponent {**/if (!isEqual(preProps.cellSizeCache, this.props.cellSizeCache)) {- this.grid.recomputeGridSize();+ this.grid?.recomputeGridSize();}}diff --git a/src/components/common/data-table/index.js b/src/components/common/data-table/index.tsxsimilarity index 94%rename from src/components/common/data-table/index.jsrename to src/components/common/data-table/index.tsxindex b0d09a3a6..0d35f717e 100644--- a/src/components/common/data-table/index.js+++ b/src/components/common/data-table/index.tsx@@ -225,7 +225,7 @@ export const Container = styled.div`const defaultColumnWidth = 200;-const columnWidthFunction = (columns, cellSizeCache, ghost) => ({index}) => {+const columnWidthFunction = (columns, cellSizeCache, ghost?) => ({index}) => {return (columns[index] || {}).ghost ? ghost : cellSizeCache[columns[index]] || defaultColumnWidth;};@@ -252,10 +252,10 @@ export const TableSection = ({scrollTop,dataGridProps,columnWidth,- setGridRef,+ setGridRef = undefined,headerCellRender,dataCellRender,- scrollLeft = undefined+ scrollLeft = 0}) => (<AutoSizer>{({width, height}) => {@@ -267,7 +267,7 @@ export const TableSection = ({const dataGridHeight = fixedHeight || height;return (<>- <div className={classnames('scroll-in-ui-thread', classList.header)}>+ <div className={classnames('scroll-in-ui-thread', classList?.header)}><GridcellRenderer={headerCellRender}{...headerGridProps}@@ -276,7 +276,7 @@ export const TableSection = ({/></div><div- className={classnames('scroll-in-ui-thread', classList.rows)}+ className={classnames('scroll-in-ui-thread', classList?.rows)}style={{top: headerGridProps.height}}@@ -287,7 +287,7 @@ export const TableSection = ({{...gridDimension}className={isPinned ? 'pinned-grid' : 'body-grid'}height={dataGridHeight - headerGridProps.height}- onScroll={onScroll}+ onScroll={onScroll}scrollTop={scrollTop}setGridRef={setGridRef}/>@@ -298,9 +298,26 @@ export const TableSection = ({</AutoSizer>);+type CellSizeCache = {[id: string]: number}++interface DataTableProps {+ cellSizeCache?: CellSizeCache;+ pinnedColumns?: string[];+ fixedWidth?: number;+ theme?: any;+ dataContainer;+ fixedHeight;+}++interface DataTableState {+ cellSizeCache?: CellSizeCache,+ moreOptionsColumn?,+ ghost?+}+DataTableFactory.deps = [FieldTokenFactory];-function DataTableFactory(FieldToken) {- class DataTable extends Component {+function DataTableFactory(FieldToken: ReturnType<typeof FieldTokenFactory>) {+ class DataTable extends Component<DataTableProps, DataTableState> {static defaultProps = {dataContainer: null,pinnedColumns: [],@@ -312,7 +329,7 @@ function DataTableFactory(FieldToken) {theme: {}};- state = {+ state: DataTableState = {cellSizeCache: {},moreOptionsColumn: null};@@ -339,7 +356,7 @@ function DataTableFactory(FieldToken) {};}- root = createRef();+ root = createRef<HTMLDivElement>();columns = props => props.columns;pinnedColumns = props => props.pinnedColumns;unpinnedColumns = createSelector(this.columns, this.pinnedColumns, (columns, pinnedColumns) =>@@ -353,7 +370,7 @@ function DataTableFactory(FieldToken) {});getCellSizeCache = () => {- const {cellSizeCache: propsCache, fixedWidth, pinnedColumns} = this.props;+ const {cellSizeCache: propsCache = {}, fixedWidth, pinnedColumns = []} = this.props;const unpinnedColumns = this.unpinnedColumns(this.props);const width = fixedWidth ? fixedWidth : this.root.current ? this.root.current.clientWidth : 0;@@ -365,7 +382,7 @@ function DataTableFactory(FieldToken) {propsCache,pinnedColumns,unpinnedColumns- );+ ) as {cellSizeCache: {}, ghost: number | null | undefined};return {cellSizeCache,@@ -384,8 +401,7 @@ function DataTableFactory(FieldToken) {isPinned,props,toggleMoreOptions,- moreOptionsColumn,- TokenComponent+ moreOptionsColumn) => {// eslint-disable-next-line react/display-namereturn cellInfo => {@@ -441,7 +457,6 @@ function DataTableFactory(FieldToken) {<section className="options"><OptionDropdownisOpened={moreOptionsColumn === column}- type={colMeta[column].type}column={column}toggleMoreOptions={toggleMoreOptions}sortTableColumn={mode => sortTableColumn(column, mode)}@@ -500,10 +515,10 @@ function DataTableFactory(FieldToken) {};render() {- const {dataContainer, pinnedColumns, theme = {}, fixedWidth, fixedHeight} = this.props;+ const {dataContainer, pinnedColumns = [], theme = {}, fixedWidth, fixedHeight} = this.props;const unpinnedColumns = this.unpinnedColumns(this.props);- const {cellSizeCache, moreOptionsColumn, ghost} = this.state;+ const {cellSizeCache = {}, moreOptionsColumn, ghost} = this.state;const unpinnedColumnsGhost = ghost ? [...unpinnedColumns, {ghost: true}] : unpinnedColumns;const pinnedColumnsWidth = pinnedColumns.reduce((acc, val) => acc + get(cellSizeCache, val, 0),@@ -550,7 +565,6 @@ function DataTableFactory(FieldToken) {onScroll={args => onScroll({...args, scrollLeft})}scrollTop={scrollTop}dataGridProps={dataGridProps}- setGridRef={pinnedGrid => (this.pinnedGrid = pinnedGrid)}columnWidth={columnWidthFunction(pinnedColumns, cellSizeCache)}headerCellRender={this.renderHeaderCell(pinnedColumns,@@ -584,7 +598,6 @@ function DataTableFactory(FieldToken) {scrollTop={scrollTop}scrollLeft={scrollLeft}dataGridProps={dataGridProps}- setGridRef={unpinnedGrid => (this.unpinnedGrid = unpinnedGrid)}columnWidth={columnWidthFunction(unpinnedColumnsGhost,cellSizeCache,diff --git a/src/components/common/data-table/option-dropdown.js b/src/components/common/data-table/option-dropdown.tsxsimilarity index 90%rename from src/components/common/data-table/option-dropdown.jsrename to src/components/common/data-table/option-dropdown.tsxindex 0f6c13ce5..f533c3b36 100644--- a/src/components/common/data-table/option-dropdown.js+++ b/src/components/common/data-table/option-dropdown.tsx@@ -51,7 +51,19 @@ const StyledOptionsDropdown = styled.div`}`;-const OptionDropdown = props => {+interface OptionDropdownProps {+ isOpened?: boolean;+ column: string;+ toggleMoreOptions: (order: string)=>void;+ sortTableColumn: (order: string)=>void;+ pinTableColumn: () => void;+ copyTableColumn: () => void;+ sortMode?: string;+ isSorted?: boolean;+ isPinned?: boolean;+}++const OptionDropdown = (props: OptionDropdownProps) => {const {isOpened,column,diff --git a/src/components/common/field-selector.tsx b/src/components/common/field-selector.tsxindex 1dd8ec12d..dc1922a36 100644--- a/src/components/common/field-selector.tsx+++ b/src/components/common/field-selector.tsx@@ -77,7 +77,7 @@ type FieldType =interface FieldSelectorFactoryProps {fields?: FieldType[];- onSelect: (items: readonly (string | number | boolean | object)[]) => void;+ onSelect: (items: readonly (string | number | boolean | object)[] | null) => void;placement?: string;value?: FieldType;filterFieldTypes?: FieldType | FieldType[];diff --git a/src/components/common/file-uploader/file-drop.d.ts b/src/components/common/file-uploader/file-drop.d.tsdeleted file mode 100644index e0cdb4345..000000000--- a/src/components/common/file-uploader/file-drop.d.ts+++ /dev/null@@ -1,19 +0,0 @@-import React from 'react';--export type FileDropProps = {- dropEffect?: 'copy' | 'move' | 'link' | 'none';- frame?: typeof document | typeof window | HTMLElement;- className?: string;- targetClassName?: string;- draggingOverFrameClassName?: string;- draggingOverTargetClassName?: string;- onDragOver?: (event: any) => void;- onDragLeave?: (event: any) => void;- onDrop?: (fileList: FileList, event: any) => void;- onFrameDragEnter?: (event: any) => void;- onFrameDragLeave?: (event: any) => void;- onFrameDrop?: (event: any) => void;-};--export const FileDrop: React.FunctionComponent<FileDropProps>;-export default FileDrop;diff --git a/src/components/common/file-uploader/file-drop.js b/src/components/common/file-uploader/file-drop.tsxsimilarity index 90%rename from src/components/common/file-uploader/file-drop.jsrename to src/components/common/file-uploader/file-drop.tsxindex f8ceaa374..587eac4c7 100644--- a/src/components/common/file-uploader/file-drop.js+++ b/src/components/common/file-uploader/file-drop.tsx@@ -25,10 +25,25 @@import React from 'react';import window from 'global/window';+export type FileDropProps = {+ dropEffect?: 'copy' | 'move' | 'link' | 'none';+ frame?: typeof document | typeof window | HTMLElement;+ className?: string;+ targetClassName?: string;+ draggingOverFrameClassName?: string;+ draggingOverTargetClassName?: string;+ onDragOver?: (event: any) => void;+ onDragLeave?: (event: any) => void;+ onDrop?: (fileList: FileList, event: any) => void;+ onFrameDragEnter?: (event: any) => void;+ onFrameDragLeave?: (event: any) => void;+ onFrameDrop?: (event: any) => void;+};+/** @typedef {import('./file-drop').FileDropProps} FileDropProps *//** @augments React.PureComponent<FileDropProps> */-class FileDrop extends React.PureComponent {+class FileDrop extends React.PureComponent<FileDropProps> {static isIE = () =>window &&window.navigator &&@@ -60,11 +75,9 @@ class FileDrop extends React.PureComponent {draggingOverTargetClassName: 'file-drop-dragging-over-target'};- constructor(props) {- super(props);- this.frameDragCounter = 0;- this.state = {draggingOverFrame: false, draggingOverTarget: false};- }++ frameDragCounter = 0;+ state = {draggingOverFrame: false, draggingOverTarget: false};componentDidMount() {this.startFrameListeners(this.props.frame);diff --git a/src/components/common/file-uploader/file-upload-progress.d.ts b/src/components/common/file-uploader/file-upload-progress.d.tsdeleted file mode 100644index f6f5ec5ac..000000000--- a/src/components/common/file-uploader/file-upload-progress.d.ts+++ /dev/null@@ -1,11 +0,0 @@-import React from 'react';- // TODO - this seems too coupled, better define a type here and adapt FileLoadingProgress to it in the app?-import {FileLoadingProgress} from 'reducers/vis-state-updaters';--export type FileUploadProgressProps = {- fileLoadingProgress: FileLoadingProgress;- theme: object;-};--const FileUploadProgress: React.FunctionComponent<FileUploadProgressProps>;-export default FileUploadProgress;diff --git a/src/components/common/file-uploader/file-upload-progress.js b/src/components/common/file-uploader/file-upload-progress.tsxsimilarity index 89%rename from src/components/common/file-uploader/file-upload-progress.jsrename to src/components/common/file-uploader/file-upload-progress.tsxindex 44828e805..a57b957a8 100644--- a/src/components/common/file-uploader/file-upload-progress.js+++ b/src/components/common/file-uploader/file-upload-progress.tsx@@ -23,6 +23,7 @@ import styled, {withTheme} from 'styled-components';import ProgressBar from '../progress-bar';import {TruncatedTitleText} from 'components/common/styled-components';import {getError} from 'utils/utils';+import {FileLoadingProgress} from 'reducers/vis-state-updaters';/** @typedef {import('./file-upload-progress').FileUploadProgressProps} FileUploadProgressProps*/@@ -66,6 +67,14 @@ const StyledContainer = styled.div`const formatPercent = percent => `${Math.floor(percent * 100)}%`;+interface UploadProgressProps {+ message?: string;+ fileName?: string;+ percent: number;+ error?: any;+ theme: any;+}+/*** @param {object} params* @param {string} params.message@@ -74,7 +83,7 @@ const formatPercent = percent => `${Math.floor(percent * 100)}%`;* @param {any} params.error* @param {object} params.theme*/-const UploadProgress = ({message, fileName, percent, error, theme}) => {+const UploadProgress = ({message, fileName, percent, error, theme}: UploadProgressProps) => {const percentStr = formatPercent(percent);const barColor = error ? theme.errorColor : theme.activeColorLT;@@ -96,8 +105,14 @@ const UploadProgress = ({message, fileName, percent, error, theme}) => {);};++interface FileUploadProgressProps {+ fileLoadingProgress: FileLoadingProgress;+ theme: any;+};+/** @type {React.FunctionComponent<FileUploadProgressProps>} */-const FileUploadProgress = ({fileLoadingProgress, theme}) => (+const FileUploadProgress = ({fileLoadingProgress, theme}: FileUploadProgressProps) => (<StyledContainer><StyledProgressWrapper>{Object.values(fileLoadingProgress).map(item => (diff --git a/src/components/common/file-uploader/file-upload.d.ts b/src/components/common/file-uploader/file-upload.d.tsdeleted file mode 100644index 4855a58ec..000000000--- a/src/components/common/file-uploader/file-upload.d.ts+++ /dev/null@@ -1,22 +0,0 @@-import React from 'react';-import {FileLoading, FileLoadingProgress} from '../../../reducers/vis-state-updaters';--export type FileUploadProps = {- onFileUpload: (files: File[]) => void;- fileLoading: FileLoading | false;- fileLoadingProgress: FileLoadingProgress;- intl: any;- theme: object;- /** A list of names of supported formats suitable to present to user */- fileFormatNames?: string[];- /** A list of typically 3 letter extensions (without '.') for file matching */- fileExtensions?: string[];- /** Set to true if app wants to do its own file filtering */- disableExtensionFilter?: boolean;-};--export const WarningMsg: React.Component;--export const FileUpload: React.Component<FileUploadProps>;--export default function FileUploadFactory(): React.Component<FileUploadProps>;diff --git a/src/components/common/file-uploader/file-upload.js b/src/components/common/file-uploader/file-upload.tsxsimilarity index 89%rename from src/components/common/file-uploader/file-upload.jsrename to src/components/common/file-uploader/file-upload.tsxindex e98a5c456..41abc7bba 100644--- a/src/components/common/file-uploader/file-upload.js+++ b/src/components/common/file-uploader/file-upload.tsx@@ -20,11 +20,13 @@import React, {Component, createRef} from 'react';import styled from 'styled-components';-import {injectIntl} from 'react-intl';+import {injectIntl, WrappedComponentProps} from 'react-intl';import UploadButton from './upload-button';import {DragNDrop, FileType} from 'components/common/icons';import FileUploadProgress from 'components/common/file-uploader/file-upload-progress';import FileDrop from './file-drop';+import {FileLoading, FileLoadingProgress} from 'reducers/vis-state-updaters';+import {isChrome} from 'utils/utils';import {GUIDES_FILE_FORMAT_DOC} from 'constants/user-guides';@@ -60,7 +62,11 @@ export const WarningMsg = styled.span`font-weight: 500;`;-const StyledFileDrop = styled.div`+interface StyledFileDropProps {+ dragOver?: boolean;+}++const StyledFileDrop = styled.div<StyledFileDropProps>`background-color: white;border-radius: 4px;border-style: ${props => (props.dragOver ? 'solid' : 'dashed')};@@ -146,9 +152,22 @@ const StyledDisclaimer = styled(StyledMessage)`margin: 0 auto;`;+type FileUploadProps = {+ onFileUpload: (files: File[]) => void;+ fileLoading: FileLoading | false;+ fileLoadingProgress: FileLoadingProgress;+ theme: object;+ /** A list of names of supported formats suitable to present to user */+ fileFormatNames?: string[];+ /** A list of typically 3 letter extensions (without '.') for file matching */+ fileExtensions?: string[];+ /** Set to true if app wants to do its own file filtering */+ disableExtensionFilter?: boolean;+} & WrappedComponentProps+function FileUploadFactory() {/** @augments {Component<FileUploadProps>} */- class FileUpload extends Component {+ class FileUpload extends Component<FileUploadProps> {state = {dragOver: false,fileLoading: false,@@ -168,7 +187,7 @@ function FileUploadFactory() {};}- frame = createRef();+ frame = createRef<HTMLDivElement>();_isValidFileType = filename => {const {fileExtensions = []} = this.props;@@ -178,7 +197,7 @@ function FileUploadFactory() {};/** @param {FileList} fileList */- _handleFileInput = (fileList, event) => {+ _handleFileInput = (fileList: FileList, event: any) => {if (event) {event.stopPropagation();}@@ -188,8 +207,8 @@ function FileUploadFactory() {const {disableExtensionFilter = false} = this.props;// TODO - move this code out of the component- const filesToLoad = [];- const errorFiles = [];+ const filesToLoad: File[] = [];+ const errorFiles: string[] = [];for (const file of files) {if (disableExtensionFilter || this._isValidFileType(file.name)) {filesToLoad.push(file);diff --git a/src/components/common/file-uploader/upload-button.d.ts b/src/components/common/file-uploader/upload-button.d.tsdeleted file mode 100644index 1ffd85da2..000000000--- a/src/components/common/file-uploader/upload-button.d.ts+++ /dev/null@@ -1,8 +0,0 @@-import React from 'react';--export type UploadButtonProps = {- onUpload: (files: FileList, event: any) => void;-};--export const UploadButton: React.FC<UploadButtonProps>;-export default UploadButton;diff --git a/src/components/common/file-uploader/upload-button.js b/src/components/common/file-uploader/upload-button.tsxsimilarity index 91%rename from src/components/common/file-uploader/upload-button.jsrename to src/components/common/file-uploader/upload-button.tsxindex e1c5c3f18..fb0d77ba3 100644--- a/src/components/common/file-uploader/upload-button.js+++ b/src/components/common/file-uploader/upload-button.tsx@@ -18,7 +18,7 @@// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN// THE SOFTWARE.-import React, {useCallback, useRef} from 'react';+import React, {ReactNode, useCallback, useRef} from 'react';import styled from 'styled-components';const Wrapper = styled.div`@@ -34,11 +34,16 @@ const Wrapper = styled.div``;const inputStyle = {display: 'none'};+interface UploadButtonProps {+ onUpload: (files: FileList, event: any) => void;+ children?: ReactNode;+}+/*Inspired by https://github.com/okonet/react-dropzone/blob/master/src/index.js*//** @type {typeof import('./upload-button').UploadButton} */-const UploadButton = ({onUpload, children}) => {+const UploadButton = ({onUpload, children}: UploadButtonProps) => {const _fileInput = useRef(null);const _onClick = useCallback(() => {diff --git a/src/components/common/item-selector/accessor.js b/src/components/common/item-selector/accessor.tssimilarity index 95%rename from src/components/common/item-selector/accessor.jsrename to src/components/common/item-selector/accessor.tsindex 8346c13e5..03103877b 100644--- a/src/components/common/item-selector/accessor.js+++ b/src/components/common/item-selector/accessor.ts@@ -21,7 +21,7 @@const Accessor = {IDENTITY_FN: input => input,- generateAccessor: field => object => object[field],+ generateAccessor: (field: string) => (object: object) => object[field],generateOptionToStringFor: function generateOptionToStringFor(prop) {if (typeof prop === 'string') {diff --git a/src/components/common/item-selector/chickleted-input.js b/src/components/common/item-selector/chickleted-input.tsxsimilarity index 78%rename from src/components/common/item-selector/chickleted-input.jsrename to src/components/common/item-selector/chickleted-input.tsxindex 19817994e..c3330e996 100644--- a/src/components/common/item-selector/chickleted-input.js+++ b/src/components/common/item-selector/chickleted-input.tsx@@ -18,29 +18,34 @@// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN// THE SOFTWARE.-import React from 'react';-import PropTypes from 'prop-types';+import React, { ElementType, MouseEventHandler, ReactNode } from 'react';import styled from 'styled-components';import Delete from '../icons/delete';import {FormattedMessage} from 'localization';-const propTypes = {+interface ChickletedInput {// required properties- onClick: PropTypes.func.isRequired,- removeItem: PropTypes.func.isRequired,+ onClick: MouseEventHandler<HTMLDivElement>,+ removeItem: Function,// optional properties- selectedItems: PropTypes.arrayOf(PropTypes.any),- disabled: PropTypes.bool,- displayOption: PropTypes.func,- focus: PropTypes.bool,- error: PropTypes.bool,- placeholder: PropTypes.string,- inputTheme: PropTypes.string+ selectedItems?: any[],+ disabled?: boolean,+ displayOption?: Function,+ focus?: boolean,+ error?: boolean,+ placeholder?: string,+ inputTheme?: string+ CustomChickletComponent?: ElementType+ className?: string};-export const ChickletButton = styled.div`+interface ChickletButtonProps {+ inputTheme?: string;+}++export const ChickletButton = styled.div<ChickletButtonProps>`background: ${props =>props.inputTheme === 'light' ? props.theme.chickletBgdLT : props.theme.chickletBgd};border-radius: 1px;@@ -71,14 +76,26 @@ export const ChickletTag = styled.span`}`;-const Chicklet = ({disabled, name, remove, inputTheme}) => (+interface ChickletProps {+ disabled?: boolean,+ name: ReactNode,+ remove?: MouseEventHandler<SVGSVGElement>,+ inputTheme?: string+}++const Chicklet = ({disabled, name, remove, inputTheme}: ChickletProps) => (<ChickletButton inputTheme={inputTheme}><ChickletTag>{name}</ChickletTag>- <Delete onClick={disabled ? null : remove} />+ <Delete onClick={disabled ? undefined : remove} /></ChickletButton>);-const ChickletedInputContainer = styled.div`+interface ChickletedInputContainerProps {+ inputTheme?: string;+ hasPlaceholder?: boolean;+}++const ChickletedInputContainer = styled.div<ChickletedInputContainerProps>`${props =>props.inputTheme === 'secondary'? props.theme.secondaryChickletedInput@@ -92,9 +109,7 @@ const ChickletedInputContainer = styled.div``;const ChickletedInput = ({- focus,disabled,- error,onClick,className,selectedItems = [],@@ -103,12 +118,9 @@ const ChickletedInput = ({displayOption = d => d,inputTheme,CustomChickletComponent-}) => (+}: ChickletedInput) => (<ChickletedInputContainerclassName={`${className} chickleted-input`}- focus={focus}- disabled={disabled}- error={error}onClick={onClick}inputTheme={inputTheme}hasPlaceholder={!selectedItems || !selectedItems.length}@@ -138,6 +150,4 @@ const ChickletedInput = ({</ChickletedInputContainer>);-ChickletedInput.propTypes = propTypes;-export default ChickletedInput;diff --git a/src/components/common/item-selector/dropdown-list.js b/src/components/common/item-selector/dropdown-list.tsxsimilarity index 72%rename from src/components/common/item-selector/dropdown-list.jsrename to src/components/common/item-selector/dropdown-list.tsxindex 2812cac53..0f1b802fe 100644--- a/src/components/common/item-selector/dropdown-list.js+++ b/src/components/common/item-selector/dropdown-list.tsx@@ -18,8 +18,7 @@// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN// THE SOFTWARE.-import React, {Component} from 'react';-import PropTypes from 'prop-types';+import React, {Component, ElementType} from 'react';import classNames from 'classnames';import styled from 'styled-components';@@ -32,11 +31,15 @@ export const classList = {};const defaultDisplay = d => d;-export const ListItem = ({value, displayOption = defaultDisplay}) => (+export const ListItem = ({value, displayOption = defaultDisplay, light}) => (<span className={classList.listItemAnchor}>{displayOption(value)}</span>);-const DropdownListWrapper = styled.div`+interface DropdownListWrapperProps {+ light?: boolean;+}++const DropdownListWrapper = styled.div<DropdownListWrapperProps>`background-color: ${props =>props.light ? props.theme.dropdownListBgdLT : props.theme.dropdownListBgd};border-top: 1px solid@@ -45,22 +48,26 @@ const DropdownListWrapper = styled.div`${props => (props.light ? props.theme.dropdownListLT : props.theme.dropdownList)};`;-export default class DropdownList extends Component {- static propTypes = {- options: PropTypes.arrayOf(PropTypes.any),- allowCustomValues: PropTypes.number,- customClasses: PropTypes.object,- customValues: PropTypes.arrayOf(PropTypes.any),- customListItemComponent: PropTypes.oneOfType([PropTypes.element, PropTypes.func]),- customListHeaderComponent: PropTypes.oneOfType([PropTypes.element, PropTypes.func]),- selectionIndex: PropTypes.number,- onOptionSelected: PropTypes.func,- displayOption: PropTypes.func.isRequired,- defaultClassNames: PropTypes.bool,- areResultsTruncated: PropTypes.bool,- resultsTruncatedMessage: PropTypes.string,- listItemComponent: PropTypes.func- };++interface DropdownListProps {+ options?: any[];+ allowCustomValues?: number;+ customClasses?: object,+ customValues?: any[],+ customListItemComponent?: ElementType,+ customListHeaderComponent?: ElementType+ selectionIndex?: number,+ onOptionSelected?: Function,+ displayOption?: Function,+ defaultClassNames?: boolean,+ areResultsTruncated?: boolean,+ resultsTruncatedMessage?: string,+ listItemComponent?: Function;+ light?: boolean;+ fixedOptions?: any[]+};++export default class DropdownList extends Component<DropdownListProps> {static defaultProps = {customClasses: {},@@ -76,15 +83,15 @@ export default class DropdownList extends Component {_onClick(result, event) {event.preventDefault();- this.props.onOptionSelected(result, event);+ this.props.onOptionSelected?.(result, event);}render() {- const {fixedOptions, light} = this.props;- const display = this.props.displayOption;+ const {fixedOptions, light, allowCustomValues = 0, customListItemComponent: CustomListItemComponent = ListItem} = this.props;+ const {displayOption: display = defaultDisplay} = this.props;// Don't render if there are no options to display- if (!this.props.options.length && this.props.allowCustomValues <= 0) {+ if (!this.props.options?.length && allowCustomValues <= 0) {return false;}@@ -102,7 +109,7 @@ export default class DropdownList extends Component {{valueOffset > 0 ? (<div className={classList.listSection}>- {fixedOptions.map((value, i) => (+ {fixedOptions?.map((value, i) => (<divclassName={classNames(classList.listItem, {hover: this.props.selectionIndex === i,@@ -112,13 +119,13 @@ export default class DropdownList extends Component {onMouseDown={e => this._onClick(value, e)}onClick={e => this._onClick(value, e)}>- <this.props.customListItemComponent value={value} displayOption={display} />+ <CustomListItemComponent value={value} displayOption={display} /></div>))}</div>) : null}- {this.props.options.map((value, i) => (+ {this.props.options?.map((value, i) => (<divclassName={classNames(classList.listItem, {hover: this.props.selectionIndex === i + valueOffset@@ -127,7 +134,7 @@ export default class DropdownList extends Component {onMouseDown={e => this._onClick(value, e)}onClick={e => this._onClick(value, e)}>- <this.props.customListItemComponent value={value} displayOption={display} />+ <CustomListItemComponent value={value} displayOption={display} /></div>))}</DropdownListWrapper>diff --git a/src/components/common/item-selector/item-selector.js b/src/components/common/item-selector/item-selector.tsxsimilarity index 81%rename from src/components/common/item-selector/item-selector.jsrename to src/components/common/item-selector/item-selector.tsxindex f3cd35e63..2d6aa01ef 100644--- a/src/components/common/item-selector/item-selector.js+++ b/src/components/common/item-selector/item-selector.tsx@@ -18,8 +18,7 @@// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN// THE SOFTWARE.-import React, {Component} from 'react';-import PropTypes from 'prop-types';+import React, {Component, ComponentType, ReactNode} from 'react';import classnames from 'classnames';import uniqBy from 'lodash.uniqby';import listensToClickOutside from 'react-onclickoutside';@@ -32,12 +31,17 @@ import {Delete, ArrowDown} from 'components/common/icons';import DropdownList, {ListItem} from './dropdown-list';import {toArray} from 'utils/utils';-import {injectIntl} from 'react-intl';+import {injectIntl, IntlShape} from 'react-intl';import {FormattedMessage} from 'localization';+interface StyledDropdownSelect {+ inputTheme?: string;+ size?: string;+}+export const StyledDropdownSelect = styled.div.attrs({className: 'item-selector__dropdown'-})`+})<StyledDropdownSelect>`${props =>props.inputTheme === 'secondary'? props.theme.secondaryInput@@ -53,7 +57,12 @@ export const StyledDropdownSelect = styled.div.attrs({}`;-const DropdownSelectValue = styled.span`+interface DropdownSelectValueProps {+ hasPlaceholder?: boolean;+ inputTheme?: string;+}++const DropdownSelectValue = styled.span<DropdownSelectValueProps>`color: ${props =>props.hasPlaceholder && props.inputTheme === 'light'? props.theme.selectColorPlaceHolderLT@@ -89,7 +98,11 @@ const DropdownSelectActionRight = styled.div`}`;-const DropdownWrapper = styled.div`+interface DropdownWrapperProps {+ placement?: string;+}++const DropdownWrapper = styled.div<DropdownWrapperProps>`border: 0;width: 100%;left: 0;@@ -102,57 +115,42 @@ const DropdownWrapper = styled.div`props.placement === 'top' ? `${props.theme.dropdownWapperMargin}px` : 'auto'};`;-class ItemSelector extends Component {- static propTypes = {- // required properties- selectedItems: PropTypes.oneOfType([- PropTypes.array,- PropTypes.string,- PropTypes.number,- PropTypes.bool,- PropTypes.object- ]),- onChange: PropTypes.func.isRequired,- options: PropTypes.arrayOf(PropTypes.any).isRequired,-- // optional properties- fixedOptions: PropTypes.arrayOf(PropTypes.any),- erasable: PropTypes.bool,- showArrow: PropTypes.bool,- displayOption: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),- getOptionValue: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),- filterOption: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),- placement: PropTypes.string,- disabled: PropTypes.bool,- isError: PropTypes.bool,- multiSelect: PropTypes.bool,- inputTheme: PropTypes.string,- onBlur: PropTypes.func,- placeholder: PropTypes.string,- closeOnSelect: PropTypes.bool,- typeaheadPlaceholder: PropTypes.string,- DropdownHeaderComponent: PropTypes.func,- DropDownRenderComponent: PropTypes.func,- DropDownLineItemRenderComponent: PropTypes.func,- CustomChickletComponent: PropTypes.func- };+type ItemSelectorProps = {+ selectedItems: ReadonlyArray<string | number | boolean | object>,+ options: ReadonlyArray<string | number | boolean | object>,+ onChange: (items: ReadonlyArray<string | number | boolean | object> | null) => void,+ fixedOptions?: any[],+ erasable?: boolean,+ showArrow?: boolean,+ searchable?: boolean,+ displayOption?: string | ((opt: any) => any),+ getOptionValue?: string | ((opt: any) => any),+ filterOption?: string | ((opt: any) => any),+ placement?: string,+ disabled?: boolean,+ isError?: boolean,+ multiSelect?: boolean,+ inputTheme?: string,+ size?: string,+ onBlur?: () => void,+ placeholder?: string,+ closeOnSelect?: boolean,+ typeaheadPlaceholder?: string,+ DropdownHeaderComponent?: ComponentType<any> | null,+ DropDownRenderComponent?: ComponentType<any>,+ DropDownLineItemRenderComponent?: ComponentType<any>,+ CustomChickletComponent?: ComponentType<any>;+ intl: IntlShape;+ children?: ReactNode;+};++class ItemSelector extends Component<ItemSelectorProps> {static defaultProps = {- erasable: false,- showArrow: false,- placement: 'bottom',- selectedItems: [],- displayOption: null,- getOptionValue: null,- filterOption: null,- fixedOptions: null,- inputTheme: 'primary',multiSelect: true,placeholder: 'placeholder.enterValue',closeOnSelect: true,searchable: true,- dropdownHeader: null,- DropdownHeaderComponent: null,DropDownRenderComponent: DropdownList,DropDownLineItemRenderComponent: ListItem};@@ -236,9 +234,10 @@ class ItemSelector extends Component {}};- _renderDropdown(intl) {+ _renderDropdown(intl: IntlShape) {+ const {placement = 'bottom'} = this.propsreturn (- <DropdownWrapper placement={this.props.placement}>+ <DropdownWrapper placement={placement}><TypeaheadcustomClasses={{results: 'list-selector',@@ -272,6 +271,7 @@ class ItemSelector extends Component {const selected = toArray(this.props.selectedItems);const hasValue = selected.length;const displayOption = Accessor.generateOptionToStringFor(this.props.displayOption);+ const {inputTheme = 'primary', DropDownLineItemRenderComponent = ListItem} = this.propsconst dropdownSelectProps = {className: classnames({@@ -281,7 +281,7 @@ class ItemSelector extends Component {disabled: this.props.disabled,onClick: this._showTypeahead,error: this.props.isError,- inputTheme: this.props.inputTheme,+ inputTheme: inputTheme,size: this.props.size};const intl = this.props.intl;@@ -297,20 +297,20 @@ class ItemSelector extends Component {placeholder={this.props.placeholder}removeItem={this._removeItem}CustomChickletComponent={this.props.CustomChickletComponent}- inputTheme={this.props.inputTheme}+ inputTheme={inputTheme}/>) : (<StyledDropdownSelect {...dropdownSelectProps}><DropdownSelectValuehasPlaceholder={!hasValue}- inputTheme={this.props.inputTheme}+ inputTheme={inputTheme}className="item-selector__dropdown__value">{hasValue ? (- <this.props.DropDownLineItemRenderComponent+ <DropDownLineItemRenderComponentdisplayOption={displayOption}value={selected[0]}- light={this.props.inputTheme === 'light'}+ light={inputTheme === 'light'}/>) : (<FormattedMessage id={this.props.placeholder || 'placeholder.selectValue'} />diff --git a/src/components/common/item-selector/typeahead.js b/src/components/common/item-selector/typeahead.tsxsimilarity index 77%rename from src/components/common/item-selector/typeahead.jsrename to src/components/common/item-selector/typeahead.tsxindex 9926c2d6e..35aeb16e9 100644--- a/src/components/common/item-selector/typeahead.js+++ b/src/components/common/item-selector/typeahead.tsx@@ -18,9 +18,8 @@// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN// THE SOFTWARE.-import React, {Component, createRef} from 'react';+import React, {Component, createRef, ElementType, KeyboardEventHandler} from 'react';import {polyfill} from 'react-lifecycles-compat';-import PropTypes from 'prop-types';import fuzzy from 'fuzzy';import classNames from 'classnames';import styled from 'styled-components';@@ -39,7 +38,11 @@ const DEFAULT_CLASS = 'typeahead';* keyboard or mouse to select.*/-const TypeaheadWrapper = styled.div`+interface TypeaheadWrapperProps {+ light?: boolean;+}++const TypeaheadWrapper = styled.div<TypeaheadWrapperProps>`display: flex;flex-direction: column;background-color: ${props =>@@ -57,7 +60,7 @@ const InputBox = styled.div.attrs({padding: 8px;`;-const TypeaheadInput = styled.input`+const TypeaheadInput = styled.input<TypeaheadWrapperProps>`${props => (props.light ? props.theme.inputLT : props.theme.secondaryInput)} :hover {cursor: pointer;background-color: ${props =>@@ -74,7 +77,7 @@ const InputIcon = styled.div.attrs({color: ${props => props.theme.inputPlaceholderColor};`;-function generateSearchFunction(props) {+function generateSearchFunction(props: TypeaheadProps) {const {searchOptions, filterOption} = props;if (typeof searchOptions === 'function') {if (filterOption !== null) {@@ -119,40 +122,63 @@ function shouldSkipSearch(input, state, showOptionsWhenEmpty) {return !(showOptionsWhenEmpty && isFocused) && emptyValue;}-class Typeahead extends Component {- static propTypes = {- name: PropTypes.string,- customClasses: PropTypes.object,- maxVisible: PropTypes.number,- resultsTruncatedMessage: PropTypes.string,- options: PropTypes.arrayOf(PropTypes.any),- fixedOptions: PropTypes.arrayOf(PropTypes.any),- allowCustomValues: PropTypes.number,- initialValue: PropTypes.string,- value: PropTypes.string,- placeholder: PropTypes.string,- disabled: PropTypes.bool,- textarea: PropTypes.bool,- inputProps: PropTypes.object,- onOptionSelected: PropTypes.func,- onChange: PropTypes.func,- onKeyDown: PropTypes.func,- onKeyPress: PropTypes.func,- onKeyUp: PropTypes.func,- onFocus: PropTypes.func,- onBlur: PropTypes.func,- filterOption: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),- searchOptions: PropTypes.func,- displayOption: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),- inputDisplayOption: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),- formInputOption: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),- defaultClassNames: PropTypes.bool,- customListComponent: PropTypes.oneOfType([PropTypes.element, PropTypes.func]),- customListItemComponent: PropTypes.oneOfType([PropTypes.element, PropTypes.func]),- customListHeaderComponent: PropTypes.oneOfType([PropTypes.element, PropTypes.func]),- showOptionsWhenEmpty: PropTypes.bool,- searchable: PropTypes.bool- };+interface TypeaheadProps {+ name?: string,+ customClasses?: any,+ maxVisible?: number,+ resultsTruncatedMessage?: string,+ options?: ReadonlyArray<string | number | boolean | object>,+ fixedOptions?: ReadonlyArray<string | number | boolean | object>,+ allowCustomValues?: number,+ initialValue?: string,+ value?: string,+ placeholder?: string,+ disabled?: boolean,+ textarea?: boolean,+ inputProps?: object,+ onOptionSelected?: (option: any, event: any) => any,+ onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void,+ onKeyDown?: (event: React.KeyboardEvent<HTMLDivElement>) => void,+ onKeyPress?: KeyboardEventHandler<HTMLDivElement>,+ onKeyUp?: KeyboardEventHandler<HTMLDivElement>,+ onFocus?: (event: React.FocusEvent<HTMLDivElement>) => void,+ onBlur?: (event: React.FocusEvent<HTMLInputElement>) => void,+ filterOption?: string | Function,+ searchOptions?: Function,+ displayOption?: string | Function,+ inputDisplayOption?: string | Function,+ formInputOption?: string | Function,+ defaultClassNames?: boolean,+ customListComponent?: ElementType,+ customListItemComponent?: ElementType | Function+ customListHeaderComponent?: ElementType | Function | null,+ showOptionsWhenEmpty?: boolean,+ searchable?: boolean;+ light?: boolean;+ inputIcon: ElementType;+ className?: string;+ selectedItems?: any[] | null;+};++interface TypeaheadState {+ /** @type {ReadonlyArray<string>} */+ searchResults: (string | undefined)[];++ // This should be called something else, 'entryValue'+ entryValue?: string;++ // A valid typeahead value+ selection?: string;++ // Index of the selection+ selectionIndex: null;++ // Keep track of the focus state of the input element, to determine+ // whether to show options when empty (if showOptionsWhenEmpty is true)+ isFocused: boolean;+}++class Typeahead extends Component<TypeaheadProps, TypeaheadState> {static defaultProps = {options: [],@@ -218,12 +244,12 @@ class Typeahead extends Component {if (this.entry.current) {this.entry.current.focus();} else {- this.root.current.focus();+ this.root.current?.focus();}}- root = createRef();- entry = createRef();+ root = createRef<HTMLDivElement>();+ entry = createRef<HTMLInputElement>();focus = () => {if (this.entry.current) {@@ -233,8 +259,8 @@ class Typeahead extends Component {_hasCustomValue = () => {return (- this.props.allowCustomValues > 0 &&- this.state.entryValue.length >= this.props.allowCustomValues &&+ Number(this.props.allowCustomValues) > 0 &&+ Number(this.state.entryValue?.length) >= Number(this.props.allowCustomValues) &&this.state.searchResults.indexOf(this.state.entryValue) < 0);};@@ -244,8 +270,9 @@ class Typeahead extends Component {};_renderIncrementalSearchResults() {+ const {customListComponent: CustomListComponent = DropdownList} = this.propsreturn (- <this.props.customListComponent+ <CustomListComponentfixedOptions={this.props.fixedOptions}options={this.props.maxVisible@@ -272,7 +299,7 @@ class Typeahead extends Component {}getSelection() {- let index = this.state.selectionIndex;+ let index = Number(this.state.selectionIndex);if (this._hasCustomValue()) {if (index === 0) {@@ -281,9 +308,9 @@ class Typeahead extends Component {index--;}if (this._hasFixedOptions()) {- return index < this.props.fixedOptions.length- ? this.props.fixedOptions[index]- : this.state.searchResults[index - this.props.fixedOptions.length];+ return index < Number(this.props.fixedOptions?.length)+ ? this.props.fixedOptions?.[index]+ : this.state.searchResults[index - Number(this.props.fixedOptions?.length)];}return this.state.searchResults[index];}@@ -298,13 +325,13 @@ class Typeahead extends Component {});}- return this.props.onOptionSelected(option, event);+ return this.props.onOptionSelected?.(option, event);};// use () => {} to avoid binding 'this'_onTextEntryUpdated = () => {if (this.props.searchable) {- const value = this.entry.current.value;+ const value = this.entry.current?.value;this.setState({searchResults: getOptionsForValue(value, this.props, this.state),@@ -317,7 +344,7 @@ class Typeahead extends Component {_onEnter = event => {const selection = this.getSelection();if (!selection) {- return this.props.onKeyDown(event);+ return this.props.onKeyDown?.(event);}return this._onOptionSelected(selection, event);};@@ -345,7 +372,7 @@ class Typeahead extends Component {}};- eventMap = event => {+ eventMap = () => {const events = {};events[KeyEvent.DOM_VK_UP] = this.navUp;@@ -391,7 +418,7 @@ class Typeahead extends Component {this._nav(-1);};- _onChange = event => {+ _onChange: React.ChangeEventHandler<HTMLInputElement> = event => {if (this.props.onChange) {this.props.onChange(event);}@@ -399,12 +426,12 @@ class Typeahead extends Component {this._onTextEntryUpdated();};- _onKeyDown = event => {+ _onKeyDown: React.KeyboardEventHandler<HTMLDivElement> = event => {// If there are no visible elements, don't perform selector navigation.// Just pass this up to the upstream onKeydown handler.// Also skip if the user is pressing the shift key, since none of our handlers are looking for shiftif (!this._hasHint() || event.shiftKey) {- return this.props.onKeyDown(event);+ return this.props.onKeyDown?.(event);}const handler = this.eventMap()[event.keyCode];@@ -412,20 +439,20 @@ class Typeahead extends Component {if (handler) {handler(event);} else {- return this.props.onKeyDown(event);+ return this.props.onKeyDown?.(event);}// Don't propagate the keystroke back to the DOM/browserevent.preventDefault();};- _onFocus = event => {+ _onFocus: React.FocusEventHandler<HTMLDivElement> = event => {this.setState({isFocused: true});if (this.props.onFocus) {return this.props.onFocus(event);}};- _onBlur = event => {+ _onBlur: React.FocusEventHandler<HTMLInputElement> = event => {this.setState({isFocused: false});if (this.props.onBlur) {return this.props.onBlur(event);@@ -450,20 +477,20 @@ class Typeahead extends Component {render() {const inputClasses = {};- inputClasses[this.props.customClasses.input] = Boolean(this.props.customClasses.input);+ inputClasses[this.props.customClasses?.input] = Boolean(this.props.customClasses?.input);const inputClassList = classNames(inputClasses);const classes = {[DEFAULT_CLASS]: this.props.defaultClassNames};- classes[this.props.className] = Boolean(this.props.className);+ classes[this.props.className?this.props.className:''] = Boolean(this.props.className);const classList = classNames(classes);return (<TypeaheadWrapperclassName={classList}ref={this.root}- tabIndex="0"+ tabIndex={0}onKeyDown={this._onKeyDown}onKeyPress={this.props.onKeyPress}onKeyUp={this.props.onKeyUp}diff --git a/src/components/common/portaled.tsx b/src/components/common/portaled.tsxindex dbed7159b..0315e7739 100644--- a/src/components/common/portaled.tsx+++ b/src/components/common/portaled.tsx@@ -18,7 +18,7 @@// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN// THE SOFTWARE.-import React, {Component, createRef, ElementType} from 'react';+import React, {Component, createRef, ElementType, ReactNode} from 'react';import debounce from 'lodash.debounce';import isEqual from 'lodash.isequal';@@ -137,13 +137,14 @@ interface PortaledProps {event: React.MouseEvent<Element, globalThis.MouseEvent> | React.KeyboardEvent<Element>) => void;theme?: any;- isOpened: boolean;+ isOpened?: boolean;top: number;- left: number;+ left?: number;right: number;overlayZIndex?: number;- modalProps: Partial<ReactModal.Props>;+ modalProps?: Partial<ReactModal.Props>;modalStyle?: Partial<typeof defaultModalStyle>;+ children?: ReactNode;}interface PortaledState {@@ -187,7 +188,7 @@ class Portaled extends Component<PortaledProps, PortaledState> {if (didOpen || didClose) {window.requestAnimationFrame(() => {if (this._unmounted) return;- this.setState({isVisible: didOpen});+ this.setState({isVisible: Boolean(didOpen)});});}@@ -209,7 +210,7 @@ class Portaled extends Component<PortaledProps, PortaledState> {const rect = this.element.current.getBoundingClientRect();const childRect = this.child.current.getBoundingClientRect();const pageOffset = getPageOffset();- const {top: topOffset, left: leftOffset, right: rightOffset} = this.props;+ const {top: topOffset, left: leftOffset = 0, right: rightOffset} = this.props;const pos = getChildPos({offsets: {topOffset, leftOffset, rightOffset},diff --git a/src/components/common/range-slider.tsx b/src/components/common/range-slider.tsxindex aa03ee924..3d0b60875 100644--- a/src/components/common/range-slider.tsx+++ b/src/components/common/range-slider.tsx@@ -63,7 +63,7 @@ interface RangeSliderProps {range?: number[];value0: number;value1: number;- onChange: (val: number[]) => void; //TODO+ onChange?: (val: number[]) => void; //TODOhistogram?: any[];isRanged?: boolean;isEnlarged?: boolean;@@ -74,9 +74,9 @@ interface RangeSliderProps {sliderHandleWidth?: number;xAxis?: ElementType;timezone?: string;- timeFormat: string;+ timeFormat?: string;playbackControlWidth?: number;- lineChart: LineChart;+ lineChart?: LineChart;marks?: number[];plotType?: string;plotValue?: number[];@@ -155,7 +155,7 @@ export default function RangeSliderFactory(RangePlot: ReturnType<typeof RangePlo};_setRangeVal1 = val => {- const {value0, range, onChange} = this.props;+ const {value0, range, onChange = () => {}} = this.props;if (!range) return;const val1 = Number(val);onChange([value0, clamp([value0, range[1]], this._roundValToStep(val1))]);@@ -163,7 +163,7 @@ export default function RangeSliderFactory(RangePlot: ReturnType<typeof RangePlo};_setRangeVal0 = val => {- const {value1, range, onChange} = this.props;+ const {value1, range, onChange = () => {}} = this.props;if (!range) return;const val0 = Number(val);onChange([clamp([range[0], value1], this._roundValToStep(val0)), value1]);@@ -225,7 +225,7 @@ export default function RangeSliderFactory(RangePlot: ReturnType<typeof RangePlohistogram,lineChart,range,- onChange,+ onChange = () => {},sliderHandleWidth,step,timezone,diff --git a/src/components/side-panel/layer-panel/add-layer-button.js b/src/components/side-panel/layer-panel/add-layer-button.jsindex aaf0867d6..ebe7e8373 100644--- a/src/components/side-panel/layer-panel/add-layer-button.js+++ b/src/components/side-panel/layer-panel/add-layer-button.js@@ -171,7 +171,6 @@ function AddLayerButtonFactory() {selectedItems={null}options={options}displayOption={Accessor.generateOptionToStringFor('label')}- getOptionValue={'value'}filterOption={'label'}searchableonOptionSelected={toggleSelectedOption}diff --git a/src/components/side-panel/panel-dropdown.js b/src/components/side-panel/panel-dropdown.jsindex 7538e85f6..e6b5cc87a 100644--- a/src/components/side-panel/panel-dropdown.js+++ b/src/components/side-panel/panel-dropdown.js@@ -27,7 +27,8 @@ class ClickOutsideCloseDropdown extends Component {static propTypes = {onClose: PropTypes.func,show: PropTypes.bool,- type: PropTypes.string+ type: PropTypes.string,+ className: PropTypes.string};static defaultProps = {diff --git a/yarn.lock b/yarn.lockindex a9ecc4d25..5cb583450 100644--- a/yarn.lock+++ b/yarn.lock@@ -3263,6 +3263,20 @@resolved "https://registry.yarnpkg.com/@types/keymirror/-/keymirror-0.1.1.tgz#1fe48e6e5e2a969cafecf0f24485ae23c72abd30"integrity sha1-H+SObl4qlpyv7PDyRIWuI8cqvTA=+"@types/lodash.get@^4.4.6":+ version "4.4.6"+ resolved "https://registry.yarnpkg.com/@types/lodash.get/-/lodash.get-4.4.6.tgz#0c7ac56243dae0f9f09ab6f75b29471e2e777240"+ integrity sha512-E6zzjR3GtNig8UJG/yodBeJeIOtgPkMgsLjDU3CbgCAPC++vJ0eCMnJhVpRZb/ENqEFlov1+3K9TKtY4UdWKtQ==+ dependencies:+ "@types/lodash" "*"++"@types/lodash.isequal@^4.5.5":+ version "4.5.5"+ resolved "https://registry.yarnpkg.com/@types/lodash.isequal/-/lodash.isequal-4.5.5.tgz#4fed1b1b00bef79e305de0352d797e9bb816c8ff"+ integrity sha512-4IKbinG7MGP131wRfceK6W4E/Qt3qssEFLF30LnJbjYiSfHGGRU/Io8YxXrZX109ir+iDETC8hw8QsDijukUVg==+ dependencies:+ "@types/lodash" "*"+"@types/lodash.pick@^4.4.6":version "4.4.6"resolved "https://registry.yarnpkg.com/@types/lodash.pick/-/lodash.pick-4.4.6.tgz#ae4e8f109e982786313bb6aac4b1a73aefa6e9be"@@ -3346,6 +3360,13 @@dependencies:"@types/react" "*"+"@types/react-onclickoutside@^6.7.4":+ version "6.7.4"+ resolved "https://registry.yarnpkg.com/@types/react-onclickoutside/-/react-onclickoutside-6.7.4.tgz#05b1ec0d31a85999873c51e166f57aefa3f037a4"+ integrity sha512-N7EnMhxqb+TaUOGJQUV8YJeL3n5qP5+cXwtWRS/FYW+DSEAb8T3xwNsgZ6wEJMHP4/QpfVHcBaFopFjJ9XBuOg==+ dependencies:+ "@types/react" "*"+"@types/react-test-renderer@*":version "17.0.0"resolved "https://registry.yarnpkg.com/@types/react-test-renderer/-/react-test-renderer-17.0.0.tgz#9be47b375eeb906fced37049e67284a438d56620"@@ -3353,6 +3374,14 @@dependencies:"@types/react" "*"+"@types/react-virtualized@^9.21.20":+ version "9.21.20"+ resolved "https://registry.yarnpkg.com/@types/react-virtualized/-/react-virtualized-9.21.20.tgz#756c78b5512a2a1804fdaf749a5f5cff3d805e5b"+ integrity sha512-i8nZf1LpuX5rG4DZLaPGayIQwjxsZwmst5VdNhEznDTENel9p3A735AdRRp2iueFOyOuWBmaEaDxg8AD3GHilA==+ dependencies:+ "@types/prop-types" "*"+ "@types/react" "*"+"@types/react-vis@^1.8.0":version "1.11.10"resolved "https://registry.yarnpkg.com/@types/react-vis/-/react-vis-1.11.10.tgz#eb281db2366215665a14f7f5161f377e90da34b7"