Skip to content
Snippets Groups Projects
Unverified Commit 43ed85df authored by Jesse Devaney's avatar Jesse Devaney Committed by GitHub
Browse files

Fix pin maps unnecessarily filtering out null values (#44853)

* prevent pin maps from filtering out rows with null values

- since pin maps are just displaying where the data is by latitude and longitude, we do not need to filter the pin just because one of the rows is null.
- the metric column selection does not make sense for pins as they just represent that data through coordinates (no aggregations or values displayed), so we should not be filtering out any data just because it is null

* add unit test
parent 6d8f0779
No related branches found
No related tags found
No related merge requests found
......@@ -132,9 +132,13 @@ export default class PinMap extends Component {
]);
// only use points with numeric coordinates & metric
const validPoints = allPoints.map(
([lat, lng, metric]) => lat != null && lng != null && metric != null,
);
const validPoints = allPoints.map(([lat, lng, metric]) => {
if (settings["map.type"] === "pin") {
return lat != null && lng != null;
}
return lat != null && lng != null && metric != null;
});
const points = allPoints.filter((_, i) => validPoints[i]);
const updatedRows = rows.filter((_, i) => validPoints[i]);
......
import PinMap from "metabase/visualizations/components/PinMap";
describe("PinMap", () => {
it("should filter out rows with null values", () => {
it("should filter out rows with null values in either the lat, long, or metric column", () => {
const onUpdateWarnings = jest.fn();
const data = {
cols: ["lat", "lng", "metric"].map(name => ({ name })),
......@@ -28,4 +28,38 @@ describe("PinMap", () => {
"We filtered out 3 row(s) containing null values.",
]);
});
it("should filter out rows only if the lat or long values are null for pin maps", () => {
const onUpdateWarnings = jest.fn();
const data = {
cols: ["lat", "lng", "metric"].map(name => ({ name })),
rows: [
[null, 0, 0],
[0, null, 0],
[0, 0, null],
[1, 2, null],
[0, 0, 0],
],
};
const props = {
settings: {
"map.latitude_column": "lat",
"map.longitude_column": "lng",
"map.metric_column": "metric",
"map.type": "pin",
},
series: [{ data }],
onUpdateWarnings,
};
const { points } = new PinMap(props)._getPoints(props);
expect(points).toEqual([
[0, 0, null],
[1, 2, null],
[0, 0, 0],
]);
expect(onUpdateWarnings.mock.calls[0][0]).toEqual([
"We filtered out 2 row(s) containing null values.",
]);
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment