Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

[Chore]: Technical: Translate root components to typescript (#1790)

dariaterekhovaaea5bcd814d6ad
diff --git a/package.json b/package.json
index a6686ac7b..8272892fc 100644
--- a/package.json
+++ b/package.json
@@ -45,7 +45,7 @@
"start:e2e": "npm run install-and-start -- examples/demo-app start-local-e2e",
"build": "rm -fr dist && babel src --out-dir dist --source-maps inline --extensions '.ts,.tsx,.js,.jsx' --ignore '**/*.d.ts'",
"build:umd": "webpack --config ./webpack/umd.js --progress --env.prod",
- "build:types": "webpack --config ./webpack/build_types.js --progress",
+ "build:types": "tsc --project tsconfig.production.json",
"analyze": "npm run analyze:bundle",
"analyze:bundle": "webpack --config ./webpack/bundle.js --progress --env.prod",
"check-licence": "uber-licence --dry",
@@ -111,9 +111,12 @@
"@types/lodash.get": "^4.4.6",
"@types/lodash.isequal": "^4.5.5",
"@types/lodash.pick": "^4.4.6",
+ "@types/mapbox__geo-viewport": "^0.4.1",
"@types/react-lifecycles-compat": "^3.0.1",
+ "@types/react-map-gl": "^6.1.2",
"@types/react-modal": "^3.13.1",
"@types/react-onclickoutside": "^6.7.4",
+ "@types/react-redux": "^7.1.23",
"@types/react-virtualized": "^9.21.20",
"@types/react-vis": "^1.8.0",
"classnames": "^2.2.1",
diff --git a/src/components/bottom-widget.tsx b/src/components/bottom-widget.tsx
index 7c795f16b..fc1531b8f 100644
--- a/src/components/bottom-widget.tsx
+++ b/src/components/bottom-widget.tsx
@@ -26,10 +26,17 @@ import AnimationControllerFactory from './common/animation-control/animation-con
import {ANIMATION_WINDOW, DIMENSIONS, FILTER_TYPES} from 'constants/default-settings';
import {getIntervalBins} from 'utils/filter-utils';
import {media} from 'styles/media-breakpoints';
+import {AnimationConfig, TimeRangeFilter} from 'reducers';
+import {bottomWidgetSelector} from './kepler-gl';
const maxWidth = 1080;
-const BottomWidgetContainer = styled.div`
+interface BottomWidgetContainerProps {
+ hasPadding?: boolean;
+ width: number;
+}
+
+const BottomWidgetContainer = styled.div<BottomWidgetContainerProps>`
display: flex;
flex-direction: column;
padding-top: ${props => (props.hasPadding ? props.theme.bottomWidgetPaddingTop : 0)}px;
@@ -46,9 +53,22 @@ const BottomWidgetContainer = styled.div`
${media.portable`padding: 0;`}
`;
+interface FilterAnimationControllerProps {
+ filter: TimeRangeFilter & {animationWindow?: string};
+ filterIdx: number;
+ setFilterAnimationTime: (idx: number, value: string, a: any[]) => void;
+}
+
FilterAnimationControllerFactory.deps = [AnimationControllerFactory];
-export function FilterAnimationControllerFactory(AnimationController: ReturnType<typeof AnimationControllerFactory>) {
- const FilterAnimationController = ({filter, filterIdx, setFilterAnimationTime, children}) => {
+export function FilterAnimationControllerFactory(
+ AnimationController: ReturnType<typeof AnimationControllerFactory>
+) {
+ const FilterAnimationController: React.FC<FilterAnimationControllerProps> = ({
+ filter,
+ filterIdx,
+ setFilterAnimationTime,
+ children
+ }) => {
const intervalBins = useMemo(() => getIntervalBins(filter), [filter]);
const steps = useMemo(() => (intervalBins ? intervalBins.map(x => x.x0) : null), [
@@ -90,12 +110,23 @@ export function FilterAnimationControllerFactory(AnimationController: ReturnType
return FilterAnimationController;
}
+interface LayerAnimationControllerProps {
+ animationConfig: AnimationConfig & {timeSteps?: number[] | null};
+ setLayerAnimationTime: (x: number) => void;
+}
+
LayerAnimationControllerFactory.deps = [AnimationControllerFactory];
-export function LayerAnimationControllerFactory(AnimationController: ReturnType<typeof AnimationControllerFactory>) {
- const LayerAnimationController = ({animationConfig, setLayerAnimationTime, children}) => (
- <AnimationController
+export function LayerAnimationControllerFactory(
+ AnimationController: ReturnType<typeof AnimationControllerFactory>
+) {
+ const LayerAnimationController: React.FC<LayerAnimationControllerProps> = ({
+ animationConfig,
+ setLayerAnimationTime,
+ children
+ }) => (
+ <AnimationController<number>
key="layer-control"
- value={animationConfig.currentTime}
+ value={Number(animationConfig.currentTime)}
domain={animationConfig.domain}
speed={animationConfig.speed}
isAnimating={animationConfig.isAnimating}
@@ -110,6 +141,10 @@ export function LayerAnimationControllerFactory(AnimationController: ReturnType<
return LayerAnimationController;
}
+type BottomWidgetProps = {
+ containerW: number;
+} & ReturnType<typeof bottomWidgetSelector>;
+
BottomWidgetFactory.deps = [
TimeWidgetFactory,
AnimationControlFactory,
@@ -124,7 +159,7 @@ export default function BottomWidgetFactory(
FilterAnimationController: ReturnType<typeof FilterAnimationControllerFactory>,
LayerAnimationController: ReturnType<typeof LayerAnimationControllerFactory>
) {
- const BottomWidget = props => {
+ const BottomWidget = (props: BottomWidgetProps) => {
const {
datasets,
filters,
@@ -172,7 +207,7 @@ export default function BottomWidgetFactory(
// if filter is not animating, pass in enlarged filter here because
// animation controller needs to call reset on it
- const filter = animatedFilter || filters[enlargedFilterIdx];
+ const filter = (animatedFilter as TimeRangeFilter) || filters[enlargedFilterIdx];
return (
<BottomWidgetContainer
@@ -234,7 +269,7 @@ export default function BottomWidgetFactory(
/* eslint-disable react/display-name */
// @ts-ignore
- return forwardRef((props, ref) => <BottomWidget {...props} rootRef={ref} />);
+ return forwardRef((props: BottomWidgetProps, ref) => <BottomWidget {...props} rootRef={ref} />);
/* eslint-enable react/display-name */
}
/* eslint-enable complexity */
diff --git a/src/components/common/animation-control/animation-control.tsx b/src/components/common/animation-control/animation-control.tsx
index 88eacbf2b..03b35feb6 100644
--- a/src/components/common/animation-control/animation-control.tsx
+++ b/src/components/common/animation-control/animation-control.tsx
@@ -58,7 +58,10 @@ const StyledDomain = styled.div.attrs({
AnimationControlFactory.deps = [PlaybackControlsFactory, FloatingTimeDisplayFactory];
-function AnimationControlFactory(PlaybackControls: ReturnType<typeof PlaybackControlsFactory>, FloatingTimeDisplay: ReturnType<typeof FloatingTimeDisplayFactory>) {
+function AnimationControlFactory(
+ PlaybackControls: ReturnType<typeof PlaybackControlsFactory>,
+ FloatingTimeDisplay: ReturnType<typeof FloatingTimeDisplayFactory>
+) {
const AnimationControl = ({
isAnimatable,
isAnimating,
diff --git a/src/components/common/animation-control/animation-controller.ts b/src/components/common/animation-control/animation-controller.ts
index e26724ea4..e42a61c3c 100644
--- a/src/components/common/animation-control/animation-controller.ts
+++ b/src/components/common/animation-control/animation-controller.ts
@@ -24,18 +24,22 @@ import {requestAnimationFrame, cancelAnimationFrame} from 'global/window';
import Console from 'global/console';
import {BASE_SPEED, FPS, ANIMATION_WINDOW} from 'constants/default-settings';
-type AnimationControllerProps = {
+interface AnimationControllerProps<T extends number | number[]> {
isAnimating?: boolean;
speed?: number;
- updateAnimation: Function;
+ updateAnimation: (x: T) => void;
animationWindow?: string;
steps?: number[] | null;
- domain: number[];
- value: number[];
+ domain: number[] | null;
+ value: T;
baseSpeed?: number;
}
-function AnimationControllerFactory() {
+class AnimationControllerType<T extends number | number[]> extends Component<
+ AnimationControllerProps<T>
+> {}
+
+function AnimationControllerFactory(): typeof AnimationControllerType {
/**
* 4 Animation Window Types
* 1. free
@@ -58,15 +62,16 @@ 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<AnimationControllerProps> {
-
+ class AnimationController<T extends number | number[]> extends Component<
+ AnimationControllerProps<T>
+ > {
static defaultProps = {
baseSpeed: BASE_SPEED,
speed: 1,
steps: null,
animationWindow: ANIMATION_WINDOW.free
};
-
+
state = {
isAnimating: false
};
@@ -86,7 +91,7 @@ function AnimationControllerFactory() {
}
_timer = null;
- _startTime: number | undefined;
+ _startTime: number = 0;
_startOrPauseAnimation() {
const {isAnimating, speed = 1} = this.props;
@@ -102,7 +107,6 @@ function AnimationControllerFactory() {
const loop = () => {
const current = new Date().getTime();
- // @ts-ignore
const delta = current - this._startTime;
if (delta >= delay) {
@@ -118,22 +122,25 @@ function AnimationControllerFactory() {
_resetAnimationByDomain = () => {
const {domain, value, animationWindow} = this.props;
+ if (!domain) {
+ return;
+ }
if (Array.isArray(value)) {
if (animationWindow === ANIMATION_WINDOW.incremental) {
- this.props.updateAnimation([value[0], value[0] + 1]);
+ this.props.updateAnimation([value[0], value[0] + 1] as T);
} else {
- this.props.updateAnimation([domain[0], domain[0] + value[1] - value[0]]);
+ this.props.updateAnimation([domain[0], domain[0] + value[1] - value[0]] as T);
}
} else {
- this.props.updateAnimation(domain[0]);
+ this.props.updateAnimation(domain[0] as T);
}
};
_resetAnimtionByTimeStep = () => {
- const {steps = null} = this.props
+ const {steps = null} = this.props;
if (!steps) return;
// go to the first steps
- this.props.updateAnimation([steps[0], 0]);
+ this.props.updateAnimation([steps[0], 0] as T);
};
_resetAnimation = () => {
@@ -186,18 +193,21 @@ function AnimationControllerFactory() {
? this._nextFrameByTimeStep()
: this._nextFrameByDomain();
- this.props.updateAnimation(nextValue);
+ this.props.updateAnimation(nextValue as T);
};
_nextFrameByDomain() {
const {domain, value, speed = 1, baseSpeed = 600, animationWindow} = this.props;
+ if (!domain) {
+ return;
+ }
const delta = ((domain[1] - domain[0]) / baseSpeed) * speed;
// loop when reaches the end
// current time is a range
if (Array.isArray(value)) {
- let value0;
- let value1;
+ let value0: number;
+ let value1: number;
const readEnd = value[1] + delta > domain[1];
if (animationWindow === ANIMATION_WINDOW.incremental) {
value0 = value[0];
@@ -210,13 +220,13 @@ function AnimationControllerFactory() {
}
// current time is a point
- return value + delta > domain[1] ? domain[0] : value + delta;
+ return Number(value) + delta > domain[1] ? domain[0] : Number(value) + delta;
}
_nextFrameByTimeStep() {
const {steps = null, value} = this.props;
if (!steps) return;
- const val = Array.isArray(value) ? value[0] : value;
+ const val = Array.isArray(value) ? value[0] : Number(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.tsx b/src/components/common/animation-control/animation-speed-slider.tsx
index 8db83aee5..82478ec81 100644
--- a/src/components/common/animation-control/animation-speed-slider.tsx
+++ b/src/components/common/animation-control/animation-speed-slider.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} from 'react';
+import React, {Component, ComponentType} from 'react';
import styled from 'styled-components';
import RangeSliderFactory from 'components/common/range-slider';
import onClickOutside from 'react-onclickoutside';
@@ -48,10 +48,12 @@ AnimationSpeedSliderFactory.deps = [RangeSliderFactory];
interface AnimationSpeedSliderProps {
onHide: () => void;
speed: number;
- updateAnimationSpeed: (val: number) => void
+ updateAnimationSpeed: (val: number) => void;
}
-export default function AnimationSpeedSliderFactory(RangeSlider: ReturnType<typeof RangeSliderFactory>) {
+export default function AnimationSpeedSliderFactory(
+ RangeSlider: ReturnType<typeof RangeSliderFactory>
+): ComponentType<AnimationSpeedSliderProps> {
class AnimationSpeedSlider extends Component<AnimationSpeedSliderProps> {
handleClickOutside = e => {
this.props.onHide();
diff --git a/src/components/common/animation-control/floating-time-display.tsx b/src/components/common/animation-control/floating-time-display.tsx
index eed85ec48..10346f9bd 100644
--- a/src/components/common/animation-control/floating-time-display.tsx
+++ b/src/components/common/animation-control/floating-time-display.tsx
@@ -106,8 +106,8 @@ const TimeDivider = () => (
</StyledHorizontalBar>
);
-interface TimeDisplayRowProps{
- timeValues?: string[]
+interface TimeDisplayRowProps {
+ timeValues?: string[];
}
const TimeDisplayRow = ({timeValues = []}: TimeDisplayRowProps) => (
@@ -119,14 +119,19 @@ const TimeDisplayRow = ({timeValues = []}: TimeDisplayRowProps) => (
);
interface FloatingTimeDisplayProps {
- currentTime: number | number[],
- defaultTimeFormat?: string,
- timeFormat?: string,
- timezone?: string
+ currentTime: number | number[];
+ defaultTimeFormat?: string;
+ timeFormat?: string;
+ timezone?: string;
}
export default function FloatingTimeDisplayFactory() {
- const FloatingTimeDisplay = ({currentTime, defaultTimeFormat, timeFormat, timezone}: FloatingTimeDisplayProps) => {
+ const FloatingTimeDisplay = ({
+ currentTime,
+ defaultTimeFormat,
+ timeFormat,
+ timezone
+ }: FloatingTimeDisplayProps) => {
const {displayDate, displayTime} = useMemo(() => {
const groupTime = Array.isArray(currentTime) ? currentTime : [currentTime];
const hasUserFormat = typeof timeFormat === 'string';
@@ -140,7 +145,7 @@ export default function FloatingTimeDisplayFactory() {
displayTime: []
};
}
- return groupTime.reduce<{displayDate: string[], displayTime: string[]}>(
+ 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.tsx b/src/components/common/animation-control/playback-controls.tsx
index dd5d2d901..4a65249fc 100644
--- a/src/components/common/animation-control/playback-controls.tsx
+++ b/src/components/common/animation-control/playback-controls.tsx
@@ -27,7 +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';
+import {ReactComponentLike} from 'prop-types';
const DELAY_SHOW = 500;
const DEFAULT_BUTTON_HEIGHT = '20px';
@@ -102,18 +102,18 @@ const DEFAULT_ANIMATE_ITEMS = {
};
interface AnimationItem {
- id: string,
- icon: ReactComponentLike,
- tooltip: string
+ id: string;
+ icon: ReactComponentLike;
+ tooltip: string;
}
interface AnimationWindowControlProps {
- onClick?: (id: string) => void,
- selected?: string,
- onHide: ()=>void,
- height?: string,
+ onClick?: (id: string) => void;
+ selected?: string;
+ onHide: () => void;
+ height?: string;
animationItems: {[key: string]: AnimationItem};
- btnStyle
+ btnStyle;
}
export const AnimationWindowControl = ({
@@ -134,7 +134,7 @@ export const AnimationWindowControl = ({
data-for={`${item.id}-tooltip`}
className="playback-control-button"
onClick={() => {
- onClick&&onClick(item.id);
+ onClick && onClick(item.id);
onHide();
}}
{...btnStyle}
@@ -152,12 +152,12 @@ export const AnimationWindowControl = ({
interface PlaybackControls {
isAnimatable?: boolean;
- isAnimating?: boolean,
- width?: number | string,
- speed: number,
- animationWindow?: string
- setFilterAnimationWindow?: (id: string) => void,
- updateAnimationSpeed,
+ isAnimating?: boolean;
+ width?: number | string;
+ speed: number;
+ animationWindow?: string;
+ setFilterAnimationWindow?: (id: string) => void;
+ updateAnimationSpeed;
pauseAnimation?: () => void;
resetAnimation: () => void;
startAnimation: () => void;
@@ -168,7 +168,9 @@ interface PlaybackControls {
}
PlaybackControlsFactory.deps = [AnimationSpeedSliderFactory];
-function PlaybackControlsFactory(AnimationSpeedSlider: ReturnType<typeof AnimationSpeedSliderFactory>) {
+function PlaybackControlsFactory(
+ AnimationSpeedSlider: ReturnType<typeof AnimationSpeedSliderFactory>
+) {
// eslint-disable-next-line complexity
const PlaybackControls = ({
isAnimatable = true,
diff --git a/src/components/common/data-table/button.tsx b/src/components/common/data-table/button.tsx
index c61ec5b9d..70c837813 100644
--- a/src/components/common/data-table/button.tsx
+++ 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, { MouseEventHandler, ReactNode } from 'react';
+import React, {MouseEventHandler} from 'react';
import styled from 'styled-components';
const StyledButton = styled.button`
@@ -39,11 +39,10 @@ const StyledButton = styled.button`
`;
type ButtonProps = {
- onClick?: MouseEventHandler<HTMLButtonElement>,
- disabled?: boolean,
- text?: string,
- children?: ReactNode
-} & React.ButtonHTMLAttributes<HTMLButtonElement>
+ onClick?: MouseEventHandler<HTMLButtonElement>;
+ disabled?: boolean;
+ text?: string;
+} & React.ButtonHTMLAttributes<HTMLButtonElement>;
const noop = () => {};
const Button = ({onClick = noop, disabled = false, text = '', children, ...props}: ButtonProps) => (
diff --git a/src/components/common/data-table/cell-size.ts b/src/components/common/data-table/cell-size.ts
index 6a45d373a..2d214edcf 100644
--- a/src/components/common/data-table/cell-size.ts
+++ b/src/components/common/data-table/cell-size.ts
@@ -119,7 +119,12 @@ function getSizeSum(sizeCache, key) {
* @param {number} containerWidth
* @param {number} roomToFill
*/
-function expandCellSize(cellSizeCache: object, columnOrder: string[], containerWidth: number, roomToFill: number) {
+function expandCellSize(
+ cellSizeCache: object,
+ columnOrder: string[],
+ containerWidth: number,
+ roomToFill: number
+) {
let remaining = roomToFill;
const expandedCellSize = columnOrder.reduce((accu, col) => {
diff --git a/src/components/common/data-table/grid.tsx b/src/components/common/data-table/grid.tsx
index 7f6aff403..ed92fb19e 100644
--- a/src/components/common/data-table/grid.tsx
+++ b/src/components/common/data-table/grid.tsx
@@ -23,8 +23,7 @@ import {Grid, GridProps} from 'react-virtualized';
import isEqual from 'lodash.isequal';
export default class GridHack extends PureComponent<GridProps> {
-
- grid: Grid | null = null
+ grid: Grid | null = null;
componentDidUpdate(preProps) {
/*
diff --git a/src/components/common/data-table/index.tsx b/src/components/common/data-table/index.tsx
index 0d35f717e..a5657a787 100644
--- a/src/components/common/data-table/index.tsx
+++ b/src/components/common/data-table/index.tsx
@@ -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,7 +298,7 @@ export const TableSection = ({
</AutoSizer>
);
-type CellSizeCache = {[id: string]: number}
+type CellSizeCache = {[id: string]: number};
interface DataTableProps {
cellSizeCache?: CellSizeCache;
@@ -310,9 +310,9 @@ interface DataTableProps {
}
interface DataTableState {
- cellSizeCache?: CellSizeCache,
- moreOptionsColumn?,
- ghost?
+ cellSizeCache?: CellSizeCache;
+ moreOptionsColumn?;
+ ghost?;
}
DataTableFactory.deps = [FieldTokenFactory];
@@ -382,7 +382,7 @@ function DataTableFactory(FieldToken: ReturnType<typeof FieldTokenFactory>) {
propsCache,
pinnedColumns,
unpinnedColumns
- ) as {cellSizeCache: {}, ghost: number | null | undefined};
+ ) as {cellSizeCache: {}; ghost: number | null | undefined};
return {
cellSizeCache,
@@ -396,13 +396,7 @@ function DataTableFactory(FieldToken: ReturnType<typeof FieldTokenFactory>) {
scaleCellsToWidth = debounce(this.doScaleCellsToWidth, 300);
- renderHeaderCell = (
- columns,
- isPinned,
- props,
- toggleMoreOptions,
- moreOptionsColumn
- ) => {
+ renderHeaderCell = (columns, isPinned, props, toggleMoreOptions, moreOptionsColumn) => {
// eslint-disable-next-line react/display-name
return cellInfo => {
const {columnIndex, key, style} = cellInfo;
diff --git a/src/components/common/data-table/option-dropdown.tsx b/src/components/common/data-table/option-dropdown.tsx
index f533c3b36..6ce13384c 100644
--- a/src/components/common/data-table/option-dropdown.tsx
+++ b/src/components/common/data-table/option-dropdown.tsx
@@ -54,8 +54,8 @@ const StyledOptionsDropdown = styled.div`
interface OptionDropdownProps {
isOpened?: boolean;
column: string;
- toggleMoreOptions: (order: string)=>void;
- sortTableColumn: (order: string)=>void;
+ toggleMoreOptions: (order: string) => void;
+ sortTableColumn: (order: string) => void;
pinTableColumn: () => void;
copyTableColumn: () => void;
sortMode?: string;
diff --git a/src/components/common/field-selector.tsx b/src/components/common/field-selector.tsx
index dc1922a36..8a5d65ca1 100644
--- a/src/components/common/field-selector.tsx
+++ b/src/components/common/field-selector.tsx
@@ -79,7 +79,7 @@ interface FieldSelectorFactoryProps {
fields?: FieldType[];
onSelect: (items: readonly (string | number | boolean | object)[] | null) => void;
placement?: string;
- value?: FieldType;
+ value?: FieldType | null;
filterFieldTypes?: FieldType | FieldType[];
inputTheme?: string;
placeholder?: string;
@@ -95,7 +95,7 @@ interface FieldSelectorFactoryProps {
function FieldSelectorFactory(
FieldListItemFactory: ReturnType<typeof FieldListItemFactoryFactory>
-) {
+): ComponentType<FieldSelectorFactoryProps> {
class FieldSelector extends Component<FieldSelectorFactoryProps> {
static defaultProps = {
erasable: true,
diff --git a/src/components/common/file-uploader/file-drop.tsx b/src/components/common/file-uploader/file-drop.tsx
index 587eac4c7..33a54bdd2 100644
--- a/src/components/common/file-uploader/file-drop.tsx
+++ b/src/components/common/file-uploader/file-drop.tsx
@@ -75,7 +75,6 @@ class FileDrop extends React.PureComponent<FileDropProps> {
draggingOverTargetClassName: 'file-drop-dragging-over-target'
};
-
frameDragCounter = 0;
state = {draggingOverFrame: false, draggingOverTarget: false};
diff --git a/src/components/common/file-uploader/file-upload-progress.tsx b/src/components/common/file-uploader/file-upload-progress.tsx
index a57b957a8..ba053b134 100644
--- a/src/components/common/file-uploader/file-upload-progress.tsx
+++ b/src/components/common/file-uploader/file-upload-progress.tsx
@@ -73,7 +73,7 @@ interface UploadProgressProps {
percent: number;
error?: any;
theme: any;
-}
+}
/**
* @param {object} params
@@ -105,11 +105,10 @@ const UploadProgress = ({message, fileName, percent, error, theme}: UploadProgre
);
};
-
interface FileUploadProgressProps {
fileLoadingProgress: FileLoadingProgress;
theme: any;
-};
+}
/** @type {React.FunctionComponent<FileUploadProgressProps>} */
const FileUploadProgress = ({fileLoadingProgress, theme}: FileUploadProgressProps) => (
diff --git a/src/components/common/file-uploader/file-upload.tsx b/src/components/common/file-uploader/file-upload.tsx
index 41abc7bba..62b5ed6cf 100644
--- a/src/components/common/file-uploader/file-upload.tsx
+++ b/src/components/common/file-uploader/file-upload.tsx
@@ -27,7 +27,6 @@ import FileUploadProgress from 'components/common/file-uploader/file-upload-prog
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';
import ReactMarkdown from 'react-markdown';
@@ -163,7 +162,7 @@ type FileUploadProps = {
fileExtensions?: string[];
/** Set to true if app wants to do its own file filtering */
disableExtensionFilter?: boolean;
-} & WrappedComponentProps
+} & WrappedComponentProps;
function FileUploadFactory() {
/** @augments {Component<FileUploadProps>} */
diff --git a/src/components/common/file-uploader/upload-button.tsx b/src/components/common/file-uploader/upload-button.tsx
index fb0d77ba3..04a67045d 100644
--- a/src/components/common/file-uploader/upload-button.tsx
+++ 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, {ReactNode, useCallback, useRef} from 'react';
+import React, {useCallback, useRef} from 'react';
import styled from 'styled-components';
const Wrapper = styled.div`
@@ -36,14 +36,13 @@ 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}: UploadButtonProps) => {
+const UploadButton: React.FC<UploadButtonProps> = ({onUpload, children}) => {
const _fileInput = useRef(null);
const _onClick = useCallback(() => {
diff --git a/src/components/common/icons/base.tsx b/src/components/common/icons/base.tsx
index 9cb966ab0..5b096aa31 100644
--- a/src/components/common/icons/base.tsx
+++ b/src/components/common/icons/base.tsx
@@ -77,7 +77,6 @@ export default class Base extends Component<BaseProps> {
const fillStyle =
Array.isArray(colors) && totalColor && getStyleClassFromColor(totalColor, colors);
-
return (
<svg
viewBox={viewBox}
diff --git a/src/components/common/item-selector/chickleted-input.tsx b/src/components/common/item-selector/chickleted-input.tsx
index c3330e996..3c81fb8bc 100644
--- a/src/components/common/item-selector/chickleted-input.tsx
+++ b/src/components/common/item-selector/chickleted-input.tsx
@@ -18,7 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-import React, { ElementType, MouseEventHandler, ReactNode } from 'react';
+import React, {ElementType, MouseEventHandler, ReactNode} from 'react';
import styled from 'styled-components';
import Delete from '../icons/delete';
@@ -26,20 +26,20 @@ import {FormattedMessage} from 'localization';
interface ChickletedInput {
// required properties
- onClick: MouseEventHandler<HTMLDivElement>,
- removeItem: Function,
+ onClick: MouseEventHandler<HTMLDivElement>;
+ removeItem: Function;
// optional properties
- selectedItems?: any[],
- disabled?: boolean,
- displayOption?: Function,
- focus?: boolean,
- error?: boolean,
- placeholder?: string,
- inputTheme?: string
- CustomChickletComponent?: ElementType
- className?: string
-};
+ selectedItems?: any[];
+ disabled?: boolean;
+ displayOption?: Function;
+ focus?: boolean;
+ error?: boolean;
+ placeholder?: string;
+ inputTheme?: string;
+ CustomChickletComponent?: ElementType;
+ className?: string;
+}
interface ChickletButtonProps {
inputTheme?: string;
@@ -77,10 +77,10 @@ export const ChickletTag = styled.span`
`;
interface ChickletProps {
- disabled?: boolean,
- name: ReactNode,
- remove?: MouseEventHandler<SVGSVGElement>,
- inputTheme?: string
+ disabled?: boolean;
+ name: ReactNode;
+ remove?: MouseEventHandler<SVGSVGElement>;
+ inputTheme?: string;
}
const Chicklet = ({disabled, name, remove, inputTheme}: ChickletProps) => (
diff --git a/src/components/common/item-selector/dropdown-list.tsx b/src/components/common/item-selector/dropdown-list.tsx
index 0f1b802fe..52c0bedc8 100644
--- a/src/components/common/item-selector/dropdown-list.tsx
+++ b/src/components/common/item-selector/dropdown-list.tsx
@@ -48,27 +48,25 @@ const DropdownListWrapper = styled.div<DropdownListWrapperProps>`
${props => (props.light ? props.theme.dropdownListLT : props.theme.dropdownList)};
`;
-
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,
+ 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[]
-};
+ fixedOptions?: any[];
+}
export default class DropdownList extends Component<DropdownListProps> {
-
static defaultProps = {
customClasses: {},
customListItemComponent: ListItem,
@@ -87,7 +85,12 @@ export default class DropdownList extends Component<DropdownListProps> {
}
render() {
- const {fixedOptions, light, allowCustomValues = 0, customListItemComponent: CustomListItemComponent = ListItem} = this.props;
+ 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
diff --git a/src/components/common/item-selector/item-selector.tsx b/src/components/common/item-selector/item-selector.tsx
index 2d6aa01ef..078ca4f81 100644
--- a/src/components/common/item-selector/item-selector.tsx
+++ b/src/components/common/item-selector/item-selector.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, ComponentType, ReactNode} from 'react';
+import React, {Component, ComponentType} from 'react';
import classnames from 'classnames';
import uniqBy from 'lodash.uniqby';
import listensToClickOutside from 'react-onclickoutside';
@@ -116,36 +116,34 @@ const DropdownWrapper = styled.div<DropdownWrapperProps>`
`;
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>,
+ 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 = {
multiSelect: true,
placeholder: 'placeholder.enterValue',
@@ -235,7 +233,7 @@ class ItemSelector extends Component<ItemSelectorProps> {
};
_renderDropdown(intl: IntlShape) {
- const {placement = 'bottom'} = this.props
+ const {placement = 'bottom'} = this.props;
return (
<DropdownWrapper placement={placement}>
<Typeahead
@@ -271,7 +269,7 @@ class ItemSelector extends Component<ItemSelectorProps> {
const selected = toArray(this.props.selectedItems);
const hasValue = selected.length;
const displayOption = Accessor.generateOptionToStringFor(this.props.displayOption);
- const {inputTheme = 'primary', DropDownLineItemRenderComponent = ListItem} = this.props
+ const {inputTheme = 'primary', DropDownLineItemRenderComponent = ListItem} = this.props;
const dropdownSelectProps = {
className: classnames({
diff --git a/src/components/common/item-selector/typeahead.tsx b/src/components/common/item-selector/typeahead.tsx
index 35aeb16e9..59040e320 100644
--- a/src/components/common/item-selector/typeahead.tsx
+++ b/src/components/common/item-selector/typeahead.tsx
@@ -123,42 +123,42 @@ function shouldSkipSearch(input, state, showOptionsWhenEmpty) {
}
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,
+ 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>} */
@@ -179,7 +179,6 @@ interface TypeaheadState {
}
class Typeahead extends Component<TypeaheadProps, TypeaheadState> {
-
static defaultProps = {
options: [],
customClasses: {},
@@ -270,7 +269,7 @@ class Typeahead extends Component<TypeaheadProps, TypeaheadState> {
};
_renderIncrementalSearchResults() {
- const {customListComponent: CustomListComponent = DropdownList} = this.props
+ const {customListComponent: CustomListComponent = DropdownList} = this.props;
return (
<CustomListComponent
fixedOptions={this.props.fixedOptions}
@@ -483,7 +482,7 @@ class Typeahead extends Component<TypeaheadProps, TypeaheadState> {
const classes = {
[DEFAULT_CLASS]: this.props.defaultClassNames
};
- classes[this.props.className?this.props.className:''] = Boolean(this.props.className);
+ classes[this.props.className ? this.props.className : ''] = Boolean(this.props.className);
const classList = classNames(classes);
return (
diff --git a/src/components/common/modal.tsx b/src/components/common/modal.tsx
index 14e31af28..26460dafa 100644
--- a/src/components/common/modal.tsx
+++ b/src/components/common/modal.tsx
@@ -149,9 +149,9 @@ export interface ModalDialogProps {
onConfirm: (...args: any) => any;
onCancel: (...args: any) => any;
confirmButton: object;
- confirmButtonLabel: string;
+ confirmButtonLabel?: string;
cancelButton: object;
- cancelButtonLabel: string;
+ cancelButtonLabel?: string;
cssStyle?: FlattenSimpleInterpolation | string;
style?: React.CSSProperties;
theme: any;
diff --git a/src/components/common/portaled.tsx b/src/components/common/portaled.tsx
index 0315e7739..847da34c7 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, ReactNode} from 'react';
+import React, {Component, createRef, ElementType} from 'react';
import debounce from 'lodash.debounce';
import isEqual from 'lodash.isequal';
@@ -144,7 +144,6 @@ interface PortaledProps {
overlayZIndex?: number;
modalProps?: Partial<ReactModal.Props>;
modalStyle?: Partial<typeof defaultModalStyle>;
- children?: ReactNode;
}
interface PortaledState {
@@ -271,10 +270,10 @@ class Portaled extends Component<PortaledProps, PortaledState> {
// failed to execute removeChild on parent node when it is already unmounted
return (
// @ts-ignore
- (context && context.current) || {
+ ((context && context.current) || {
removeChild: () => {},
appendChild: () => {}
- }
+ }) as HTMLElement
);
}}
onRequestClose={onClose}
diff --git a/src/components/common/range-slider.tsx b/src/components/common/range-slider.tsx
index 3d0b60875..286b2bcd3 100644
--- a/src/components/common/range-slider.tsx
+++ b/src/components/common/range-slider.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, ComponentType, createRef, ElementType} from 'react';
import {polyfill} from 'react-lifecycles-compat';
import {createSelector} from 'reselect';
import styled from 'styled-components';
@@ -84,7 +84,9 @@ interface RangeSliderProps {
RangeSliderFactory.deps = [RangePlotFactory];
-export default function RangeSliderFactory(RangePlot: ReturnType<typeof RangePlotFactory>) {
+export default function RangeSliderFactory(
+ RangePlot: ReturnType<typeof RangePlotFactory>
+): ComponentType<RangeSliderProps> {
class RangeSlider extends Component<RangeSliderProps> {
static defaultProps = {
isEnlarged: false,
diff --git a/src/components/container.js b/src/components/container.tsx
similarity index 81%
rename from src/components/container.js
rename to src/components/container.tsx
index f85b3006e..a6ef9d0d5 100644
--- a/src/components/container.js
+++ b/src/components/container.tsx
@@ -18,8 +18,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-import React, {Component} from 'react';
-import {connect} from 'react-redux';
+import React, {Component, ComponentType, Dispatch} from 'react';
+import {connect, ConnectedProps} from 'react-redux';
import memoize from 'lodash.memoize';
import {console as Console} from 'global/window';
import {injector, provideRecipesToInjector, flattenDeps} from './injector';
@@ -28,6 +28,7 @@ import {forwardTo} from 'actions/action-wrapper';
import {registerEntry, deleteEntry, renameEntry} from 'actions/identity-actions';
import {notNullorUndefined} from 'utils/data-utils';
+import {KeplerGlState} from 'reducers/core';
export const ERROR_MSG = {
noState:
@@ -36,9 +37,28 @@ export const ERROR_MSG = {
`If it is not mounted as state.keplerGl by default, you need to provide getState as a prop`
};
+const mapStateToProps = (state: any, props: ContainerProps) => ({state, ...props});
+const dispatchToProps = (dispatch: Dispatch<any>) => ({dispatch});
+const connector = connect(mapStateToProps, dispatchToProps);
+
+type ContainerProps = {
+ id: string;
+ mapboxApiAccessToken: string;
+ mapboxApiUrl?: string;
+ mapStylesReplaceDefault?: boolean;
+ initialUiState?: object;
+ width: number;
+ mint?: boolean;
+ getState: (state: any) => KeplerGlState;
+};
+
+type PropsFromRedux = ConnectedProps<typeof connector> & ContainerProps;
+
ContainerFactory.deps = [KeplerGlFactory];
-export function ContainerFactory(KeplerGl) {
+export function ContainerFactory(
+ KeplerGl: ReturnType<typeof KeplerGlFactory>
+): ComponentType<PropsFromRedux> {
/** @lends KeplerGl */
/**
* Main Kepler.gl Component
@@ -66,7 +86,8 @@ export function ContainerFactory(KeplerGl) {
* @param {Number} props.width - _required_ Width of the KeplerGl UI.
* @public
*/
- class Container extends Component {
+
+ class Container extends Component<PropsFromRedux> {
// default id and address if not provided
static defaultProps = {
id: 'map',
@@ -74,20 +95,16 @@ export function ContainerFactory(KeplerGl) {
mint: true
};
- constructor(props, ctx) {
- super(props, ctx);
+ getSelector = memoize((id, getState) => state => {
+ if (!getState(state)) {
+ // log error
+ Console.error(ERROR_MSG.noState);
- this.getSelector = memoize((id, getState) => state => {
- if (!getState(state)) {
- // log error
- Console.error(ERROR_MSG.noState);
-
- return null;
- }
- return getState(state)[id];
- });
- this.getDispatch = memoize((id, dispatch) => forwardTo(id, dispatch));
- }
+ return null;
+ }
+ return getState(state)[id];
+ });
+ getDispatch = memoize((id, dispatch) => forwardTo(id, dispatch));
componentDidMount() {
const {
@@ -150,9 +167,7 @@ export function ContainerFactory(KeplerGl) {
}
}
- const mapStateToProps = (state, props) => ({state, ...props});
- const dispatchToProps = dispatch => ({dispatch});
- return connect(mapStateToProps, dispatchToProps)(Container);
+ return connector(Container);
}
const allDependencies = flattenDeps([], ContainerFactory);
diff --git a/src/components/context.d.ts b/src/components/context.d.ts
deleted file mode 100644
index baa75f39e..000000000
--- a/src/components/context.d.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-import {createContext, RefType} from 'react';
-
-export const RootContext = createContext<RefType<any> | null>(null);
-
-const KeplerGlContext = createContext({
- selector: state => state,
- id: 'map'
-});
-
-export default KeplerGlContext;
diff --git a/src/components/context.js b/src/components/context.ts
similarity index 90%
rename from src/components/context.js
rename to src/components/context.ts
index cee2d05bc..d23c8d662 100644
--- a/src/components/context.js
+++ b/src/components/context.ts
@@ -18,7 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-import {createContext} from 'react';
+import {createContext, RefObject} from 'react';
const identity = state => state;
// New Context API only supported after 16.3
@@ -27,6 +27,6 @@ const KeplerGlContext = createContext({
id: 'map'
});
-export const RootContext = createContext(null);
+export const RootContext = createContext<RefObject<HTMLDivElement> | null>(null);
export default KeplerGlContext;
diff --git a/src/components/geocoder-panel.js b/src/components/geocoder-panel.tsx
similarity index 88%
rename from src/components/geocoder-panel.js
rename to src/components/geocoder-panel.tsx
index c52e75183..881757d41 100644
--- a/src/components/geocoder-panel.js
+++ b/src/components/geocoder-panel.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} from 'react';
import styled from 'styled-components';
import Processors from 'processors';
import {FlyToInterpolator} from '@deck.gl/core';
@@ -34,6 +33,7 @@ import {
GEOCODER_ICON_COLOR,
GEOCODER_ICON_SIZE
} from 'constants/default-settings';
+import {MapState} from 'reducers';
const ICON_LAYER = {
id: GEOCODER_LAYER_ID,
@@ -65,7 +65,11 @@ const PARSED_CONFIG = KeplerGlSchema.parseSavedConfig({
}
});
-const StyledGeocoderPanel = styled.div`
+interface StyledGeocoderPanelProps {
+ width?: number;
+}
+
+const StyledGeocoderPanel = styled.div<StyledGeocoderPanelProps>`
position: absolute;
top: ${props => props.theme.geocoderTop}px;
right: ${props => props.theme.geocoderRight}px;
@@ -107,18 +111,22 @@ export function getUpdateVisDataPayload(lat, lon, text) {
];
}
-export default function GeocoderPanelFactory() {
- class GeocoderPanel extends Component {
- static propTypes = {
- isGeocoderEnabled: PropTypes.bool.isRequired,
- mapboxApiAccessToken: PropTypes.string.isRequired,
- mapState: PropTypes.object.isRequired,
- updateVisData: PropTypes.func.isRequired,
- removeDataset: PropTypes.func.isRequired,
- updateMap: PropTypes.func.isRequired,
-
- transitionDuration: PropTypes.number,
- width: PropTypes.number
+interface GeocoderPanelProps {
+ isGeocoderEnabled: boolean;
+ mapState: MapState;
+ mapboxApiAccessToken: string;
+ updateVisData: Function;
+ removeDataset: Function;
+ updateMap: Function;
+
+ transitionDuration?: number;
+ width?: number;
+}
+
+export default function GeocoderPanelFactory(): ComponentType<GeocoderPanelProps> {
+ class GeocoderPanel extends Component<GeocoderPanelProps> {
+ defaultProps = {
+ transitionDuration: 3000
};
removeGeocoderDataset() {
@@ -187,9 +195,5 @@ export default function GeocoderPanelFactory() {
}
}
- GeocoderPanel.defaultProps = {
- transitionDuration: 3000
- };
-
return GeocoderPanel;
}
diff --git a/src/components/index.d.ts b/src/components/index.d.ts
deleted file mode 100644
index 9b6f6b926..000000000
--- a/src/components/index.d.ts
+++ /dev/null
@@ -1,48 +0,0 @@
-import React from 'react';
-import {FeatureFlags} from './context';
-
-export {withState} from './injector';
-
-export * from './context';
-export * from './bottom-widget';
-export * from './kepler-gl';
-export * from './map-container';
-export * from './maps-layout';
-export * from './modal-container';
-export * from './container';
-
-// TODO: we need more specific types for the following components
-export * from './map/map-legend';
-export * from './map/split-map-button';
-export * from './side-panel/common/dataset-tag';
-export {default as Checkbox} from './common/checkbox';
-export * from './common/styled-components';
-export * from './common/tippy-tooltip'
-export * as Icons from './common/icons/index.tsx';
-export * from './common/file-uploader/file-drop';
-export * from './common/file-uploader/upload-button';
-export {default as Portaled} from './common/portaled';
-
-export const PanelHeaderAction: (...props: any[]) => JSX.Element;
-export const TippyTooltip: (...props: any[]) => JSX.Element;
-export const Toggle3dButtonFactory: (...deps: any) => React.ElementType;
-export const ToggleGlobeButtonFactory: (...deps: any) => React.ElementType;
-export const MapsLayoutFactory: (...deps: any) => React.ElementType;
-export const PanelHeaderDropdownFactory: (...deps: any) => React.ElementType;
-export const NotificationItemFactory: (...deps: any) => React.ElementType;
-export const DropdownList: React.ElementType;
-export const VerticalToolbar: React.ElementType;
-export const ToolbarItem: React.ElementType;
-export const ModalTitle: React.ElementType;
-export const ItemSelector: React.ElementType;
-export const Slider: React.ElementType;
-export const LoadingSpinner: React.ElementType;
-export const LayerConfigGroup: React.ElementType;
-export const ChannelByValueSelector: React.ElementType;
-export const LayerColorRangeSelector: React.ElementType;
-export const LayerColorSelector: React.ElementType;
-export const VisConfigSlider: React.ElementType;
-export const ConfigGroupCollapsibleContent: React.ElementType;
-export const PanelLabel: React.ElementType;
-
-export const useFeatureFlags: () => FeatureFlags;
diff --git a/src/components/index.js b/src/components/index.ts
similarity index 100%
rename from src/components/index.js
rename to src/components/index.ts
diff --git a/src/components/injector.js b/src/components/injector.tsx
similarity index 89%
rename from src/components/injector.js
rename to src/components/injector.tsx
index 0b7f7bb58..19fe7f884 100644
--- a/src/components/injector.js
+++ b/src/components/injector.tsx
@@ -24,6 +24,16 @@ import {bindActionCreators} from 'redux';
import {console as Console} from 'global/window';
import KeplerGlContext from 'components/context';
+export type FactoryElement = (...args) => React.Component;
+export type Factory = FactoryElement & {
+ deps: FactoryElement[];
+};
+
+export type InjectorType = {
+ provide: (factory: any, replacement: any) => InjectorType;
+ get: (fac: any, parent?: any) => any;
+};
+
const MissingComp = () => <div />;
export const ERROR_MSG = {
@@ -38,7 +48,7 @@ export const ERROR_MSG = {
notFunc: 'factory and its replacement should be a function'
};
-export function injector(map = new Map()) {
+export function injector(map = new Map()): InjectorType {
const cache = new Map(); // map<factory, factory -> ?>
const get = (fac, parent) => {
const factory = map.get(fac);
@@ -71,14 +81,14 @@ export function injector(map = new Map()) {
}
// entryPoint
-export function flattenDeps(allDeps, factory) {
+export function flattenDeps(allDeps: Factory[], factory: any): Factory[] {
const addToDeps = allDeps.concat([factory]);
return Array.isArray(factory.deps) && factory.deps.length
? factory.deps.reduce((accu, dep) => flattenDeps(accu, dep), addToDeps)
: addToDeps;
}
-export function provideRecipesToInjector(recipes, appInjector) {
+export function provideRecipesToInjector(recipes: [Factory, Factory][], appInjector: InjectorType) {
const provided = new Map();
return recipes.reduce((inj, recipe) => {
@@ -128,7 +138,7 @@ export function typeCheckRecipe(recipe) {
const identity = state => state;
// Helper to add reducer state to custom component
-export function withState(lenses = [], mapStateToProps = identity, actions = {}) {
+export function withState(lenses: any[] = [], mapStateToProps = identity, actions = {}) {
return Component => {
const WrappedComponent = ({state, ...props}) => (
<KeplerGlContext.Consumer>
diff --git a/src/components/kepler-gl.js b/src/components/kepler-gl.tsx
similarity index 81%
rename from src/components/kepler-gl.js
rename to src/components/kepler-gl.tsx
index 857763330..7fecfe3a7 100644
--- a/src/components/kepler-gl.js
+++ b/src/components/kepler-gl.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} from 'react';
+import React, {Component, createRef, Dispatch} from 'react';
import Console from 'global/console';
import {bindActionCreators} from 'redux';
import styled, {ThemeProvider, withTheme} from 'styled-components';
@@ -27,6 +27,7 @@ import {connect as keplerGlConnect} from 'connect/keplergl-connect';
import {IntlProvider} from 'react-intl';
import {messages} from '../localization';
import {RootContext} from 'components/context';
+import {OnErrorCallBack, OnSuccessCallBack} from 'actions/provider-actions';
import * as VisStateActions from 'actions/vis-state-actions';
import * as MapStateActions from 'actions/map-state-actions';
@@ -34,6 +35,14 @@ import * as MapStyleActions from 'actions/map-style-actions';
import * as UIStateActions from 'actions/ui-state-actions';
import * as ProviderActions from 'actions/provider-actions';
+type KeplerGlActions = {
+ visStateActions: typeof VisStateActions;
+ mapStateActions: typeof MapStateActions;
+ mapStyleActions: typeof MapStyleActions;
+ uiStateActions: typeof UIStateActions;
+ providerActions: typeof ProviderActions;
+};
+
import {
DIMENSIONS,
KEPLER_GL_NAME,
@@ -59,6 +68,8 @@ import {mergeMessages} from 'utils/locale-utils';
import {theme as basicTheme, themeLT, themeBS} from 'styles/base';
import {observeDimensions, unobserveDimensions} from '../utils/observe-dimensions';
+import {KeplerGlState} from 'reducers/core';
+import {Provider} from 'cloud-providers';
// Maybe we should think about exporting this or creating a variable
// as part of the base.js theme
@@ -95,7 +106,11 @@ const GlobalStyle = styled.div`
}
`;
-const BottomWidgetOuter = styled.div(
+interface BottomWidgetOuterProps {
+ absolute?: boolean;
+}
+
+const BottomWidgetOuter = styled.div<BottomWidgetOuterProps>(
({absolute}) => `
${absolute ? 'position: absolute; bottom: 0; right: 0;' : ''}
pointer-events: none; /* prevent padding from blocking input */
@@ -105,10 +120,10 @@ const BottomWidgetOuter = styled.div(
}`
);
-export const mapFieldsSelector = props => ({
+export const mapFieldsSelector = (props: KeplerGLProps) => ({
getMapboxRef: props.getMapboxRef,
mapboxApiAccessToken: props.mapboxApiAccessToken,
- mapboxApiUrl: props.mapboxApiUrl,
+ mapboxApiUrl: props.mapboxApiUrl ? props.mapboxApiUrl : DEFAULT_KEPLER_GL_PROPS.mapboxApiUrl,
mapState: props.mapState,
mapStyle: props.mapStyle,
onDeckInitialized: props.onDeckInitialized,
@@ -144,9 +159,9 @@ export function getVisibleDatasets(datasets) {
return filterObjectByPredicate(datasets, (key, value) => key !== GEOCODER_DATASET_NAME);
}
-export const sidePanelSelector = (props, availableProviders, filteredDatasets) => ({
- appName: props.appName,
- version: props.version,
+export const sidePanelSelector = (props: KeplerGLProps, availableProviders, filteredDatasets) => ({
+ appName: props.appName ? props.appName : DEFAULT_KEPLER_GL_PROPS.appName,
+ version: props.version ? props.version : DEFAULT_KEPLER_GL_PROPS.version,
appWebsite: props.appWebsite,
mapStyle: props.mapStyle,
onSaveMap: props.onSaveMap,
@@ -154,6 +169,7 @@ export const sidePanelSelector = (props, availableProviders, filteredDatasets) =
mapStyleActions: props.mapStyleActions,
visStateActions: props.visStateActions,
uiStateActions: props.uiStateActions,
+ mapStateActions: props.mapStateActions,
datasets: filteredDatasets,
filters: props.visState.filters,
@@ -164,12 +180,12 @@ export const sidePanelSelector = (props, availableProviders, filteredDatasets) =
mapInfo: props.visState.mapInfo,
layerBlending: props.visState.layerBlending,
- width: props.sidePanelWidth,
+ width: props.sidePanelWidth ? props.sidePanelWidth : DEFAULT_KEPLER_GL_PROPS.width,
availableProviders,
mapSaved: props.providerState.mapSaved
});
-export const plotContainerSelector = props => ({
+export const plotContainerSelector = (props: KeplerGLProps) => ({
width: props.width,
height: props.height,
exportImageSetting: props.uiState.exportImage,
@@ -181,10 +197,10 @@ export const plotContainerSelector = props => ({
splitMaps: props.visState.splitMaps
});
-export const isSplitSelector = props =>
+export const isSplitSelector = (props: KeplerGLProps) =>
props.visState.splitMaps && props.visState.splitMaps.length > 1;
-export const bottomWidgetSelector = (props, theme) => ({
+export const bottomWidgetSelector = (props: KeplerGLProps, theme) => ({
filters: props.visState.filters,
datasets: props.visState.datasets,
uiState: props.uiState,
@@ -195,8 +211,8 @@ export const bottomWidgetSelector = (props, theme) => ({
sidePanelWidth: props.uiState.readOnly ? 0 : props.sidePanelWidth + theme.sidePanel.margin.left
});
-export const modalContainerSelector = (props, rootNode) => ({
- appName: props.appName,
+export const modalContainerSelector = (props: KeplerGLProps, rootNode) => ({
+ appName: props.appName ? props.appName : DEFAULT_KEPLER_GL_PROPS.appName,
mapStyle: props.mapStyle,
visState: props.visState,
mapState: props.mapState,
@@ -212,14 +228,16 @@ export const modalContainerSelector = (props, rootNode) => ({
rootNode,
// User defined cloud provider props
- cloudProviders: props.cloudProviders,
+ cloudProviders: props.cloudProviders
+ ? props.cloudProviders
+ : DEFAULT_KEPLER_GL_PROPS.cloudProviders,
onExportToCloudSuccess: props.onExportToCloudSuccess,
onLoadCloudMapSuccess: props.onLoadCloudMapSuccess,
onLoadCloudMapError: props.onLoadCloudMapError,
onExportToCloudError: props.onExportToCloudError
});
-export const geoCoderPanelSelector = props => ({
+export const geoCoderPanelSelector = (props: KeplerGLProps) => ({
isGeocoderEnabled: props.visState.interactionConfig.geocoder.enabled,
mapboxApiAccessToken: props.mapboxApiAccessToken,
mapState: props.mapState,
@@ -228,7 +246,7 @@ export const geoCoderPanelSelector = props => ({
updateMap: props.mapStateActions.updateMap
});
-export const notificationPanelSelector = props => ({
+export const notificationPanelSelector = (props: KeplerGLProps) => ({
removeNotification: props.uiStateActions.removeNotification,
notifications: props.uiState.notifications
});
@@ -247,6 +265,39 @@ export const DEFAULT_KEPLER_GL_PROPS = {
readOnly: false
};
+type KeplerGLBasicProps = {
+ mapboxApiAccessToken: string;
+ mapboxApiUrl?: string;
+ id: string;
+ width?: number;
+ height?: number;
+
+ appWebsite?: any;
+ onSaveMap?: () => void;
+ onViewStateChange?: () => void;
+ onDeckInitialized?: () => void;
+ onKeplerGlInitialized?: () => void;
+ getMapboxRef?: () => React.RefObject<any>;
+ mapStyles?: {id: string; style?: object}[];
+ mapStylesReplaceDefault?: boolean;
+ appName?: string;
+ version?: string;
+ sidePanelWidth?: number;
+ theme?: object;
+ cloudProviders?: Provider[];
+ deckGlProps?: object;
+ onLoadCloudMapSuccess?: OnSuccessCallBack;
+ onLoadCloudMapError?: OnErrorCallBack;
+ onExportToCloudSuccess?: OnSuccessCallBack;
+ onExportToCloudError?: OnErrorCallBack;
+ readOnly?: boolean;
+
+ localeMessages?: {[key: string]: {[key: string]: string}};
+ dispatch: Dispatch<any>;
+};
+
+type KeplerGLProps = KeplerGlState & KeplerGlActions & KeplerGLBasicProps;
+
KeplerGlFactory.deps = [
BottomWidgetFactory,
GeoCoderPanelFactory,
@@ -259,18 +310,18 @@ KeplerGlFactory.deps = [
];
function KeplerGlFactory(
- BottomWidget,
- GeoCoderPanel,
- MapContainer,
- MapsLayout,
- ModalContainer,
- SidePanel,
- PlotContainer,
- NotificationPanel
-) {
+ BottomWidget: ReturnType<typeof BottomWidgetFactory>,
+ GeoCoderPanel: ReturnType<typeof GeoCoderPanelFactory>,
+ MapContainer: ReturnType<typeof MapContainerFactory>,
+ MapsLayout: ReturnType<typeof MapsLayoutFactory>,
+ ModalContainer: ReturnType<typeof ModalContainerFactory>,
+ SidePanel: ReturnType<typeof SidePanelFactory>,
+ PlotContainer: ReturnType<typeof PlotContainerFactory>,
+ NotificationPanel: ReturnType<typeof NotificationPanelFactory>
+): React.ComponentType<KeplerGLBasicProps & {selector: (...args: any[]) => KeplerGlState}> {
/** @typedef {import('./kepler-gl').UnconnectedKeplerGlProps} KeplerGlProps */
/** @augments React.Component<KeplerGlProps> */
- class KeplerGL extends Component {
+ class KeplerGL extends Component<KeplerGLProps & {selector: (...args: any[]) => KeplerGlState}> {
static defaultProps = DEFAULT_KEPLER_GL_PROPS;
state = {
@@ -300,7 +351,7 @@ function KeplerGlFactory(
static contextType = RootContext;
- root = createRef();
+ root = createRef<HTMLDivElement>();
bottomWidgetRef = createRef();
/* selectors */
@@ -322,7 +373,7 @@ function KeplerGlFactory(
filteredDatasetsSelector = createSelector(this.datasetsSelector, getVisibleDatasets);
availableProviders = createSelector(
- props => props.cloudProviders,
+ (props: KeplerGLProps) => props.cloudProviders,
providers =>
Array.isArray(providers) && providers.length
? {
@@ -333,7 +384,7 @@ function KeplerGlFactory(
);
localeMessagesSelector = createSelector(
- props => props.localeMessages,
+ (props: KeplerGLProps) => props.localeMessages,
customMessages => (customMessages ? mergeMessages(messages, customMessages) : messages)
);
@@ -369,9 +420,9 @@ function KeplerGlFactory(
render() {
const {
- id,
- width,
- height,
+ id = 'map',
+ width = DEFAULT_KEPLER_GL_PROPS.width,
+ height = DEFAULT_KEPLER_GL_PROPS.height,
uiState,
visState,
// readOnly override
@@ -429,7 +480,7 @@ function KeplerGlFactory(
>
<NotificationPanel {...notificationPanelFields} />
{!uiState.readOnly && !readOnly && <SidePanel {...sideFields} />}
- <MapsLayout className="maps">{mapContainers}</MapsLayout>
+ <MapsLayout>{mapContainers}</MapsLayout>
{isExportingImage && <PlotContainer {...plotContainerFields} />}
{interactionConfig.geocoder.enabled && <GeoCoderPanel {...geoCoderPanelFields} />}
<BottomWidgetOuter absolute>
@@ -455,7 +506,7 @@ function KeplerGlFactory(
return keplerGlConnect(mapStateToProps, makeMapDispatchToProps)(withTheme(KeplerGL));
}
-export function mapStateToProps(state = {}, props) {
+export function mapStateToProps(state: KeplerGlState, props: KeplerGLProps) {
return {
...props,
visState: state.visState,
diff --git a/src/components/map-container.d.ts b/src/components/map-container.d.ts
deleted file mode 100644
index 798870c2a..000000000
--- a/src/components/map-container.d.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-import React from 'react';
-
-export type MapContainerProps = {
- // TODO
- primary: boolean;
-};
-
-export default function MapContainerFactory(): React.Component<MapContainerProps>;
-
-export const Attribution: React.FC<{}>;
diff --git a/src/components/map-container.js b/src/components/map-container.tsx
similarity index 86%
rename from src/components/map-container.js
rename to src/components/map-container.tsx
index bfe014283..14edec79f 100644
--- a/src/components/map-container.js
+++ b/src/components/map-container.tsx
@@ -20,13 +20,16 @@
// libraries
import React, {Component, createRef} from 'react';
-import PropTypes from 'prop-types';
import MapboxGLMap from 'react-map-gl';
import DeckGL from '@deck.gl/react';
import {createSelector} from 'reselect';
import WebMercatorViewport from 'viewport-mercator-project';
import {errorNotification} from 'utils/notifications-utils';
+import * as VisStateActions from 'actions/vis-state-actions';
+import * as MapStateActions from 'actions/map-state-actions';
+import * as UIStateActions from 'actions/ui-state-actions';
+
// components
import MapPopoverFactory from 'components/map/map-popover';
import MapControlFactory from 'components/map/map-control';
@@ -42,7 +45,8 @@ import {
getLayerHoverProp,
renderDeckGlLayer,
prepareLayersToRender,
- prepareLayersForDeck
+ prepareLayersForDeck,
+ LayerHoverProp
} from 'utils/layer-utils';
// default-settings
@@ -56,19 +60,32 @@ import {
import ErrorBoundary from 'components/common/error-boundary';
import {observeDimensions, unobserveDimensions} from '../utils/observe-dimensions';
import {LOCALE_CODES} from 'localization/locales';
+import {
+ Datasets,
+ Filter,
+ InteractionConfig,
+ MapControls,
+ MapState,
+ MapStyle,
+ Viewport
+} from 'reducers';
+import {Layer} from 'layers';
+import {SplitMapLayers} from 'reducers/vis-state-updaters';
+import {LayerBaseConfig, VisualChannelDomain} from 'layers/base-layer';
+import {Property} from 'csstype';
/** @type {{[key: string]: React.CSSProperties}} */
const MAP_STYLE = {
container: {
display: 'inline-block',
- position: 'relative',
+ position: 'relative' as Property.Position,
width: '100%',
height: '100%'
},
top: {
- position: 'absolute',
+ position: 'absolute' as Property.Position,
top: '0px',
- pointerEvents: 'none',
+ pointerEvents: 'none' as Property.PointerEvents,
width: '100%',
height: '100%'
}
@@ -77,6 +94,7 @@ const MAP_STYLE = {
const MAPBOXGL_STYLE_UPDATE = 'style.load';
const MAPBOXGL_RENDER = 'render';
const TRANSITION_DURATION = 0;
+const nop = () => {};
export const Attribution = () => (
<StyledAttrbution>
@@ -109,39 +127,55 @@ export const Attribution = () => (
MapContainerFactory.deps = [MapPopoverFactory, MapControlFactory, EditorFactory];
-export default function MapContainerFactory(MapPopover, MapControl, Editor) {
- class MapContainer extends Component {
+type MapboxStyle = string | object | undefined;
+
+interface MapContainerProps {
+ datasets: Datasets;
+ interactionConfig: InteractionConfig;
+ layerBlending: string;
+ layerOrder: number[];
+ layerData: any[];
+ layers: Layer[];
+ filters: Filter[];
+ mapState: MapState;
+ mapControls: MapControls;
+ mapStyle: {bottomMapStyle?: MapboxStyle; topMapStyle?: MapboxStyle} & MapStyle;
+ mousePos: any;
+ mapboxApiAccessToken: string;
+ mapboxApiUrl: string;
+ visStateActions: typeof VisStateActions;
+ mapStateActions: typeof MapStateActions;
+ uiStateActions: typeof UIStateActions;
+
+ // optional
+ primary?: boolean; // primary one will be reporting its size to appState
+ readOnly?: boolean;
+ isExport?: boolean;
+ clicked?: any;
+ hoverInfo?: any;
+ mapLayers?: SplitMapLayers | null;
+ onMapToggleLayer?: Function;
+ onMapStyleLoaded?: Function;
+ onMapRender?: Function;
+ getMapboxRef?: (mapbox?: MapboxGLMap | null, index?: number) => void;
+ index?: number;
+
+ locale?: any;
+ editor?: any;
+ MapComponent?: typeof MapboxGLMap;
+ deckGlProps?: any;
+ onDeckInitialized?: (a: any, b: any) => void;
+ onViewStateChange?: (viewport: Viewport) => void;
+}
+
+export default function MapContainerFactory(
+ MapPopover,
+ MapControl,
+ Editor
+): React.ComponentType<MapContainerProps> {
+ class MapContainer extends Component<MapContainerProps> {
static propTypes = {
// required
- datasets: PropTypes.object,
- interactionConfig: PropTypes.object.isRequired,
- layerBlending: PropTypes.string.isRequired,
- layerOrder: PropTypes.arrayOf(PropTypes.any).isRequired,
- layerData: PropTypes.arrayOf(PropTypes.any).isRequired,
- layers: PropTypes.arrayOf(PropTypes.any).isRequired,
- filters: PropTypes.arrayOf(PropTypes.any).isRequired,
- mapState: PropTypes.object.isRequired,
- mapControls: PropTypes.object.isRequired,
- mapStyle: PropTypes.object.isRequired,
- mousePos: PropTypes.object.isRequired,
- mapboxApiAccessToken: PropTypes.string.isRequired,
- mapboxApiUrl: PropTypes.string,
- visStateActions: PropTypes.object.isRequired,
- mapStateActions: PropTypes.object.isRequired,
- uiStateActions: PropTypes.object.isRequired,
-
- // optional
- primary: PropTypes.bool, // primary one will be reporting its size to appState
- readOnly: PropTypes.bool,
- isExport: PropTypes.bool,
- clicked: PropTypes.object,
- hoverInfo: PropTypes.object,
- mapLayers: PropTypes.object,
- onMapToggleLayer: PropTypes.func,
- onMapStyleLoaded: PropTypes.func,
- onMapRender: PropTypes.func,
- getMapboxRef: PropTypes.func,
- index: PropTypes.number
};
static defaultProps = {
@@ -151,26 +185,36 @@ export default function MapContainerFactory(MapPopover, MapControl, Editor) {
primary: true
};
- constructor(props) {
- super(props);
+ previousLayers = {
+ // [layers.id]: mapboxLayerConfig
+ };
- this.previousLayers = {
- // [layers.id]: mapboxLayerConfig
- };
+ displayName = 'MapContainer';
+
+ _deck: any = null;
+ _map: mapboxgl.Map | null = null;
+ _ref = createRef<HTMLDivElement>();
+ _deckGLErrorsElapsed: {[id: string]: number} = {};
- this._deck = null;
- this._ref = createRef();
+ constructor(props) {
+ super(props);
}
componentDidMount() {
+ if (!this._ref.current) {
+ return;
+ }
observeDimensions(this._ref.current, this._handleResize);
}
componentWillUnmount() {
// unbind mapboxgl event listener
if (this._map) {
- this._map.off(MAPBOXGL_STYLE_UPDATE);
- this._map.off(MAPBOXGL_RENDER);
+ this._map?.off(MAPBOXGL_STYLE_UPDATE, nop);
+ this._map?.off(MAPBOXGL_RENDER, nop);
+ }
+ if (!this._ref.current) {
+ return;
}
unobserveDimensions(this._ref.current);
}
@@ -218,10 +262,10 @@ export default function MapContainerFactory(MapPopover, MapControl, Editor) {
this.props.visStateActions.onLayerClick(null);
};
- _onLayerSetDomain = (idx, colorDomain) => {
+ _onLayerSetDomain = (idx: number, colorDomain: VisualChannelDomain) => {
this.props.visStateActions.layerConfigChange(this.props.layers[idx], {
colorDomain
- });
+ } as Partial<LayerBaseConfig>);
};
_handleMapToggleLayer = layerId => {
@@ -239,7 +283,7 @@ export default function MapContainerFactory(MapPopover, MapControl, Editor) {
}
};
- _setMapboxMap = mapbox => {
+ _setMapboxMap: React.LegacyRef<MapboxGLMap> = mapbox => {
if (!this._map && mapbox) {
this._map = mapbox.getMap();
// i noticed in certain context we don't access the actual map element
@@ -279,7 +323,6 @@ export default function MapContainerFactory(MapPopover, MapControl, Editor) {
const notificationId = `${layer.id}-${error.message}`;
// Throttle error notifications, as React doesn't like too many state changes from here.
- this._deckGLErrorsElapsed = this._deckGLErrorsElapsed || {};
const lastShown = this._deckGLErrorsElapsed[notificationId];
if (!lastShown || lastShown < Date.now() - THROTTLE_NOTIFICATION_TIME) {
this._deckGLErrorsElapsed[notificationId] = Date.now();
@@ -328,7 +371,7 @@ export default function MapContainerFactory(MapPopover, MapControl, Editor) {
: false;
let pinnedPosition = {};
- let layerPinnedProp = null;
+ let layerPinnedProp: LayerHoverProp | null = null;
if (pinned || clicked) {
// project lnglat to screen so that tooltip follows the object on zoom
const viewport = new WebMercatorViewport(mapState);
@@ -488,7 +531,7 @@ export default function MapContainerFactory(MapPopover, MapControl, Editor) {
_toggleMapControl = panelId => {
const {index, uiStateActions} = this.props;
- uiStateActions.toggleMapControl(panelId, index);
+ uiStateActions.toggleMapControl(panelId, Number(index));
};
/* eslint-disable complexity */
@@ -498,7 +541,7 @@ export default function MapContainerFactory(MapPopover, MapControl, Editor) {
mapStyle,
mapStateActions,
layers,
- MapComponent,
+ MapComponent = MapboxGLMap,
datasets,
mapboxApiAccessToken,
mapboxApiUrl,
@@ -546,7 +589,7 @@ export default function MapContainerFactory(MapPopover, MapControl, Editor) {
mapIndex={index}
mapControls={mapControls}
readOnly={this.props.readOnly}
- scale={mapState.scale || 1}
+ scale={1}
top={interactionConfig.geocoder && interactionConfig.geocoder.enabled ? 52 : 0}
editor={editor}
locale={locale}
@@ -602,16 +645,14 @@ export default function MapContainerFactory(MapPopover, MapControl, Editor) {
}
render() {
- const {mapState, mapStyle} = this.props;
+ const {mapStyle} = this.props;
return (
- <StyledMapContainer ref={this._ref} style={MAP_STYLE.container} globe={mapState.globe}>
+ <StyledMapContainer ref={this._ref} style={MAP_STYLE.container}>
{mapStyle.bottomMapStyle && this._renderMap()}
</StyledMapContainer>
);
}
}
- MapContainer.displayName = 'MapContainer';
-
return MapContainer;
}
diff --git a/src/components/map/map-control.d.ts b/src/components/map/map-control.d.ts
index 4be128d48..f2014bb33 100644
--- a/src/components/map/map-control.d.ts
+++ b/src/components/map/map-control.d.ts
@@ -35,5 +35,5 @@ export type MapControlProps = {
mapHeight?: number;
};
-export type MapControl = React.FC<MapControlProps>;
+export type MapControl = React.Component<MapControlProps>;
export function MapControlFactory(): MapControl;
diff --git a/src/components/maps-layout.tsx b/src/components/maps-layout.tsx
index 5759fc239..509ef45fb 100644
--- a/src/components/maps-layout.tsx
+++ b/src/components/maps-layout.tsx
@@ -30,7 +30,7 @@ const Outer = styled.div`
MapsLayoutFactory.deps = [];
-export default function MapsLayoutFactory() {
+export default function MapsLayoutFactory(): React.ComponentType {
class MapsLayout extends React.Component {
render() {
return <Outer>{this.props.children}</Outer>;
diff --git a/src/components/modal-container.d.ts b/src/components/modal-container.d.ts
deleted file mode 100644
index 5c2148bd9..000000000
--- a/src/components/modal-container.d.ts
+++ /dev/null
@@ -1,38 +0,0 @@
-import React from 'react';
-import * as VisStateActions from '../actions/vis-state-actions';
-import * as UIStateActions from '../actions/ui-state-actions';
-import * as MapStyleActions from '../actions/map-style-actions';
-import * as ProviderActions from '../actions/provider-actions';
-import {OnErrorCallBack, OnSuccessCallBack} from 'actions/provider-actions';
-
-import {MapState} from 'reducers/map-state-updaters';
-import {MapStyle} from 'reducers/map-style-updaters';
-import {UiState} from 'reducers/ui-state-updaters';
-import {VisState} from 'reducers/vis-state-updaters';
-import {ProviderState} from 'reducers/provider-state-updaters';
-
-export type ModalContainerProps = {
- appName: string;
- rootNode: React.ReactNode;
- containerW: number;
- containerH: number;
- mapboxApiAccessToken: string;
- mapboxApiUrl?: string;
- mapState: MapState;
- mapStyle: MapStyle;
- uiState: UiState;
- visState: VisState;
- providerState: ProviderState;
- visStateActions: typeof VisStateActions;
- uiStateActions: typeof UIStateActions;
- mapStyleActions: typeof MapStyleActions;
- providerActions: typeof ProviderActions;
- onSaveToStorage: () => void;
- cloudProviders: object[];
- onLoadCloudMapSuccess: OnSuccessCallBack;
- onLoadCloudMapError: OnErrorCallBack;
- onExportToCloudSuccess: OnSuccessCallBack;
- onExportToCloudError: OnErrorCallBack;
-};
-
-export default function ModalContainerFactory(): React.Component<ModelContainerProps>;
diff --git a/src/components/modal-container.js b/src/components/modal-container.tsx
similarity index 88%
rename from src/components/modal-container.js
rename to src/components/modal-container.tsx
index 5dcdcf694..901ca1828 100644
--- a/src/components/modal-container.js
+++ b/src/components/modal-container.tsx
@@ -19,9 +19,7 @@
// THE SOFTWARE.
import React, {Component} from 'react';
-import PropTypes from 'prop-types';
import {css} from 'styled-components';
-import {findDOMNode} from 'react-dom';
import {createSelector} from 'reselect';
import get from 'lodash.get';
import document from 'global/document';
@@ -62,6 +60,15 @@ import {
import KeyEvent from 'constants/keyevent';
import {getFileFormatNames, getFileExtensions} from '../reducers/vis-state-selectors';
+import {MapState, MapStyle, UiState, VisState} from 'reducers';
+import {OnSuccessCallBack, OnErrorCallBack} from 'actions';
+import {ProviderState} from 'reducers/provider-state-updaters';
+
+import * as VisStateActions from 'actions/vis-state-actions';
+import * as UIStateActions from 'actions/ui-state-actions';
+import * as MapStyleActions from 'actions/map-style-actions';
+import * as ProviderActions from 'actions/provider-actions';
+import {ModalDialogProps} from './common/modal';
const DataTableModalStyle = css`
top: 80px;
@@ -89,6 +96,30 @@ const DefaultStyle = css`
max-width: 960px;
`;
+export type ModalContainerProps = {
+ appName: string;
+ rootNode: React.ReactNode;
+ containerW: number;
+ containerH: number;
+ mapboxApiAccessToken: string;
+ mapboxApiUrl?: string;
+ mapState: MapState;
+ mapStyle: MapStyle;
+ uiState: UiState;
+ visState: VisState;
+ providerState: ProviderState;
+ visStateActions: typeof VisStateActions;
+ uiStateActions: typeof UIStateActions;
+ mapStyleActions: typeof MapStyleActions;
+ providerActions: typeof ProviderActions;
+ onSaveToStorage?: () => void;
+ cloudProviders: object[];
+ onLoadCloudMapSuccess?: OnSuccessCallBack;
+ onLoadCloudMapError?: OnErrorCallBack;
+ onExportToCloudSuccess?: OnSuccessCallBack;
+ onExportToCloudError?: OnErrorCallBack;
+};
+
ModalContainerFactory.deps = [
DeleteDatasetModalFactory,
OverWriteMapModalFactory,
@@ -104,38 +135,22 @@ ModalContainerFactory.deps = [
];
export default function ModalContainerFactory(
- DeleteDatasetModal,
- OverWriteMapModal,
- DataTableModal,
- LoadDataModal,
- ExportImageModal,
- ExportDataModal,
- ExportMapModal,
- AddMapStyleModal,
- ModalDialog,
- SaveMapModal,
- ShareMapModal
-) {
+ DeleteDatasetModal: ReturnType<typeof DeleteDatasetModalFactory>,
+ OverWriteMapModal: ReturnType<typeof OverWriteMapModalFactory>,
+ DataTableModal: ReturnType<typeof DataTableModalFactory>,
+ LoadDataModal: ReturnType<typeof LoadDataModalFactory>,
+ ExportImageModal: ReturnType<typeof ExportImageModalFactory>,
+ ExportDataModal: ReturnType<typeof ExportDataModalFactory>,
+ ExportMapModal: ReturnType<typeof ExportMapModalFactory>,
+ AddMapStyleModal: ReturnType<typeof AddMapStyleModalFactory>,
+ ModalDialog: ReturnType<typeof ModalDialogFactory>,
+ SaveMapModal: ReturnType<typeof SaveMapModalFactory>,
+ ShareMapModal: ReturnType<typeof ShareMapModalFactory>
+): React.ElementType<ModalContainerProps> {
/** @typedef {import('./modal-container').ModalContainerProps} ModalContainerProps */
/** @augments React.Component<ModalContainerProps> */
- class ModalContainer extends Component {
+ class ModalContainer extends Component<ModalContainerProps> {
// TODO - remove when prop types are fully exported
- static propTypes = {
- rootNode: PropTypes.object,
- containerW: PropTypes.number,
- containerH: PropTypes.number,
- mapboxApiAccessToken: PropTypes.string.isRequired,
- mapboxApiUrl: PropTypes.string,
- mapState: PropTypes.object.isRequired,
- mapStyle: PropTypes.object.isRequired,
- uiState: PropTypes.object.isRequired,
- visState: PropTypes.object.isRequired,
- visStateActions: PropTypes.object.isRequired,
- uiStateActions: PropTypes.object.isRequired,
- mapStyleActions: PropTypes.object.isRequired,
- onSaveToStorage: PropTypes.func,
- cloudProviders: PropTypes.arrayOf(PropTypes.object)
- };
componentDidMount = () => {
document.addEventListener('keyup', this._onKeyUp);
};
@@ -259,7 +274,6 @@ export default function ModalContainerFactory(
mapState,
uiState,
visState,
- rootNode,
visStateActions,
uiStateActions,
providerState
@@ -267,8 +281,8 @@ export default function ModalContainerFactory(
const {currentModal, datasetKeyToRemove} = uiState;
const {datasets, layers, editingDataset} = visState;
- let template = null;
- let modalProps = {};
+ let template: JSX.Element | null = null;
+ let modalProps: Partial<ModalDialogProps> = {};
// TODO - currentModal is a string
// @ts-ignore
@@ -328,6 +342,7 @@ export default function ModalContainerFactory(
template = (
<LoadDataModal
{...providerState}
+ //@ts-expect-error //TODO Remove it once LoadDataModal is translated
onClose={this._closeModal}
onFileUpload={this._onFileUpload}
onLoadCloudMap={this._onLoadCloudMap}
@@ -450,6 +465,7 @@ export default function ModalContainerFactory(
break;
case SAVE_MAP_ID:
template = (
+ //@ts-expect-error //TODO Remove it once SaveMapModal is translated
<SaveMapModal
{...providerState}
exportImage={uiState.exportImage}
@@ -529,7 +545,6 @@ export default function ModalContainerFactory(
return this.props.rootNode ? (
<ModalDialog
- parentSelector={() => findDOMNode(rootNode)}
isOpen={Boolean(currentModal)}
onCancel={this._closeModal}
{...modalProps}
diff --git a/src/components/modals/load-data-modal.d.ts b/src/components/modals/load-data-modal.d.ts
index f19f5e49a..ba3e1f3c5 100644
--- a/src/components/modals/load-data-modal.d.ts
+++ b/src/components/modals/load-data-modal.d.ts
@@ -25,6 +25,6 @@ export function LoadDataModalFactory(
ModalTabs: React.Component,
FileUpload: React.Component,
LoadStorageMap: React.Component
-): React.Component<LoadDataModalProps>;
+): React.ComponentType<LoadDataModalProps>;
export default LoadDataModalFactory;
diff --git a/src/components/notification-panel.js b/src/components/notification-panel.tsx
similarity index 84%
rename from src/components/notification-panel.js
rename to src/components/notification-panel.tsx
index fdb65169f..591af4ec2 100644
--- a/src/components/notification-panel.js
+++ b/src/components/notification-panel.tsx
@@ -19,11 +19,12 @@
// THE SOFTWARE.
import React, {Component} from 'react';
-import PropTypes from 'prop-types';
import styled from 'styled-components';
import NotificationItemFactory from './notification-panel/notification-item';
import {DEFAULT_NOTIFICATION_TOPICS} from 'constants/default-settings';
+import {Notifications} from 'reducers';
+import {removeNotification} from 'actions/ui-state-actions';
const NotificationPanelContent = styled.div`
background: transparent;
@@ -42,13 +43,15 @@ const NotificationPanelContent = styled.div`
NotificationPanelFactory.deps = [NotificationItemFactory];
-export default function NotificationPanelFactory(NotificationItem) {
- return class NotificationPanel extends Component {
- static propTypes = {
- removeNotification: PropTypes.func.isRequired,
- notifications: PropTypes.arrayOf(PropTypes.object).isRequired
- };
+interface NotificationPanelProps {
+ removeNotification?: typeof removeNotification;
+ notifications: Notifications[];
+}
+export default function NotificationPanelFactory(
+ NotificationItem: ReturnType<typeof NotificationItemFactory>
+) {
+ return class NotificationPanel extends Component<NotificationPanelProps> {
render() {
const globalNotifications = this.props.notifications.filter(
n => n.topic === DEFAULT_NOTIFICATION_TOPICS.global
diff --git a/src/components/plot-container.js b/src/components/plot-container.tsx
similarity index 85%
rename from src/components/plot-container.js
rename to src/components/plot-container.tsx
index 8b6c67a7d..68dcf8482 100644
--- a/src/components/plot-container.js
+++ b/src/components/plot-container.tsx
@@ -20,7 +20,6 @@
// libraries
import React, {Component, createRef} from 'react';
-import PropTypes from 'prop-types';
import {createSelector} from 'reselect';
import styled from 'styled-components';
import {StaticMap} from 'react-map-gl';
@@ -34,23 +33,14 @@ import {scaleMapStyleByResolution} from 'utils/map-style-utils/mapbox-gl-style-e
import {findMapBounds} from 'utils/data-utils';
import {getCenterAndZoomFromBounds} from 'utils/projection-utils';
import {GEOCODER_LAYER_ID} from 'constants/default-settings';
+import {ExportImage, SplitMap} from 'reducers';
+import {setExportImageDataUri, setExportImageError, setExportImageSetting} from 'actions';
+import {mapFieldsSelector} from './kepler-gl';
const CLASS_FILTER = ['mapboxgl-control-container', 'attrition-link', 'attrition-logo'];
const DOM_FILTER_FUNC = node => !CLASS_FILTER.includes(node.className);
const OUT_OF_SCREEN_POSITION = -9999;
-const propTypes = {
- width: PropTypes.number.isRequired,
- height: PropTypes.number.isRequired,
- exportImageSetting: PropTypes.object.isRequired,
- addNotification: PropTypes.func.isRequired,
- mapFields: PropTypes.object.isRequired,
- setExportImageSetting: PropTypes.object.isRequired,
- setExportImageDataUri: PropTypes.func.isRequired,
- setExportImageError: PropTypes.func.isRequired,
- splitMaps: PropTypes.arrayOf(PropTypes.object)
-};
-
PlotContainerFactory.deps = [MapContainerFactory, MapsLayoutFactory];
// Remove mapbox logo in exported map, because it contains non-ascii characters
@@ -66,7 +56,12 @@ const StyledPlotContainer = styled.div`
left: ${OUT_OF_SCREEN_POSITION}px;
`;
-const StyledMapContainer = styled.div`
+interface StyledMapContainerProps {
+ width?: number;
+ height?: number;
+}
+
+const StyledMapContainer = styled.div<StyledMapContainerProps>`
width: ${props => props.width}px;
height: ${props => props.height}px;
display: flex;
@@ -79,8 +74,24 @@ const deckGlProps = {
}
};
-export default function PlotContainerFactory(MapContainer, MapsLayout) {
- class PlotContainer extends Component {
+interface PlotContainerProps {
+ width?: number;
+ height?: number;
+ exportImageSetting: ExportImage;
+ addNotification: Function;
+ mapFields: ReturnType<typeof mapFieldsSelector>;
+ setExportImageSetting: typeof setExportImageSetting;
+ setExportImageDataUri: typeof setExportImageDataUri;
+ setExportImageError: typeof setExportImageError;
+ splitMaps?: SplitMap[];
+ enableErrorNotification?: boolean;
+}
+
+export default function PlotContainerFactory(
+ MapContainer: ReturnType<typeof MapContainerFactory>,
+ MapsLayout: ReturnType<typeof MapsLayoutFactory>
+): React.ComponentType<PlotContainerProps> {
+ class PlotContainer extends Component<PlotContainerProps> {
constructor(props) {
super(props);
this._onMapRender = debounce(this._onMapRender, 500);
@@ -103,7 +114,7 @@ export default function PlotContainerFactory(MapContainer, MapsLayout) {
}
}
- plottingAreaRef = createRef();
+ plottingAreaRef = createRef<HTMLDivElement>();
mapStyleSelector = props => props.mapFields.mapStyle;
mapScaleSelector = props => {
@@ -153,14 +164,14 @@ export default function PlotContainerFactory(MapContainer, MapsLayout) {
};
render() {
- const {exportImageSetting, mapFields, splitMaps} = this.props;
- const {imageSize = {}, legend} = exportImageSetting;
+ const {exportImageSetting, mapFields, splitMaps = []} = this.props;
+ const {imageSize, legend} = exportImageSetting;
const {mapState} = mapFields;
const isSplit = splitMaps && splitMaps.length > 1;
const size = {
- width: imageSize.imageW || 1,
- height: imageSize.imageH || 1
+ width: imageSize?.imageW || 1,
+ height: imageSize?.imageH || 1
};
const width = size.width / (isSplit ? 2 : 1);
const height = size.height;
@@ -232,7 +243,5 @@ export default function PlotContainerFactory(MapContainer, MapsLayout) {
);
}
}
-
- PlotContainer.propsTypes = propTypes;
return PlotContainer;
}
diff --git a/src/components/side-panel.tsx b/src/components/side-panel.tsx
index 325f06c15..fc11682aa 100644
--- a/src/components/side-panel.tsx
+++ b/src/components/side-panel.tsx
@@ -58,29 +58,29 @@ type SidePanelItem = {
id: string;
label: string;
iconComponent: ComponentType<any>;
- component?: ComponentType<any>
+ component?: ComponentType<any>;
};
type SidePanelProps = {
appName: string;
appWebsite: string;
- filters: Filter;
+ filters: Filter[];
interactionConfig: InteractionConfig;
layerBlending: string;
- layers: Layer;
+ layers: Layer[];
layerClasses: LayerClassesType;
layerOrder: number[];
mapStyle: MapStyle;
- onSaveMap: Function;
+ onSaveMap?: Function;
width: number;
- mapInfo: {title: string, description: string}
+ mapInfo: {title: string; description: string};
datasets: Datasets;
uiStateActions: typeof UIStateActions;
visStateActions: typeof VisStateActions;
mapStateActions: typeof MapStateActions;
mapStyleActions: typeof MapStyleActions;
uiState: UiState;
- availableProviders: {hasShare: boolean, hasStorage: boolean};
+ availableProviders: {hasShare: boolean; hasStorage: boolean};
mapSaved?: string | null;
panels: SidePanelItem[];
version: string;
@@ -204,19 +204,19 @@ export default function SidePanelFactory(
const onShowAddDataModal = useCallback(() => toggleModal(ADD_DATA_ID), [toggleModal]);
const onShowAddMapStyleModal = useCallback(() => toggleModal(ADD_MAP_STYLE_ID), [toggleModal]);
const onRemoveDataset = useCallback(dataId => openDeleteModal(dataId), [openDeleteModal]);
- const onSaveToStorage = useMemo(() => ((hasStorage ? onClickSaveToStorage : null)), [
+ const onSaveToStorage = useMemo(() => (hasStorage ? onClickSaveToStorage : null), [
hasStorage,
onClickSaveToStorage
]);
const onSaveAsToStorage = useMemo(
- () => ((hasStorage && mapSaved ? onClickSaveAsToStorage : null)),
+ () => (hasStorage && mapSaved ? onClickSaveAsToStorage : null),
[hasStorage, mapSaved, onClickSaveAsToStorage]
);
const currentPanel = useMemo(() => panels.find(({id}) => id === activeSidePanel), [
activeSidePanel,
panels
]);
- const onShareMap = useMemo(() => ((hasShare ? onClickShareMap : null)), [
+ const onShareMap = useMemo(() => (hasShare ? onClickShareMap : null), [
hasShare,
onClickShareMap
]);
diff --git a/src/connect/keplergl-connect.ts b/src/connect/keplergl-connect.ts
index 7bd7770af..0f5c35bd8 100644
--- a/src/connect/keplergl-connect.ts
+++ b/src/connect/keplergl-connect.ts
@@ -18,18 +18,19 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-import {connect as reduxConnect} from 'react-redux';
+import {JSXElementConstructor} from 'react';
+import {connect as reduxConnect, GetProps, Matching} from 'react-redux';
import withLocalSelector from './with-local-selector';
const defaultMapStateToProps = (state, _, __) => state;
const defaultMapDispatchToProps = () => (dispatch, _, __) => ({dispatch});
-export const connect = (
+export const connect = <T extends JSXElementConstructor<Matching<any, GetProps<T>>>>(
mapStateToProps = defaultMapStateToProps,
makeMapDispatchToProps = defaultMapDispatchToProps,
reduxMergeProps?,
options?
-) => BaseComponent => {
+) => (BaseComponent: T) => {
const mapDispatchToProps = makeMapDispatchToProps();
const reduxMapState = (state, props) => mapStateToProps(props.selector(state), props, state);
diff --git a/src/connect/with-local-selector.tsx b/src/connect/with-local-selector.tsx
index 384dc69f9..45b59e6b3 100644
--- a/src/connect/with-local-selector.tsx
+++ b/src/connect/with-local-selector.tsx
@@ -18,9 +18,10 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-import React, {Component, ComponentType} from 'react';
+import React, {Component} from 'react';
import {createSelector} from 'reselect';
import KeplerGlContext from 'components/context';
+import {KeplerGlState} from 'reducers/combined-updaters';
const identity = state => state;
@@ -32,8 +33,11 @@ const mergeSelectors = (parentSelector, childSelector) => state =>
// when a selector is passed to a container component,
// it will be stored in the context and passed down to child components,
// as well as prop to the given component
-const withLocalSelector = (ParentComponent): ComponentType => {
- class WithConnectSelector extends Component {
+
+const withLocalSelector = <P extends {}>(
+ ParentComponent: React.ComponentType<P>
+): React.ComponentType<P & {selector: (...args: any[]) => KeplerGlState}> => {
+ class WithConnectSelector extends Component<P & {selector: (...args: any[]) => KeplerGlState}> {
static contextType = KeplerGlContext;
selectorFromContext = (_, ctx) => (ctx.selector ? ctx.selector : identity);
diff --git a/src/reducers/ui-state-updaters.ts b/src/reducers/ui-state-updaters.ts
index e1269f166..fa5cc4fd7 100644
--- a/src/reducers/ui-state-updaters.ts
+++ b/src/reducers/ui-state-updaters.ts
@@ -87,12 +87,12 @@ export type MapControl = {
activeMapIndex?: number;
};
export type MapControls = {
- visibleLayers: MapControl;
- mapLegend: MapControl;
- toggle3d: MapControl;
- splitMap: MapControl;
- mapDraw: MapControl;
- mapLocale: MapControl;
+ visibleLayers?: MapControl;
+ mapLegend?: MapControl;
+ toggle3d?: MapControl;
+ splitMap?: MapControl;
+ mapDraw?: MapControl;
+ mapLocale?: MapControl;
};
export type LoadFiles = {
diff --git a/tsconfig.json b/tsconfig.json
index c9e5e230a..ae36ecdf8 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,8 +1,8 @@
{
"compilerOptions": {
"target": "es2020",
- "allowJs": true,
- "checkJs": true,
+ "allowJs": false,
+ "checkJs": false,
"jsx": "react",
"noEmit": true,
"module": "esnext",
diff --git a/tsconfig.production.json b/tsconfig.production.json
new file mode 100644
index 000000000..d0d4c3e9c
--- /dev/null
+++ b/tsconfig.production.json
@@ -0,0 +1,38 @@
+{
+ "compilerOptions": {
+ "target": "es2020",
+ "allowJs": false,
+ "checkJs": false,
+ "jsx": "react",
+ "module": "esnext",
+ "moduleResolution": "node",
+ "declaration":true,
+ "emitDeclarationOnly":true,
+ "noImplicitAny": false,
+ "noImplicitReturns": true,
+ "noImplicitThis": true,
+ "noUnusedLocals": true,
+ "outDir": "dist",
+ "sourceMap": true,
+ "strictNullChecks": true,
+ "suppressImplicitAnyIndexErrors": false,
+ "esModuleInterop": true,
+ "allowSyntheticDefaultImports": true,
+ "skipLibCheck": true,
+ "strict": true,
+ "resolveJsonModule": true,
+ "isolatedModules": true,
+ "baseUrl": "./src",
+ "paths": {
+ "*": ["*"]
+ }
+ },
+ "include": [
+ "src"
+ ],
+ "exclude": [
+ "src/deckgl-layers",
+ "src/layers",
+ "*.js" //TODO remove one all translations finished
+ ]
+}
diff --git a/yarn.lock b/yarn.lock
index 4ea797def..e8e03a03a 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -3192,6 +3192,11 @@
resolved "https://registry.yarnpkg.com/@types/exenv/-/exenv-1.2.0.tgz#84ff936feeafc917c3c66f80b43e917f56eed00b"
integrity sha512-kSyh9q6bvrOGEnJ9X9Io5gjXaakcSRQTax/Nj2ZKJHuOZ7bH4uvUgLyXA9uV2QBCP7+T8KS0JHbPfP1/79ckKw==
+"@types/geojson@*":
+ version "7946.0.8"
+ resolved "https://registry.yarnpkg.com/@types/geojson/-/geojson-7946.0.8.tgz#30744afdb385e2945e22f3b033f897f76b1f12ca"
+ integrity sha512-1rkryxURpr6aWP7R786/UQOkJ3PcpQiWkAXBmdWc7ryFWqN6a4xfK7BtjXvFBKO9LjQ+MWQSWxYeZX1OApnArA==
+
"@types/geojson@^7946.0.7":
version "7946.0.7"
resolved "https://registry.yarnpkg.com/@types/geojson/-/geojson-7946.0.7.tgz#c8fa532b60a0042219cdf173ca21a975ef0666ad"
@@ -3225,7 +3230,7 @@
resolved "https://registry.yarnpkg.com/@types/hammerjs/-/hammerjs-2.0.41.tgz#f6ecf57d1b12d2befcce00e928a6a097c22980aa"
integrity sha512-ewXv/ceBaJprikMcxCmWU1FKyMAQ2X7a9Gtmzw8fcg2kIePI1crERDM818W+XYrxqdBBOdlf2rm137bU+BltCA==
-"@types/hoist-non-react-statics@^3.3.1":
+"@types/hoist-non-react-statics@^3.3.0", "@types/hoist-non-react-statics@^3.3.1":
version "3.3.1"
resolved "https://registry.yarnpkg.com/@types/hoist-non-react-statics/-/hoist-non-react-statics-3.3.1.tgz#1124aafe5118cb591977aeb1ceaaed1070eb039f"
integrity sha512-iMIqiko6ooLrTh1joXodJK5X9xeEALT1kM5G3ZLhD3hszxBdIEd5C75U834D9mLcINgD4OyZf5uQXjkuYydWvA==
@@ -3303,6 +3308,18 @@
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.178.tgz#341f6d2247db528d4a13ddbb374bcdc80406f4f8"
integrity sha512-0d5Wd09ItQWH1qFbEyQ7oTQ3GZrMfth5JkbN3EvTKLXcHLRDSXeLnlvlOn0wvxVIwK5o2M8JzP/OWz7T3NRsbw==
+"@types/mapbox-gl@*":
+ version "2.6.3"
+ resolved "https://registry.yarnpkg.com/@types/mapbox-gl/-/mapbox-gl-2.6.3.tgz#09e4992bb540fe5e024eebc5fbc315317cb13ffe"
+ integrity sha512-oF5eQmczkoPQfxfRSwpF9GcrWi3YleptJ67uiCQKps+7aKxwIbww0EHHqIrxvOg49l07+AZBtJU2FPKZm1jKAg==
+ dependencies:
+ "@types/geojson" "*"
+
+"@types/mapbox__geo-viewport@^0.4.1":
+ version "0.4.1"
+ resolved "https://registry.yarnpkg.com/@types/mapbox__geo-viewport/-/mapbox__geo-viewport-0.4.1.tgz#77cc476c40fcbc168dceb0e0f85cb486402191a9"
+ integrity sha512-aW7Orm58KsT9KmpZb1sqM2l/KufsS1IUsL1RCplVLfUIbpTk3PYkpOat3CN7jA8KcO1w1TuNFapn0g+/rASWzQ==
+
"@types/mdast@^3.0.0", "@types/mdast@^3.0.3":
version "3.0.3"
resolved "https://registry.yarnpkg.com/@types/mdast/-/mdast-3.0.3.tgz#2d7d671b1cd1ea3deb306ea75036c2a0407d2deb"
@@ -3367,6 +3384,16 @@
dependencies:
"@types/react" "*"
+"@types/react-map-gl@^6.1.2":
+ version "6.1.2"
+ resolved "https://registry.yarnpkg.com/@types/react-map-gl/-/react-map-gl-6.1.2.tgz#42959b751097f8547b1ce8b74773541b024b3c4f"
+ integrity sha512-/9+6j/Ej+tOVL2W2CYljw1CVnfH5xwgpiEfz0s8LFlIBzMFa/Nk/wKIYt/WE5wek0kVJEcU/RQ1RA3qvK7E03w==
+ dependencies:
+ "@types/geojson" "*"
+ "@types/mapbox-gl" "*"
+ "@types/react" "*"
+ "@types/viewport-mercator-project" "*"
+
"@types/react-modal@^3.13.1":
version "3.13.1"
resolved "https://registry.yarnpkg.com/@types/react-modal/-/react-modal-3.13.1.tgz#5b9845c205fccc85d9a77966b6e16dc70a60825a"
@@ -3381,6 +3408,16 @@
dependencies:
"@types/react" "*"
+"@types/react-redux@^7.1.23":
+ version "7.1.23"
+ resolved "https://registry.yarnpkg.com/@types/react-redux/-/react-redux-7.1.23.tgz#3c2bb1bcc698ae69d70735f33c5a8e95f41ac528"
+ integrity sha512-D02o3FPfqQlfu2WeEYwh3x2otYd2Dk1o8wAfsA0B1C2AJEFxE663Ozu7JzuWbznGgW248NaOF6wsqCGNq9d3qw==
+ dependencies:
+ "@types/hoist-non-react-statics" "^3.3.0"
+ "@types/react" "*"
+ hoist-non-react-statics "^3.3.0"
+ redux "^4.0.0"
+
"@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"
@@ -3450,6 +3487,13 @@
resolved "https://registry.yarnpkg.com/@types/unist/-/unist-2.0.3.tgz#9c088679876f374eb5983f150d4787aa6fb32d7e"
integrity sha512-FvUupuM3rlRsRtCN+fDudtmytGO6iHJuuRKS1Ss0pG5z8oX0diNEw94UEL7hgDbpN94rgaK5R7sWm6RrSkZuAQ==
+"@types/viewport-mercator-project@*":
+ version "6.1.2"
+ resolved "https://registry.yarnpkg.com/@types/viewport-mercator-project/-/viewport-mercator-project-6.1.2.tgz#81c28c868625bb83d373a2b726cebb7958a71d8e"
+ integrity sha512-21U4s61ZMUx95F2Uc9DpXBlcSKlrkeChM+hbGWmpz8HtL+zwl/zP5pJarJmxKv/764iR9xf5870jYZ8Mby5xuQ==
+ dependencies:
+ gl-matrix "^3.2.0"
+
"@types/webpack-sources@*":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@types/webpack-sources/-/webpack-sources-2.0.0.tgz#08216ab9be2be2e1499beaebc4d469cec81e82a7"
@@ -6590,7 +6634,16 @@ end-of-stream@^1.0.0, end-of-stream@^1.1.0, end-of-stream@^1.4.1:
dependencies:
once "^1.4.0"
-enhanced-resolve@^4.1.1, enhanced-resolve@^4.3.0:
+enhanced-resolve@^4.1.1:
+ version "4.5.0"
+ resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-4.5.0.tgz#2f3cfd84dbe3b487f18f2db2ef1e064a571ca5ec"
+ integrity sha512-Nv9m36S/vxpsI+Hc4/ZGRs0n9mXqSWGGq49zxb/cJfPAQMbUtttJAlNPS4AQzaBdw/pKskw5bMbekT/Y7W/Wlg==
+ dependencies:
+ graceful-fs "^4.1.2"
+ memory-fs "^0.5.0"
+ tapable "^1.0.0"
+
+enhanced-resolve@^4.3.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-4.3.0.tgz#3b806f3bfafc1ec7de69551ef93cca46c1704126"
integrity sha512-3e87LvavsdxyoCfGusJnrZ5G8SLPOFeHSNpZI/ATL9a5leXo2k0w6MKnbqhdBad9qTobSfB20Ld7UmgoNbAZkQ==
@@ -7889,6 +7942,11 @@ gl-matrix@^3.0.0, gl-matrix@^3.2.1:
resolved "https://registry.yarnpkg.com/gl-matrix/-/gl-matrix-3.3.0.tgz#232eef60b1c8b30a28cbbe75b2caf6c48fd6358b"
integrity sha512-COb7LDz+SXaHtl/h4LeaFcNdJdAQSDeVqjiIihSXNrkWObZLhDI4hIkZC11Aeqp7bcE72clzB0BnDXr2SmslRA==
+gl-matrix@^3.2.0:
+ version "3.4.3"
+ resolved "https://registry.yarnpkg.com/gl-matrix/-/gl-matrix-3.4.3.tgz#fc1191e8320009fd4d20e9339595c6041ddc22c9"
+ integrity sha512-wcCp8vu8FT22BnvKVPjXa/ICBWRq/zjFfdofZy1WSpQZpphblv12/bOQLBC1rMM7SGOFS9ltVmKOHil5+Ml7gA==
+
gl@^4.2.2:
version "4.8.0"
resolved "https://registry.yarnpkg.com/gl/-/gl-4.8.0.tgz#2bf8702d11ae5a76412f3731f3ed652bd77d043b"
@@ -12951,6 +13009,13 @@ redux-thunk@^2.4.1:
resolved "https://registry.yarnpkg.com/redux-thunk/-/redux-thunk-2.4.1.tgz#0dd8042cf47868f4b29699941de03c9301a75714"
integrity sha512-OOYGNY5Jy2TWvTL1KgAlVy6dcx3siPJ1wTq741EPyUKfn6W6nChdICjZwCd0p8AZBs5kWpZlbkXW2nE/zjUa+Q==
+redux@^4.0.0, redux@^4.1.2:
+ version "4.1.2"
+ resolved "https://registry.yarnpkg.com/redux/-/redux-4.1.2.tgz#140f35426d99bb4729af760afcf79eaaac407104"
+ integrity sha512-SH8PglcebESbd/shgf6mii6EIoRM0zrQyjcuQ+ojmfxjTtE0z9Y8pa62iA/OJ58qjP6j27uyW4kUF4jl/jd6sw==
+ dependencies:
+ "@babel/runtime" "^7.9.2"
+
redux@^4.0.5:
version "4.0.5"
resolved "https://registry.yarnpkg.com/redux/-/redux-4.0.5.tgz#4db5de5816e17891de8a80c424232d06f051d93f"
@@ -12959,13 +13024,6 @@ redux@^4.0.5:
loose-envify "^1.4.0"
symbol-observable "^1.2.0"
-redux@^4.1.2:
- version "4.1.2"
- resolved "https://registry.yarnpkg.com/redux/-/redux-4.1.2.tgz#140f35426d99bb4729af760afcf79eaaac407104"
- integrity sha512-SH8PglcebESbd/shgf6mii6EIoRM0zrQyjcuQ+ojmfxjTtE0z9Y8pa62iA/OJ58qjP6j27uyW4kUF4jl/jd6sw==
- dependencies:
- "@babel/runtime" "^7.9.2"
-
reflect.ownkeys@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/reflect.ownkeys/-/reflect.ownkeys-0.2.0.tgz#749aceec7f3fdf8b63f927a04809e90c5c0b3460"
@@ -15567,7 +15625,12 @@ uuid@^8.3.0:
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==
-v8-compile-cache@^2.1.1, v8-compile-cache@^2.2.0:
+v8-compile-cache@^2.1.1:
+ version "2.3.0"
+ resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz#2de19618c66dc247dcfb6f99338035d8245a2cee"
+ integrity sha512-l8lCEmLcLYZh4nbunNZvQCJc5pv7+RCwa8q/LdUx8u7lsWvPDKmpodJAJNwkAhJC//dFY48KuIEmjtd4RViDrA==
+
+v8-compile-cache@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.2.0.tgz#9471efa3ef9128d2f7c6a7ca39c4dd6b5055b132"
integrity sha512-gTpR5XQNKFwOd4clxfnhaqvfqMpqEwr4tOtCyz4MtYZX2JYhfr1JvBFKdS+7K/9rfpZR3VLX+YWBbKoxCgS43Q==