Skip to content

Commit

Permalink
#9697: fix spatial filter and widget connection issues (#9781)
Browse files Browse the repository at this point in the history
* #9697: fix spatial filter and widget connection issues
* Description:
- Fix issue of not filtering chart widget if there is a spatial filter and user clicks on disable layer filter icon in TOC to show/hide spatial filter
- Fix issue of not showing empty content in chart widget or 0 number in counter widget if extent not includes any features
- write req. unit tests

* #9697: fix spatial filter and widget connection issues
Description:
- Resolve review comments
  • Loading branch information
mahmoudadel54 authored Dec 14, 2023
1 parent bb31d41 commit e45def9
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,9 @@ describe('widgets emptyChartState enhancer', () => {
ReactDOM.render(<Dummy data={[]}/>, document.getElementById("container"));
expect(document.querySelector(".ms-widget-empty-message")).toExist();
});
it("should render empty chart state in case of data has empty arr item", () => {
const Dummy = emptyChartState(() => <div id="dummy"></div>);
ReactDOM.render(<Dummy data={[[]]}/>, document.getElementById("container"));
expect(document.querySelector(".ms-widget-empty-message")).toExist();
});
});
2 changes: 1 addition & 1 deletion web/client/components/widgets/enhancers/emptyChartState.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import emptyState from '../../misc/enhancers/emptyState';
import WidgetEmptyMessage from '../widget/WidgetEmptyMessage';

export default emptyState(
({data = []}) => !data || data.length === 0,
({data = []}) => !data || data.length === 0 || data?.flat()?.length === 0,
({mapSync, iconFit} = {}) => ({
iconFit,
messageId: mapSync ? "widgets.errors.nodatainviewport" : "widgets.errors.nodata",
Expand Down
2 changes: 1 addition & 1 deletion web/client/components/widgets/widget/CounterView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const CounterView = enhanceCounter(({
const renderCounter = ({ dataKey } = {}, i) => (<Counter
key={dataKey}
uom={get(options, `seriesOptions[${i}].uom`)}
value={data[0][dataKey]}
value={data[0][dataKey] || 0}
counterOpts={counterOpts}
formula={formula}
style={{ textAlign: "center", ...style }}
Expand Down
16 changes: 15 additions & 1 deletion web/client/reducers/__tests__/widgets-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,18 @@ describe('Test the widgets reducer', () => {
name: "layer3",
id: "3"
}
}, {
layer: {
visibility: false,
name: "layer3",
id: "3"
}, traces: [{
layer: {
visibility: false,
name: "layer3",
id: "3"
}, id: "traceId"
}]
}
]
}]
Expand All @@ -164,8 +176,10 @@ describe('Test the widgets reducer', () => {
expect(widgetObjects[1].layer).toEqual(newTargetLayer);
expect(widgetObjects[2].layer).toEqual(state.containers[DEFAULT_TARGET].widgets[2].layer);
expect(widgetObjects[3].layer).toEqual(newTargetLayer);
expect(widgetObjects[4].charts[0].layer).toEqual(newTargetLayer);
expect(widgetObjects[4].charts[0].layer.id).toEqual(newTargetLayer.id);
expect(widgetObjects[4].charts[1].layer).toEqual(state.containers[DEFAULT_TARGET].widgets[4].charts[1].layer);
expect(widgetObjects[4].charts[2].layer).toEqual(state.containers[DEFAULT_TARGET].widgets[4].charts[1].layer);
expect(widgetObjects[4].charts[2].traces[0].layer).toEqual(state.containers[DEFAULT_TARGET].widgets[4].charts[2].traces[0].layer);
});
it('deleteWidget', () => {
const state = {
Expand Down
12 changes: 9 additions & 3 deletions web/client/reducers/widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,15 @@ function widgetsReducer(state = emptyState, action) {
// every chart stores the layer object configuration
// so we need to loop around them to update correctly the layer properties
// including the layerFilter
return set("charts", w.charts.map((chart) =>
get(chart, "layer.id") === action.layer.id ? set("layer", action.layer, chart) : chart
), w);
let chartsCopy = w?.charts?.length ? [...w.charts] : [];
chartsCopy = chartsCopy.map(chart=>{
let chartItem = {...chart};
chartItem.traces = chartItem?.traces?.map(trace=>
get(trace, "layer.id") === action.layer.id ? set("layer", action.layer, trace) : trace
);
return chartItem;
});
return set("charts", chartsCopy, w);
}
return get(w, "layer.id") === action.layer.id ? set("layer", action.layer, w) : w;
}), state);
Expand Down

0 comments on commit e45def9

Please sign in to comment.