Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#9697: fix spatial filter and widget connection issues #9781

Merged
merged 2 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions web/client/epics/widgetsbuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const initEditorOnNewChart = (action$, {getState = () => {}} = {}) => act
charts: [
{
chartId,
layer,
mahmoudadel54 marked this conversation as resolved.
Show resolved Hide resolved
legend: false,
cartesian: true,
traces: [
Expand Down
14 changes: 14 additions & 0 deletions 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 @@ -166,6 +178,8 @@ describe('Test the widgets reducer', () => {
expect(widgetObjects[3].layer).toEqual(newTargetLayer);
expect(widgetObjects[4].charts[0].layer).toEqual(newTargetLayer);
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
13 changes: 10 additions & 3 deletions web/client/reducers/widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,16 @@ 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 = get(chart, "layer.id") === action.layer.id ? set("layer", action.layer, chart) : chart;
mahmoudadel54 marked this conversation as resolved.
Show resolved Hide resolved
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
Loading