Skip to content

Commit

Permalink
onStateChange callback for range widget (#890)
Browse files Browse the repository at this point in the history
  • Loading branch information
padawannn authored Jul 22, 2024
1 parent 48a293a commit 256c497
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Not released

- onStateChange callback for range widget [#890](https://github.com/CartoDB/carto-react/pull/890)
- fix LegendWidget update logic for multiple legends case [#889](https://github.com/CartoDB/carto-react/pull/889)
- onStateChange callback for all widgets [#886](https://github.com/CartoDB/carto-react/pull/886)

Expand Down
15 changes: 14 additions & 1 deletion packages/react-widgets/src/widgets/RangeWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ function RangeWidget({
[column, filters]
);

const customOnStateChange = ({ state, data }) => {
if (!onStateChange) return;
if (!data) return onStateChange({ state });
return onStateChange({
state,
data: {
values: data,
min,
max
}
});
};

const {
data = { min: undefined, max: undefined },
isLoading,
Expand All @@ -75,7 +88,7 @@ function RangeWidget({
},
global,
onError,
onStateChange,
onStateChange: customOnStateChange,
attemptRemoteCalculation: _hasFeatureFlag(_FeatureFlags.REMOTE_WIDGETS)
});

Expand Down

0 comments on commit 256c497

Please sign in to comment.