Skip to content

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

[chore] Making EffectPanelHeader actions configurable (#2432)

Igor Dykhtab5a6e9ce4c9b
diff --git a/src/components/src/effects/effect-panel-header.tsx b/src/components/src/effects/effect-panel-header.tsx
index 1035f45d6..9165b7413 100644
--- a/src/components/src/effects/effect-panel-header.tsx
+++ b/src/components/src/effects/effect-panel-header.tsx
@@ -41,6 +41,7 @@ export type EffectPanelHeaderProps = {
effectId: string;
isEnabled: boolean;
isConfigActive: boolean;
+ isJsonEditorActive: boolean;
showSortHandle?: boolean;
isDragNDropEnabled: boolean;
onToggleEnabled: () => void;
@@ -52,6 +53,13 @@ export type EffectPanelHeaderProps = {
hidden: React.ComponentType<Partial<BaseProps>>;
enableConfig: React.ComponentType<Partial<BaseProps>>;
};
+ actionItems?: {
+ key: string;
+ isHidden?: boolean;
+ tooltip: string;
+ classNames?: Record<string, boolean>;
+ icon: React.ElementType;
+ }[];
};
export const defaultProps = {
@@ -173,38 +181,71 @@ export function EffectPanelHeaderActionSectionFactory(
onToggleEnabled,
onRemoveEffect,
onToggleEnableConfig,
+ actionItems,
actionIcons = defaultActionIcons
} = props;
+ const effectActionItems = useMemo(
+ () =>
+ actionItems ?? [
+ {
+ key: 'remove-effect',
+ isHidden: true,
+ tooltip: 'tooltip.removeEffect',
+ onClick: onRemoveEffect,
+ icon: actionIcons.remove
+ },
+ {
+ key: 'visibility-toggle',
+ tooltip: isEnabled ? 'tooltip.disableEffect' : 'tooltip.enabledEffect',
+ onClick: onToggleEnabled,
+ icon: isEnabled ? actionIcons.visible : actionIcons.hidden
+ },
+ {
+ key: 'enable-config',
+ classNames: {'is-open': isConfigActive},
+ tooltip: 'tooltip.effectSettings',
+ onClick: onToggleEnableConfig,
+ icon: actionIcons.enableConfig
+ }
+ ],
+ [actionItems, isEnabled, onRemoveEffect, onToggleEnabled, actionIcons]
+ );
+
return (
<HeaderActionSection className="effect-panel__header__actions">
<StyledPanelHeaderHiddenActions isConfigActive={isConfigActive}>
- <PanelHeaderAction
- className="effect__remove-effect"
- testId="remove-effect-action"
- id={effectId}
- tooltip={'tooltip.removeEffect'}
- onClick={onRemoveEffect}
- tooltipType="error"
- IconComponent={actionIcons.remove}
- />
+ {effectActionItems
+ // @ts-expect-error typed in follow up
+ .filter(item => Boolean(item.isHidden))
+ .map((item, i) => (
+ <PanelHeaderAction
+ key={item.key}
+ className={`effect__${item.key}`}
+ testId={`${item.key}-action`}
+ id={effectId}
+ tooltip={item.tooltip}
+ onClick={item.onClick}
+ tooltipType="error"
+ IconComponent={item.icon}
+ />
+ ))}
</StyledPanelHeaderHiddenActions>
- <PanelHeaderAction
- className="effect__visibility-toggle"
- id={effectId}
- tooltip={isEnabled ? 'tooltip.disableEffect' : 'tooltip.enabledEffect'}
- onClick={onToggleEnabled}
- IconComponent={isEnabled ? actionIcons.visible : actionIcons.hidden}
- />
- <PanelHeaderAction
- className={classnames('effect__enable-config ', {
- 'is-open': isConfigActive
- })}
- id={effectId}
- tooltip={'tooltip.effectSettings'}
- onClick={onToggleEnableConfig}
- IconComponent={actionIcons.enableConfig}
- />
+ {effectActionItems
+ // @ts-expect-error typed in follow up
+ .filter(item => !item.isHidden)
+ .map((item, i) => (
+ <PanelHeaderAction
+ key={item.key}
+ className={classnames(`effect__${item.key}`, item.classNames)}
+ testId={`${item.key}-action`}
+ id={effectId}
+ tooltip={item.tooltip}
+ onClick={item.onClick}
+ tooltipType="error"
+ IconComponent={item.icon}
+ />
+ ))}
</HeaderActionSection>
);
};
diff --git a/src/components/src/effects/effect-panel.tsx b/src/components/src/effects/effect-panel.tsx
index 8a074abba..f34892bfd 100644
--- a/src/components/src/effects/effect-panel.tsx
+++ b/src/components/src/effects/effect-panel.tsx
@@ -78,7 +78,7 @@ function EffectPanelFactory(
render() {
const {effect, isDraggable, listeners} = this.props;
- const {id, type, isConfigActive, isEnabled} = effect;
+ const {id, type, isConfigActive, isJsonEditorActive, isEnabled} = effect;
const sortingAllowed = type !== LIGHT_AND_SHADOW_EFFECT.type;
@@ -96,6 +96,7 @@ function EffectPanelFactory(
effectId={id}
type={type}
isEnabled={isEnabled}
+ isJsonEditorActive={isJsonEditorActive}
onToggleEnabled={this._toggleEnabled}
onRemoveEffect={this._removeEffect}
onToggleEnableConfig={this._toggleConfigActive}
diff --git a/src/effects/src/effect.ts b/src/effects/src/effect.ts
index 46f594392..79ad06495 100644
--- a/src/effects/src/effect.ts
+++ b/src/effects/src/effect.ts
@@ -12,6 +12,7 @@ export class Effect implements EffectInterface {
type: string;
isEnabled: boolean;
isConfigActive: boolean;
+ isJsonEditorActive: boolean;
// effect specific parameters for a deck.gl effect (uniforms)
parameters: {[key: string]: any};
deckEffect: any;
@@ -24,6 +25,7 @@ export class Effect implements EffectInterface {
this.type = _props.type;
this.isEnabled = _props.isEnabled;
this.isConfigActive = _props.isConfigActive;
+ this.isJsonEditorActive = _props.isJsonEditorActive;
this.parameters = _props.parameters;
this._uiConfig = POSTPROCESSING_EFFECTS[this.type]?.parameters || [];
@@ -42,6 +44,7 @@ export class Effect implements EffectInterface {
type: props.type || DEFAULT_POST_PROCESSING_EFFECT_TYPE,
isEnabled: props.isEnabled ?? true,
isConfigActive: props.isConfigActive ?? true,
+ isJsonEditorActive: props.isJsonEditorActive ?? false,
parameters: {...props.parameters}
};
}
@@ -51,6 +54,7 @@ export class Effect implements EffectInterface {
this.type = props.type ?? this.type;
this.isEnabled = props.isEnabled ?? this.isEnabled;
this.isConfigActive = props.isConfigActive ?? this.isConfigActive;
+ this.isJsonEditorActive = props.isJsonEditorActive ?? this.isJsonEditorActive;
this.parameters = {...this.parameters, ...props.parameters};
}
diff --git a/src/reducers/src/vis-state-updaters.ts b/src/reducers/src/vis-state-updaters.ts
index ace0130a7..166f9ace3 100644
--- a/src/reducers/src/vis-state-updaters.ts
+++ b/src/reducers/src/vis-state-updaters.ts
@@ -1517,12 +1517,26 @@ export const updateEffectUpdater = (
return state;
}
+ let effectOrder = state.effectOrder;
+ if (props.id !== undefined && props.id !== id) {
+ const idx2 = state.effects.findIndex(l => l.id === props.id);
+ if (idx2 >= 0) {
+ Console.warn(`can not update effect with existing effect id ${id}`);
+ return state;
+ }
+
+ effectOrder = effectOrder.map(effectOrderId =>
+ effectOrderId === id ? (props.id as string) : effectOrderId
+ );
+ }
+
const newEffects = [...state.effects];
newEffects[idx].setProps(props);
return {
...state,
- effects: newEffects
+ effects: newEffects,
+ effectOrder
};
};
diff --git a/src/types/effects.d.ts b/src/types/effects.d.ts
index 397a13edd..1ce0778d6 100644
--- a/src/types/effects.d.ts
+++ b/src/types/effects.d.ts
@@ -16,6 +16,7 @@ export type EffectDescription = {
export type EffectUpdateProps = {
isEnabled: boolean;
isConfigActive: boolean;
+ isJsonEditorActive: boolean;
// effect specific parameters for a deck.gl effect (uniforms)
parameters: {[key: string]: any};
};
@@ -32,6 +33,7 @@ export interface Effect {
type: string;
isEnabled: boolean;
isConfigActive: boolean;
+ isJsonEditorActive: boolean;
// effect specific parameters for a deck.gl effect (uniforms)
parameters: {[key: string]: any};
deckEffect: any;
diff --git a/test/node/reducers/vis-state-test.js b/test/node/reducers/vis-state-test.js
index 2beb13acc..bee065d00 100644
--- a/test/node/reducers/vis-state-test.js
+++ b/test/node/reducers/vis-state-test.js
@@ -5552,6 +5552,7 @@ test('#VisStateUpdater -> updateEffect', t => {
let nextState = reducer(initialState, VisStateActions.addEffect({id: 'e_1'}));
nextState = reducer(nextState, VisStateActions.addEffect({}));
+ nextState = reducer(nextState, VisStateActions.addEffect({id: 'e_3'}));
const expectedEffect = {
id: 'e_1',
@@ -5567,9 +5568,19 @@ test('#VisStateUpdater -> updateEffect', t => {
cmpEffects(t, expectedEffect, nextState.effects[0], {id: true});
- // bad id, shouldn't fail
+ // non-existing id, shouldn't fail
nextState = reducer(nextState, VisStateActions.updateEffect('fake_id', {}));
+ // update effect id
+ nextState = reducer(nextState, VisStateActions.updateEffect('e_1', {id: 'e_2'}));
+ cmpEffects(t, {...expectedEffect, id: 'e_2'}, nextState.effects[0], {id: true});
+ t.equal(nextState.effectOrder[2], 'e_2', 'Effect id should be updated');
+
+ // update effect to an existing effect id
+ nextState = reducer(nextState, VisStateActions.updateEffect('e_2', {id: 'e_3'}));
+ cmpEffects(t, {...expectedEffect, id: 'e_2'}, nextState.effects[0], {id: true});
+ t.equal(nextState.effectOrder[2], 'e_2', "Effect id shouldn't be updated");
+
t.end();
});