Skip to content

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

[CHORE] Typescript fixes (#1383)

Shan Hefc2fb04d0106
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 5b15d91ef..431a44dc7 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -35,6 +35,9 @@ jobs:
- name: Install Dependecies
run: yarn
+ - name: Lint
+ run: yarn lint
+
- name: Test
run: xvfb-run --auto-servernum yarn cover
diff --git a/babel.config.js b/babel.config.js
index 56e72de59..46f4f2122 100644
--- a/babel.config.js
+++ b/babel.config.js
@@ -25,6 +25,7 @@ const PLUGINS = [
'@babel/plugin-transform-modules-commonjs',
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-export-namespace-from',
+ '@babel/plugin-proposal-optional-chaining',
[
'@babel/transform-runtime',
{
diff --git a/examples/webpack.config.local.js b/examples/webpack.config.local.js
index c21e1d4fc..9c7bdb87a 100644
--- a/examples/webpack.config.local.js
+++ b/examples/webpack.config.local.js
@@ -170,6 +170,7 @@ function makeBabelRule(env, exampleDir) {
presets: ['@babel/preset-env', '@babel/preset-react'],
plugins: [
'@babel/plugin-proposal-class-properties',
+ '@babel/plugin-proposal-optional-chaining',
'@babel/plugin-proposal-export-namespace-from',
[
'module-resolver',
diff --git a/package.json b/package.json
index eb697ddac..b182e1606 100644
--- a/package.json
+++ b/package.json
@@ -168,6 +168,7 @@
"@babel/parser": "^7.3.3",
"@babel/plugin-proposal-class-properties": "^7.3.0",
"@babel/plugin-proposal-export-namespace-from": "^7.2.0",
+ "@babel/plugin-proposal-optional-chaining": "^7.2.0",
"@babel/plugin-transform-modules-commonjs": "^7.2.0",
"@babel/plugin-transform-runtime": "^7.0.0",
"@babel/polyfill": "^7.0.0",
@@ -181,6 +182,7 @@
"@probe.gl/test-utils": "^3.0.1",
"@testing-library/react-hooks": "^3.4.2",
"@types/d3-array": "^2.0.0",
+ "@types/geojson": "^7946.0.7",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.0.0",
"babel-plugin-istanbul": "^6.0.0",
@@ -275,5 +277,8 @@
"maintainers": [
"Shan He <[email protected]>",
"Giuseppe Macri <[email protected]>"
- ]
+ ],
+ "volta": {
+ "node": "10.23.0"
+ }
}
diff --git a/src/actions/actions.d.ts b/src/actions/actions.d.ts
index dd640f921..870acfbf5 100644
--- a/src/actions/actions.d.ts
+++ b/src/actions/actions.d.ts
@@ -29,7 +29,7 @@ import {UiState} from 'reducers/ui-state-updaters';
* Input dataest parsed to addDataToMap
*/
export type ProtoDataset = {
- info: {
+ info?: {
id: string;
label: string;
format?: string;
diff --git a/src/actions/ui-state-actions.d.ts b/src/actions/ui-state-actions.d.ts
index 6db5415d6..2c1e12b54 100644
--- a/src/actions/ui-state-actions.d.ts
+++ b/src/actions/ui-state-actions.d.ts
@@ -20,6 +20,7 @@
import ActionTypes from 'constants/action-types';
import {Merge} from '../reducers/types';
+import {ExportImage} from '../reducers/ui-state-updaters';
/** TOGGLE_SIDE_PANEL */
export type ToggleSidePanelUpdaterAction = {
@@ -91,14 +92,7 @@ export function removeNotification(
/** SET_EXPORT_IMAGE_SETTING */
export type SetExportImageSettingUpdaterAction = {
- payload: {
- ratio?: string;
- resolution?: string;
- legend?: string;
- center?: boolean;
- exporting?: boolean;
- processing?: boolean;
- };
+ payload: Partial<ExportImage>;
};
export function setExportImageSetting(newSetting:
SetExportImageSettingUpdaterAction['payload']
diff --git a/src/cloud-providers/index.d.ts b/src/cloud-providers/index.d.ts
index 429203cc5..148ef21ec 100644
--- a/src/cloud-providers/index.d.ts
+++ b/src/cloud-providers/index.d.ts
@@ -1,4 +1,4 @@
-import {ReactElementLike} from 'prop-types';
+import {ComponentType} from 'prop-types';
import {MapData, ExportFileOptions} from 'actions/provider-actions';
export type Millisecond = number;
@@ -21,16 +21,22 @@ export type Thumbnail = {
export type ProviderProps = {
name?: string;
displayName?: string;
- icon?: ReactElementLike;
+ icon?: ComponentType<IconProps>;
thumbnail?: Thumbnail;
};
+interface IconProps {
+ height?: number | string;
+ width?: number | string;
+}
+
export class Provider {
constructor(p: ProviderProps);
name: string;
displayName: string;
- icon: ReactElementLike;
+ icon: ComponentType<IconProps>;
thumbnail: Thumbnail;
+ getManagementUrl?: () => string;
hasPrivateStorage(): boolean;
hasSharingUrl(): boolean;
getShareUrl(fullUrl?: boolean): string;
diff --git a/src/components/bottom-widget.js b/src/components/bottom-widget.js
index 7c0e79e09..99fdf07a0 100644
--- a/src/components/bottom-widget.js
+++ b/src/components/bottom-widget.js
@@ -24,7 +24,7 @@ import PropTypes from 'prop-types';
import TimeWidgetFactory from './filters/time-widget';
import AnimationControlFactory from './common/animation-control/animation-control';
import AnimationControllerFactory from './common/animation-control/animation-controller';
-import {ANIMATION_WINDOW, FILTER_TYPES} from 'constants';
+import {ANIMATION_WINDOW, FILTER_TYPES} from 'constants/default-settings';
import {getIntervalBins} from 'utils/filter-utils';
const propTypes = {
@@ -56,12 +56,7 @@ const BottomWidgetContainer = styled.div`
FilterAnimationControllerFactory.deps = [AnimationControllerFactory];
export function FilterAnimationControllerFactory(AnimationController) {
- const FilterAnimationController = ({
- filter = {},
- filterIdx,
- setFilterAnimationTime,
- children
- }) => {
+ const FilterAnimationController = ({filter, filterIdx, setFilterAnimationTime, children}) => {
const intervalBins = useMemo(() => getIntervalBins(filter), [filter]);
const steps = useMemo(() => (intervalBins ? intervalBins.map(x => x.x0) : null), [
@@ -171,6 +166,10 @@ export default function BottomWidgetFactory(
const showAnimationControl = animatableLayer.length && readyToAnimation;
const showTimeWidget = enlargedFilterIdx > -1 && Object.keys(datasets).length > 0;
+ // if filter is not animating, pass in enlarged filter here because
+ // animation controller needs to call reset on it
+ const filter = animatedFilter || filters[enlargedFilterIdx];
+
return (
<BottomWidgetContainer
width={Math.min(maxWidth, enlargedFilterWidth)}
@@ -194,36 +193,35 @@ export default function BottomWidgetFactory(
) : null
}
</LayerAnimationController>
- <FilterAnimationController
- /* pass if filter is not animating, pass in
- enlarged filter here because animation controller needs to call reset on it
- we can */
- filter={animatedFilter || filters[enlargedFilterIdx]}
- filterIdx={enlargedFilterIdx}
- setFilterAnimationTime={visStateActions.setFilterAnimationTime}
- >
- {animationControlProps =>
- showTimeWidget ? (
- <TimeWidget
- filter={filters[enlargedFilterIdx]}
- index={enlargedFilterIdx}
- isAnyFilterAnimating={Boolean(animatedFilter)}
- datasets={datasets}
- readOnly={readOnly}
- showTimeDisplay={showFloatingTimeDisplay}
- setFilterPlot={visStateActions.setFilterPlot}
- setFilter={visStateActions.setFilter}
- setFilterAnimationTime={visStateActions.setFilterAnimationTime}
- setFilterAnimationWindow={visStateActions.setFilterAnimationWindow}
- toggleAnimation={visStateActions.toggleFilterAnimation}
- updateAnimationSpeed={visStateActions.updateFilterAnimationSpeed}
- enlargeFilter={visStateActions.enlargeFilter}
- animationControlProps={animationControlProps}
- isAnimatable={!animationConfig || !animationConfig.isAnimating}
- />
- ) : null
- }
- </FilterAnimationController>
+ {filter && (
+ <FilterAnimationController
+ filter={filter}
+ filterIdx={enlargedFilterIdx}
+ setFilterAnimationTime={visStateActions.setFilterAnimationTime}
+ >
+ {animationControlProps =>
+ showTimeWidget ? (
+ <TimeWidget
+ filter={filters[enlargedFilterIdx]}
+ index={enlargedFilterIdx}
+ isAnyFilterAnimating={Boolean(animatedFilter)}
+ datasets={datasets}
+ readOnly={readOnly}
+ showTimeDisplay={showFloatingTimeDisplay}
+ setFilterPlot={visStateActions.setFilterPlot}
+ setFilter={visStateActions.setFilter}
+ setFilterAnimationTime={visStateActions.setFilterAnimationTime}
+ setFilterAnimationWindow={visStateActions.setFilterAnimationWindow}
+ toggleAnimation={visStateActions.toggleFilterAnimation}
+ updateAnimationSpeed={visStateActions.updateFilterAnimationSpeed}
+ enlargeFilter={visStateActions.enlargeFilter}
+ animationControlProps={animationControlProps}
+ isAnimatable={!animationConfig || !animationConfig.isAnimating}
+ />
+ ) : null
+ }
+ </FilterAnimationController>
+ )}
</BottomWidgetContainer>
);
};
diff --git a/src/components/common/action-panel.d.ts b/src/components/common/action-panel.d.ts
new file mode 100644
index 000000000..a0980ed00
--- /dev/null
+++ b/src/components/common/action-panel.d.ts
@@ -0,0 +1,24 @@
+import {FunctionComponent, PropsWithChildren, ComponentType, CSSProperties} from 'react';
+
+export type ActionPanelItemProps = PropsWithChildren<{
+ color?: string,
+ className?: string,
+ Icon?: ComponentType<any>,
+ label: string,
+ onClick?: () => void,
+ isSelection?: boolean,
+ isActive?: boolean,
+ style?: CSSProperties
+}>;
+
+export const ActionPanelItem: FunctionComponent<ActionPanelItemProps>;
+
+export type ActionPanelProps = PropsWithChildren<{
+ color?: string,
+ className?: string,
+ direction?: string
+}>;
+
+export const ActionPanel: FunctionComponent<ActionPanelProps>;
+
+export default ActionPanel;
diff --git a/src/components/common/action-panel.js b/src/components/common/action-panel.js
index 0a15c0b2e..222ae1868 100644
--- a/src/components/common/action-panel.js
+++ b/src/components/common/action-panel.js
@@ -93,13 +93,14 @@ const renderChildren = (child, index) =>
className: classnames('action-panel-item', child.props.className)
});
+/** @type {typeof import('./action-panel').ActionPanelItem} */
export const ActionPanelItem = React.memo(
({children, color, className, Icon, label, onClick, isSelection, isActive, style}) => {
const onClickCallback = useCallback(
event => {
event.preventDefault();
event.stopPropagation();
- onClick();
+ onClick?.();
},
[onClick]
);
@@ -122,7 +123,7 @@ export const ActionPanelItem = React.memo(
) : (
<span className="label">{label}</span>
)}
- {children && children.length ? (
+ {children ? (
<div>
<div className="label-icon">
<ArrowRight height="16px" />
@@ -155,6 +156,7 @@ const StyledActionPanel = styled.div`
`;
// React compound element https://medium.com/@Dane_s/react-js-compound-components-a6e54b5c9992
+/** @type {typeof import('./action-panel').ActionPanel} */
const ActionPanel = ({children, className, direction = 'column'}) => (
<StyledActionPanel className={className} direction={direction}>
{React.Children.map(children, renderChildren)}
diff --git a/src/components/common/animation-control/animation-control.js b/src/components/common/animation-control/animation-control.js
index 5031def86..46bea3d17 100644
--- a/src/components/common/animation-control/animation-control.js
+++ b/src/components/common/animation-control/animation-control.js
@@ -27,7 +27,7 @@ import {BottomWidgetInner} from 'components/common/styled-components';
import PlaybackControlsFactory from './playback-controls';
import FloatingTimeDisplayFactory from './floating-time-display';
import {snapToMarks} from 'utils/data-utils';
-import {DEFAULT_TIME_FORMAT} from 'constants';
+import {DEFAULT_TIME_FORMAT} from 'constants/default-settings';
const SliderWrapper = styled.div`
display: flex;
diff --git a/src/components/common/animation-control/animation-controller.js b/src/components/common/animation-control/animation-controller.js
index 75e0c8702..016047b05 100644
--- a/src/components/common/animation-control/animation-controller.js
+++ b/src/components/common/animation-control/animation-controller.js
@@ -21,8 +21,8 @@
import {Component} from 'react';
import {bisectLeft} from 'd3-array';
import {requestAnimationFrame, cancelAnimationFrame} from 'global/window';
-import {BASE_SPEED, FPS, ANIMATION_WINDOW} from 'constants';
import Console from 'global/console';
+import {BASE_SPEED, FPS, ANIMATION_WINDOW} from 'constants/default-settings';
function AnimationControllerFactory() {
/**
diff --git a/src/components/common/animation-control/playback-controls.js b/src/components/common/animation-control/playback-controls.js
index b52f0ddec..feb15e0cb 100644
--- a/src/components/common/animation-control/playback-controls.js
+++ b/src/components/common/animation-control/playback-controls.js
@@ -25,7 +25,7 @@ import {FormattedMessage} from 'localization';
import {Button, Tooltip} from 'components/common/styled-components';
import AnimationSpeedSliderFactory from './animation-speed-slider';
import {Reset, Play, Pause, Rocket, AnchorWindow, FreeWindow} from 'components/common/icons';
-import {ANIMATION_WINDOW} from 'constants';
+import {ANIMATION_WINDOW} from 'constants/default-settings';
import {preciseRound} from 'utils/data-utils';
const DELAY_SHOW = 500;
@@ -74,9 +74,9 @@ export const IconButton = styled(Button)`
function nop() {}
const DEFAULT_ICONS = {
/* eslint-disable react/display-name */
- reset: () => <Reset height="18px" />,
- play: () => <Play height="18px" />,
- pause: () => <Pause height="18px" />,
+ reset: _ => <Reset height="18px" />,
+ play: _ => <Play height="18px" />,
+ pause: _ => <Pause height="18px" />,
/* eslint-enable react/display-name */
speed: Rocket,
animationFree: FreeWindow,
@@ -149,7 +149,6 @@ function PlaybackControlsFactory(AnimationSpeedSlider) {
buttonStyle = 'secondary',
buttonHeight = DEFAULT_BUTTON_HEIGHT
}) => {
-
const [isSpeedControlVisible, toggleSpeedControl] = useState(false);
const [showAnimationWindowControl, setShowAnimationWindowControl] = useState(false);
@@ -185,9 +184,8 @@ function PlaybackControlsFactory(AnimationSpeedSlider) {
>
{(() => {
if (animationItems[animationWindow]) {
- return React.createElement(animationItems[animationWindow].icon, {
- height: buttonHeight
- });
+ const WindowIcon = animationItems[animationWindow].icon;
+ return <WindowIcon height={buttonHeight} />;
}
return null;
})()}
diff --git a/src/components/common/item-selector/item-selector.d.ts b/src/components/common/item-selector/item-selector.d.ts
new file mode 100644
index 000000000..1c818b120
--- /dev/null
+++ b/src/components/common/item-selector/item-selector.d.ts
@@ -0,0 +1,31 @@
+import {FunctionComponent, ComponentType} from 'react';
+
+export type ItemSelectorProps = {
+ selectedItems: ReadonlyArray<string | number | boolean | object>,
+ options: ReadonlyArray<string | number | boolean | object>,
+ onChange: (items: ReadonlyArray<string | number | boolean | object>) => 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>
+};
+
+const ItemSelector: FunctionComponent<ItemSelectorProps>;
+export default ItemSelector;
diff --git a/src/components/common/item-selector/item-selector.js b/src/components/common/item-selector/item-selector.js
index 6ca586359..7cbd89508 100644
--- a/src/components/common/item-selector/item-selector.js
+++ b/src/components/common/item-selector/item-selector.js
@@ -279,7 +279,6 @@ class ItemSelector extends Component {
}),
disabled: this.props.disabled,
onClick: this._showTypeahead,
- onFocus: this._showPopover,
error: this.props.isError,
inputTheme: this.props.inputTheme,
size: this.props.size
diff --git a/src/components/common/item-selector/typeahead.js b/src/components/common/item-selector/typeahead.js
index 34dc40b04..1ec3ed5af 100644
--- a/src/components/common/item-selector/typeahead.js
+++ b/src/components/common/item-selector/typeahead.js
@@ -195,6 +195,7 @@ class Typeahead extends Component {
super(props);
this.state = {
+ /** @type {ReadonlyArray<string>} */
searchResults: [],
// This should be called something else, 'entryValue'
diff --git a/src/components/common/map-layer-selector.d.ts b/src/components/common/map-layer-selector.d.ts
new file mode 100644
index 000000000..e03908e5d
--- /dev/null
+++ b/src/components/common/map-layer-selector.d.ts
@@ -0,0 +1,10 @@
+import {FunctionComponent} from 'react';
+import {Layer} from 'reducers';
+
+export type MapLayerSelectorProps = {
+ layers: ReadonlyArray<Layer>,
+ onMapToggleLayer: (layerId: string) => void
+};
+
+const MapLayerSelector: FunctionComponent<MapLayerSelectorProps>;
+export default MapLayerSelector;
diff --git a/src/components/common/map-layer-selector.js b/src/components/common/map-layer-selector.js
index 9af39cd66..916191b80 100644
--- a/src/components/common/map-layer-selector.js
+++ b/src/components/common/map-layer-selector.js
@@ -19,18 +19,10 @@
// THE SOFTWARE.
import React from 'react';
-import PropTypes from 'prop-types';
import styled from 'styled-components';
-// import Switch from 'components/common/switch';
import Checkbox from 'components/common/checkbox';
import {generateHashId} from '../../utils/utils';
-const propTypes = {
- // Required
- layers: PropTypes.arrayOf(PropTypes.object).isRequired,
- onMapToggleLayer: PropTypes.func.isRequired
-};
-
const MapLayerSelect = styled.div`
padding: 12px;
@@ -39,6 +31,7 @@ const MapLayerSelect = styled.div`
}
`;
+/** @type {typeof import('./map-layer-selector').default} */
const MapLayerSelector = ({layers, onMapToggleLayer}) => (
<MapLayerSelect className="map-layer-selector">
{layers.map((layer, index) => (
@@ -58,6 +51,4 @@ const MapLayerSelector = ({layers, onMapToggleLayer}) => (
</MapLayerSelect>
);
-MapLayerSelector.propTypes = propTypes;
-
export default MapLayerSelector;
diff --git a/src/components/common/progress-bar.d.ts b/src/components/common/progress-bar.d.ts
index bd26a3351..46e6ddaaa 100644
--- a/src/components/common/progress-bar.d.ts
+++ b/src/components/common/progress-bar.d.ts
@@ -1,4 +1,4 @@
-import React from 'react';
+import {FunctionComponent} from 'react';
export type ProgressBarProps = {
percent: string,
@@ -9,5 +9,5 @@ export type ProgressBarProps = {
theme: object;
};
-const ProgressBar: React.FunctionCompoment<ProgressBarProps>;
+const ProgressBar: FunctionComponent<ProgressBarProps>;
export default ProgressBar;
diff --git a/src/components/common/switch.js b/src/components/common/switch.js
index 93b6ef7b2..65fdf59e7 100644
--- a/src/components/common/switch.js
+++ b/src/components/common/switch.js
@@ -31,7 +31,8 @@ const propTypes = {
onBlur: PropTypes.func,
onChange: PropTypes.func,
onFocus: PropTypes.func,
- value: PropTypes.string
+ value: PropTypes.string,
+ secondary: PropTypes.bool
};
const Switch = props => {
diff --git a/src/components/common/time-slider-marker.js b/src/components/common/time-slider-marker.js
index 10d6d7fd4..fed566685 100644
--- a/src/components/common/time-slider-marker.js
+++ b/src/components/common/time-slider-marker.js
@@ -84,7 +84,7 @@ function TimeSliderMarkerFactory() {
}
const TimeSliderMarker = ({width, domain, isEnlarged = true, height = HEIGHT}) => {
- const xAxisRef = useRef();
+ const xAxisRef = useRef(null);
const scale = useMemo(
() =>
Array.isArray(domain)
diff --git a/src/components/common/toolbar-item.d.ts b/src/components/common/toolbar-item.d.ts
new file mode 100644
index 000000000..2b9b8fb64
--- /dev/null
+++ b/src/components/common/toolbar-item.d.ts
@@ -0,0 +1,14 @@
+import {ComponentType, FunctionComponent, MouseEvent} from 'react';
+
+export type ToolbarItemProps = {
+ id?: string,
+ label: string,
+ className?: string,
+ active?: boolean,
+ onClose?: () => void,
+ onClick: (event: MouseEvent<HTMLDivElement>) => void,
+ icon?: ComponentType<any>
+};
+
+export const ToolbarItem: FunctionComponent<ToolbarItemProps>;
+export default ToolbarItem;
diff --git a/src/components/common/toolbar-item.js b/src/components/common/toolbar-item.js
index 40ebc4c0c..3b060e269 100644
--- a/src/components/common/toolbar-item.js
+++ b/src/components/common/toolbar-item.js
@@ -56,6 +56,7 @@ const StyledDiv = styled.div.attrs({
}
`;
+/** @type {typeof import('./toolbar-item').ToolbarItem} */
const ToolbarItem = React.memo(props => (
<StyledDiv
id={props.id}
diff --git a/src/components/context.d.ts b/src/components/context.d.ts
new file mode 100644
index 000000000..baa75f39e
--- /dev/null
+++ b/src/components/context.d.ts
@@ -0,0 +1,10 @@
+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/editor/feature-styles.js b/src/components/editor/feature-styles.js
index 45b9be356..8a8481eff 100644
--- a/src/components/editor/feature-styles.js
+++ b/src/components/editor/feature-styles.js
@@ -70,6 +70,6 @@ export function getStyle({feature, state}) {
return {
...style,
- ...(RENDER_TYPE_STYLES[renderType] || noOp)(state)
+ ...(RENDER_TYPE_STYLES[renderType] || noOp)()
};
}
diff --git a/src/components/filters/filter-panels/filter-panel-types.d.ts b/src/components/filters/filter-panels/filter-panel-types.d.ts
new file mode 100644
index 000000000..af2e48ae6
--- /dev/null
+++ b/src/components/filters/filter-panels/filter-panel-types.d.ts
@@ -0,0 +1,28 @@
+import {FunctionComponent, ComponentType} from 'react';
+import {Filter, Dataset, Field} from 'reducers';
+import {Layer} from 'layers';
+
+interface PanelAction {
+ id: string,
+ tooltip: string,
+ onClick: () => void,
+ iconComponent: ComponentType<any>,
+ active: boolean
+}
+
+export type FilterPanelProps = {
+ idx: number,
+ layers: ReadonlyArray<Layer>,
+ datasets: ReadonlyArray<Dataset>,
+ allAvailableFields: ReadonlyArray<Field>,
+ filter: Filter,
+ panelActions: ReadonlyArray<PanelAction>,
+ isAnyFilterAnimating: boolean,
+ enlargeFilter: () => void,
+ setFilter: (idx: number, field: string, value: any) => void,
+ removeFilter: () => void,
+ toggleAnimation: () => void,
+ toggleFilterFeature: () => void
+};
+
+export type FilterPanelComponent = FunctionComponent<FilterPanelProps>;
diff --git a/src/components/filters/filter-panels/filter-panel-with-field-select.js b/src/components/filters/filter-panels/filter-panel-with-field-select.js
index 37d8b3169..95bc75eb3 100644
--- a/src/components/filters/filter-panels/filter-panel-with-field-select.js
+++ b/src/components/filters/filter-panels/filter-panel-with-field-select.js
@@ -38,6 +38,7 @@ function FieldPanelWithFieldSelectFactory(
FieldSelector,
PanelHeaderAction
) {
+ /** @type {import('./filter-panel-types').FilterPanelComponent} */
const FilterPanelWithFieldSelect = React.memo(
({
allAvailableFields,
diff --git a/src/components/filters/filter-panels/multi-select-filter-panel.js b/src/components/filters/filter-panels/multi-select-filter-panel.js
index cce172c4f..4b6f92547 100644
--- a/src/components/filters/filter-panels/multi-select-filter-panel.js
+++ b/src/components/filters/filter-panels/multi-select-filter-panel.js
@@ -25,6 +25,7 @@ import FieldPanelWithFieldSelectFactory from 'components/filters/filter-panels/f
MultiSelectFilterPanelFactory.deps = [FieldPanelWithFieldSelectFactory, MultiSelectFilterFactory];
function MultiSelectFilterPanelFactory(FieldPanelWithFieldSelect, MultiSelectFilter) {
+ /** @type {import('./filter-panel-types').FilterPanelComponent} */
const MultiSelectFilterPanel = React.memo(
({
idx,
diff --git a/src/components/filters/filter-panels/new-filter-panel.js b/src/components/filters/filter-panels/new-filter-panel.js
index e286a015e..3ec9d57b0 100644
--- a/src/components/filters/filter-panels/new-filter-panel.js
+++ b/src/components/filters/filter-panels/new-filter-panel.js
@@ -31,6 +31,7 @@ NewFilterPanelFactory.deps = [
];
function NewFilterPanelFactory(FilterPanelHeader, SourceDataSelector, FieldSelector) {
+ /** @type {import('./filter-panel-types').FilterPanelComponent} */
const NewFilterPanel = React.memo(
({idx, filter, datasets, allAvailableFields, setFilter, removeFilter, enlargeFilter}) => {
const onFieldSelector = useCallback(field => setFilter(idx, 'name', field.name), [
diff --git a/src/components/filters/filter-panels/polygon-filter-panel.js b/src/components/filters/filter-panels/polygon-filter-panel.js
index 16fce0205..1204e1249 100644
--- a/src/components/filters/filter-panels/polygon-filter-panel.js
+++ b/src/components/filters/filter-panels/polygon-filter-panel.js
@@ -36,6 +36,7 @@ PolygonFilterPanelFactory.deps = [
];
function PolygonFilterPanelFactory(FilterPanelHeader, PolygonFilter, PanelHeaderAction) {
+ /** @type {import('./filter-panel-types').FilterPanelComponent} */
const PolygonFilterPanel = React.memo(
({
idx,
diff --git a/src/components/filters/filter-panels/range-filter-panel.js b/src/components/filters/filter-panels/range-filter-panel.js
index 310ab9370..0904dcddd 100644
--- a/src/components/filters/filter-panels/range-filter-panel.js
+++ b/src/components/filters/filter-panels/range-filter-panel.js
@@ -25,6 +25,7 @@ import FieldPanelWithFieldSelectFactory from 'components/filters/filter-panels/f
RangeFilterPanelFactory.deps = [FieldPanelWithFieldSelectFactory, RangeFilterFactory];
function RangeFilterPanelFactory(FieldPanelWithFieldSelect, RangeFilter) {
+ /** @type {import('./filter-panel-types').FilterPanelComponent} */
const RangeFilterPanel = React.memo(
({
idx,
diff --git a/src/components/filters/filter-panels/single-select-filter-panel.js b/src/components/filters/filter-panels/single-select-filter-panel.js
index f1f357f87..fb4cc082e 100644
--- a/src/components/filters/filter-panels/single-select-filter-panel.js
+++ b/src/components/filters/filter-panels/single-select-filter-panel.js
@@ -25,6 +25,7 @@ import FieldPanelWithFieldSelectFactory from 'components/filters/filter-panels/f
SingleSelectFilterPanelFactory.deps = [FieldPanelWithFieldSelectFactory, SingleSelectFilterFactory];
function SingleSelectFilterPanelFactory(FieldPanelWithFieldSelect, SingleSelectFilter) {
+ /** @type {import('./filter-panel-types').FilterPanelComponent} */
const SingleSelectFilterPanel = React.memo(
({
idx,
diff --git a/src/components/filters/filter-panels/time-range-filter-panel.js b/src/components/filters/filter-panels/time-range-filter-panel.js
index 0b16e052b..8a5527386 100644
--- a/src/components/filters/filter-panels/time-range-filter-panel.js
+++ b/src/components/filters/filter-panels/time-range-filter-panel.js
@@ -31,6 +31,7 @@ TimeRangeFilterPanelFactory.deps = [
];
function TimeRangeFilterPanelFactory(FieldPanelWithFieldSelect, TimeRangeFilter) {
+ /** @type {import('./filter-panel-types').FilterPanelComponent} */
const TimeRangeFilterPanel = React.memo(
({
idx,
diff --git a/src/components/filters/polygon-filter.d.ts b/src/components/filters/polygon-filter.d.ts
new file mode 100644
index 000000000..11cc095e3
--- /dev/null
+++ b/src/components/filters/polygon-filter.d.ts
@@ -0,0 +1,13 @@
+import {FunctionComponent} from 'react';
+import {Filter} from 'reducers';
+import {Layer} from 'layers';
+
+export type PolygonFilterProps = {
+ filter: Filter,
+ layers: ReadonlyArray<Layer>,
+ setLayers: (ids: ReadonlyArray<string>) => void
+};
+
+export const PolygonFilter: FunctionComponent<PolygonFilterProps>;
+
+export default function PolygonFilterFactory(): PolygonFilter;
diff --git a/src/components/filters/polygon-filter.js b/src/components/filters/polygon-filter.js
index da2251b09..4b927ffbd 100644
--- a/src/components/filters/polygon-filter.js
+++ b/src/components/filters/polygon-filter.js
@@ -28,6 +28,7 @@ const isAlreadySelected = (selectedLayers, layerId) =>
selectedLayers.findIndex(l => l.id === layerId) === -1;
function PolygonFilterFactory() {
+ /** @type {typeof import('./polygon-filter').PolygonFilter} */
const PolygonFilter = React.memo(({filter, layers, setLayers}) => {
const setNewLayers = useCallback(
newLayers => {
@@ -36,7 +37,7 @@ function PolygonFilterFactory() {
[setLayers]
);
- const selectedLayers = useMemo(() => layers.filter(l => filter.layerId.includes(l.id)), [
+ const selectedLayers = useMemo(() => layers.filter(l => filter.layerId?.includes(l.id)), [
filter,
layers
]);
diff --git a/src/components/geocoder/geocoder.d.ts b/src/components/geocoder/geocoder.d.ts
new file mode 100644
index 000000000..1ef55ee2a
--- /dev/null
+++ b/src/components/geocoder/geocoder.d.ts
@@ -0,0 +1,33 @@
+import {FunctionComponent} from 'react';
+import {Viewport} from 'reducers/map-state-updaters';
+import {IntlShape} from 'react-intl';
+
+interface Result {
+ center: [number, number],
+ place_name: string
+}
+
+export type Results = ReadonlyArray<Result>;
+
+type GeocoderProps = {
+ mapboxApiAccessToken: string,
+ className?: string,
+ limit?: number,
+ timeout?: number,
+ formatItem?: (item: Result) => string,
+ viewport: Viewport,
+ onSelected: (viewport: Viewport, item: Result) => void,
+ onDeleteMarker: () => void,
+ transitionDuration: number,
+ pointZoom: number,
+ width: number
+};
+
+type IntlProps = {
+ intl: IntlShape
+};
+
+export type GeocoderComponent = FunctionComponent<GeocoderPropsProps & IntlProps>;
+
+const Geocoder: FunctionComponent<GeocoderPropsProps>;
+export default Geocoder;
diff --git a/src/components/geocoder/geocoder.js b/src/components/geocoder/geocoder.js
index ae2760715..a2fbc74d3 100644
--- a/src/components/geocoder/geocoder.js
+++ b/src/components/geocoder/geocoder.js
@@ -106,6 +106,7 @@ const StyledContainer = styled.div`
}
`;
+/** @type {import('./geocoder').GeocoderComponent} */
const GeoCoder = ({
mapboxApiAccessToken,
className = '',
@@ -120,10 +121,12 @@ const GeoCoder = ({
width,
intl
}) => {
- const [inputValue, setInputValue] = useState(null);
+ const [inputValue, setInputValue] = useState('');
const [showResults, setShowResults] = useState(false);
const [showDelete, setShowDelete] = useState(false);
- const [results, setResults] = useState([]);
+ /** @type {import('./geocoder').Results} */
+ const initialResults = [];
+ const [results, setResults] = useState(initialResults);
const [selectedIndex, setSelectedIndex] = useState(0);
const client = useMemo(() => new MapboxClient(mapboxApiAccessToken), [mapboxApiAccessToken]);
diff --git a/src/components/kepler-gl.d.ts b/src/components/kepler-gl.d.ts
index 0432b31e4..e3bbd4bd1 100644
--- a/src/components/kepler-gl.d.ts
+++ b/src/components/kepler-gl.d.ts
@@ -1,17 +1,59 @@
-import React from 'react';
+import {ComponentClass, RefType} from 'react';
import {LoaderObject} from '@loaders.gl/loader-utils';
+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';
+import * as VisStateActions from 'actions/vis-state-actions';
+import * as MapStateActions from 'actions/map-state-actions';
+import * as MapStyleActions from 'actions/map-style-actions';
+import * as UIStateActions from 'actions/ui-state-actions';
+import * as ProviderActions from 'actions/provider-actions';
export type KeplerGlProps = {
- mapStyles: object[];
- mapStylesReplaceDefault: boolean;
- mapboxApiUrl: string;
- width: number;
- height: number;
- appName: string;
- version: string;
- sidePanelWidth: number;
- theme: object;
- cloudProviders: object[];
+ id: string,
+ appWebsite: any,
+ onSaveMap?: () => void,
+ onViewStateChange?: () => void,
+ onDeckInitialized?: () => void,
+ onKeplerGlInitialized?: () => void,
+ mapboxApiAccessToken: string,
+ mapboxApiUrl: string,
+ getMapboxRef: () => React.RefType<any>,
+ mapStyles: {id: string, style?: object}[],
+ mapStylesReplaceDefault: boolean,
+ mapboxApiUrl: string,
+ width: number,
+ height: number,
+ appName: string,
+ version: string,
+ sidePanelWidth: number,
+ theme: object,
+ cloudProviders: object[],
+ deckGlProps?: object,
+ onLoadCloudMapSuccess?: OnSuccessCallBack,
+ onLoadCloudMapError?: OnErrorCallBack,
+ onExportToCloudSuccess?:OnSuccessCallBack,
+ onExportToCloudError?: OnErrorCallBack,
+ readOnly?: boolean
};
-export default function KeplerGlFactory(): React.Component<KeplerGlProps>;
+export type UnconnectedKeplerGlProps = KeplerGlProps & {
+ mapState: MapState,
+ mapStyle: MapStyle,
+ uiState: UiState,
+ visState: VisState,
+ providerState: ProviderState,
+ visStateActions: typeof VisStateActions,
+ uiStateActions: typeof UIStateActions,
+ mapStateActions: typeof MapStateActions,
+ mapStyleActions: typeof MapStyleActions,
+ providerActions: typeof ProviderActions
+};
+
+export type KeplerGlComponent = ComponentClass<UnconnectedKeplerGlProps>;
+export const DEFAULT_KEPLER_GL_PROPS: Partial<KeplerGlProps>;
+
+export default function KeplerGlFactory(): ComponentClass<KeplerGlProps>;
diff --git a/src/components/kepler-gl.js b/src/components/kepler-gl.js
index 94de7a7ca..b9d1a47c6 100644
--- a/src/components/kepler-gl.js
+++ b/src/components/kepler-gl.js
@@ -250,14 +250,14 @@ function KeplerGlFactory(
PlotContainer,
NotificationPanel
) {
- /** @typedef {import('./kepler-gl').KeplerGlProps} KeplerGlProps */
+ /** @typedef {import('./kepler-gl').UnconnectedKeplerGlProps} KeplerGlProps */
/** @augments React.Component<KeplerGlProps> */
class KeplerGL extends Component {
static defaultProps = DEFAULT_KEPLER_GL_PROPS;
componentDidMount() {
this._validateMapboxToken();
- this._loadMapStyle(this.props.mapStyles);
+ this._loadMapStyle();
this._handleResize(this.props);
if (typeof this.props.onKeplerGlInitialized === 'function') {
this.props.onKeplerGlInitialized();
@@ -276,9 +276,9 @@ function KeplerGlFactory(
this._handleResize(this.props);
}
}
+ static contextType = RootContext;
root = createRef();
- static contextType = RootContext;
/* selectors */
themeSelector = props => props.theme;
@@ -436,9 +436,11 @@ export function mapStateToProps(state = {}, props) {
}
const defaultUserActions = {};
-const getDispatch = dispatch => dispatch;
+
+const getDispatch = (dispatch, props) => dispatch;
const getUserActions = (dispatch, props) => props.actions || defaultUserActions;
+/** @type {() => import('reselect').OutputParametricSelector<any, any, any, any>} */
function makeGetActionCreators() {
return createSelector([getDispatch, getUserActions], (dispatch, userActions) => {
const [visStateActions, mapStateActions, mapStyleActions, uiStateActions, providerActions] = [
diff --git a/src/components/map-container.js b/src/components/map-container.js
index c8db3f42a..5b5382af0 100644
--- a/src/components/map-container.js
+++ b/src/components/map-container.js
@@ -44,6 +44,7 @@ import {getLayerHoverProp, renderDeckGlLayer} from 'utils/layer-utils';
import ThreeDBuildingLayer from 'deckgl-layers/3d-building-layer/3d-building-layer';
import {FILTER_TYPES, GEOCODER_LAYER_ID} from 'constants/default-settings';
+/** @type {{[key: string]: React.CSSProperties}} */
const MAP_STYLE = {
container: {
display: 'inline-block',
@@ -511,7 +512,7 @@ export default function MapContainerFactory(MapPopover, MapControl, Editor) {
onMouseMove={this.props.visStateActions.onMouseMove}
>
{this._renderDeckOverlay(layersToRender)}
- {this._renderMapboxOverlays(layersToRender)}
+ {this._renderMapboxOverlays()}
<Editor
index={index}
datasets={datasets}
diff --git a/src/components/map/layer-hover-info.d.ts b/src/components/map/layer-hover-info.d.ts
new file mode 100644
index 000000000..7efdd6fcb
--- /dev/null
+++ b/src/components/map/layer-hover-info.d.ts
@@ -0,0 +1,12 @@
+import {FunctionComponent} from 'react';
+
+export type RowProps = {
+ name: string,
+ value: string,
+ deltaValue?: string | null,
+ url?: string
+};
+
+export type RowComponent = React.FunctionComponent<RowProps>;
+
+export const StyledLayerName: FunctionComponent<any>;
\ No newline at end of file
diff --git a/src/components/map/layer-hover-info.js b/src/components/map/layer-hover-info.js
index cec9db031..b3fdb4814 100644
--- a/src/components/map/layer-hover-info.js
+++ b/src/components/map/layer-hover-info.js
@@ -53,6 +53,7 @@ const StyledTable = styled.table`
}
`;
+/** @type {import('./layer-hover-info').RowComponent} */
const Row = ({name, value, deltaValue, url}) => {
// Set 'url' to 'value' if it looks like a url
if (!url && value && typeof value === 'string' && value.match(/^http/)) {
diff --git a/src/components/map/map-control.d.ts b/src/components/map/map-control.d.ts
new file mode 100644
index 000000000..cd31bfea6
--- /dev/null
+++ b/src/components/map/map-control.d.ts
@@ -0,0 +1,110 @@
+import {Element} from 'react';
+import {Layer} from 'layers';
+import {Editor} from 'reducers/vis-state-updaters';
+
+export type LocalePanelProps = {
+ availableLocales: ReadonlyArray<string>,
+ onSetLocale: (locale: string) => void,
+ activeLocale: string,
+ isActive: boolean,
+ onToggleMenuPanel: () => void,
+ disableClose?: boolean
+};
+
+export type LocalePanelComponent = React.FunctionComponent<LocalePanelProps>;
+
+export type LayerSelectorPanelProps = {
+ items: ReadonlyArray<Layer>,
+ onMapToggleLayer: (layerId: string) => void,
+ isActive: boolean,
+ toggleMenuPanel: () => void,
+ disableClose?: boolean
+};
+
+export type LayerSelectorPanelComponent = React.FunctionComponent<LayerSelectorPanelProps>;
+
+export type MapControlTooltipProps = {
+ id: string,
+ message: string
+};
+
+export type MapControlTooltipComponent = React.FunctionComponent<MapControlTooltipProps>;
+
+interface MapDrawPanelIcons {
+ visible: ComponentType<any>,
+ hidden: ComponentType<any>,
+ polygon: ComponentType<any>,
+ cursor: ComponentType<any>,
+ innerPolygon: ComponentType<any>,
+ rectangle: ComponentType<any>
+}
+
+export type MapDrawPanelProps = {
+ editor: Editor,
+ isActive: boolean,
+ onToggleMenuPanel: () => void,
+ onSetEditorMode: (mode: string) => void,
+ onToggleEditorVisibility: () => void,
+ actionIcons: MapDrawPanelIcons
+};
+
+export type MapDrawPanelComponent = React.FunctionComponent<MapDrawPanelProps>;
+export function MapDrawPanelFactory(): MapDrawPanelComponent;
+
+export type MapControlPanelProps = {
+ children: Element,
+ header?: string,
+ scale?: number,
+ onClick: () => void,
+ isExport?: boolean,
+ disableClose?: boolean,
+ logoComponent?: Element
+};
+
+export type MapControlPanelComponent = React.FunctionComponent<MapControlPanelProps>;
+
+interface MapLegendPanelIcons {
+ legend: ComponentType<any>
+}
+
+export type MapLegendPanelProps = {
+ layers: ReadonlyArray<Layer>,
+ isActive: boolean,
+ scale: number,
+ onToggleMenuPanel: () => void,
+ isExport: boolean,
+ disableClose?: boolean,
+ logoComponent: Element,
+ actionIcons: MapLegendPanelIcons
+};
+
+export type MapLegendPanelComponent = React.FunctionComponent<MapLegendPanelProps>;
+export function MapLegendPanelFactory(): MapLegendPanelComponent;
+
+interface Toggle3dButtonIcons {
+ cube: ComponentType<any>
+}
+
+export type Toggle3dButtonProps = {
+ dragRotate: boolean,
+ onTogglePerspective: () => void,
+ actionIcons: Toggle3dButtonIcons
+};
+
+export type Toggle3dButtonComponent = React.FunctionComponent<Toggle3dButtonProps>;
+export function Toggle3dButtonFactory(): Toggle3dButtonComponent;
+
+interface SplitMapButtonIcons {
+ delete: ComponentType<any>,
+ split: ComponentType<any>
+}
+
+export type SplitMapButtonProps = {
+ isSplit: boolean,
+ mapIndex: number,
+ onToggleSplitMap: (index?: number) => void,
+ actionIcons: SplitMapButtonIcons
+};
+
+export type SplitMapButtonComponent = React.FunctionComponent<SplitMapButtonProps>;
+export function SplitMapButtonFactory(): SplitMapButtonComponent;
diff --git a/src/components/map/map-control.js b/src/components/map/map-control.js
index 0e158ed19..1d4068339 100644
--- a/src/components/map/map-control.js
+++ b/src/components/map/map-control.js
@@ -99,12 +99,13 @@ const StyledMapControlPanelHeader = styled.div.attrs({
}
`;
-const ActionPanel = ({className, children}) => (
+const ActionPanel = ({className = '', children}) => (
<StyledMapControlAction className={className}>{children}</StyledMapControlAction>
);
ActionPanel.displayName = 'ActionPanel';
+/** @type {import('./map-control').MapControlTooltipComponent} */
const MapControlTooltip = React.memo(({id, message}) => (
<Tooltip id={id} place="left" effect="solid">
<span>
@@ -123,9 +124,10 @@ const MapLegendTooltip = ({id, message}) => (
</Tooltip>
);
+/** @type {import('./map-control').LayerSelectorPanelComponent} */
const LayerSelectorPanel = React.memo(({items, onMapToggleLayer, isActive, toggleMenuPanel}) =>
!isActive ? (
- <MapControlButton
+ (<MapControlButton
key={1}
onClick={e => {
e.preventDefault();
@@ -140,16 +142,17 @@ const LayerSelectorPanel = React.memo(({items, onMapToggleLayer, isActive, toggl
id="toggle-layer"
message={isActive ? 'tooltip.hideLayerPanel' : 'tooltip.showLayerPanel'}
/>
- </MapControlButton>
+ </MapControlButton>)
) : (
- <MapControlPanel header="header.visibleLayers" onClick={toggleMenuPanel}>
+ (<MapControlPanel header="header.visibleLayers" onClick={toggleMenuPanel}>
<MapLayerSelector layers={items} onMapToggleLayer={onMapToggleLayer} />
- </MapControlPanel>
+ </MapControlPanel>)
)
);
LayerSelectorPanel.displayName = 'LayerSelectorPanel';
+/** @type {import('./map-control').MapControlPanelComponent} */
const MapControlPanel = React.memo(
({children, header, onClick, scale = 1, isExport, disableClose = false, logoComponent}) => (
<StyledMapControlPanel
@@ -184,6 +187,7 @@ export function MapLegendPanelFactory() {
const defaultActionIcons = {
legend: Legend
};
+ /** @type {import('./map-control').MapLegendPanelComponent} */
const MapLegendPanel = ({
layers,
isActive,
@@ -195,7 +199,7 @@ export function MapLegendPanelFactory() {
actionIcons = defaultActionIcons
}) =>
!isActive ? (
- <MapControlButton
+ (<MapControlButton
key={2}
data-tip
data-for="show-legend"
@@ -207,9 +211,9 @@ export function MapLegendPanelFactory() {
>
<actionIcons.legend height="22px" />
<MapLegendTooltip id="show-legend" message={'tooltip.showLegend'} />
- </MapControlButton>
+ </MapControlButton>)
) : (
- <MapControlPanel
+ (<MapControlPanel
scale={scale}
header={'header.layerLegend'}
onClick={onToggleMenuPanel}
@@ -218,18 +222,20 @@ export function MapLegendPanelFactory() {
logoComponent={logoComponent}
>
<MapLegend layers={layers} />
- </MapControlPanel>
+ </MapControlPanel>)
);
MapLegendPanel.displayName = 'MapControlPanel';
return MapLegendPanel;
}
+
SplitMapButtonFactory.deps = [];
export function SplitMapButtonFactory() {
const defaultActionIcons = {
delete: Delete,
split: Split
};
+ /** @type {import('./map-control').SplitMapButtonComponent} */
const SplitMapButton = React.memo(
({isSplit, mapIndex, onToggleSplitMap, actionIcons = defaultActionIcons}) => (
<MapControlButton
@@ -255,11 +261,13 @@ export function SplitMapButtonFactory() {
SplitMapButton.displayName = 'SplitMapButton';
return SplitMapButton;
}
+
Toggle3dButtonFactory.deps = [];
export function Toggle3dButtonFactory() {
const defaultActionIcons = {
cube: Cube3d
};
+ /** @type {import('./map-control').Toggle3dButtonComponent} */
const Toggle3dButton = React.memo(
({dragRotate, onTogglePerspective, actionIcons = defaultActionIcons}) => (
<MapControlButton
@@ -298,6 +306,7 @@ export function MapDrawPanelFactory() {
innerPolygon: Polygon,
rectangle: Rectangle
};
+ /** @type {import('./map-control').MapDrawPanelComponent} */
const MapDrawPanel = React.memo(
({
editor,
@@ -315,7 +324,6 @@ export function MapDrawPanelFactory() {
className="edit-feature"
onClick={() => onSetEditorMode(EDITOR_MODES.EDIT)}
label="toolbar.select"
- iconHeight="22px"
icon={actionIcons.cursor}
active={editor.mode === EDITOR_MODES.EDIT}
/>
@@ -323,7 +331,6 @@ export function MapDrawPanelFactory() {
className="draw-feature"
onClick={() => onSetEditorMode(EDITOR_MODES.DRAW_POLYGON)}
label="toolbar.polygon"
- iconHeight="22px"
icon={actionIcons.innerPolygon}
active={editor.mode === EDITOR_MODES.DRAW_POLYGON}
/>
@@ -331,7 +338,6 @@ export function MapDrawPanelFactory() {
className="draw-rectangle"
onClick={() => onSetEditorMode(EDITOR_MODES.DRAW_RECTANGLE)}
label="toolbar.rectangle"
- iconHeight="22px"
icon={actionIcons.rectangle}
active={editor.mode === EDITOR_MODES.DRAW_RECTANGLE}
/>
@@ -339,7 +345,6 @@ export function MapDrawPanelFactory() {
className="toggle-features"
onClick={onToggleEditorVisibility}
label={editor.visible ? 'toolbar.hide' : 'toolbar.show'}
- iconHeight="22px"
icon={editor.visible ? actionIcons.visible : actionIcons.hidden}
/>
</StyledToolbar>
@@ -365,6 +370,7 @@ export function MapDrawPanelFactory() {
return MapDrawPanel;
}
+/** @type {import('./map-control').LocalePanelComponent} */
const LocalePanel = React.memo(
({availableLocales, isActive, onToggleMenuPanel, onSetLocale, activeLocale}) => {
const onClickItem = useCallback(
@@ -563,6 +569,7 @@ function MapControlFactory(MapDrawPanel, Toggle3dButton, SplitMapButton, MapLege
availableLocales={Object.keys(LOCALE_CODES)}
onSetLocale={this.props.onSetLocale}
onToggleMenuPanel={() => onToggleMapControl('mapLocale')}
+ disableClose={mapLocale.disableClose}
/>
</ActionPanel>
) : null}
diff --git a/src/components/map/map-legend.d.ts b/src/components/map/map-legend.d.ts
new file mode 100644
index 000000000..ebafc8bf2
--- /dev/null
+++ b/src/components/map/map-legend.d.ts
@@ -0,0 +1,29 @@
+import {FunctionComponent} from 'react';
+import {Layer, LayerConfig, VisualChannel, VisualChannelDescription} from 'layers';
+
+export type SingleColorLegendProps = {
+ width: number,
+ color: string
+};
+
+export const SingleColorLegend: FunctionComponent<SingleColorLegendProps>;
+
+export type LayerColorLegendProps = {
+ description: VisualChannelDescription,
+ config: LayerConfig,
+ width: number,
+ colorChannel: VisualChannel
+};
+
+export const LayerColorLegend: FunctionComponent<LayerColorLegendProps>;
+
+export type MapLegendProps = {
+ layers?: ReadonlyArray<Layer>,
+ width?: number,
+ options?: {
+ showLayerName?: boolean
+ }
+};
+
+const MapLegend: FunctionComponent<MapLegendProps>;
+export default MapLegend;
diff --git a/src/components/map/map-legend.js b/src/components/map/map-legend.js
index a6f356320..ac7f6daca 100644
--- a/src/components/map/map-legend.js
+++ b/src/components/map/map-legend.js
@@ -19,7 +19,6 @@
// THE SOFTWARE.
import React from 'react';
-import PropTypes from 'prop-types';
import styled from 'styled-components';
import {rgb} from 'd3-color';
import ColorLegend from 'components/common/color-legend';
@@ -88,16 +87,14 @@ export const LayerSizeLegend = ({label, name}) => (
</div>
);
-const propTypes = {
- layers: PropTypes.arrayOf(PropTypes.object)
-};
+const SINGLE_COLOR_DOMAIN = [''];
-const SingleColorDomain = [''];
+/** @type {typeof import('./map-legend').SingleColorLegend} */
export const SingleColorLegend = React.memo(({width, color}) => (
<ColorLegend
scaleType="ordinal"
displayLabel={false}
- domain={SingleColorDomain}
+ domain={SINGLE_COLOR_DOMAIN}
fieldType={null}
range={{colors: [rgb(...color).toString()]}}
width={width}
@@ -106,6 +103,7 @@ export const SingleColorLegend = React.memo(({width, color}) => (
SingleColorLegend.displayName = 'SingleColorLegend';
+/** @type {typeof import('./map-legend').LayerColorLegend} */
export const LayerColorLegend = React.memo(({description, config, width, colorChannel}) => {
const enableColorBy = description.measure;
const {scale, field, domain, range, property} = colorChannel;
@@ -145,13 +143,8 @@ LayerColorLegend.displayName = 'LayerColorLegend';
const isColorChannel = visualChannel =>
[CHANNEL_SCALES.color, CHANNEL_SCALES.colorAggr].includes(visualChannel.channelScaleType);
-/**
- * @param {Layer[]} layers
- * @param {number} width
- * @param {object} options
- * @param {boolean} options.showLayerName
- */
-const MapLegend = ({layers = [], width, options = {}}) => (
+/** @type {typeof import('./map-legend').default }> */
+const MapLegend = ({layers = [], width, options}) => (
<div className="map-legend">
{layers.map((layer, index) => {
if (!layer.isValidToSave() || layer.config.hidden) {
@@ -170,7 +163,7 @@ const MapLegend = ({layers = [], width, options = {}}) => (
key={index}
width={containerW}
>
- {options.showLayerName !== false ? (
+ {options?.showLayerName !== false ? (
<div className="legend--layer_name">{layer.config.label}</div>
) : null}
{colorChannels.map(colorChannel =>
@@ -205,6 +198,5 @@ const MapLegend = ({layers = [], width, options = {}}) => (
</div>
);
-MapLegend.propTypes = propTypes;
-
+/** @type {typeof import('./map-legend').default }> */
export default MapLegend;
diff --git a/src/components/map/map-popover.d.ts b/src/components/map/map-popover.d.ts
new file mode 100644
index 000000000..3f9277768
--- /dev/null
+++ b/src/components/map/map-popover.d.ts
@@ -0,0 +1,28 @@
+import {FunctionComponent} from 'react';
+import {IntlShape} from 'react-intl';
+import {LayerHoverProp} from '../../utils/layer-utils';
+
+export type MapPopoverProps = {
+ x: number;
+ y: number;
+ mapW: number;
+ mapH: number;
+ frozen?: boolean;
+ coordinate: [number, number] | boolean;
+ layerHoverProp: LayerHoverProp | null;
+ isBase?: boolean;
+ zoom: number;
+ onClose: () => void;
+};
+
+type IntlProps = {
+ intl: IntlShape;
+};
+
+export const MapPopover: FunctionComponent<MapPopoverProps & IntlProps>;
+function MapPopoverFactory(
+ LayerHoverInfo: React.Component,
+ CoordinateInfo: React.Component
+): FunctionComponent<MapPopoverProps & IntlProps>;
+
+export default MapPopoverFactory;
diff --git a/src/components/map/map-popover.js b/src/components/map/map-popover.js
index 0e33f098c..2eee1cf65 100644
--- a/src/components/map/map-popover.js
+++ b/src/components/map/map-popover.js
@@ -20,7 +20,6 @@
import React, {useState, useCallback, useRef, useLayoutEffect} from 'react';
import styled from 'styled-components';
-import PropTypes from 'prop-types';
import LayerHoverInfoFactory from './layer-hover-info';
import CoordinateInfoFactory from './coordinate-info';
import {Pin, ArrowLeft, ArrowRight} from 'components/common/icons';
@@ -182,6 +181,7 @@ export function usePosition({layerHoverProp, x, y, mapW, mapH}, popover) {
return {moveLeft, moveRight, isLeft, pos};
}
export default function MapPopoverFactory(LayerHoverInfo, CoordinateInfo) {
+ /** @type {typeof import('./map-popover').MapPopover} */
const MapPopover = ({
x,
y,
@@ -241,18 +241,5 @@ export default function MapPopoverFactory(LayerHoverInfo, CoordinateInfo) {
);
};
- MapPopover.propTypes = {
- layerHoverProp: PropTypes.object,
- coordinate: PropTypes.oneOfType([PropTypes.array, PropTypes.bool]),
- frozen: PropTypes.bool,
- x: PropTypes.number,
- y: PropTypes.number,
- z: PropTypes.number,
- mapW: PropTypes.number.isRequired,
- mapH: PropTypes.number.isRequired,
- onClose: PropTypes.func.isRequired,
- isBase: PropTypes.bool
- };
-
return injectIntl(MapPopover);
}
diff --git a/src/components/modals/export-image-modal.d.ts b/src/components/modals/export-image-modal.d.ts
index 39adff841..9ec0909b3 100644
--- a/src/components/modals/export-image-modal.d.ts
+++ b/src/components/modals/export-image-modal.d.ts
@@ -1,17 +1,21 @@
-import React from 'react';
-import {setExportImageSetting, cleanupExportImage} from '../../actions';
+import {FunctionComponent} from 'react';
+import {SetExportImageSettingUpdaterAction} from '../../actions';
import {ExportImage} from '../../reducers';
-import {WithIntlProps} from 'react-intl';
+import {IntlShape} from 'react-intl';
-export type ExportImageModalProps = WithIntlProps<{
+export type ExportImageModalProps = {
exportImage: ExportImage;
mapW: number;
mapH: number;
- onUpdateImageSetting: typeof setExportImageSetting;
- cleanupExportImage: typeof cleanupExportImage;
-}>;
+ onUpdateImageSetting: (payload: SetExportImageSettingUpdaterAction.payload) => void;
+ cleanupExportImage: () => void;
+};
-export const ExportImageModal: React.FunctionComponent<ExportImageModalProps>;
-function ExportImageModalFactory(): React.FunctionComponent<ExportImageModalProps>;
+type IntlProps = {
+ intl: IntlShape;
+};
+
+export const ExportImageModal: FunctionComponent<ExportImageModalProps & IntlProps>;
+function ExportImageModalFactory(): FunctionComponent<ExportImageModalProps>;
export default ExportImageModalFactory;
diff --git a/src/components/modals/export-image-modal.js b/src/components/modals/export-image-modal.js
index feb70aedb..69a74825d 100644
--- a/src/components/modals/export-image-modal.js
+++ b/src/components/modals/export-image-modal.js
@@ -29,8 +29,6 @@ import Switch from 'components/common/switch';
import {injectIntl} from 'react-intl';
import {FormattedMessage} from 'localization';
-/** @typedef {import('./export-image-modal').ExportImageModalProps} ExportImageModalProps */
-
const ImageOptionList = styled.div`
display: flex;
flex-direction: column;
@@ -56,9 +54,7 @@ const ImageOptionList = styled.div`
`;
const ExportImageModalFactory = () => {
- /**
- * @type {React.FunctionComponent<ExportImageModalProps>}
- */
+ /** @type {typeof import('./export-image-modal').ExportImageModal} */
const ExportImageModal = ({
mapW,
mapH,
diff --git a/src/components/modals/export-map-modal/export-html-map.d.ts b/src/components/modals/export-map-modal/export-html-map.d.ts
index ab30a67e4..504e182b1 100644
--- a/src/components/modals/export-map-modal/export-html-map.d.ts
+++ b/src/components/modals/export-map-modal/export-html-map.d.ts
@@ -1,18 +1,21 @@
import React from 'react';
import {setUserMapboxAccessToken, setExportHTMLMapMode} from '../../actions';
-import {WithIntlProps} from 'react-intl';
+import {IntlShape} from 'react-intl';
-export type ExportHtmlMapProps = WithIntlProps<{
+export type ExportHtmlMapProps = {
onChangeExportMapHTMLMode: typeof setExportHTMLMapMode;
onEditUserMapboxAccessToken: typeof setUserMapboxAccessToken;
options: {
userMapboxToken?: string;
mode?: string;
};
- intl: any;
-}>;
+};
-export const ExportHtmlMap: React.FunctionComponent<ExportHtmlMapProps>;
+type IntlProps = {
+ intl: IntlShape;
+};
+
+export const ExportHtmlMap: React.FunctionComponent<ExportHtmlMapProps & IntlProps>;
function ExportHtmlMapFactory(): React.FunctionComponent<ExportHtmlMapProps>;
export default ExportHtmlMapFactory;
diff --git a/src/components/modals/export-map-modal/export-html-map.js b/src/components/modals/export-map-modal/export-html-map.js
index 8b881343e..0d1158c38 100644
--- a/src/components/modals/export-map-modal/export-html-map.js
+++ b/src/components/modals/export-map-modal/export-html-map.js
@@ -19,7 +19,6 @@
// THE SOFTWARE.
import React from 'react';
-import PropTypes from 'prop-types';
import {StyledExportSection, StyledType, CheckMark} from 'components/common/styled-components';
import {StyledExportMapSection, StyledWarning, ExportMapLink} from './components';
import {EXPORT_HTML_MAP_MODE_OPTIONS} from 'constants/default-settings';
@@ -28,8 +27,6 @@ import styled from 'styled-components';
import {injectIntl} from 'react-intl';
import {FormattedMessage} from 'localization';
-/** @typedef {import('./export-html-map').ExportHtmlMapProps} ExportHtmlMapProps */
-
const ExportMapStyledExportSection = styled(StyledExportSection)`
.disclaimer {
font-size: ${props => props.theme.inputFontSize};
@@ -63,15 +60,8 @@ const BigStyledTile = styled(StyledType)`
}
`;
-const exportHtmlPropTypes = {
- options: PropTypes.object,
- onEditUserMapboxAccessToken: PropTypes.func.isRequired
-};
-
function ExportHtmlMapFactory() {
- /**
- * @type {React.FunctionComponent<ExportHtmlMapProps>}
- */
+ /** @type {typeof import('./export-html-map').ExportHtmlMap} */
const ExportHtmlMap = ({
onChangeExportMapHTMLMode = mode => {},
onEditUserMapboxAccessToken = token => {},
@@ -147,7 +137,6 @@ function ExportHtmlMapFactory() {
</div>
);
- ExportHtmlMap.propTypes = exportHtmlPropTypes;
ExportHtmlMap.displayName = 'ExportHtmlMap';
return injectIntl(ExportHtmlMap);
diff --git a/src/components/modals/image-modal-container.d.ts b/src/components/modals/image-modal-container.d.ts
index 869420fd8..e8257808f 100644
--- a/src/components/modals/image-modal-container.d.ts
+++ b/src/components/modals/image-modal-container.d.ts
@@ -1,12 +1,12 @@
import React from 'react';
-import {setExportImageSetting, cleanupExportImage} from '../../actions';
+import {SetExportImageSettingUpdaterAction} from '../../actions';
import {Provider} from '../../cloud-providers';
export type ImageModalContainerProps = {
cloudProviders?: Provider[];
currentProvider?: string;
- onUpdateImageSetting: typeof setExportImageSetting;
- cleanupExportImage: typeof cleanupExportImage;
+ onUpdateImageSetting: (newSetting: SetExportImageSettingUpdaterAction['payload']) => void;
+ cleanupExportImage: () => void;
};
export const ImageModalContainer: React.FunctionComponent<ImageModalContainerProps>;
diff --git a/src/components/modals/image-modal-container.js b/src/components/modals/image-modal-container.js
index abe914ccc..801c180bf 100644
--- a/src/components/modals/image-modal-container.js
+++ b/src/components/modals/image-modal-container.js
@@ -45,7 +45,7 @@ const ImageModalContainer = ({
}, [onUpdateImageSetting, cleanupExportImage]);
useEffect(() => {
- if (currentProvider && cloudProviders.length) {
+ if (currentProvider && cloudProviders && cloudProviders.length) {
const provider = cloudProviders.find(p => p.name === currentProvider);
if (provider && provider.thumbnail) {
@@ -70,8 +70,7 @@ const ImageModalContainer = ({
};
ImageModalContainer.defaultProps = {
- cloudProviders: [],
- currentProvider: null
+ cloudProviders: []
};
export default ImageModalContainer;
diff --git a/src/components/modals/overwrite-map-modal.d.ts b/src/components/modals/overwrite-map-modal.d.ts
index 75d99e4f0..e7c139de0 100644
--- a/src/components/modals/overwrite-map-modal.d.ts
+++ b/src/components/modals/overwrite-map-modal.d.ts
@@ -1,6 +1,6 @@
import React from 'react';
import {Provider} from '../../cloud-providers';
-import {setExportImageSetting, cleanupExportImage} from '../../actions';
+import {ImageModalContainerProps} from './image-modal-container';
export type OverwriteMapModalProps = {
mapSaved: string;
@@ -10,8 +10,8 @@ export type OverwriteMapModalProps = {
currentProvider: string;
// callbacks
- onUpdateImageSetting: typeof setExportImageSetting;
- cleanupExportImage: typeof cleanupExportImage;
+ onUpdateImageSetting: ImageModalContainerProps['onUpdateImageSetting'];
+ cleanupExportImage: onUpdateImageSetting['cleanupExportImage'];
};
function OverwriteMapModalFactory(): React.FunctionComponent<OverwriteMapModal>;
diff --git a/src/components/modals/provider-modal-container.d.ts b/src/components/modals/provider-modal-container.d.ts
new file mode 100644
index 000000000..16aaac0c9
--- /dev/null
+++ b/src/components/modals/provider-modal-container.d.ts
@@ -0,0 +1,12 @@
+import React from 'react';
+import {SetCloudProviderPayload} from '../../actions';
+import {Provider} from '../../cloud-providers';
+
+export type ProviderModalContainerProps = {
+ cloudProviders?: Provider[];
+ currentProvider?: string;
+ onSetCloudProvider: (provider: SetCloudProviderPayload) => void;
+};
+
+export const ProviderModalContainer: React.FunctionComponent<ProviderModalContainerProps>;
+export default ProviderModalContainer;
diff --git a/src/components/modals/save-map-modal.d.ts b/src/components/modals/save-map-modal.d.ts
index 96f5d2039..905002565 100644
--- a/src/components/modals/save-map-modal.d.ts
+++ b/src/components/modals/save-map-modal.d.ts
@@ -2,11 +2,10 @@ import React from 'react';
import {Provider} from '../../cloud-providers';
import {MapInfo, ExportImage} from '../../reducers';
import {
- setCloudProvider,
- setExportImageSetting,
- cleanupExportImage,
setMapInfo
} from '../../actions';
+import {ImageModalContainerProps} from './image-modal-container';
+import {ProviderModalContainerProps} from './provider-modal-container';
type CharacterLimits = {
title: number;
@@ -18,14 +17,14 @@ export type SaveMapModalProps = {
exportImage: ExportImage;
cloudProviders: Provider[];
isProviderLoading: boolean;
- currentProvider: string;
+ currentProvider?: string;
providerError?: any;
characterLimits?: CharacterLimits;
// callbacks
- onSetCloudProvider: typeof setCloudProvider;
- onUpdateImageSetting: typeof setExportImageSetting;
- cleanupExportImage: typeof cleanupExportImage;
+ onSetCloudProvider: ProviderModalContainerProps['onSetCloudProvider'];
+ onUpdateImageSetting: ImageModalContainerProps['onUpdateImageSetting'];
+ cleanupExportImage: onUpdateImageSetting['cleanupExportImage'];
onSetMapInfo: typeof setMapInfo;
};
diff --git a/src/components/modals/save-map-modal.js b/src/components/modals/save-map-modal.js
index fc9dabb72..b442f6af6 100644
--- a/src/components/modals/save-map-modal.js
+++ b/src/components/modals/save-map-modal.js
@@ -71,7 +71,7 @@ const StyledSaveMapModal = styled.div.attrs({
}
`;
-const nop = () => {};
+const nop = _ => {};
export const MapInfoPanel = ({
mapInfo = {description: '', title: ''},
@@ -232,7 +232,6 @@ function SaveMapModalFactory() {
SaveMapModal.defaultProps = {
characterLimits: MAP_INFO_CHARACTER,
cloudProviders: [],
- currentProvider: null,
providerError: null,
isProviderLoading: false,
onSetCloudProvider: nop,
diff --git a/src/components/side-panel/cloud-storage-dropdown.js b/src/components/side-panel/cloud-storage-dropdown.js
index 1ab3dabe6..84d0b8255 100644
--- a/src/components/side-panel/cloud-storage-dropdown.js
+++ b/src/components/side-panel/cloud-storage-dropdown.js
@@ -19,7 +19,7 @@
// THE SOFTWARE.
import React from 'react';
-import {PanelHeaderDropdownFactory, Icons} from 'kepler.gl/components';
+import {PanelHeaderDropdownFactory, Icons} from 'components';
const CloudStorageItems = [
{
diff --git a/src/components/side-panel/common/dataset-title.js b/src/components/side-panel/common/dataset-title.js
index f5928d07f..61b77895b 100644
--- a/src/components/side-panel/common/dataset-title.js
+++ b/src/components/side-panel/common/dataset-title.js
@@ -26,7 +26,7 @@ import {CenterFlexbox, Tooltip} from 'components/common/styled-components';
import {ArrowRight, Table, Trash} from 'components/common/icons';
import DatasetTagFactory from 'components/side-panel/common/dataset-tag';
-function nop() {}
+function nop(_) {}
const StyledDatasetTitle = styled.div`
color: ${props => props.theme.textColor};
diff --git a/src/components/side-panel/layer-manager.js b/src/components/side-panel/layer-manager.js
index 83583f5ca..bb3dde47f 100644
--- a/src/components/side-panel/layer-manager.js
+++ b/src/components/side-panel/layer-manager.js
@@ -22,7 +22,7 @@ import React, {Component, useCallback} from 'react';
import classnames from 'classnames';
import PropTypes from 'prop-types';
-import {sortableContainer, sortableElement} from 'react-sortable-hoc';
+import {SortableContainer, SortableElement} from 'react-sortable-hoc';
import styled from 'styled-components';
import {createSelector} from 'reselect';
import {injectIntl} from 'react-intl';
@@ -121,7 +121,7 @@ LayerManagerFactory.deps = [AddDataButtonFactory, LayerPanelFactory, SourceDataC
function LayerManagerFactory(AddDataButton, LayerPanel, SourceDataCatalog) {
// By wrapping layer panel using a sortable element we don't have to implement the drag and drop logic into the panel itself;
// Developers can provide any layer panel implementation and it will still be sortable
- const SortableItem = sortableElement(({children, isSorting}) => {
+ const SortableItem = SortableElement(({children, isSorting}) => {
return (
<SortableStyledItem className={classnames('sortable-layer-items', {sorting: isSorting})}>
{children}
@@ -129,7 +129,7 @@ function LayerManagerFactory(AddDataButton, LayerPanel, SourceDataCatalog) {
);
});
- const SortableContainer = sortableContainer(({children}) => {
+ const WrappedSortableContainer = SortableContainer(({children}) => {
return <div>{children}</div>;
});
@@ -225,7 +225,7 @@ function LayerManagerFactory(AddDataButton, LayerPanel, SourceDataCatalog) {
<AddDataButton onClick={this.props.showAddDataModal} isInactive={!defaultDataset} />
<SidePanelDivider />
<SidePanelSection>
- <SortableContainer
+ <WrappedSortableContainer
onSortEnd={this._handleSort}
onSortStart={this._onSortStart}
updateBeforeSortStart={this._updateBeforeSortStart}
@@ -252,7 +252,7 @@ function LayerManagerFactory(AddDataButton, LayerPanel, SourceDataCatalog) {
</SortableItem>
)
)}
- </SortableContainer>
+ </WrappedSortableContainer>
</SidePanelSection>
<SidePanelSection>
{defaultDataset ? (
diff --git a/src/components/side-panel/layer-panel/custom-palette.js b/src/components/side-panel/layer-panel/custom-palette.js
index 01323ed1e..200f6bd78 100644
--- a/src/components/side-panel/layer-panel/custom-palette.js
+++ b/src/components/side-panel/layer-panel/custom-palette.js
@@ -22,7 +22,7 @@ import React, {Component, createRef} from 'react';
import classnames from 'classnames';
import PropTypes from 'prop-types';
import styled, {css} from 'styled-components';
-import {sortableContainer, sortableElement, sortableHandle} from 'react-sortable-hoc';
+import {SortableContainer, SortableElement, SortableHandle} from 'react-sortable-hoc';
import Portaled from 'components/common/portaled';
import {Button, InlineInput} from 'components/common/styled-components';
@@ -123,7 +123,7 @@ const StyledInlineInput = styled.div`
}
`;
-const SortableItem = sortableElement(({children, isSorting}) => (
+const SortableItem = SortableElement(({children, isSorting}) => (
<StyledSortableItem
className={classnames('custom-palette__sortable-items', {sorting: isSorting})}
>
@@ -131,9 +131,12 @@ const SortableItem = sortableElement(({children, isSorting}) => (
</StyledSortableItem>
));
-const SortableContainer = sortableContainer(({children}) => <div>{children}</div>);
+// TODO: Should className be applied to the div here?
+const WrappedSortableContainer = SortableContainer(({children, className}) => (
+ <div className={className}>{children}</div>
+));
-const DragHandle = sortableHandle(({className, children}) => (
+const DragHandle = SortableHandle(({className, children}) => (
<StyledDragHandle className={className}>{children}</StyledDragHandle>
));
@@ -225,7 +228,7 @@ class CustomPalette extends Component {
<StyledColorRange>
<ColorPalette colors={colors} />
</StyledColorRange>
- <SortableContainer
+ <WrappedSortableContainer
className="custom-palette-container"
onSortEnd={this._onSortEnd}
onSortStart={this._onSortStart}
@@ -238,7 +241,7 @@ class CustomPalette extends Component {
<DragHandle className="layer__drag-handle">
<VertDots height="20px" />
</DragHandle>
- <StyledSwatch color={color} onClick={e => this._onSwatchClick(index, e)} />
+ <StyledSwatch color={color} onClick={() => this._onSwatchClick(index)} />
<StyledInlineInput>
<InlineInput
type="text"
@@ -256,7 +259,7 @@ class CustomPalette extends Component {
</StyledTrash>
</SortableItem>
))}
- </SortableContainer>
+ </WrappedSortableContainer>
{/* Add Step Button */}
<Button className="add-step__button" link onClick={this._onColorAdd}>
+ Add Step
diff --git a/src/components/side-panel/layer-panel/custom-picker.js b/src/components/side-panel/layer-panel/custom-picker.js
index 1cc9f123f..c6506d49a 100644
--- a/src/components/side-panel/layer-panel/custom-picker.js
+++ b/src/components/side-panel/layer-panel/custom-picker.js
@@ -69,6 +69,7 @@ class CustomPicker extends Component {
render() {
const {color, onChange} = this.props;
+ /** @type {any} - TS complains this doesn't match SketchPickerStylesProps */
const pickerStyle = this.pickerStyleSelector(this.props);
return (
<StyledPicker>
diff --git a/src/components/side-panel/layer-panel/layer-configurator.js b/src/components/side-panel/layer-panel/layer-configurator.js
index 75686d7f3..e44b96088 100644
--- a/src/components/side-panel/layer-panel/layer-configurator.js
+++ b/src/components/side-panel/layer-panel/layer-configurator.js
@@ -903,7 +903,9 @@ export default function LayerConfiguratorFactory(
render() {
const {layer, datasets, updateLayerConfig, layerTypeOptions, updateLayerType} = this.props;
- const {fields = [], fieldPairs} = layer.config.dataId ? datasets[layer.config.dataId] : {};
+ const {fields = [], fieldPairs = undefined} = layer.config.dataId
+ ? datasets[layer.config.dataId]
+ : {};
const {config} = layer;
const visConfiguratorProps = getVisConfiguratorProps(this.props);
diff --git a/src/components/side-panel/layer-panel/layer-panel-header.js b/src/components/side-panel/layer-panel/layer-panel-header.js
index 54e6eaaaa..14a9334c0 100644
--- a/src/components/side-panel/layer-panel/layer-panel-header.js
+++ b/src/components/side-panel/layer-panel/layer-panel-header.js
@@ -22,7 +22,7 @@ import React, {useState} from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import styled from 'styled-components';
-import {sortableHandle} from 'react-sortable-hoc';
+import {SortableHandle} from 'react-sortable-hoc';
import PanelHeaderActionFactory from 'components/side-panel/panel-header-action';
import {ArrowDown, EyeSeen, EyeUnseen, Trash, VertDots} from 'components/common/icons';
@@ -93,7 +93,7 @@ const StyledDragHandle = styled.div`
}
`;
-export const DragHandle = sortableHandle(({className, children}) => (
+export const DragHandle = SortableHandle(({className, children}) => (
<StyledDragHandle className={className}>{children}</StyledDragHandle>
));
diff --git a/src/connect/keplergl-connect.js b/src/connect/keplergl-connect.js
index 643cb08f2..7d9c6cfca 100644
--- a/src/connect/keplergl-connect.js
+++ b/src/connect/keplergl-connect.js
@@ -21,8 +21,8 @@
import {connect as reduxConnect} from 'react-redux';
import withLocalSelector from './with-local-selector';
-const defaultMapStateToProps = state => state;
-const defaultMapDispatchToProps = () => dispatch => ({dispatch});
+const defaultMapStateToProps = (state, _, __) => state;
+const defaultMapDispatchToProps = () => (dispatch, _, __) => ({dispatch});
export const connect = (
mapStateToProps = defaultMapStateToProps,
diff --git a/src/connect/with-local-selector.d.ts b/src/connect/with-local-selector.d.ts
new file mode 100644
index 000000000..d36c4e4c9
--- /dev/null
+++ b/src/connect/with-local-selector.d.ts
@@ -0,0 +1,8 @@
+import {Component} from 'react';
+import KeplerGlContext from 'components/context';
+
+interface ContextSelector {
+ (state: any, context: any): KeplerGlContext;
+}
+
+export default function withLocalSelector<P, S>(component: Component<P, S>): Component<P, S>;
diff --git a/src/connect/with-local-selector.js b/src/connect/with-local-selector.js
index 3d5b74038..c38aab245 100644
--- a/src/connect/with-local-selector.js
+++ b/src/connect/with-local-selector.js
@@ -44,6 +44,8 @@ const withLocalSelector = ParentComponent => {
this.selectorFromProps,
(ctx, props) => mergeSelectors(ctx, props)
);
+ // TODO: This is tricky to type, revisit
+ /** @type import('./with-local-selector').ContextSelector */
contextSelector = createSelector(this.computedSelector, this.idFromProps, (selector, id) => ({
selector,
id
diff --git a/src/constants/default-settings.js b/src/constants/default-settings.js
index 12ae1e9b4..fae017c0a 100644
--- a/src/constants/default-settings.js
+++ b/src/constants/default-settings.js
@@ -145,9 +145,9 @@ export const DIMENSIONS = {
/**
* Theme name that can be passed to `KeplerGl` `prop.theme`.
- * Available themes are `Theme.light` and `Theme.dark`. Default theme is `Theme.dark`
+ * Available themes are `THEME.light` and `THEME.dark`. Default theme is `THEME.dark`
* @constant
- * @type {string}
+ * @type {object}
* @public
* @example
* ```js
@@ -287,6 +287,7 @@ export const TRIP_ARC_FIELDS = {
export const FILTER_TYPES = keyMirror({
range: null,
select: null,
+ input: null,
timeRange: null,
multiSelect: null,
polygon: null
diff --git a/src/deckgl-layers/3d-building-layer/3d-building-utils.js b/src/deckgl-layers/3d-building-layer/3d-building-utils.js
index a28423ab1..be8710704 100644
--- a/src/deckgl-layers/3d-building-layer/3d-building-utils.js
+++ b/src/deckgl-layers/3d-building-layer/3d-building-utils.js
@@ -19,7 +19,7 @@
// THE SOFTWARE.
import Protobuf from 'pbf';
-import {VectorTile, VectorTileFeature} from '@mapbox/vector-tile';
+import {VectorTile} from '@mapbox/vector-tile';
import {worldToLngLat} from 'viewport-mercator-project';
/* global fetch */
@@ -79,7 +79,6 @@ function project(x, y, scale, line, extent) {
/* eslint-disable */
export function vectorTileFeatureToProp(vectorTileFeature, project) {
let coords = getCoordinates(vectorTileFeature);
- const type = VectorTileFeature.types[vectorTileFeature.type];
const extent = vectorTileFeature.extent;
let i;
let j;
@@ -129,7 +128,7 @@ function getCoordinates(vectorTileFeature) {
line = [];
}
- line.push([x, y]);
+ if (line) line.push([x, y]);
} else if (cmd === 7) {
// Workaround for https://github.com/mapbox/mapnik-vector-tile/issues/90
if (line) {
@@ -171,7 +170,7 @@ function classifyRings(rings) {
polygons.push(polygon);
}
polygon = [rings[i]];
- } else {
+ } else if (polygon) {
polygon.push(rings[i]);
}
}
diff --git a/src/layers/base-layer.js b/src/layers/base-layer.js
index d4530c82b..b59afe75e 100644
--- a/src/layers/base-layer.js
+++ b/src/layers/base-layer.js
@@ -374,16 +374,16 @@ export default class Layer {
* Assign a field pair to column config, return column config
* @param key - Column Key
* @param pair - field Pair
- * @returns {{}} - Column config
+ * @returns {object} - Column config
*/
assignColumnPairs(key, pair) {
- if (!this.columnPairs || !this.columnPairs[key]) {
+ if (!this.columnPairs || !this.columnPairs?.[key]) {
// should not end in this state
return this.config.columns;
}
- const {pair: partnerKey, fieldPairKey} = this.columnPairs[key];
- const {fieldPairKey: partnerFieldPairKey} = this.columnPairs[partnerKey];
+ const {pair: partnerKey, fieldPairKey} = this.columnPairs?.[key];
+ const {fieldPairKey: partnerFieldPairKey} = this.columnPairs?.[partnerKey];
return {
...this.config.columns,
@@ -394,9 +394,9 @@ export default class Layer {
/**
* Calculate a radius zoom multiplier to render points, so they are visible in all zoom level
- * @param mapState
- * @param mapState.zoom - actual zoom
- * @param mapState.zoomOffset - zoomOffset when render in the plot container for export image
+ * @param {object} mapState
+ * @param {number} mapState.zoom - actual zoom
+ * @param {number | void} mapState.zoomOffset - zoomOffset when render in the plot container for export image
* @returns {number}
*/
getZoomFactor({zoom, zoomOffset = 0}) {
@@ -405,9 +405,9 @@ export default class Layer {
/**
* Calculate a elevation zoom multiplier to render points, so they are visible in all zoom level
- * @param mapState
- * @param mapState.zoom - actual zoom
- * @param mapState.zoomOffset - zoomOffset when render in the plot container for export image
+ * @param {object} mapState
+ * @param {number} mapState.zoom - actual zoom
+ * @param {number | void} mapState.zoomOffset - zoomOffset when render in the plot container for export image
* @returns {number}
*/
getElevationZoomFactor({zoom, zoomOffset = 0}) {
@@ -676,8 +676,6 @@ export default class Layer {
/**
* Check whether layer has all columns
- *
- * @param {object} layer
* @returns {boolean} yes or no
*/
hasAllColumns() {
@@ -693,7 +691,6 @@ export default class Layer {
/**
* Check whether layer has data
*
- * @param {object} layer
* @param {Array | Object} layerData
* @returns {boolean} yes or no
*/
@@ -701,7 +698,6 @@ export default class Layer {
if (!layerData) {
return false;
}
-
return Boolean(layerData.data && layerData.data.length);
}
@@ -898,7 +894,7 @@ export default class Layer {
* helper function to update one layer domain when state.data changed
* if state.data change is due ot update filter, newFiler will be passed
* called by updateAllLayerDomainData
- * @param {Object} dataset
+ * @param {Object} datasets
* @param {Object} newFilter
* @returns {object} layer
*/
@@ -1130,7 +1126,7 @@ export default class Layer {
accu.push(
new TextLayer({
...sharedProps,
- id: `${this.id}-label-${textLabel[i].field.name}`,
+ id: `${this.id}-label-${textLabel[i].field?.name}`,
data: data.data,
getText: d.getText,
getPosition,
@@ -1149,7 +1145,7 @@ export default class Layer {
getFilterValue: data.getFilterValue,
updateTriggers: {
...updateTriggers,
- getText: textLabel[i].field.name,
+ getText: textLabel[i].field?.name,
getPixelOffset: {
...updateTriggers.getRadius,
mapState,
@@ -1166,4 +1162,18 @@ export default class Layer {
return accu;
}, []);
}
+
+ calculateDataAttribute(dataset, getPosition) {
+ // implemented in subclasses
+ return [];
+ }
+
+ updateLayerMeta(allData, getPosition) {
+ // implemented in subclasses
+ }
+
+ getPositionAccessor() {
+ // implemented in subclasses
+ return () => null;
+ }
}
diff --git a/src/layers/h3-hexagon-layer/h3-utils.js b/src/layers/h3-hexagon-layer/h3-utils.js
index 20759cf1c..d8530a96d 100644
--- a/src/layers/h3-hexagon-layer/h3-utils.js
+++ b/src/layers/h3-hexagon-layer/h3-utils.js
@@ -53,7 +53,7 @@ export function idToPolygonGeo({object}, properties) {
}
export const isHexField = (field, fieldIdx, allData) => {
- if (!field.type === ALL_FIELD_TYPES.string) {
+ if (field.type !== ALL_FIELD_TYPES.string) {
return false;
}
const firstDP = allData.find(d => notNullorUndefined(d[fieldIdx]));
diff --git a/src/layers/index.d.ts b/src/layers/index.d.ts
index 0929fec43..7a766fd17 100644
--- a/src/layers/index.d.ts
+++ b/src/layers/index.d.ts
@@ -54,12 +54,17 @@ export type VisualChannel = {
key: string;
channelScaleType: string;
nullValue: any;
- defaultValue: any;
+ defaultMeasure: any;
accessor?: string;
condition?: (config: any) => boolean;
getAttributeValue?: (config: any) => (d: any) => any;
};
+export type VisualChannelDescription = {
+ label: string;
+ measure: string;
+};
+
export class Layer {
constructor(
prop?: {
@@ -71,15 +76,17 @@ export class Layer {
config: LayerConfig;
visConfigSettings: any;
visualChannels: {[key: string]: VisualChannel};
+ _oldDataUpdateTriggers: any;
hasAllColumns(): boolean;
updateLayerConfig(p: Partial<LayerConfig>): Layer;
- updateLayerDomain(datasets: Datasets, fitler?: Filter): Layer;
+ updateLayerDomain(datasets: Datasets, filter?: Filter): Layer;
updateLayerVisualChannel(dataset: Dataset, channel: string): Layer;
shouldCalculateLayerData(props: string[]): boolean;
formatLayerData(datasets: Datasets, oldLayerData?: any);
updateLayerColorUI(prop: string, newConfig: Partial<ColorUI>): Layer;
validateVisualChannel(channel: string): void;
isValidToSave(): boolean;
+ getVisualChannelDescription(key: string): VisualChannelDescription;
isLayerHovered(objectInfo: any): boolean;
getHoverData(object: any, allData?: Dataset['allData'], fields?: Dataset['fields']): any;
}
@@ -100,4 +107,3 @@ export type LayerClassesType = {
s2: Layer;
};
export const LayerClasses: LayerClassesType;
-export const LAYER_TYPES: {[key in keyof LayerClassesType]: string};
diff --git a/src/layers/layer-factory.d.ts b/src/layers/layer-factory.d.ts
index d37d085e9..327e4acee 100644
--- a/src/layers/layer-factory.d.ts
+++ b/src/layers/layer-factory.d.ts
@@ -142,3 +142,4 @@ export const DEFAULT_CUSTOM_PALETTE: ColorRange;
export const DEFAULT_COLOR_UI: ColorUI;
export const LAYER_VIS_CONFIGS: LayerVisConfig;
export const LAYER_TEXT_CONFIGS: LayerTextConfig;
+export const UNKNOWN_COLOR_KEY: string;
diff --git a/src/layers/layer-update.js b/src/layers/layer-update.js
index 493cc2005..94ee4bc90 100644
--- a/src/layers/layer-update.js
+++ b/src/layers/layer-update.js
@@ -24,10 +24,11 @@
*
* @param {Object} updateTriggers {getPosition: {column}, getData: {filteredIndex}}
* @param {Object} oldUpdateTriggers
- * @returns {Boolean|Object} `false` if nothing changed, or `triggerChanged` as an object
+ * @returns {boolean|object} `false` if nothing changed, or `triggerChanged` as an object
*/
export function diffUpdateTriggers(updateTriggers, oldUpdateTriggers = {}) {
const triggerChanged = {};
+ /** @type {boolean|object} */
let reason = false;
for (const triggerName in updateTriggers) {
diff --git a/src/layers/mapbox-utils.js b/src/layers/mapbox-utils.js
index a3208c4cb..86244b86d 100644
--- a/src/layers/mapbox-utils.js
+++ b/src/layers/mapbox-utils.js
@@ -20,6 +20,9 @@
import {OVERLAY_TYPE} from './base-layer';
+/** @typedef {import("geojson").FeatureCollection} FeatureCollection */
+/** @typedef {import("geojson").Feature} Feature */
+
/**
* This function will convert layers to mapbox layers
* @param {Array<Object>} layers the layers to be converted
@@ -128,14 +131,11 @@ function updateSourceData(map, sourceId, data) {
}
/**
*
- * @param points
- * @param columns {
- * lat: {fieldIdx},
- * lng: {fieldIdx},
- * alt: {fieldIdx}
- * }
- * @param properties [{label: {fieldIdx}]
- * @returns {{type: string, properties: {}, features: {type: string, properties: {}, geometry: {type: string, coordinates: *[]}}[]}}
+ * @param allData
+ * @param filteredIndex
+ * @param getGeometry {(point: any) => any}
+ * @param getProperties {(point: any, index: number) => any}
+ * @returns FeatureCollection
*/
export function geoJsonFromData(
allData = [],
@@ -145,6 +145,7 @@ export function geoJsonFromData(
) {
const geojson = {
type: 'FeatureCollection',
+ /** @type {Feature[]} */
features: []
};
diff --git a/src/reducers/index.d.ts b/src/reducers/index.d.ts
index dcef113b1..80e91a4bd 100644
--- a/src/reducers/index.d.ts
+++ b/src/reducers/index.d.ts
@@ -49,7 +49,7 @@ export * as combinedUpdaters from './combined-updaters';
// reducer merges
export * as visStateMergers from './vis-state-merger';
-// export tyes
+// export types
export {
AnimationConfig,
Brush,
@@ -81,7 +81,7 @@ export {
SplitMap,
TimeRangeFieldDomain,
TimeRangeFilter,
- Tooltip,
+ TooltipInfo,
VisState
} from './vis-state-updaters';
@@ -115,4 +115,4 @@ export {
UiState
} from './ui-state-updaters';
-export * from './types';
\ No newline at end of file
+export * from './types';
diff --git a/src/reducers/provider-state-updaters.js b/src/reducers/provider-state-updaters.js
index 1aeb572e8..d78c7bf27 100644
--- a/src/reducers/provider-state-updaters.js
+++ b/src/reducers/provider-state-updaters.js
@@ -89,7 +89,7 @@ function createGlobalNotificationTasks({type, message, delayClose = true}) {
const id = generateHashId();
const successNote = {
id,
- type: DEFAULT_NOTIFICATION_TYPES[type] || DEFAULT_NOTIFICATION_TYPES.success,
+ type: DEFAULT_NOTIFICATION_TYPES[type || ''] || DEFAULT_NOTIFICATION_TYPES.success,
topic: DEFAULT_NOTIFICATION_TOPICS.global,
message
};
diff --git a/src/reducers/vis-state-merger.d.ts b/src/reducers/vis-state-merger.d.ts
index 097e9cf68..0b40527d7 100644
--- a/src/reducers/vis-state-merger.d.ts
+++ b/src/reducers/vis-state-merger.d.ts
@@ -63,6 +63,13 @@ export function validateLayersByDatasets(
layers: ParsedConfig['visState']['layers']
): {validated: Layer[]; failed: ParsedConfig['visState']['layers']};
+export function validateColumn(
+ // TODO: Better types here
+ column: any,
+ columns: any[],
+ allFields: Dataset['fields']
+): boolean;
+
export type VisStateMergers = Merger[];
export const VIS_STATE_MERGERS: VisStateMergers;
diff --git a/src/reducers/vis-state-updaters.d.ts b/src/reducers/vis-state-updaters.d.ts
index 724be60b6..c84ce19a3 100644
--- a/src/reducers/vis-state-updaters.d.ts
+++ b/src/reducers/vis-state-updaters.d.ts
@@ -108,10 +108,10 @@ export type TimeRangeFilter = FilterBase &
fieldType: 'timestamp';
fixedDomain: true;
value: [number, number];
- bins?: Object,
+ bins?: Object;
plotType: {
- [key: string]: any
- }
+ [key: string]: any;
+ };
};
export type PolygonFilter = FilterBase & {
@@ -243,7 +243,7 @@ export type TooltipField = {
format: string | null;
};
export type CompareType = string | null;
-export type Tooltip = BaseInteraction & {
+export type TooltipInfo = BaseInteraction & {
config: {
fieldsToShow: {
[key: string]: TooltipField[];
@@ -264,7 +264,7 @@ export type Coordinate = BaseInteraction & {
position: number[] | null;
};
export type InteractionConfig = {
- tooltip: Tooltip;
+ tooltip: TooltipInfo;
geocoder: Geocoder;
brush: Brush;
coordinate: Coordinate;
diff --git a/src/reducers/vis-state-updaters.js b/src/reducers/vis-state-updaters.js
index 27bee407c..457150d9a 100644
--- a/src/reducers/vis-state-updaters.js
+++ b/src/reducers/vis-state-updaters.js
@@ -1907,14 +1907,16 @@ export function sortTableColumnUpdater(state, {dataId, column, mode}) {
if (!dataset) {
return state;
}
- if (!mode) {
+ let sortMode = mode;
+ if (!sortMode) {
const currentMode = get(dataset, ['sortColumn', column]);
- mode = currentMode
+ // @ts-ignore - should be fixable in a TS file
+ sortMode = currentMode
? Object.keys(SORT_ORDER).find(m => m !== currentMode)
: SORT_ORDER.ASCENDING;
}
- const sorted = sortDatasetByColumn(dataset, column, mode);
+ const sorted = sortDatasetByColumn(dataset, column, sortMode);
return set(['datasets', dataId], sorted, state);
}
diff --git a/src/schemas/schema-manager.d.ts b/src/schemas/schema-manager.d.ts
index ffeb3cdec..34bcabab7 100644
--- a/src/schemas/schema-manager.d.ts
+++ b/src/schemas/schema-manager.d.ts
@@ -1,7 +1,7 @@
import {
InteractionConfig,
Filter,
- Tooltip,
+ TooltipInfo,
SplitMap,
AnimationConfig,
VisState,
@@ -30,16 +30,16 @@ export type SavedFilter = {
export type ParsedFilter = Partial<SavedFilter>;
export type SavedInteractionConfig = {
- tooltip: Tooltip['config'] & {
+ tooltip: TooltipInfo['config'] & {
enabled: boolean;
};
- geocoder: Tooltip['geocoder'] & {
+ geocoder: TooltipInfo['geocoder'] & {
enabled: boolean;
};
- brush: Tooltip['brush'] & {
+ brush: TooltipInfo['brush'] & {
enabled: boolean;
};
- coordinate: Tooltip['coordinate'] & {
+ coordinate: TooltipInfo['coordinate'] & {
enabled: boolean;
};
};
@@ -198,7 +198,9 @@ export type SavedMap = {
};
export type LoadedMap = {datasets?: ParsedDataset[] | null; config?: ParsedConfig | null};
-export const reducerSchema: {[key: string]: typeof mapStateSchema | typeof visStateSchema | typeof mapStyleSchema};
+export const reducerSchema: {
+ [key: string]: typeof mapStateSchema | typeof visStateSchema | typeof mapStyleSchema;
+};
export class KeplerGLSchema {
constructor(prop: {
diff --git a/src/typedefs/README.md b/src/typedefs/README.md
new file mode 100644
index 000000000..2144f7928
--- /dev/null
+++ b/src/typedefs/README.md
@@ -0,0 +1,3 @@
+## typedefs
+
+This directory holds stubbed Typescript definitions for untyped modules we depend on. These only cover module exports used in Kepler.gl, and are insufficient for general use; ideally we can replace them in the future with proper definitions as those modules provide more types.
\ No newline at end of file
diff --git a/src/typedefs/deck.gl__core.d.ts b/src/typedefs/deck.gl__core.d.ts
new file mode 100644
index 000000000..075c8ae78
--- /dev/null
+++ b/src/typedefs/deck.gl__core.d.ts
@@ -0,0 +1,64 @@
+// Copyright (c) 2020 Uber Technologies, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+/**
+ * Stubbed Typescript types for certain classes in @deck.gl/core
+ * TODO: This is initially focused on fixing things for our own usage;
+ * we should eventually package proper types with the module.
+ */
+declare module '@deck.gl/core' {
+ export class Layer {
+ constructor(any): Layer;
+ id: string;
+ state: any;
+ props: any;
+ context: any;
+ draw(any): void;
+ setState(any): void;
+ setNeedsUpdate(): void;
+ setNeedsRedraw(): void;
+ getShaders(any?): any;
+ getAttributeManager(): any;
+ use64bitPositions(): boolean;
+ finalizeState(): void;
+ }
+
+ export class CompositeLayer extends Layer {
+ getSubLayerAccessor(any): any;
+ getSubLayerProps(any): any;
+ getSubLayerRow(any, any, number): any;
+ }
+
+ export class SimpleMeshLayer extends Layer {}
+
+ export const log = any;
+ export const project32: any;
+ export const picking: any;
+
+ export const FlyToInterpolator: any;
+ export const _GlobeView: any;
+ export const MapView: any;
+
+ interface ConstantMap {
+ [key: string]: string;
+ }
+
+ export const COORDINATE_SYSTEM: ConstantMap;
+}
diff --git a/src/typedefs/deck.gl__mesh-layers.d.ts b/src/typedefs/deck.gl__mesh-layers.d.ts
new file mode 100644
index 000000000..451f61046
--- /dev/null
+++ b/src/typedefs/deck.gl__mesh-layers.d.ts
@@ -0,0 +1,33 @@
+// Copyright (c) 2020 Uber Technologies, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+/**
+ * Very rough Typescript types for certain classes in @deck.gl/mesh-layers
+ * TODO: This is initially focused on fixing things for our own usage;
+ * we should eventually package proper types with the module.
+ */
+
+declare module '@deck.gl/mesh-layers' {
+ import {Layer} from '@deck.gl/core';
+
+ export class SimpleMeshLayer extends Layer {
+ constructor(any): SimpleMeshLayer;
+ }
+}
diff --git a/src/utils/data-utils.d.ts b/src/utils/data-utils.d.ts
index f479a7231..da8b5a139 100644
--- a/src/utils/data-utils.d.ts
+++ b/src/utils/data-utils.d.ts
@@ -5,14 +5,16 @@ import {Bounds} from 'reducers/map-state-updaters';
export function maybeToDate(isTime: boolean, fieldIdx: number, format: string, d: any[]): any;
export function timeToUnixMilli(value: any, format: string): Millisecond | null;
-export function notNullorUndefined(d: any): boolean;
+export function notNullorUndefined<T extends NonNullable<any>>(d: T | null | undefined): d is T;
export function isNumber(d: any): boolean;
export function isPlainObject(d: any): boolean;
export function numberSort(a: any, b: any): any;
export function unique(values: any[]): any[];
+export function arrayMove(array: any[], from: number, to: number);
export function getSortingFunction(fieldType: string): numberSort | undefined;
export function preciseRound(num: number, decimals: number): string;
export function parseFieldValue(value: any, type: string): string;
+export function getLatLngBounds(points: [number, number], idx: number, limit: [number, number]): [number, number];
export function getSampleData(data: any[], sampleSize?: number, getValue?: any): any[];
export function findMapBounds(layers: Layer[]): Bounds | null;
function formatter(v: any): any;
diff --git a/src/utils/dataset-utils.js b/src/utils/dataset-utils.js
index 72296221f..5ffb4ef76 100644
--- a/src/utils/dataset-utils.js
+++ b/src/utils/dataset-utils.js
@@ -84,6 +84,7 @@ export function createNewDataEntry({info, data, metadata}, datasets = {}) {
}
const allData = validatedData.rows;
+ /** @type {import('../actions').ProtoDataset['info']} */
const datasetInfo = {
id: generateHashId(4),
label: 'new dataset',
@@ -190,7 +191,7 @@ export function sortDatasetByColumn(dataset, column, mode) {
return dataset;
}
- const sortBy = SORT_ORDER[mode] || SORT_ORDER.ASCENDING;
+ const sortBy = SORT_ORDER[mode || ''] || SORT_ORDER.ASCENDING;
if (sortBy === SORT_ORDER.UNSORT) {
return {
diff --git a/src/utils/filter-utils.d.ts b/src/utils/filter-utils.d.ts
index 133161f8b..dce70ef1e 100644
--- a/src/utils/filter-utils.d.ts
+++ b/src/utils/filter-utils.d.ts
@@ -167,7 +167,9 @@ export function validateFiltersUpdateDatasets(state: VisState, filtersToValidate
updatedDatasets: Datasets
}
export function isInPolygon(point: number[], polygon: object): boolean;
-export function getIntervalBins(filter: TimeRangeFilter)
+export function getIntervalBins(filter: TimeRangeFilter);
+export function getTimeWidgetHintFormatter(domain: [number, number]): string;
+
export const FILTER_UPDATER_PROPS: {
dataId: string;
diff --git a/src/utils/interaction-utils.d.ts b/src/utils/interaction-utils.d.ts
index 8a9baf790..9b5399b67 100644
--- a/src/utils/interaction-utils.d.ts
+++ b/src/utils/interaction-utils.d.ts
@@ -5,6 +5,10 @@ import {InteractionConfig, Field, TooltipField, CompareType} from '../reducers/v
*/
export const TOOLTIP_MINUS_SIGN: string;
+export const BRUSH_CONFIG: {
+ range: [number, number]
+};
+
export function getDefaultInteraction(): InteractionConfig;
export function findFieldsToShow(p: {
fields: Field[];
diff --git a/src/utils/layer-utils.d.ts b/src/utils/layer-utils.d.ts
index 6637a2473..d283ec71b 100644
--- a/src/utils/layer-utils.d.ts
+++ b/src/utils/layer-utils.d.ts
@@ -19,7 +19,7 @@
// THE SOFTWARE.
import {Layer, LayerClassesType} from 'layers';
-import {VisState, Dataset, TooltipField} from 'reducers/vis-state-updaters';
+import {VisState, Dataset, TooltipField, CompareType} from 'reducers/vis-state-updaters';
export function calculateLayerData(
layer: Layer,
@@ -39,6 +39,8 @@ export type LayerHoverProp = {
fields: Field[];
fieldsToShow: TooltipField[];
layer: Layer;
+ primaryData?: any[];
+ compareType?: CompareType
};
export function findDefaultLayer(dataset: Dataset, layerClasses: LayerClassesType): Layer[];
@@ -49,3 +51,5 @@ export function getLayerHoverProp(arg: {
layersToRender: LayersToRender;
datasets: VisState['datasets'];
}): LayerHoverProp | null;
+
+export function renderDeckGlLayer(props: any, layerCallbacks: {[key]: any}, idx: number);
diff --git a/test/node/utils/dataset-utils-test.js b/test/node/utils/dataset-utils-test.js
index 0ced853c3..09e773cc6 100644
--- a/test/node/utils/dataset-utils-test.js
+++ b/test/node/utils/dataset-utils-test.js
@@ -29,7 +29,7 @@ test('datasetUtils.findDefaultColorField', t => {
const dataset = createNewDataEntry({
info: {id: 'taro'},
data: processCsvData(csvData)
- })['taro'];
+ }).taro;
const defaultField = findDefaultColorField(dataset);
// Unfortunately lat_1 is not detected as part of a field pair :(
@@ -42,7 +42,7 @@ test('datasetUtils.findDefaultColorField empty', t => {
const dataset = createNewDataEntry({
info: {id: 'taro'},
data: processCsvData('a\na')
- })['taro'];
+ }).taro;
const defaultField = findDefaultColorField(dataset);
t.notOk(defaultField, 'default field is null');
diff --git a/tsconfig.json b/tsconfig.json
index 97183b6e8..c9e5e230a 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -26,31 +26,11 @@
"*": ["*"]
}
},
- "paths": {
- "actions": "src/actions",
- "actions/*": "src/actions/*",
- "reducers": "src/reducers",
- "reducers/*": "src/reducers/*"
- },
"include": [
- "src/actions",
- "src/cloud-providers",
- "src/processors",
- "src/reducers",
- "src/schemas",
- "src/utils",
- "src/components/common/file-uploader",
- "src/components/common/progress-bar.js",
- "src/components/modals/load-data-modal.js",
- "src/components/modal-container.js",
- "src/components/kepler.gl"
-
- // TODO: add types
- // "src/constants",
- // "src/deckgl-layers",
- // "src/layers"
- // "src/localization",
- // "src/middleware",
- // "src/tasks"
+ "src"
+ ],
+ "exclude": [
+ "src/deckgl-layers",
+ "src/layers"
]
}
diff --git a/yarn.lock b/yarn.lock
index 5f10b12fd..2cfc51231 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -429,7 +429,7 @@
"@babel/helper-plugin-utils" "^7.10.4"
"@babel/plugin-syntax-optional-catch-binding" "^7.8.0"
-"@babel/plugin-proposal-optional-chaining@^7.0.0", "@babel/plugin-proposal-optional-chaining@^7.12.7":
+"@babel/plugin-proposal-optional-chaining@^7.0.0", "@babel/plugin-proposal-optional-chaining@^7.12.7", "@babel/plugin-proposal-optional-chaining@^7.2.0":
version "7.12.7"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-optional-chaining/-/plugin-proposal-optional-chaining-7.12.7.tgz#e02f0ea1b5dc59d401ec16fb824679f683d3303c"
integrity sha512-4ovylXZ0PWmwoOvhU2vhnzVNnm88/Sm9nx7V8BPgMvAzn5zDou3/Awy0EjglyubVHasJj+XCEkr/r1X3P5elCA==
@@ -2028,6 +2028,11 @@
resolved "https://registry.yarnpkg.com/@types/d3-array/-/d3-array-2.8.0.tgz#4b70ccb0c6d2ef28dac1e7e653b3ecd1f4b1d1ee"
integrity sha512-Q0ubcGHAmCRPh90/hoYB4eKWhxYKUxphwSeQrlz2tiabQ8S9zqhaE2CZJtCaLH2cjqKcjr52WPvmOA7ha0O4ZA==
+"@types/geojson@^7946.0.7":
+ version "7946.0.7"
+ resolved "https://registry.yarnpkg.com/@types/geojson/-/geojson-7946.0.7.tgz#c8fa532b60a0042219cdf173ca21a975ef0666ad"
+ integrity sha512-wE2v81i4C4Ol09RtsWFAqg3BUitWbHSpSlIo+bNdsCJijO9sjme+zm+73ZMCa/qMC8UEERxzGbvmr1cffo2SiQ==
+
"@types/glob@^7.1.1":
version "7.1.3"
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.1.3.tgz#e6ba80f36b7daad2c685acd9266382e68985c183"