Skip to content

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

[Chore]: Technical: Translate map components to typescript (#1803)

dariaterekhovaaebd8c3327d680
diff --git a/package.json b/package.json
index 6410bb6a4..2f2c341b1 100644
--- a/package.json
+++ b/package.json
@@ -122,6 +122,7 @@
"@types/lodash.uniqby": "^4.7.7",
"@types/lodash.xor": "^4.5.7",
"@types/mapbox__geo-viewport": "^0.4.1",
+ "@types/react-dom": "^18.0.0",
"@types/react-lifecycles-compat": "^3.0.1",
"@types/react-map-gl": "^6.1.2",
"@types/react-modal": "^3.13.1",
diff --git a/src/components/geocoder-panel.tsx b/src/components/geocoder-panel.tsx
index 6d1b8be70..4c454cdc6 100644
--- a/src/components/geocoder-panel.tsx
+++ b/src/components/geocoder-panel.tsx
@@ -25,7 +25,7 @@ import {FlyToInterpolator} from '@deck.gl/core';
import KeplerGlSchema from 'schemas';
import {getCenterAndZoomFromBounds} from 'utils/projection-utils';
-import Geocoder, { Result } from './geocoder/geocoder';
+import Geocoder, {Result} from './geocoder/geocoder';
import {
GEOCODER_DATASET_NAME,
GEOCODER_LAYER_ID,
diff --git a/src/components/map/coordinate-info.js b/src/components/map/coordinate-info.tsx
similarity index 92%
rename from src/components/map/coordinate-info.js
rename to src/components/map/coordinate-info.tsx
index d79252a7f..d09c715fd 100644
--- a/src/components/map/coordinate-info.js
+++ b/src/components/map/coordinate-info.tsx
@@ -28,8 +28,13 @@ import {StyledLayerName} from './layer-hover-info';
const DECIMAL = 6;
const DECIMAL_Z = 1;
+export interface CoordinateInfoProps {
+ coordinate: number[];
+ zoom: number;
+}
+
const CoordinateInfoFactory = () => {
- const CoordinateInfo = ({coordinate, zoom}) => (
+ const CoordinateInfo: React.FC<CoordinateInfoProps> = ({coordinate, zoom}) => (
<div className="coordingate-hover-info">
<StyledLayerName className="map-popover__layer-name">
<CursorClick height="12px" />
diff --git a/src/components/map/layer-hover-info.d.ts b/src/components/map/layer-hover-info.d.ts
deleted file mode 100644
index 7efdd6fcb..000000000
--- a/src/components/map/layer-hover-info.d.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-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.tsx
similarity index 96%
rename from src/components/map/layer-hover-info.js
rename to src/components/map/layer-hover-info.tsx
index 20e8dcb01..8bc642e5e 100644
--- a/src/components/map/layer-hover-info.js
+++ b/src/components/map/layer-hover-info.tsx
@@ -51,8 +51,15 @@ const StyledTable = styled.table`
}
`;
+interface RowProps {
+ name: string;
+ value: string;
+ deltaValue?: string | null;
+ url?: string;
+}
+
/** @type {import('./layer-hover-info').RowComponent} */
-const Row = ({name, value, deltaValue, url}) => {
+const Row: React.FC<RowProps> = ({name, value, deltaValue, url}) => {
// Set 'url' to 'value' if it looks like a url
if (!url && value && typeof value === 'string' && value.match(/^http/)) {
url = value;
diff --git a/src/components/map/layer-selector-panel.d.ts b/src/components/map/layer-selector-panel.d.ts
deleted file mode 100644
index b588112ee..000000000
--- a/src/components/map/layer-selector-panel.d.ts
+++ /dev/null
@@ -1,15 +0,0 @@
-import React from 'react';
-import {Layer} from 'layers';
-import {MapControls} from 'reducers/ui-state-updaters';
-
-export type LayerSelectorPanelProps = {
- onMapToggleLayer: (layerId: string) => void;
- onToggleMapControl: (control: string) => void;
- layers: ReadonlyArray<Layer>;
- layersToRender: {[key: string]: boolean};
- isSplit: boolean;
- mapControls: MapControls;
- readOnly: boolean;
-};
-
-export type LayerSelectorPanelComponent = React.FunctionComponent<LayerSelectorPanelProps>;
diff --git a/src/components/map/layer-selector-panel.js b/src/components/map/layer-selector-panel.tsx
similarity index 82%
rename from src/components/map/layer-selector-panel.js
rename to src/components/map/layer-selector-panel.tsx
index 99628a22a..6bda88930 100644
--- a/src/components/map/layer-selector-panel.js
+++ b/src/components/map/layer-selector-panel.tsx
@@ -26,12 +26,27 @@ import {Layers} from '../common/icons';
import MapLayerSelector from '../common/map-layer-selector';
import MapControlTooltipFactory from './map-control-tooltip';
import MapControlPanelFactory from './map-control-panel';
+import {Layer} from 'layers';
+import {MapControl, MapControls} from 'reducers';
LayerSelectorPanelFactory.deps = [MapControlTooltipFactory, MapControlPanelFactory];
-function LayerSelectorPanelFactory(MapControlTooltip, MapControlPanel) {
+export type LayerSelectorPanelProps = {
+ onMapToggleLayer: (layerId: string) => void;
+ onToggleMapControl: (control: string) => void;
+ layers: ReadonlyArray<Layer>;
+ layersToRender: {[key: string]: boolean};
+ isSplit: boolean;
+ mapControls: MapControls;
+ readOnly: boolean;
+};
+
+function LayerSelectorPanelFactory(
+ MapControlTooltip: ReturnType<typeof MapControlTooltipFactory>,
+ MapControlPanel: ReturnType<typeof MapControlPanelFactory>
+) {
/** @type {import('./layer-selector-panel').LayerSelectorPanelComponent} */
- const LayerSelectorPanel = ({
+ const LayerSelectorPanel: React.FC<LayerSelectorPanelProps> = ({
onMapToggleLayer,
onToggleMapControl,
layers,
@@ -40,7 +55,7 @@ function LayerSelectorPanelFactory(MapControlTooltip, MapControlPanel) {
mapControls,
readOnly
}) => {
- const visibleLayers = mapControls?.visibleLayers || {};
+ const visibleLayers = mapControls?.visibleLayers || {} as MapControl;
const {active: isActive, show, disableClose} = visibleLayers || {};
const legendLayers = useMemo(
@@ -71,7 +86,7 @@ function LayerSelectorPanelFactory(MapControlTooltip, MapControlPanel) {
);
return isVisible ? (
- (!isActive ? (
+ !isActive ? (
<MapControlButton
key={1}
onClick={onToggleMenuPanel}
@@ -93,7 +108,7 @@ function LayerSelectorPanelFactory(MapControlTooltip, MapControlPanel) {
>
<MapLayerSelector layers={legendLayers} onMapToggleLayer={onMapToggleLayer} />
</MapControlPanel>
- ))
+ )
) : null;
};
diff --git a/src/components/map/locale-panel.d.ts b/src/components/map/locale-panel.d.ts
deleted file mode 100644
index dff7808df..000000000
--- a/src/components/map/locale-panel.d.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-import React from 'react';
-import {MapControls} from 'reducers';
-
-export type LocalePanelProps = {
- availableLocales: ReadonlyArray<string>;
- onSetLocale: (locale: string) => void;
- locale: string;
- onToggleMapControl: (control: string) => void;
- mapControls: MapControls;
-};
-
-export type LocalePanelComponent = React.FunctionComponent<LocalePanelProps>;
diff --git a/src/components/map/locale-panel.js b/src/components/map/locale-panel.tsx
similarity index 86%
rename from src/components/map/locale-panel.js
rename to src/components/map/locale-panel.tsx
index 0188adfba..b7a65837e 100644
--- a/src/components/map/locale-panel.js
+++ b/src/components/map/locale-panel.tsx
@@ -27,14 +27,26 @@ import MapControlTooltipFactory from './map-control-tooltip';
import MapControlToolbarFactory from './map-control-toolbar';
import {FormattedMessage} from '../../localization';
import TippyTooltip from 'components/common/tippy-tooltip';
+import {MapControls} from 'reducers';
LocalePanelFactory.deps = [MapControlTooltipFactory, MapControlToolbarFactory];
-function LocalePanelFactory(MapControlTooltip, MapControlToolbar) {
+export type LocalePanelProps = {
+ availableLocales: ReadonlyArray<string>;
+ onSetLocale: (locale: string) => void;
+ locale: string;
+ onToggleMapControl: (control: string) => void;
+ mapControls: MapControls;
+};
+
+function LocalePanelFactory(
+ MapControlTooltip: ReturnType<typeof MapControlTooltipFactory>,
+ MapControlToolbar: ReturnType<typeof MapControlToolbarFactory>
+) {
/** @type {import('./locale-panel').LocalePanelComponent} */
- const LocalePanel = React.memo(
+ const LocalePanel: React.FC<LocalePanelProps> = React.memo(
({availableLocales, onToggleMapControl, onSetLocale, locale: currentLocal, mapControls}) => {
- const {active: isActive, disableClose, show} = mapControls.mapLocale || {};
+ const {active: isActive, show} = mapControls.mapLocale || {};
const onClickItem = useCallback(
locale => {
@@ -81,7 +93,6 @@ function LocalePanelFactory(MapControlTooltip, MapControlToolbar) {
className={classnames('map-control-button', 'map-locale', {isActive})}
onClick={onClickButton}
active={isActive}
- disableClose={disableClose}
>
<span className="map-control-button__locale">{currentLocal.toUpperCase()}</span>
</MapControlButton>
diff --git a/src/components/map/map-control-panel.d.ts b/src/components/map/map-control-panel.d.ts
deleted file mode 100644
index 346c8fc1e..000000000
--- a/src/components/map/map-control-panel.d.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-import React from 'react';
-
-export type MapControlPanelProps = {
- header?: string;
- scale?: number;
- onClick: () => void;
- onPinClick?: () => void;
- pinnable?: boolean;
- disableClose?: boolean;
- isExport?: boolean;
- logoComponent?: Element;
-};
-
-export type MapControlPanelComponent = React.FunctionComponent<MapControlPanelProps>;
diff --git a/src/components/map/map-control-panel.js b/src/components/map/map-control-panel.tsx
similarity index 91%
rename from src/components/map/map-control-panel.js
rename to src/components/map/map-control-panel.tsx
index 851b61be5..33cd3e379 100644
--- a/src/components/map/map-control-panel.js
+++ b/src/components/map/map-control-panel.tsx
@@ -74,9 +74,20 @@ const StyledIcon = styled(IconRoundSmall)`
}
`;
+export type MapControlPanelProps = {
+ header?: string;
+ scale?: number;
+ onClick: React.MouseEventHandler<HTMLDivElement>;
+ onPinClick?: React.MouseEventHandler<HTMLDivElement>;
+ pinnable?: boolean;
+ disableClose?: boolean;
+ isExport?: boolean;
+ logoComponent?: Element;
+};
+
function MapControlPanelFactory() {
/** @type {import('./map-control-panel').MapControlPanelComponent} */
- const MapControlPanel = React.memo(
+ const MapControlPanel: React.FC<MapControlPanelProps> = React.memo(
({
children,
header,
diff --git a/src/components/map/map-control-toolbar.js b/src/components/map/map-control-toolbar.tsx
similarity index 100%
rename from src/components/map/map-control-toolbar.js
rename to src/components/map/map-control-toolbar.tsx
diff --git a/src/components/map/map-control-tooltip.d.ts b/src/components/map/map-control-tooltip.d.ts
deleted file mode 100644
index 7d274ee4e..000000000
--- a/src/components/map/map-control-tooltip.d.ts
+++ /dev/null
@@ -1,8 +0,0 @@
-import React from 'react';
-
-export type MapControlTooltipProps = {
- id: string;
- message: string;
-};
-
-export type MapControlTooltipComponent = React.FunctionComponent<MapControlTooltipProps>;
diff --git a/src/components/map/map-control-tooltip.js b/src/components/map/map-control-tooltip.tsx
similarity index 90%
rename from src/components/map/map-control-tooltip.js
rename to src/components/map/map-control-tooltip.tsx
index eceb13620..e1ade1261 100644
--- a/src/components/map/map-control-tooltip.js
+++ b/src/components/map/map-control-tooltip.tsx
@@ -22,9 +22,14 @@ import React from 'react';
import {Tooltip} from 'components/common/styled-components';
import {FormattedMessage} from 'localization';
+export type MapControlTooltipProps = {
+ id: string;
+ message: string;
+};
+
function MapControlTooltipFactory() {
/** @type {import('./map-control-tooltip').MapControlTooltipComponent} */
- const MapControlTooltip = React.memo(({id, message}) => (
+ const MapControlTooltip: React.FC<MapControlTooltipProps> = React.memo(({id, message}) => (
<Tooltip id={id} place="left" effect="solid">
<span>
<FormattedMessage id={message} />
diff --git a/src/components/map/map-control.d.ts b/src/components/map/map-control.d.ts
deleted file mode 100644
index f2014bb33..000000000
--- a/src/components/map/map-control.d.ts
+++ /dev/null
@@ -1,39 +0,0 @@
-import React from 'react';
-import {Editor, MapControls} from 'reducers';
-import {Datasets} from 'reducers/vis-state-updaters';
-import {FeatureFlags} from '../context';
-import {Layer} from 'layers';
-
-export type MapControlComponentProps = Partial<MapControlProps>;
-
-export type MapControlProps = {
- availableLocales: ReadonlyArray<string>;
- datasets: Datasets;
- dragRotate: boolean;
- isSplit: boolean;
- primary: boolean;
- layers: Layer[];
- layersToRender: {[key: string]: boolean};
- mapIndex: number;
- mapControls: MapControls;
- onTogglePerspective: () => void;
- onToggleSplitMap: () => void;
- onToggleMapControl: (control: string) => void;
- onSetEditorMode: (mode: string) => void;
- onToggleEditorVisibility: () => void;
- top: number;
- onSetLocale: () => void;
- locale: string;
- logoComponent: React.FC | React.ReactNode;
-
- // optional
- readOnly?: boolean;
- scale?: number;
- mapLayers?: {[key: string]: boolean};
- editor: Editor;
- actionComponents: React.FC[] | React.Component[];
- mapHeight?: number;
-};
-
-export type MapControl = React.Component<MapControlProps>;
-export function MapControlFactory(): MapControl;
diff --git a/src/components/map/map-control.js b/src/components/map/map-control.tsx
similarity index 67%
rename from src/components/map/map-control.js
rename to src/components/map/map-control.tsx
index 5661564f3..acd3694a1 100644
--- a/src/components/map/map-control.js
+++ b/src/components/map/map-control.tsx
@@ -29,8 +29,14 @@ import LayerSelectorPanelFactory from './layer-selector-panel';
import MapLegendPanelFactory from './map-legend-panel';
import MapDrawPanelFactory from './map-draw-panel';
import LocalePanelFactory from './locale-panel';
+import {Datasets, Editor, MapControls} from 'reducers';
+import {Layer} from 'layers';
-const StyledMapControl = styled.div`
+interface StyledMapControlProps {
+ top?: number;
+}
+
+const StyledMapControl = styled.div<StyledMapControlProps>`
right: 0;
padding: ${props => props.theme.mapControl.padding}px;
z-index: 10;
@@ -48,6 +54,35 @@ const StyledMapControl = styled.div`
const LegendLogo = <KeplerGlLogo version={false} appName="kepler.gl" />;
+export type MapControlProps = {
+ availableLocales: ReadonlyArray<string>;
+ datasets: Datasets;
+ dragRotate: boolean;
+ isSplit: boolean;
+ primary: boolean;
+ layers: Layer[];
+ layersToRender: {[key: string]: boolean};
+ mapIndex: number;
+ mapControls: MapControls;
+ onTogglePerspective: () => void;
+ onToggleSplitMap: () => void;
+ onToggleMapControl: (control: string) => void;
+ onSetEditorMode: (mode: string) => void;
+ onToggleEditorVisibility: () => void;
+ top: number;
+ onSetLocale: () => void;
+ locale: string;
+ logoComponent: React.FC | React.ReactNode;
+
+ // optional
+ readOnly?: boolean;
+ scale?: number;
+ mapLayers?: {[key: string]: boolean};
+ editor: Editor;
+ actionComponents: React.FC[] | React.Component[];
+ mapHeight?: number;
+};
+
MapControlFactory.deps = [
MapDrawPanelFactory,
Toggle3dButtonFactory,
@@ -58,12 +93,12 @@ MapControlFactory.deps = [
];
function MapControlFactory(
- MapDrawPanel,
- Toggle3dButton,
- SplitMapButton,
- MapLegendPanel,
- LayerSelectorPanel,
- LocalePanel
+ MapDrawPanel: ReturnType<typeof MapDrawPanelFactory>,
+ Toggle3dButton: ReturnType<typeof Toggle3dButtonFactory>,
+ SplitMapButton: ReturnType<typeof SplitMapButtonFactory>,
+ MapLegendPanel: ReturnType<typeof MapLegendPanelFactory>,
+ LayerSelectorPanel: ReturnType<typeof LayerSelectorPanelFactory>,
+ LocalePanel: ReturnType<typeof LocalePanelFactory>
) {
const DEFAULT_ACTIONS = [
SplitMapButton,
@@ -75,7 +110,10 @@ function MapControlFactory(
];
/** @type {import('./map-control').MapControl} */
- const MapControl = ({actionComponents = DEFAULT_ACTIONS, ...props}) => {
+ const MapControl: React.FC<MapControlProps> = ({
+ actionComponents = DEFAULT_ACTIONS,
+ ...props
+ }) => {
return (
<StyledMapControl className="map-control" top={props.top}>
{actionComponents.map((ActionComponent, index) => (
diff --git a/src/components/map/map-draw-panel.d.ts b/src/components/map/map-draw-panel.d.ts
deleted file mode 100644
index efe5a592f..000000000
--- a/src/components/map/map-draw-panel.d.ts
+++ /dev/null
@@ -1,16 +0,0 @@
-import React from 'react';
-import {Editor, MapControls} from 'reducers';
-import {MapDrawPanelIcons} from './map-control';
-
-export type MapDrawPanelProps = {
- editor: Editor,
- mapControls: MapControls,
- onToggleMapControl: (control: string) => void;
- onSetEditorMode: (mode: string) => void,
- onToggleEditorVisibility: () => void,
- actionIcons: MapDrawPanelIcons
-};
-
-export type MapDrawPanelComponent = React.FunctionComponent<MapDrawPanelProps>;
-export function MapDrawPanelFactory(): MapDrawPanelComponent;
-
diff --git a/src/components/map/map-draw-panel.js b/src/components/map/map-draw-panel.tsx
similarity index 91%
rename from src/components/map/map-draw-panel.js
rename to src/components/map/map-draw-panel.tsx
index 39792c6f6..a5a8037e6 100644
--- a/src/components/map/map-draw-panel.js
+++ b/src/components/map/map-draw-panel.tsx
@@ -37,12 +37,24 @@ import MapControlPanelFactory from './map-control-panel';
import MapControlToolbarFactory from './map-control-toolbar';
import {FormattedMessage} from '../../localization';
import TippyTooltip from 'components/common/tippy-tooltip';
+import {Editor, MapControls} from 'reducers';
+import {BaseProps} from 'components/common/icons/base';
MapDrawPanelFactory.deps = [
MapControlTooltipFactory,
MapControlPanelFactory,
MapControlToolbarFactory
];
+
+export type MapDrawPanelProps = {
+ editor: Editor;
+ mapControls: MapControls;
+ onToggleMapControl: (control: string) => void;
+ onSetEditorMode: (mode: string) => void;
+ onToggleEditorVisibility: () => void;
+ actionIcons: {[id: string]: React.ComponentType<Partial<BaseProps>>};
+};
+
function MapDrawPanelFactory(MapControlTooltip, MapControlPanel, MapControlToolbar) {
const defaultActionIcons = {
visible: EyeSeen,
@@ -53,7 +65,7 @@ function MapDrawPanelFactory(MapControlTooltip, MapControlPanel, MapControlToolb
rectangle: Rectangle
};
/** @type {import('./map-draw-panel').MapDrawPanelComponent} */
- const MapDrawPanel = React.memo(
+ const MapDrawPanel: React.FC<MapDrawPanelProps> = React.memo(
({
editor,
mapControls,
diff --git a/src/components/map/map-legend-panel.d.ts b/src/components/map/map-legend-panel.d.ts
deleted file mode 100644
index b617f94fa..000000000
--- a/src/components/map/map-legend-panel.d.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import React, {Element} from 'react';
-import {Layer} from 'layers';
-import {MapControls} from 'reducers';
-
-interface MapLegendPanelIcons {
- legend: ComponentType<any>;
-}
-
-export type MapLegendPanelProps = {
- layers: ReadonlyArray<Layer>;
- scale: number;
- onToggleMapControl: (control: string) => void;
- isExport: boolean;
- logoComponent: Element;
- actionIcons: MapLegendPanelIcons;
- mapControls: MapControls;
- mapHeight?: number;
-};
-
-export type MapLegendPanelComponent = React.FunctionComponent<MapLegendPanelProps>;
-export function MapLegendPanelFactory(): MapLegendPanelComponent;
diff --git a/src/components/map/map-legend-panel.js b/src/components/map/map-legend-panel.tsx
similarity index 88%
rename from src/components/map/map-legend-panel.js
rename to src/components/map/map-legend-panel.tsx
index 4d124f911..45be0b11b 100644
--- a/src/components/map/map-legend-panel.js
+++ b/src/components/map/map-legend-panel.tsx
@@ -18,7 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-import React, {useState} from 'react';
+import React, {ComponentType, useState} from 'react';
import styled from 'styled-components';
import {Legend} from 'components/common/icons';
@@ -30,6 +30,8 @@ import Tippy from '@tippyjs/react/headless';
import TippyTooltip from 'components/common/tippy-tooltip';
import {createPortal} from 'react-dom';
import {DIMENSIONS} from 'constants/default-settings';
+import {MapControl, MapControls} from 'reducers';
+import {Layer} from 'layers';
MapLegendPanelFactory.deps = [MapControlPanelFactory, MapLegendFactory];
@@ -39,13 +41,28 @@ const PinToBottom = styled.div`
right: ${DIMENSIONS.mapControl.mapLegend.pinned.right}px;
`;
+interface MapLegendPanelIcons {
+ legend: ComponentType<any>;
+}
+
+export type MapLegendPanelProps = {
+ layers: ReadonlyArray<Layer>;
+ scale: number;
+ onToggleMapControl: (control: string) => void;
+ isExport: boolean;
+ logoComponent: Element;
+ actionIcons: MapLegendPanelIcons;
+ mapControls: MapControls;
+ mapHeight?: number;
+};
+
function MapLegendPanelFactory(MapControlPanel, MapLegend) {
const defaultActionIcons = {
legend: Legend
};
/** @type {import('./map-legend-panel').MapLegendPanelComponent} */
- const MapLegendPanel = ({
+ const MapLegendPanel: React.FC<MapLegendPanelProps> = ({
layers,
mapControls,
scale,
@@ -55,7 +72,7 @@ function MapLegendPanelFactory(MapControlPanel, MapLegend) {
actionIcons = defaultActionIcons,
mapHeight
}) => {
- const mapLegend = mapControls?.mapLegend || {};
+ const mapLegend = mapControls?.mapLegend || {} as MapControl;
const {active: isPinned} = mapLegend || {};
const onClick = () => {
diff --git a/src/components/map/map-legend.d.ts b/src/components/map/map-legend.d.ts
deleted file mode 100644
index 31e41920a..000000000
--- a/src/components/map/map-legend.d.ts
+++ /dev/null
@@ -1,59 +0,0 @@
-import {FunctionComponent} from 'react';
-import {Layer, LayerConfig, VisualChannel, VisualChannelDescription} from 'layers';
-import {MapLegendPanelComponent} from './map-legend-panel';
-
-export type LayerSizeLegendProps = {
- label: string;
- name: string;
-};
-
-export const LayerSizeLegend: FunctionComponent<LayerSizeLegendProps>;
-
-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 LayerLegendHeaderProps = {
- layer: Layer;
- options?: {
- showLayerName?: boolean;
- };
-};
-
-export const LayerLegendHeader: FunctionComponent<LayerLegendHeaderProps>;
-
-export function LayerLegendHeaderFactory(): LayerLegendHeader;
-
-export type LayerLegendContentProps = {
- layer: Layer;
- containerW: number;
-};
-
-export const LayerLegendContent: FunctionComponent<LayerLegendContentProps>;
-
-export function LayerLegendContentFactory(): LayerLegendContent;
-
-export type MapLegendProps = {
- layers?: ReadonlyArray<Layer>;
- width?: number;
- mapHeight?: number;
- options?: {
- showLayerName?: boolean;
- };
-};
-
-export const MapLegend: FunctionComponent<MapLegendProps>;
-
-export function MapLegendFactory(): MapLegend;
diff --git a/src/components/map/map-legend.js b/src/components/map/map-legend.tsx
similarity index 71%
rename from src/components/map/map-legend.js
rename to src/components/map/map-legend.tsx
index dfd92cbc4..81f6babc4 100644
--- a/src/components/map/map-legend.js
+++ b/src/components/map/map-legend.tsx
@@ -24,8 +24,14 @@ import {rgb} from 'd3-color';
import ColorLegend from 'components/common/color-legend';
import {CHANNEL_SCALES, DIMENSIONS} from 'constants/default-settings';
import {FormattedMessage} from 'localization';
+import Layer, {LayerBaseConfig, VisualChannel, VisualChannelDescription} from 'layers/base-layer';
-export const StyledMapControlLegend = styled.div`
+interface StyledMapControlLegendProps {
+ width?: number;
+ last?: boolean;
+}
+
+export const StyledMapControlLegend = styled.div<StyledMapControlLegendProps>`
padding: 10px ${props => props.theme.mapControl.padding}px 10px
${props => props.theme.mapControl.padding}px;
font-size: 11px;
@@ -77,8 +83,13 @@ export const VisualChannelMetric = ({name}) => {
);
};
+export type LayerSizeLegendProps = {
+ label: string;
+ name: string;
+};
+
/** @type {typeof import('./map-legend').LayerSizeLegend} */
-export const LayerSizeLegend = ({label, name}) =>
+export const LayerSizeLegend: React.FC<LayerSizeLegendProps> = ({label, name}) =>
label ? (
(<div className="legend--layer_size-schema">
<p>
@@ -91,8 +102,13 @@ export const LayerSizeLegend = ({label, name}) =>
const SINGLE_COLOR_DOMAIN = [''];
+export type SingleColorLegendProps = {
+ width: number;
+ color: string;
+};
+
/** @type {typeof import('./map-legend').SingleColorLegend} */
-export const SingleColorLegend = React.memo(({width, color}) => (
+export const SingleColorLegend: React.FC<SingleColorLegendProps> = React.memo(({width, color}) => (
<ColorLegend
scaleType="ordinal"
displayLabel={false}
@@ -105,49 +121,65 @@ export const SingleColorLegend = React.memo(({width, color}) => (
SingleColorLegend.displayName = 'SingleColorLegend';
+export type LayerColorLegendProps = {
+ description: VisualChannelDescription;
+ config: LayerBaseConfig;
+ width: number;
+ colorChannel: VisualChannel;
+};
+
/** @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;
- const [colorScale, colorField, colorDomain] = [scale, field, domain].map(k => config[k]);
- const colorRange = config.visConfig[range];
+export const LayerColorLegend: React.FC<LayerColorLegendProps> = React.memo(
+ ({description, config, width, colorChannel}) => {
+ const enableColorBy = description.measure;
+ const {scale, field, domain, range, property} = colorChannel;
+ const [colorScale, colorField, colorDomain] = [scale, field, domain].map(k => config[k]);
+ const colorRange = config.visConfig[range];
- return (
- <div>
- <div className="legend--layer_color-schema">
- <div>
- {enableColorBy ? <VisualChannelMetric name={enableColorBy} /> : null}
- <div className="legend--layer_color-legend">
- {enableColorBy ? (
- <ColorLegend
- scaleType={colorScale}
- displayLabel
- domain={colorDomain}
- fieldType={(colorField && colorField.type) || 'real'}
- range={colorRange}
- width={width}
- />
- ) : (
- <SingleColorLegend
- color={config.visConfig[property] || config[property] || config.color}
- width={width}
- />
- )}
+ return (
+ <div>
+ <div className="legend--layer_color-schema">
+ <div>
+ {enableColorBy ? <VisualChannelMetric name={enableColorBy} /> : null}
+ <div className="legend--layer_color-legend">
+ {enableColorBy ? (
+ <ColorLegend
+ scaleType={colorScale}
+ displayLabel
+ domain={colorDomain}
+ fieldType={(colorField && colorField.type) || 'real'}
+ range={colorRange}
+ width={width}
+ />
+ ) : (
+ <SingleColorLegend
+ color={config.visConfig[property] || config[property] || config.color}
+ width={width}
+ />
+ )}
+ </div>
</div>
</div>
</div>
- </div>
- );
-});
+ );
+ }
+);
LayerColorLegend.displayName = 'LayerColorLegend';
const isColorChannel = visualChannel =>
[CHANNEL_SCALES.color, CHANNEL_SCALES.colorAggr].includes(visualChannel.channelScaleType);
+export type LayerLegendHeaderProps = {
+ layer: Layer;
+ options?: {
+ showLayerName?: boolean;
+ };
+};
+
export function LayerLegendHeaderFactory() {
/** @type {typeof import('./map-legend').LayerLegendHeader }> */
- const LayerLegendHeader = ({options, layer}) => {
+ const LayerLegendHeader: React.FC<LayerLegendHeaderProps> = ({options, layer}) => {
return options?.showLayerName !== false ? (
<div className="legend--layer_name">{layer.config.label}</div>
) : null;
@@ -155,9 +187,14 @@ export function LayerLegendHeaderFactory() {
return LayerLegendHeader;
}
+export type LayerLegendContentProps = {
+ layer: Layer;
+ containerW: number;
+};
+
export function LayerLegendContentFactory() {
/** @type {typeof import('./map-legend').LayerLegendContent }> */
- const LayerLegendContent = ({layer, containerW}) => {
+ const LayerLegendContent: React.FC<LayerLegendContentProps> = ({layer, containerW}) => {
const colorChannels = Object.values(layer.visualChannels).filter(isColorChannel);
const nonColorChannels = Object.values(layer.visualChannels).filter(vc => !isColorChannel(vc));
@@ -195,10 +232,19 @@ export function LayerLegendContentFactory() {
return LayerLegendContent;
}
+export type MapLegendProps = {
+ layers?: ReadonlyArray<Layer>;
+ width?: number;
+ mapHeight?: number;
+ options?: {
+ showLayerName?: boolean;
+ };
+};
+
MapLegendFactory.deps = [LayerLegendHeaderFactory, LayerLegendContentFactory];
function MapLegendFactory(LayerLegendHeader, LayerLegendContent) {
/** @type {typeof import('./map-legend').MapLegend }> */
- const MapLegend = ({layers = [], width, mapHeight, options}) => (
+ const MapLegend: React.FC<MapLegendProps> = ({layers = [], width, mapHeight, options}) => (
<div
className="map-legend"
{...(mapHeight && {
diff --git a/src/components/map/map-popover.d.ts b/src/components/map/map-popover.d.ts
deleted file mode 100644
index 698922e24..000000000
--- a/src/components/map/map-popover.d.ts
+++ /dev/null
@@ -1,28 +0,0 @@
-import React from 'react';
-import {FunctionComponent} from 'react';
-import {IntlShape} from 'react-intl';
-import {LayerHoverProp} from '../../utils/layer-utils';
-
-export type MapPopoverProps = {
- x: number;
- y: number;
- frozen?: boolean;
- coordinate: [number, number] | boolean;
- layerHoverProp: LayerHoverProp | null;
- isBase?: boolean;
- zoom: number;
- container?: HTMLElement | null;
- 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.tsx
similarity index 91%
rename from src/components/map/map-popover.js
rename to src/components/map/map-popover.tsx
index b04d4e940..eb341539f 100644
--- a/src/components/map/map-popover.js
+++ b/src/components/map/map-popover.tsx
@@ -23,9 +23,10 @@ import styled from 'styled-components';
import LayerHoverInfoFactory from './layer-hover-info';
import CoordinateInfoFactory from './coordinate-info';
import {ArrowLeft, ArrowRight, Pin} from 'components/common/icons';
-import {injectIntl} from 'react-intl';
+import {injectIntl, IntlShape} from 'react-intl';
import {FormattedMessage} from 'localization';
import Tippy from '@tippyjs/react/headless';
+import {LayerHoverProp} from 'utils/layer-utils';
const MAX_WIDTH = 500;
const MAX_HEIGHT = 600;
@@ -167,9 +168,28 @@ function getPopperOptions(container) {
};
}
-export default function MapPopoverFactory(LayerHoverInfo, CoordinateInfo) {
+export type MapPopoverProps = {
+ x: number;
+ y: number;
+ frozen?: boolean;
+ coordinate: [number, number] | boolean;
+ layerHoverProp: LayerHoverProp | null;
+ isBase?: boolean;
+ zoom: number;
+ container?: HTMLElement | null;
+ onClose: () => void;
+};
+
+type IntlProps = {
+ intl: IntlShape;
+};
+
+export default function MapPopoverFactory(
+ LayerHoverInfo: ReturnType<typeof LayerHoverInfoFactory>,
+ CoordinateInfo: ReturnType<typeof CoordinateInfoFactory>
+) {
/** @type {typeof import('./map-popover').MapPopover} */
- const MapPopover = ({
+ const MapPopover: React.FC<MapPopoverProps & IntlProps> = ({
x,
y,
frozen,
diff --git a/src/components/map/split-map-button.d.ts b/src/components/map/split-map-button.d.ts
deleted file mode 100644
index 7e12de8f2..000000000
--- a/src/components/map/split-map-button.d.ts
+++ /dev/null
@@ -1,19 +0,0 @@
-import React from 'react';
-import {MapControls} from 'reducers';
-
-interface SplitMapButtonIcons {
- delete: ComponentType<any>;
- split: ComponentType<any>;
-}
-
-export type SplitMapButtonProps = {
- isSplit: boolean;
- mapIndex: number;
- onToggleSplitMap: (index?: number) => void;
- actionIcons: SplitMapButtonIcons;
- readOnly: boolean;
- mapControls: MapControls;
-};
-
-export type SplitMapButtonComponent = React.FunctionComponent<SplitMapButtonProps>;
-export function SplitMapButtonFactory(): SplitMapButtonComponent;
diff --git a/src/components/map/split-map-button.js b/src/components/map/split-map-button.tsx
similarity index 80%
rename from src/components/map/split-map-button.js
rename to src/components/map/split-map-button.tsx
index e185b9d00..087f44d49 100644
--- a/src/components/map/split-map-button.js
+++ b/src/components/map/split-map-button.tsx
@@ -18,25 +18,38 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-import React, {useCallback, useMemo} from 'react';
+import React, {ComponentType, useCallback, useMemo} from 'react';
import classnames from 'classnames';
import {MapControlButton} from 'components/common/styled-components';
import {Delete, Split} from 'components/common/icons';
-import MapControlTooltipFactory from './map-control-tooltip';
-import MapControlPanelFactory from './map-control-panel';
import {FormattedMessage} from '../../localization';
import TippyTooltip from '../common/tippy-tooltip';
+import {MapControl, MapControls} from 'reducers';
-SplitMapButtonFactory.deps = [MapControlTooltipFactory, MapControlPanelFactory];
+SplitMapButtonFactory.deps = [];
-function SplitMapButtonFactory(MapControlTooltip) {
+interface SplitMapButtonIcons {
+ delete: ComponentType<any>;
+ split: ComponentType<any>;
+}
+
+export type SplitMapButtonProps = {
+ isSplit: boolean;
+ mapIndex: number;
+ onToggleSplitMap: (index?: number) => void;
+ actionIcons: SplitMapButtonIcons;
+ readOnly: boolean;
+ mapControls: MapControls;
+};
+
+function SplitMapButtonFactory() {
const defaultActionIcons = {
delete: Delete,
split: Split
};
/** @type {import('./split-map-button').SplitMapButtonComponent} */
- const SplitMapButton = ({
+ const SplitMapButton: React.FC<SplitMapButtonProps> = ({
isSplit,
mapIndex,
onToggleSplitMap,
@@ -44,7 +57,7 @@ function SplitMapButtonFactory(MapControlTooltip) {
mapControls,
readOnly
}) => {
- const splitMap = mapControls?.splitMap || {};
+ const splitMap = mapControls?.splitMap || {} as MapControl;
const onClick = useCallback(
event => {
event.preventDefault();
@@ -59,7 +72,7 @@ function SplitMapButtonFactory(MapControlTooltip) {
return null;
}
return isVisible ? (
- (<TippyTooltip
+ <TippyTooltip
placement="left"
render={() => (
<div id="action-toggle">
@@ -74,7 +87,7 @@ function SplitMapButtonFactory(MapControlTooltip) {
>
{isSplit ? <actionIcons.delete height="18px" /> : <actionIcons.split height="18px" />}
</MapControlButton>
- </TippyTooltip>)
+ </TippyTooltip>
) : null;
};
diff --git a/src/components/map/toggle-3d-button.d.ts b/src/components/map/toggle-3d-button.d.ts
deleted file mode 100644
index 3cf94633f..000000000
--- a/src/components/map/toggle-3d-button.d.ts
+++ /dev/null
@@ -1,16 +0,0 @@
-import React from 'react';
-import {MapControls} from 'reducers';
-
-interface Toggle3dButtonIcons {
- cube: ComponentType<any>;
-}
-
-export type Toggle3dButtonProps = {
- dragRotate: boolean;
- onTogglePerspective: () => void;
- actionIcons: Toggle3dButtonIcons;
- mapControls: MapControls;
-};
-
-export type Toggle3dButtonComponent = React.FunctionComponent<Toggle3dButtonProps>;
-export function Toggle3dButtonFactory(): Toggle3dButtonComponent;
diff --git a/src/components/map/toggle-3d-button.js b/src/components/map/toggle-3d-button.tsx
similarity index 83%
rename from src/components/map/toggle-3d-button.js
rename to src/components/map/toggle-3d-button.tsx
index 9a295fc58..abdd5a8dc 100644
--- a/src/components/map/toggle-3d-button.js
+++ b/src/components/map/toggle-3d-button.tsx
@@ -18,24 +18,34 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-import React, {useCallback, useMemo} from 'react';
+import React, {ComponentType, useCallback, useMemo} from 'react';
import classnames from 'classnames';
import {Cube3d} from 'components/common/icons';
import {MapControlButton} from 'components/common/styled-components';
-import MapControlTooltipFactory from './map-control-tooltip';
-import MapControlPanelFactory from './map-control-panel';
import {FormattedMessage} from '../../localization';
import TippyTooltip from 'components/common/tippy-tooltip';
+import {MapControls} from 'reducers';
-Toggle3dButtonFactory.deps = [MapControlTooltipFactory, MapControlPanelFactory];
+Toggle3dButtonFactory.deps = [];
-function Toggle3dButtonFactory(MapControlTooltip) {
+interface Toggle3dButtonIcons {
+ cube: ComponentType<any>;
+}
+
+export type Toggle3dButtonProps = {
+ dragRotate: boolean;
+ onTogglePerspective: () => void;
+ actionIcons: Toggle3dButtonIcons;
+ mapControls: MapControls;
+};
+
+function Toggle3dButtonFactory() {
const defaultActionIcons = {
cube: Cube3d
};
/** @type {import('./toggle-3d-button').Toggle3dButtonComponent} */
- const Toggle3dButton = ({
+ const Toggle3dButton: React.FC<Toggle3dButtonProps> = ({
dragRotate,
onTogglePerspective,
actionIcons = defaultActionIcons,
@@ -54,7 +64,7 @@ function Toggle3dButtonFactory(MapControlTooltip) {
}, [mapControls]);
return isVisible ? (
- (<TippyTooltip
+ <TippyTooltip
placement="left"
render={() => (
<div id="action-3d">
@@ -69,7 +79,7 @@ function Toggle3dButtonFactory(MapControlTooltip) {
>
<actionIcons.cube height="22px" />
</MapControlButton>
- </TippyTooltip>)
+ </TippyTooltip>
) : null;
};
diff --git a/src/components/modal-container.tsx b/src/components/modal-container.tsx
index 4a80dbe6c..f197022c1 100644
--- a/src/components/modal-container.tsx
+++ b/src/components/modal-container.tsx
@@ -99,7 +99,7 @@ const DefaultStyle = css`
export type ModalContainerProps = {
appName: string;
- rootNode: React.ReactNode;
+ rootNode: React.ReactInstance | null | undefined;
containerW: number;
containerH: number;
mapboxApiAccessToken: string;
diff --git a/yarn.lock b/yarn.lock
index cd0dc80b2..51f376ad6 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -3440,6 +3440,13 @@
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.3.tgz#2ab0d5da2e5815f94b0b9d4b95d1e5f243ab2ca7"
integrity sha512-KfRL3PuHmqQLOG+2tGpRO26Ctg+Cq1E01D2DMriKEATHgWLfeNDmq9e29Q9WIky0dQ3NPkd1mzYH8Lm936Z9qw==
+"@types/react-dom@^18.0.0":
+ version "18.0.0"
+ resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-18.0.0.tgz#b13f8d098e4b0c45df4f1ed123833143b0c71141"
+ integrity sha512-49897Y0UiCGmxZqpC8Blrf6meL8QUla6eb+BBhn69dTXlmuOlzkfr7HHY/O8J25e1lTUMs+YYxSlVDAaGHCOLg==
+ dependencies:
+ "@types/react" "*"
+
"@types/react-lifecycles-compat@^3.0.1":
version "3.0.1"
resolved "https://registry.yarnpkg.com/@types/react-lifecycles-compat/-/react-lifecycles-compat-3.0.1.tgz#a0b1fe18cfb9435bd52737829a69cbe93faf32e2"