Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
chore: add reduxLogLevel config to suppress noisy Redux actions in dev console (#3597)
Igor Dykhta28f4596b9f6d
diff --git a/examples/demo-app/src/store.js b/examples/demo-app/src/store.jsindex 0c6d1fc77..7e665c50a 100644--- a/examples/demo-app/src/store.js+++ b/examples/demo-app/src/store.js@@ -6,6 +6,7 @@ import {createLogger} from 'redux-logger';import thunk from 'redux-thunk';import {enhanceReduxMiddleware} from '@kepler.gl/reducers';+import {getApplicationConfig} from '@kepler.gl/utils';// eslint-disable-next-line no-unused-varsimport Window from 'global/window';@@ -18,14 +19,38 @@ const reducers = combineReducers({export const middlewares = enhanceReduxMiddleware([thunk]);-const NOISY_ACTIONS = new Set(['@@kepler.gl/MOUSE_MOVE', '@@kepler.gl/LAYER_HOVER']);+// Actions suppressed at each log level. Each level is a superset of the one above.+// Set window.__KEPLER_LOG_FULL__ = true in the browser console to override and log everything.+const LEVEL1_ACTIONS = new Set([+ '@@kepler.gl/MOUSE_MOVE',+ '@@kepler.gl/LAYER_HOVER',+ '@@kepler.gl/SET_LOADING_INDICATOR',+ '@@openassistant/SET_MAP_BOUNDARY'+]);++const LEVEL2_ACTIONS = new Set([+ ...LEVEL1_ACTIONS,+ '@@kepler.gl/LOAD_MAP_STYLES',+ '@@kepler.gl/MAP_LOAD_STARTED',+ '@@kepler.gl/LAYER_VISUAL_CHANGE',+ '@@kepler.gl/UPDATE_MAP',+ '@@kepler.gl/ON_MAP_CLICK',+ '@@kepler.gl/FILTER_CHANGE'+]);++const SUPPRESSED_BY_LEVEL = [+ new Set(), // 0 — log everything+ LEVEL1_ACTIONS, // 1 — suppress UI noise (default)+ LEVEL2_ACTIONS // 2 — suppress UI noise + map/layer chatter+];-// Set window.__KEPLER_LOG_FULL__ = true in the console to include-// high-frequency actions (MOUSE_MOVE, LAYER_HOVER, UPDATE_MAP).if (NODE_ENV === 'local') {+ const level = getApplicationConfig().reduxLogLevel ?? 1;+ const suppressed = SUPPRESSED_BY_LEVEL[level] ?? LEVEL1_ACTIONS;+const logger = createLogger({collapsed: () => true,- predicate: (_getState, action) => Window.__KEPLER_LOG_FULL__ || !NOISY_ACTIONS.has(action.type)+ predicate: (_getState, action) => Window.__KEPLER_LOG_FULL__ || !suppressed.has(action.type)});middlewares.push(logger);}@@ -42,8 +67,10 @@ let composeEnhancers = compose;*/if (Window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) {+ const level = getApplicationConfig().reduxLogLevel ?? 1;+ const suppressed = SUPPRESSED_BY_LEVEL[level] ?? LEVEL1_ACTIONS;composeEnhancers = Window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({- actionsBlacklist: [...NOISY_ACTIONS]+ actionsBlacklist: [...suppressed]});}diff --git a/src/utils/src/application-config.ts b/src/utils/src/application-config.tsindex f5c18ebaf..d33326c23 100644--- a/src/utils/src/application-config.ts+++ b/src/utils/src/application-config.ts@@ -50,6 +50,32 @@ export type BaseMapLibraryConfig = {* A mechanism to override default Kepler values/settings so that we* without having to make application-specific changes to the kepler repo.*/+/**+ * Controls which Redux actions are suppressed by the dev-mode Redux logger.+ * Mirrors the `log.level` convention used by luma.gl / deck.gl.+ *+ * - `0` — log every action (no filtering)+ * - `1` — suppress the highest-frequency UI noise:+ * MOUSE_MOVE, LAYER_HOVER, SET_MAP_BOUNDARY, SET_LOADING_INDICATOR+ * - `2` — suppress everything in level 1 plus map/layer update chatter:+ * LOAD_MAP_STYLES, UPDATE_MAP, LAYER_VISUAL_CHANGE,+ * ON_MAP_CLICK, FILTER_CHANGE, MAP_LOAD_STARTED+ *+ * Effects by context:+ * - **redux-logger** (console output): only active when `NODE_ENV === 'local'` (i.e. `yarn start`)+ * - **Redux DevTools** (`actionsBlacklist`): active whenever the browser extension is present,+ * regardless of `NODE_ENV`+ *+ * Default: `1`+ *+ * @example+ * ```ts+ * initApplicationConfig({ reduxLogLevel: 2 }); // quieter dev console+ * initApplicationConfig({ reduxLogLevel: 0 }); // see every action+ * ```+ */+export type ReduxLogLevel = 0 | 1 | 2;+export type KeplerApplicationConfig = {/** Default name of export HTML file, can be overridden by user */defaultHtmlName?: string;@@ -172,6 +198,9 @@ export type KeplerApplicationConfig = {* ```*/customIconUrl?: string;++ /** Controls Redux action logging verbosity in dev mode. See {@link ReduxLogLevel}. */+ reduxLogLevel?: ReduxLogLevel;};const DEFAULT_APPLICATION_CONFIG: Required<KeplerApplicationConfig> = {@@ -254,7 +283,9 @@ const DEFAULT_APPLICATION_CONFIG: Required<KeplerApplicationConfig> = {customIcons: [],- customIconUrl: ''+ customIconUrl: '',++ reduxLogLevel: 1};const applicationConfig: Required<KeplerApplicationConfig> = DEFAULT_APPLICATION_CONFIG;diff --git a/src/utils/src/index.ts b/src/utils/src/index.tsindex 44b5fa7ea..edcb9e626 100644--- a/src/utils/src/index.ts+++ b/src/utils/src/index.ts@@ -186,7 +186,8 @@ export type {BaseMapLibraryConfig,MapLibInstance,GetMapRef,- SvgIcon+ SvgIcon,+ ReduxLogLevel} from './application-config';export type {DatabaseAdapter, DatabaseConnection} from './application-config-types';