Skip to content

Commit

Permalink
[fix] prevent second shadow effect (#2631)
Browse files Browse the repository at this point in the history
Signed-off-by: Ihor Dykhta <dikhta.igor@gmail.com>
Co-authored-by: Ilya Boyandin <iboyandin@foursquare.com>
  • Loading branch information
igorDykhta and ilyabo authored Sep 13, 2024
1 parent f8e7b41 commit 7e3ea28
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/reducers/src/vis-state-updaters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ import {
FILTER_VIEW_TYPES,
MAX_DEFAULT_TOOLTIPS,
DEFAULT_TEXT_LABEL,
COMPARE_TYPES
COMPARE_TYPES,
LIGHT_AND_SHADOW_EFFECT
} from '@kepler.gl/constants';
import {
pick_,
Expand Down Expand Up @@ -1436,6 +1437,14 @@ export const addEffectUpdater = (
state: VisState,
action: VisStateActions.AddEffectUpdaterAction
): VisState => {
if (
action.config?.type === LIGHT_AND_SHADOW_EFFECT.type &&
state.effects.some(effect => effect.type === LIGHT_AND_SHADOW_EFFECT.type)
) {
Console.warn(`Can't add more than one ${LIGHT_AND_SHADOW_EFFECT.name} effect`);
return state;
}

const newEffect = createEffect(action.config);

// collapse configurators for other effects
Expand Down
18 changes: 16 additions & 2 deletions test/node/reducers/vis-state-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ import {
LAYER_VIS_CONFIGS,
DEFAULT_TEXT_LABEL,
DEFAULT_COLOR_UI,
FILTER_VIEW_TYPES
FILTER_VIEW_TYPES,
LIGHT_AND_SHADOW_EFFECT
} from '@kepler.gl/constants';

const {ArcLayer, PointLayer, GeojsonLayer, LineLayer, TripLayer} = KeplerGlLayers;
Expand Down Expand Up @@ -5426,13 +5427,26 @@ test('#VisStateUpdater -> addEffect', t => {
nextState,
VisStateActions.addEffect({
id: 'e_shadow',
type: 'lightAndShadow',
type: LIGHT_AND_SHADOW_EFFECT.type,
parameters: {timestamp: 1689280466362, timezone: 'UTC'}
})
);

t.equal(nextState.effects.length, 2, 'should add second effect');

nextState = reducer(
nextState,
VisStateActions.addEffect({
type: LIGHT_AND_SHADOW_EFFECT.type
})
);

t.equal(
nextState.effects.length,
2,
`shouldn't add second ${LIGHT_AND_SHADOW_EFFECT.name} effect`
);

const expectedEffect2 = {
id: 'e_shadow',
type: 'lightAndShadow',
Expand Down

0 comments on commit 7e3ea28

Please sign in to comment.