Skip to content

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

[Chore]: Technical: Translate redusers (UI-state and provider-states) (#1726)

Maksim Suslov306169846175
diff --git a/src/reducers/provider-state-updaters.d.ts b/src/reducers/provider-state-updaters.d.ts
deleted file mode 100644
index 13c68929f..000000000
--- a/src/reducers/provider-state-updaters.d.ts
+++ /dev/null
@@ -1,88 +0,0 @@
-import * as ProviderActions from 'actions/provider-actions';
-import {MapListItem} from 'cloud-providers';
-
-type ActionPayload<P> = {
- type?: string;
- payload: P;
-};
-
-export type ProviderState = {
- isProviderLoading: boolean;
- isCloudMapLoading: boolean;
- providerError: any;
- currentProvider: string | null;
- successInfo: any;
- mapSaved: null | string;
- initialState: any;
- visualizations: MapListItem[]
-};
-
-export const INITIAL_PROVIDER_STATE: ProviderState;
-
-export function withTask<T>(s: T, any): T;
-
-export function exportFileToCloudUpdater(
- state: ProviderState,
- action: ActionPayload<ProviderActions.ExportFileToCloudPayload>
-): ProviderState;
-
-export function exportFileSuccessUpdater(
- state: ProviderState,
- action: ActionPayload<ProviderActions.ExportFileSuccessPayload>
-): ProviderState;
-
-export function postSaveLoadSuccessUpdater(
- state: ProviderState,
- action: ActionPayload<ProviderActions.PostSaveLoadSuccessPayload>
-): ProviderState;
-
-export function exportFileErrorUpdater(
- state: ProviderState,
- action: ActionPayload<ProviderActions.ExportFileErrorPayload>
-): ProviderState;
-
-export function loadCloudMapUpdater(
- state: ProviderState,
- action: ActionPayload<ProviderActions.LoadCloudMapPayload>
-): ProviderState;
-
-export function loadCloudMapSuccessUpdater(
- state: ProviderState,
- action: ActionPayload<ProviderActions.LoadCloudMapSuccessPayload>
-): ProviderState;
-
-export function loadCloudMapErrorUpdater(
- state: ProviderState,
- action: ActionPayload<ProviderActions.LoadCloudMapErrorPayload>
-): ProviderState;
-
-export function resetProviderStatusUpdater(
- state: ProviderState,
- action: ActionPayload<ProviderActions.ResetProviderStatusPayload>
-): ProviderState;
-
-export function setCloudProviderUpdater(
- state: ProviderState,
- action: ActionPayload<ProviderActions.SetCloudProviderPayload>
-): ProviderState;
-
-export function getSavedMapsUpdater(
- state: ProviderState,
- action: ActionPayload<ProviderActions.GetSavedMapsPayload>
-): ProviderState;
-
-export function getSavedMapsSuccessUpdater(
- state: ProviderState,
- action: ActionPayload<ProviderActions.GetSavedMapsSuccessPayload>
-): ProviderState;
-
-export function getSavedMapsErrorUpdater(
- state: ProviderState,
- action: ActionPayload<ProviderActions.GetSavedMapsErrorPayload>
-): ProviderState;
-
-export function createGlobalNotificationTasks(p: {
- type?: string;
- message: string;
- delayClose?: boolean;
-}): any[];
diff --git a/src/reducers/provider-state-updaters.js b/src/reducers/provider-state-updaters.ts
similarity index 77%
rename from src/reducers/provider-state-updaters.js
rename to src/reducers/provider-state-updaters.ts
index c39f98d36..bb539f30f 100644
--- a/src/reducers/provider-state-updaters.js
+++ b/src/reducers/provider-state-updaters.ts
@@ -20,14 +20,14 @@
import {withTask} from 'react-palm/tasks';
import {default as Console} from 'global/console';
-import {generateHashId, getError, isPlainObject, toArray} from 'utils/utils';
+import {generateHashId, getError, isPlainObject, toArray} from '../utils/utils';
import {
EXPORT_FILE_TO_CLOUD_TASK,
ACTION_TASK,
DELAY_TASK,
LOAD_CLOUD_MAP_TASK,
GET_SAVED_MAPS_TASK
-} from 'tasks/tasks';
+} from '../tasks/tasks';
import {
exportFileSuccess,
exportFileError,
@@ -37,20 +37,39 @@ import {
getSavedMapsError,
loadCloudMapError,
resetProviderStatus
-} from 'actions/provider-actions';
-import {removeNotification, toggleModal, addNotification} from 'actions/ui-state-actions';
-import {addDataToMap} from 'actions/actions';
+} from '../actions/provider-actions';
+import {removeNotification, toggleModal, addNotification} from '../actions/ui-state-actions';
+import {addDataToMap} from '../actions/actions';
import {
DEFAULT_NOTIFICATION_TYPES,
DEFAULT_NOTIFICATION_TOPICS,
DATASET_FORMATS,
OVERWRITE_MAP_ID
-} from 'constants/default-settings';
+} from '../constants/default-settings';
-import {FILE_CONFLICT_MSG} from 'cloud-providers';
-import {DATASET_HANDLERS} from 'processors/data-processor';
+import {FILE_CONFLICT_MSG} from '../cloud-providers';
+import {DATASET_HANDLERS} from '../processors/data-processor';
-export const INITIAL_PROVIDER_STATE = {
+import * as ProviderActions from '../actions/provider-actions';
+import {MapListItem} from '../cloud-providers';
+
+type ActionPayload<P> = {
+ type?: string;
+ payload: P;
+};
+
+export type ProviderState = {
+ isProviderLoading: boolean;
+ isCloudMapLoading: boolean;
+ providerError: any;
+ currentProvider: string | null;
+ successInfo: any;
+ mapSaved: null | string;
+ initialState?: any;
+ visualizations: MapListItem[];
+};
+
+export const INITIAL_PROVIDER_STATE: ProviderState = {
isProviderLoading: false,
isCloudMapLoading: false,
providerError: null,
@@ -60,6 +79,8 @@ export const INITIAL_PROVIDER_STATE = {
visualizations: []
};
+declare function withTask<T>(s: T, any: any): T;
+
function createActionTask(action, payload) {
if (typeof action === 'function') {
return ACTION_TASK().map(_ => action(payload));
@@ -82,10 +103,15 @@ function _validateProvider(provider, method) {
return true;
}
-/**
- * @type {typeof import('./provider-state-updaters').createGlobalNotificationTasks}
- */
-function createGlobalNotificationTasks({type, message, delayClose = true}) {
+function createGlobalNotificationTasks({
+ type,
+ message,
+ delayClose = true
+}: {
+ type?: string;
+ message: string;
+ delayClose?: boolean;
+}) {
const id = generateHashId();
const successNote = {
id,
@@ -101,9 +127,11 @@ function createGlobalNotificationTasks({type, message, delayClose = true}) {
* This method will export the current kepler config file to the chosen cloud proder
* add returns a share URL
*
- * @type {typeof import('./provider-state-updaters').exportFileToCloudUpdater}
*/
-export const exportFileToCloudUpdater = (state, action) => {
+export const exportFileToCloudUpdater = (
+ state: ProviderState,
+ action: ActionPayload<ProviderActions.ExportFileToCloudPayload>
+): ProviderState => {
const {mapData, provider, options = {}, onSuccess, onError, closeModal} = action.payload;
if (!_validateProvider(provider, 'uploadMap')) {
@@ -131,11 +159,10 @@ export const exportFileToCloudUpdater = (state, action) => {
return withTask(newState, uploadFileTask);
};
-/**
- *
- * @type {typeof import('./provider-state-updaters').exportFileSuccessUpdater}
- */
-export const exportFileSuccessUpdater = (state, action) => {
+export const exportFileSuccessUpdater = (
+ state: ProviderState,
+ action: ActionPayload<ProviderActions.ExportFileSuccessPayload>
+): ProviderState => {
const {response, provider, options = {}, onSuccess, closeModal} = action.payload;
const newState = {
@@ -161,9 +188,11 @@ export const exportFileSuccessUpdater = (state, action) => {
/**
* Close modal on success and display notification
- * @type {typeof import('./provider-state-updaters').postSaveLoadSuccessUpdater}
*/
-export const postSaveLoadSuccessUpdater = (state, action) => {
+export const postSaveLoadSuccessUpdater = (
+ state: ProviderState,
+ action: ActionPayload<ProviderActions.PostSaveLoadSuccessPayload>
+): ProviderState => {
const message = action.payload || `Saved / Load to ${state.currentProvider} Success`;
const tasks = [
@@ -175,11 +204,10 @@ export const postSaveLoadSuccessUpdater = (state, action) => {
return withTask(state, tasks);
};
-/**
- *
- * @type {typeof import('./provider-state-updaters').exportFileErrorUpdater}
- */
-export const exportFileErrorUpdater = (state, action) => {
+export const exportFileErrorUpdater = (
+ state: ProviderState,
+ action: ActionPayload<ProviderActions.ExportFileErrorPayload>
+): ProviderState => {
const {error, provider, onError} = action.payload;
const newState = {
@@ -198,7 +226,10 @@ export const exportFileErrorUpdater = (state, action) => {
return task ? withTask(newState, task) : newState;
};
-export const loadCloudMapUpdater = (state, action) => {
+export const loadCloudMapUpdater = (
+ state: ProviderState,
+ action: ActionPayload<ProviderActions.LoadCloudMapPayload>
+): ProviderState => {
const {loadParams, provider, onSuccess, onError} = action.payload;
if (!loadParams) {
Console.warn('load map error: loadParams is undefined');
@@ -217,8 +248,10 @@ export const loadCloudMapUpdater = (state, action) => {
// payload called by provider.downloadMap
const uploadFileTask = LOAD_CLOUD_MAP_TASK({provider, payload: loadParams}).bimap(
// success
+ // @ts-expect-error
response => loadCloudMapSuccess({response, loadParams, provider, onSuccess, onError}),
// error
+ // @ts-expect-error
error => loadCloudMapError({error, provider, onError})
);
@@ -289,11 +322,10 @@ function parseLoadMapResponse(response, loadParams, provider) {
};
}
-/**
- *
- * @type {typeof import('./provider-state-updaters').loadCloudMapSuccessUpdater}
- */
-export const loadCloudMapSuccessUpdater = (state, action) => {
+export const loadCloudMapSuccessUpdater = (
+ state: ProviderState,
+ action: ActionPayload<ProviderActions.LoadCloudMapSuccessPayload>
+): ProviderState => {
const {response, loadParams, provider, onSuccess, onError} = action.payload;
const formatError = checkLoadMapResponseError(response);
@@ -323,11 +355,10 @@ export const loadCloudMapSuccessUpdater = (state, action) => {
return tasks.length ? withTask(newState, tasks) : newState;
};
-/**
- *
- * @type {typeof import('./provider-state-updaters').loadCloudMapErrorUpdater}
- */
-export const loadCloudMapErrorUpdater = (state, action) => {
+export const loadCloudMapErrorUpdater = (
+ state: ProviderState,
+ action: ActionPayload<ProviderActions.LoadCloudMapErrorPayload>
+): ProviderState => {
const message = getError(action.payload.error) || `Error loading saved map`;
Console.warn(message);
@@ -345,11 +376,7 @@ export const loadCloudMapErrorUpdater = (state, action) => {
);
};
-/**
- *
- * @type {typeof import('./provider-state-updaters').resetProviderStatusUpdater}
- */
-export const resetProviderStatusUpdater = (state, action) => ({
+export const resetProviderStatusUpdater = (state: ProviderState): ProviderState => ({
...state,
isProviderLoading: false,
providerError: null,
@@ -359,9 +386,11 @@ export const resetProviderStatusUpdater = (state, action) => ({
/**
* Set current cloudProvider
- * @type {typeof import('./provider-state-updaters').setCloudProviderUpdater}
*/
-export const setCloudProviderUpdater = (state, action) => ({
+export const setCloudProviderUpdater = (
+ state: ProviderState,
+ action: ActionPayload<ProviderActions.SetCloudProviderPayload>
+): ProviderState => ({
...state,
isProviderLoading: false,
providerError: null,
@@ -369,11 +398,10 @@ export const setCloudProviderUpdater = (state, action) => ({
currentProvider: action.payload
});
-/**
- *
- * @type {typeof import('./provider-state-updaters').getSavedMapsUpdater}
- */
-export const getSavedMapsUpdater = (state, action) => {
+export const getSavedMapsUpdater = (
+ state: ProviderState,
+ action: ActionPayload<ProviderActions.GetSavedMapsPayload>
+): ProviderState => {
const provider = action.payload;
if (!_validateProvider(provider, 'listMaps')) {
return state;
@@ -395,21 +423,19 @@ export const getSavedMapsUpdater = (state, action) => {
);
};
-/**
- *
- * @type {typeof import('./provider-state-updaters').getSavedMapsSuccessUpdater}
- */
-export const getSavedMapsSuccessUpdater = (state, action) => ({
+export const getSavedMapsSuccessUpdater = (
+ state: ProviderState,
+ action: ActionPayload<ProviderActions.GetSavedMapsSuccessPayload>
+): ProviderState => ({
...state,
isProviderLoading: false,
visualizations: action.payload.visualizations
});
-/**
- *
- * @type {typeof import('./provider-state-updaters').getSavedMapsErrorUpdater}
- */
-export const getSavedMapsErrorUpdater = (state, action) => {
+export const getSavedMapsErrorUpdater = (
+ state: ProviderState,
+ action: ActionPayload<ProviderActions.GetSavedMapsErrorPayload>
+): ProviderState => {
const message =
getError(action.payload.error) || `Error getting saved maps from ${state.currentProvider}`;
diff --git a/src/reducers/provider-state.js b/src/reducers/provider-state.ts
similarity index 99%
rename from src/reducers/provider-state.js
rename to src/reducers/provider-state.ts
index a3dddd1b2..c63a631e2 100644
--- a/src/reducers/provider-state.js
+++ b/src/reducers/provider-state.ts
@@ -43,7 +43,7 @@ const actionHandler = {
// construct provider-state reducer
export const providerStateReducerFactory = (initialState = {}) =>
- // @ts-ignore
+ // @ts-expect-error
handleActions(actionHandler, {
...providerStateUpdaters.INITIAL_PROVIDER_STATE,
...initialState,
diff --git a/src/reducers/ui-state-updaters.d.ts b/src/reducers/ui-state-updaters.d.ts
deleted file mode 100644
index 34be98db6..000000000
--- a/src/reducers/ui-state-updaters.d.ts
+++ /dev/null
@@ -1,207 +0,0 @@
-import * as UiStateActions from 'actions/ui-state-actions';
-import {ToggleSplitMapUpdaterAction} from 'actions/map-state-actions';
-import {LoadFilesUpdaterAction, LoadFilesErrUpdaterAction} from ' actions/vis-state-actions';
-
-export type ExportImage = {
- ratio: string;
- resolution: string;
- legend: boolean;
- mapH: number;
- mapW: number;
- imageSize: {
- zoomOffset: number;
- scale: number;
- imageW: number;
- imageH: number;
- };
- // exporting state
- imageDataUri: string;
- exporting: boolean;
- processing: boolean;
- error: Error;
-};
-
-export type ExportData = {
- selectedDataset: string;
- dataType: string;
- filtered: boolean;
-};
-
-export type ExportHtml = {
- exportMapboxAccessToken: null | string;
- userMapboxToken: string;
- mode: string;
-};
-export type ExportJson = {
- hasData: boolean;
-};
-export type ExportMap = {
- HTML: ExportHtml;
- JSON: ExportJson;
- format: 'HTML' | 'JSON';
-};
-
-export type MapControl = {
- show: boolean;
- active: boolean;
- disableClose?: boolean;
- activeMapIndex?: number;
-};
-export type MapControls = {
- visibleLayers: MapControl;
- mapLegend: MapControl;
- toggle3d: MapControl;
- splitMap: MapControl;
- mapDraw: MapControl;
- mapLocale: MapControl;
-};
-
-export type LoadFiles = {
- fileLoading: boolean;
-};
-
-export type Notifications = {
- message: string;
- type: string;
- topic: string;
- id: string;
- count: number;
- isExpanded?: boolean;
-};
-
-export type Locale = string;
-
-export type LayerPanelListView = 'list' | 'sortByDataset'
-
-export type UiState = {
- readOnly: boolean;
- activeSidePanel: string;
- currentModal: string | null;
- datasetKeyToRemove: string | null;
- visibleDropdown: string | null;
- // export image modal ui
- exportImage: ExportImage;
- // export data modal ui
- exportData: ExportData;
- // html export
- exportMap: ExportMap;
- // map control panels
- mapControls: MapControls;
- // ui notifications
- notifications: Notifications[];
- // load files
- loadFiles: LoadFiles;
- // Locale of the UI
- locale: Locale;
- layerPanelListView: LayerPanelListView;
-};
-
-export const DEFAULT_MAP_CONTROLS: MapControls;
-export const DEFAULT_EXPORT_IMAGE: ExportImage;
-export const INITIAL_UI_STATE: UiState;
-
-export function toggleSidePanelUpdater(
- state: UiState,
- action: UiStateActions.ToggleSidePanelUpdaterAction
-): UiState;
-export function toggleModalUpdater(
- state: UiState,
- action: UiStateActions.ToggleModalUpdaterAction
-): UiState;
-export function showExportDropdownUpdater(
- state: UiState,
- action: UiStateActions.ShowExportDropdownUpdaterAction
-): UiState;
-export function hideExportDropdownUpdater(
- state: UiState,
- action: UiStateActions.HideExportDropdownUpdaterAction
-): UiState;
-export function toggleMapControlUpdater(
- state: UiState,
- action: UiStateActions.ToggleMapControlUpdaterAction
-): UiState;
-export function setMapControlVisibilityUpdater(
- state: UiState,
- action: UiStateActions.setMapControlVisibilityUpdaterAction
-): UiState;
-export function openDeleteModalUpdater(
- state: UiState,
- action: UiStateActions.OpenDeleteModalUpdaterAction
-): UiState;
-export function addNotificationUpdater(
- state: UiState,
- action: UiStateActions.AddNotificationUpdaterAction
-): UiState;
-export function removeNotificationUpdater(
- state: UiState,
- action: UiStateActions.RemoveNotificationUpdaterAction
-): UiState;
-export function setExportImageSettingUpdater(
- state: UiState,
- action: UiStateActions.SetExportImageSettingUpdaterAction
-): UiState;
-export function setExportImageDataUriUpdater(
- state: UiState,
- action: UiStateActions.SetExportImageDataUriUpdaterAction
-): UiState;
-export function setExportImageErrorUpdater(
- state: UiState,
- action: UiStateActions.SetExportImageErrorUpdaterAction
-): UiState;
-export function cleanupExportImageUpdater(
- state: UiState,
- action: UiStateActions.CleanupExportImageUpdaterAction
-): UiState;
-export function startExportingImageUpdater(
- state: UiState,
- action: UiStateActions.startExportingImage
-): UiState;
-export function setExportSelectedDatasetUpdater(
- state: UiState,
- action: UiStateActions.SetExportSelectedDatasetUpdaterAction
-): UiState;
-export function setExportDataTypeUpdater(
- state: UiState,
- action: UiStateActions.SetExportDataTypeUpdaterAction
-): UiState;
-export function setExportFilteredUpdater(
- state: UiState,
- action: UiStateActions.SetExportFilteredUpdaterAction
-): UiState;
-export function setExportDataUpdater(
- state: UiState,
- action: UiStateActions.SetExportDataUpdaterAction
-): UiState;
-export function setUserMapboxAccessTokenUpdater(
- state: UiState,
- action: UiStateActions.SetUserMapboxAccessTokenUpdaterAction
-): UiState;
-export function setExportMapFormatUpdater(
- state: UiState,
- action: UiStateActions.SetExportMapFormatUpdaterAction
-): UiState;
-export function setExportMapHTMLModeUpdater(
- state: UiState,
- action: UiStateActions.SetExportHTMLMapModeUpdaterAction
-): UiState;
-export function showDatasetTableUpdater(state: UiState);
-export function setLocaleUpdater(
- state: UiState,
- action: UiStateActions.SetLocaleUpdaterAction
-): UiState;
-export function toggleLayerPanelListViewUpdater(
- state: UiState,
- action: UiStateActions.ToggleLayerPanelListViewAction
-): UiState;
-
-export function loadFilesUpdater(state: UiState, action: LoadFilesUpdaterAction): UiState;
-export function loadFilesErrUpdater(state: UiState, action: LoadFilesErrUpdaterAction): UiState;
-export function loadFilesSuccessUpdater(state: UiState): UiState;
-export function toggleSplitMapUpdater(state: UiState, action: ToggleSplitMapUpdaterAction): UiState;
-export function initUiStateUpdater(
- state: UiState,
- action: {
- type?: ActionTypes.INIT;
- payload: KeplerGlInitPayload;
- }
-): UiState;
diff --git a/src/reducers/ui-state-updaters.js b/src/reducers/ui-state-updaters.ts
similarity index 71%
rename from src/reducers/ui-state-updaters.js
rename to src/reducers/ui-state-updaters.ts
index bb29a214d..19adbe606 100644
--- a/src/reducers/ui-state-updaters.js
+++ b/src/reducers/ui-state-updaters.ts
@@ -18,7 +18,6 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-// @ts-nocheck
import {
ADD_DATA_ID,
DATA_TABLE_ID,
@@ -33,9 +32,109 @@ import {
} from 'constants/default-settings';
import {LOCALE_CODES} from 'localization/locales';
import {createNotification, errorNotification} from 'utils/notifications-utils';
-import {calculateExportImageSize} from 'utils/export-utils';
+import {calculateExportImageSize} from '../utils/export-utils.js';
import {payload_, apply_, compose_} from './composer-helpers';
+import ActionTypes from '../constants/action-types';
+import * as UiStateActions from 'actions/ui-state-actions';
+import {KeplerGlInitPayload, loadFilesErrUpdaterAction} from '../actions';
+
+export type ExportImage = {
+ ratio: string;
+ resolution: string;
+ legend: boolean;
+ mapH: number;
+ mapW: number;
+ imageSize: {
+ zoomOffset: number;
+ scale: number;
+ imageW: number;
+ imageH: number;
+ };
+ // exporting state
+ imageDataUri: string;
+ exporting: boolean;
+ processing: boolean;
+ error: Error | false;
+ // This field was not in the .d.ts file
+ center: boolean;
+};
+
+export type ExportData = {
+ selectedDataset: string;
+ dataType: string;
+ filtered: boolean;
+};
+
+export type ExportHtml = {
+ exportMapboxAccessToken: null | string;
+ userMapboxToken: string;
+ mode: string;
+};
+export type ExportJson = {
+ hasData: boolean;
+};
+export type ExportMap = {
+ HTML: ExportHtml;
+ JSON: ExportJson;
+ format: 'HTML' | 'JSON';
+};
+
+export type MapControl = {
+ show: boolean;
+ active: boolean;
+ disableClose?: boolean;
+ activeMapIndex?: number;
+};
+export type MapControls = {
+ visibleLayers: MapControl;
+ mapLegend: MapControl;
+ toggle3d: MapControl;
+ splitMap: MapControl;
+ mapDraw: MapControl;
+ mapLocale: MapControl;
+};
+
+export type LoadFiles = {
+ fileLoading: boolean;
+};
+
+export type Notifications = {
+ message: string;
+ type: string;
+ topic: string;
+ id: string;
+ count: number;
+ isExpanded?: boolean;
+};
+
+export type Locale = string;
+
+export type LayerPanelListView = 'list' | 'sortByDataset';
+
+export type UiState = {
+ readOnly: boolean;
+ activeSidePanel: string;
+ currentModal: string | null;
+ datasetKeyToRemove: string | null;
+ visibleDropdown: string | null;
+ // export image modal ui
+ exportImage: ExportImage;
+ // export data modal ui
+ exportData: ExportData;
+ // html export
+ exportMap: ExportMap;
+ // map control panels
+ mapControls: MapControls;
+ // ui notifications
+ notifications: Notifications[];
+ // load files
+ loadFiles: LoadFiles;
+ // Locale of the UI
+ locale: Locale;
+ layerPanelListView: LayerPanelListView;
+};
+
export const DEFAULT_ACTIVE_SIDE_PANEL = 'layer';
export const DEFAULT_MODAL = ADD_DATA_ID;
@@ -76,10 +175,11 @@ export const DEFAULT_MODAL = ADD_DATA_ID;
* export default composedReducer;
*/
/* eslint-disable no-unused-vars */
+// @ts-expect-error
const uiStateUpdaters = null;
/* eslint-enable no-unused-vars */
-const DEFAULT_MAP_CONTROLS_FEATURES = {
+const DEFAULT_MAP_CONTROLS_FEATURES: MapControl = {
show: true,
active: false,
disableClose: false,
@@ -97,15 +197,16 @@ const DEFAULT_MAP_CONTROLS_FEATURES = {
* @property splitMap Default: `{show: true}`
* @property mapDraw Default: `{show: true, active: false}`
* @property mapLocale Default: `{show: false, active: false}`
- * @type {import('./ui-state-updaters').MapControls}
* @public
*/
-export const DEFAULT_MAP_CONTROLS = Object.keys(MAP_CONTROLS).reduce(
+export const DEFAULT_MAP_CONTROLS: MapControls = (Object.keys(MAP_CONTROLS) as Array<
+ keyof typeof MAP_CONTROLS
+>).reduce(
(final, current) => ({
...final,
[current]: DEFAULT_MAP_CONTROLS_FEATURES
}),
- {}
+ {} as MapControls
);
/**
@@ -121,10 +222,9 @@ export const DEFAULT_MAP_CONTROLS = Object.keys(MAP_CONTROLS).reduce(
* @property imageDataUri Default: `''`,
* @property exporting Default: `false`
* @property error Default: `false`
- * @type {import('./ui-state-updaters').ExportImage}
* @public
*/
-export const DEFAULT_EXPORT_IMAGE = {
+export const DEFAULT_EXPORT_IMAGE: ExportImage = {
// user options
ratio: EXPORT_IMG_RATIOS.SCREEN,
resolution: RESOLUTIONS.ONE_X,
@@ -159,10 +259,9 @@ export const DEFAULT_LOAD_FILES = {
* @property selectedDataset Default: `''`,
* @property dataType Default: `'csv'`,
* @property filtered Default: `true`,
- * @type {import('./ui-state-updaters').ExportData}
* @public
*/
-export const DEFAULT_EXPORT_DATA = {
+export const DEFAULT_EXPORT_DATA: ExportData = {
selectedDataset: '',
dataType: EXPORT_DATA_TYPE.CSV,
filtered: true
@@ -178,10 +277,9 @@ export const DEFAULT_NOTIFICATIONS = [];
* @property exportMapboxAccessToken - Default: null, this is used when we provide a default mapbox token for users to take advantage of
* @property userMapboxToken - Default: '', mapbox token provided by user through input field
* @property mode - Default: 'READ', read only or editable
- * @type {import('./ui-state-updaters').ExportHtml}
* @public
*/
-export const DEFAULT_EXPORT_HTML = {
+export const DEFAULT_EXPORT_HTML: ExportHtml = {
exportMapboxAccessToken: null,
userMapboxToken: '',
mode: EXPORT_HTML_MAP_MODES.READ
@@ -190,10 +288,9 @@ export const DEFAULT_EXPORT_HTML = {
/**
* @constant
* @property hasData - Default: 'true',
- * @type {import('./ui-state-updaters').ExportJson}
* @public
*/
-export const DEFAULT_EXPORT_JSON = {
+export const DEFAULT_EXPORT_JSON: ExportJson = {
hasData: true
};
@@ -203,10 +300,9 @@ export const DEFAULT_EXPORT_JSON = {
* @property HTML - Default: 'DEFAULT_EXPORT_HTML',
* @property JSON - Default: 'DEFAULT_EXPORT_JSON',
* @property format - Default: 'HTML',
- * @type {import('./ui-state-updaters').ExportMap}
* @public
*/
-export const DEFAULT_EXPORT_MAP = {
+export const DEFAULT_EXPORT_MAP: ExportMap = {
[EXPORT_MAP_FORMATS.HTML]: DEFAULT_EXPORT_HTML,
[EXPORT_MAP_FORMATS.JSON]: DEFAULT_EXPORT_JSON,
format: EXPORT_MAP_FORMATS.HTML
@@ -228,10 +324,9 @@ export const DEFAULT_EXPORT_MAP = {
* @property notifications Default: `[]`
* @property notifications Default: `[]`
* @property loadFiles
- * @type {import('./ui-state-updaters').UiState}
* @public
*/
-export const INITIAL_UI_STATE = {
+export const INITIAL_UI_STATE: UiState = {
readOnly: false,
activeSidePanel: DEFAULT_ACTIVE_SIDE_PANEL,
currentModal: DEFAULT_MODAL,
@@ -259,7 +354,13 @@ export const INITIAL_UI_STATE = {
* @memberof uiStateUpdaters
*/
-export const initUiStateUpdater = (state, action) => ({
+export const initUiStateUpdater = (
+ state: UiState,
+ action: {
+ type?: typeof ActionTypes['INIT'];
+ payload: KeplerGlInitPayload;
+ }
+): UiState => ({
...state,
...(action.payload || {}).initialUiState
});
@@ -271,10 +372,12 @@ export const initUiStateUpdater = (state, action) => ({
* @param action
* @param action.payload id of side panel to be shown, one of `layer`, `filter`, `interaction`, `map`. close side panel if `null`
* @returns nextState
- * @type {typeof import('./ui-state-updaters').toggleSidePanelUpdater}
* @public
*/
-export const toggleSidePanelUpdater = (state, {payload: id}) => {
+export const toggleSidePanelUpdater = (
+ state: UiState,
+ {payload: id}: UiStateActions.ToggleSidePanelUpdaterAction
+): UiState => {
return id === state.activeSidePanel
? state
: {
@@ -296,10 +399,12 @@ export const toggleSidePanelUpdater = (state, {payload: id}) => {
* - [`EXPORT_DATA_ID`](../constants/default-settings.md#export_data_id)
* - [`ADD_MAP_STYLE_ID`](../constants/default-settings.md#add_map_style_id)
* @returns nextState
- * @type {typeof import('./ui-state-updaters').toggleModalUpdater}
* @public
*/
-export const toggleModalUpdater = (state, {payload: id}) => ({
+export const toggleModalUpdater = (
+ state: UiState,
+ {payload: id}: UiStateActions.ToggleModalUpdaterAction
+): UiState => ({
...state,
currentModal: id
});
@@ -307,10 +412,12 @@ export const toggleModalUpdater = (state, {payload: id}) => ({
/**
* Hide and show side panel header dropdown, activated by clicking the share link on top of the side panel
* @memberof uiStateUpdaters
- * @type {typeof import('./ui-state-updaters').showExportDropdownUpdater}
* @public
*/
-export const showExportDropdownUpdater = (state, {payload: id}) => ({
+export const showExportDropdownUpdater = (
+ state: UiState,
+ {payload: id}: UiStateActions.ShowExportDropdownUpdaterAction
+): UiState => ({
...state,
visibleDropdown: id
});
@@ -318,10 +425,9 @@ export const showExportDropdownUpdater = (state, {payload: id}) => ({
/**
* Hide side panel header dropdown, activated by clicking the share link on top of the side panel
* @memberof uiStateUpdaters
- * @type {typeof import('./ui-state-updaters').hideExportDropdownUpdater}
* @public
*/
-export const hideExportDropdownUpdater = state => ({
+export const hideExportDropdownUpdater = (state: UiState): UiState => ({
...state,
visibleDropdown: null
});
@@ -333,10 +439,12 @@ export const hideExportDropdownUpdater = state => ({
* @param action action
* @param action.payload map control panel id, one of the keys of: [`DEFAULT_MAP_CONTROLS`](#default_map_controls)
* @returns nextState
- * @type {typeof import('./ui-state-updaters').toggleMapControlUpdater}
* @public
*/
-export const toggleMapControlUpdater = (state, {payload: {panelId, index = 0}}) => ({
+export const toggleMapControlUpdater = (
+ state: UiState,
+ {payload: {panelId, index = 0}}: UiStateActions.ToggleMapControlUpdaterAction
+): UiState => ({
...state,
mapControls: {
...state.mapControls,
@@ -361,10 +469,12 @@ export const toggleMapControlUpdater = (state, {payload: {panelId, index = 0}})
* @param action action
* @param action.payload map control panel id, one of the keys of: [`DEFAULT_MAP_CONTROLS`](#default_map_controls)
* @returns nextState
- * @type {typeof import('./ui-state-updaters').setMapControlVisibilityUpdater}
* @public
*/
-export const setMapControlVisibilityUpdater = (state, {payload: {panelId, show}}) => {
+export const setMapControlVisibilityUpdater = (
+ state: UiState,
+ {payload: {panelId, show}}: UiStateActions.setMapControlVisibilityUpdaterAction
+): UiState => {
if (!state.mapControls?.[panelId]) {
return state;
}
@@ -388,10 +498,12 @@ export const setMapControlVisibilityUpdater = (state, {payload: {panelId, show}}
* @param action
* @param action.payload dataset id
* @returns nextState
- * @type {typeof import('./ui-state-updaters').openDeleteModalUpdater}
* @public
*/
-export const openDeleteModalUpdater = (state, {payload: datasetKeyToRemove}) => ({
+export const openDeleteModalUpdater = (
+ state: UiState,
+ {payload: datasetKeyToRemove}: UiStateActions.OpenDeleteModalUpdaterAction
+): UiState => ({
...state,
currentModal: DELETE_DATA_ID,
datasetKeyToRemove
@@ -402,10 +514,12 @@ export const openDeleteModalUpdater = (state, {payload: datasetKeyToRemove}) =>
* @memberof uiStateUpdaters
* @param state `uiState`
* @returns nextState
- * @type {typeof import('./ui-state-updaters').setExportImageSettingUpdater}
* @public
*/
-export const setExportImageSettingUpdater = (state, {payload: newSetting}) => {
+export const setExportImageSettingUpdater = (
+ state: UiState,
+ {payload: newSetting}: UiStateActions.SetExportImageSettingUpdaterAction
+): UiState => {
const updated = {...state.exportImage, ...newSetting};
const imageSize = calculateExportImageSize(updated) || state.exportImage.imageSize;
@@ -425,10 +539,12 @@ export const setExportImageSettingUpdater = (state, {payload: newSetting}) => {
* @param action
* @param action.payload export image data uri
* @returns nextState
- * @type {typeof import('./ui-state-updaters').setExportImageDataUriUpdater}
* @public
*/
-export const setExportImageDataUriUpdater = (state, {payload: dataUri}) => ({
+export const setExportImageDataUriUpdater = (
+ state: UiState,
+ {payload: dataUri}: UiStateActions.SetExportImageDataUriUpdaterAction
+): UiState => ({
...state,
exportImage: {
...state.exportImage,
@@ -439,10 +555,12 @@ export const setExportImageDataUriUpdater = (state, {payload: dataUri}) => ({
/**
* @memberof uiStateUpdaters
- * @type {typeof import('./ui-state-updaters').setExportImageErrorUpdater}
* @public
*/
-export const setExportImageErrorUpdater = (state, {payload: error}) => ({
+export const setExportImageErrorUpdater = (
+ state: UiState,
+ {payload: error}: UiStateActions.SetExportImageErrorUpdaterAction
+): UiState => ({
...state,
exportImage: {
...state.exportImage,
@@ -454,10 +572,9 @@ export const setExportImageErrorUpdater = (state, {payload: error}) => ({
/**
* Delete cached export image
* @memberof uiStateUpdaters
- * @type {typeof import('./ui-state-updaters').cleanupExportImageUpdater}
* @public
*/
-export const cleanupExportImageUpdater = state => ({
+export const cleanupExportImageUpdater = (state: UiState): UiState => ({
...state,
exportImage: {
...state.exportImage,
@@ -475,10 +592,12 @@ export const cleanupExportImageUpdater = state => ({
* @param state
* @param options
* @returns {UiState}
- * @type {typeof import('./ui-state-updaters').startExportingImage}
* @public
*/
-export const startExportingImageUpdater = (state, {payload: options = {}}) => {
+export const startExportingImageUpdater = (
+ state: UiState,
+ {payload: options = {}}: {payload: Partial<ExportImage>}
+): UiState => {
const imageSettings = {
...options,
exporting: true
@@ -497,10 +616,12 @@ export const startExportingImageUpdater = (state, {payload: options = {}}) => {
* @param action
* @param action.payload dataset id
* @returns nextState
- * @type {typeof import('./ui-state-updaters').setExportSelectedDatasetUpdater}
* @public
*/
-export const setExportSelectedDatasetUpdater = (state, {payload: dataset}) => ({
+export const setExportSelectedDatasetUpdater = (
+ state: UiState,
+ {payload: dataset}: UiStateActions.SetExportSelectedDatasetUpdaterAction
+): UiState => ({
...state,
exportData: {
...state.exportData,
@@ -515,10 +636,12 @@ export const setExportSelectedDatasetUpdater = (state, {payload: dataset}) => ({
* @param action
* @param action.payload one of `'text/csv'`
* @returns nextState
- * @type {typeof import('./ui-state-updaters').setExportDataTypeUpdater}
* @public
*/
-export const setExportDataTypeUpdater = (state, {payload: dataType}) => ({
+export const setExportDataTypeUpdater = (
+ state: UiState,
+ {payload: dataType}: UiStateActions.SetExportDataTypeUpdaterAction
+): UiState => ({
...state,
exportData: {
...state.exportData,
@@ -533,10 +656,12 @@ export const setExportDataTypeUpdater = (state, {payload: dataType}) => ({
* @param action
* @param action.payload
* @returns nextState
- * @type {typeof import('./ui-state-updaters').setExportFilteredUpdater}
* @public
*/
-export const setExportFilteredUpdater = (state, {payload: filtered}) => ({
+export const setExportFilteredUpdater = (
+ state: UiState,
+ {payload: filtered}: UiStateActions.SetExportFilteredUpdaterAction
+): UiState => ({
...state,
exportData: {
...state.exportData,
@@ -549,10 +674,9 @@ export const setExportFilteredUpdater = (state, {payload: filtered}) => ({
* @memberof uiStateUpdaters
* @param state `uiState`
* @returns nextState
- * @type {typeof import('./ui-state-updaters').setExportDataUpdater}
* @public
*/
-export const setExportDataUpdater = state => ({
+export const setExportDataUpdater = (state: UiState): UiState => ({
...state,
exportMap: {
...state.exportMap,
@@ -569,10 +693,12 @@ export const setExportDataUpdater = state => ({
* @param action
* @param action.payload
* @returns nextState
- * @type {typeof import('./ui-state-updaters').setUserMapboxAccessTokenUpdater}
* @public
*/
-export const setUserMapboxAccessTokenUpdater = (state, {payload: userMapboxToken}) => ({
+export const setUserMapboxAccessTokenUpdater = (
+ state: UiState,
+ {payload: userMapboxToken}: UiStateActions.SetUserMapboxAccessTokenUpdaterAction
+): UiState => ({
...state,
exportMap: {
...state.exportMap,
@@ -589,12 +715,15 @@ export const setUserMapboxAccessTokenUpdater = (state, {payload: userMapboxToken
* @param action
* @param action.payload format to use to export the map into
* @return nextState
- * @type {typeof import('./ui-state-updaters').setExportMapFormatUpdater}
*/
-export const setExportMapFormatUpdater = (state, {payload: format}) => ({
+export const setExportMapFormatUpdater = (
+ state: UiState,
+ {payload: format}: UiStateActions.SetExportMapFormatUpdaterAction
+): UiState => ({
...state,
exportMap: {
...state.exportMap,
+ // @ts-expect-error
format
}
});
@@ -605,9 +734,11 @@ export const setExportMapFormatUpdater = (state, {payload: format}) => ({
* @param action
* @param action.payload to be set (available modes: EXPORT_HTML_MAP_MODES)
* @return nextState
- * @type {typeof import('./ui-state-updaters').setExportMapHTMLModeUpdater}
*/
-export const setExportMapHTMLModeUpdater = (state, {payload: mode}) => ({
+export const setExportMapHTMLModeUpdater = (
+ state: UiState,
+ {payload: mode}: UiStateActions.SetExportHTMLMapModeUpdaterAction
+): UiState => ({
...state,
exportMap: {
...state.exportMap,
@@ -626,19 +757,24 @@ export const setExportMapHTMLModeUpdater = (state, {payload: mode}) => ({
* @param action
* @param action.payload Params of a notification
* @returns nextState
- * @type {typeof import('./ui-state-updaters').addNotificationUpdater}
* @public
*/
-export const addNotificationUpdater = (state, {payload}) => {
+export const addNotificationUpdater = (
+ state: UiState,
+ {payload}: UiStateActions.AddNotificationUpdaterAction
+): UiState => {
let notifications;
+ // @ts-expect-error
const payloadId = payload?.id;
const notificationToUpdate = payloadId ? state.notifications.find(n => n.id === payloadId) : null;
if (notificationToUpdate) {
notifications = state.notifications.map(n =>
+ // @ts-expect-error
n.id === payloadId ? createNotification(payload) : n
);
} else {
+ // @ts-expect-error
notifications = [...(state.notifications || []), createNotification(payload)];
}
@@ -652,10 +788,12 @@ export const addNotificationUpdater = (state, {payload}) => {
* @param action
* @param action.payload id of the notification to be removed
* @returns nextState
- * @type {typeof import('./ui-state-updaters').removeNotificationUpdater}
* @public
*/
-export const removeNotificationUpdater = (state, {payload: id}) => ({
+export const removeNotificationUpdater = (
+ state: UiState,
+ {payload: id}: UiStateActions.RemoveNotificationUpdaterAction
+): UiState => ({
...state,
notifications: state.notifications.filter(n => n.id !== id)
});
@@ -665,10 +803,9 @@ export const removeNotificationUpdater = (state, {payload: id}) => ({
* @memberof uiStateUpdaters
* @param state `uiState`
* @returns nextState
- * @type {typeof import('./ui-state-updaters').loadFilesUpdater}
* @public
*/
-export const loadFilesUpdater = state => ({
+export const loadFilesUpdater = (state: UiState): UiState => ({
...state,
loadFiles: {
...state.loadFiles,
@@ -681,9 +818,8 @@ export const loadFilesUpdater = state => ({
* @memberof uiStateUpdaters
* @param state `uiState`
* @returns nextState
- * @type {typeof import('./ui-state-updaters').loadFilesSuccessUpdater}
*/
-export const loadFilesSuccessUpdater = state => ({
+export const loadFilesSuccessUpdater = (state: UiState): UiState => ({
...state,
loadFiles: {
...state.loadFiles,
@@ -698,10 +834,9 @@ export const loadFilesSuccessUpdater = state => ({
* @param action
* @param action.error
* @returns nextState
- * @type {typeof import('./ui-state-updaters').loadFilesErrUpdater}
* @public
*/
-export const loadFilesErrUpdater = (state, {error}) =>
+export const loadFilesErrUpdater = (state: UiState, {error}: loadFilesErrUpdaterAction): UiState =>
addNotificationUpdater(
{
...state,
@@ -723,10 +858,9 @@ export const loadFilesErrUpdater = (state, {error}) =>
* @memberof uiStateUpdaters
* @param state
* @returns nextState
- * @type {typeof import('./ui-state-updaters').toggleSplitMapUpdater}
* @public
*/
-export const toggleSplitMapUpdater = state => ({
+export const toggleSplitMapUpdater = (state: UiState): UiState => ({
...state,
mapControls: Object.entries(state.mapControls).reduce(
(acc, entry) => ({
@@ -736,7 +870,7 @@ export const toggleSplitMapUpdater = state => ({
activeMapIndex: 0
}
}),
- {}
+ {} as MapControls
)
});
@@ -745,10 +879,10 @@ export const toggleSplitMapUpdater = state => ({
* @memberof uiStateUpdaters
* @param state
* @returns nextState
- * @type {typeof import('./ui-state-updaters').showDatasetTableUpdater}
* @public
*/
-export const showDatasetTableUpdater = state => toggleModalUpdater(state, {payload: DATA_TABLE_ID});
+export const showDatasetTableUpdater = (state: UiState): UiState =>
+ toggleModalUpdater(state, {payload: DATA_TABLE_ID});
/**
* Set the locale of the UI
@@ -758,10 +892,12 @@ export const showDatasetTableUpdater = state => toggleModalUpdater(state, {paylo
* @param action.payload
* @param action.payload.locale locale
* @returns nextState
- * @type {typeof import('./ui-state-updaters').setLocaleUpdater}
* @public
*/
-export const setLocaleUpdater = (state, {payload: {locale}}) => ({
+export const setLocaleUpdater = (
+ state: UiState,
+ {payload: {locale}}: UiStateActions.SetLocaleUpdaterAction
+): UiState => ({
...state,
locale
});
@@ -773,10 +909,13 @@ export const setLocaleUpdater = (state, {payload: {locale}}) => ({
* @param action
* @param action.payload layer panel listView value. Can be 'list' or 'sortByDataset'
* @returns nextState
- * @type {typeof import('./ui-state-updaters').toggleLayerPanelListViewUpdater}
* @public
*/
-export const toggleLayerPanelListViewUpdater = (state, {payload: listView}) => {
+export const toggleLayerPanelListViewUpdater = (
+ state: UiState,
+ {payload: listView}: UiStateActions.ToggleLayerPanelListViewAction
+): UiState => {
+ // @ts-expect-error
return listView === state.layerPanelListView
? state
: {
diff --git a/src/reducers/ui-state.js b/src/reducers/ui-state.ts
similarity index 99%
rename from src/reducers/ui-state.js
rename to src/reducers/ui-state.ts
index d0dec158e..4ca069d51 100644
--- a/src/reducers/ui-state.js
+++ b/src/reducers/ui-state.ts
@@ -64,7 +64,7 @@ const actionHandler = {
/* Reducer */
export const uiStateReducerFactory = (initialState = {}) =>
- // @ts-ignore
+ // @ts-expect-error
handleActions(actionHandler, {
...uiStateUpdaters.INITIAL_UI_STATE,
...initialState,
diff --git a/src/utils/export-utils.d.ts b/src/utils/export-utils.d.ts
index fa4255d1d..392fca05f 100644
--- a/src/utils/export-utils.d.ts
+++ b/src/utils/export-utils.d.ts
@@ -14,3 +14,5 @@ export const getScaleFromImageSize: (
mapH: number
) => number;
export const dataURItoBlob: (dataURI: string) => Blob;
+
+export const calculateExportImageSize: ({mapW, mapH, ratio, resolution}) => any;