Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Fix zoom and hover on map while editing (#64174)

Romeo Van Snickfa2820320e48
diff --git a/e2e/test/scenarios/dashboard/dashboard-reproductions.cy.spec.js b/e2e/test/scenarios/dashboard/dashboard-reproductions.cy.spec.js
index 18d3c785624..25265f33909 100644
--- a/e2e/test/scenarios/dashboard/dashboard-reproductions.cy.spec.js
+++ b/e2e/test/scenarios/dashboard/dashboard-reproductions.cy.spec.js
@@ -2204,3 +2204,60 @@ describe("issue 63176", () => {
});
});
});
+
+describe("issue 64138", () => {
+ const MAP_QUESTION = {
+ query: {
+ "source-table": PEOPLE_ID,
+ },
+
+ display: "map",
+ displayIsLocked: true,
+ visualization_settings: {
+ "map.type": "pin",
+ "map.pin_type": "markers",
+ },
+ };
+
+ beforeEach(() => {
+ H.restore();
+ cy.signInAsNormalUser();
+
+ H.createQuestionAndDashboard({
+ questionDetails: MAP_QUESTION,
+ }).then(({ body: { dashboard_id } }) => {
+ H.visitDashboard(dashboard_id);
+ });
+ });
+
+ it("should hide map controls when editing dashboard (metabase#64138)", () => {
+ H.editDashboard();
+
+ cy.log("hovering the map should not show the zoom controls");
+ H.getDashboardCard(0)
+ .realHover({
+ position: "center",
+ })
+ .within(() => {
+ cy.findByLabelText("Zoom in").should("not.exist");
+ cy.findByText("Set as default view").should("be.visible").click();
+ });
+
+ cy.log("hovering marker icons should not open their tooltips");
+ getMarkerIcon(0).realHover();
+ H.popover({ skipVisibilityCheck: true }).should("not.exist");
+
+ cy.log("clicking marker icons should not navigate to the question");
+ getMarkerIcon(0).click({ force: true });
+ cy.location("pathname").should("match", /^\/dashboard\/[0-9]+$/);
+ H.modal().should("not.exist");
+ });
+
+ function getMarkerIcon(index) {
+ // pick the last one so it will be on top
+ return H.getDashboardCard(index)
+ .get(".leaflet-marker-icon")
+ .should("have.length.gt", 0)
+ .last();
+ }
+});
diff --git a/frontend/src/metabase/visualizations/components/LeafletMap.jsx b/frontend/src/metabase/visualizations/components/LeafletMap.jsx
index 76c246a333c..17ed113cc71 100644
--- a/frontend/src/metabase/visualizations/components/LeafletMap.jsx
+++ b/frontend/src/metabase/visualizations/components/LeafletMap.jsx
@@ -84,7 +84,14 @@ export default class LeafletMap extends Component {
}
componentDidUpdate(prevProps) {
- const { bounds, settings } = this.props;
+ const { bounds, settings, zoomControl } = this.props;
+
+ if (zoomControl === false) {
+ this.map.removeControl(this.map.zoomControl);
+ } else {
+ this.map.addControl(this.map.zoomControl);
+ }
+
if (
!prevProps ||
prevProps.points !== this.props.points ||
diff --git a/frontend/src/metabase/visualizations/components/LeafletMarkerPinMap.jsx b/frontend/src/metabase/visualizations/components/LeafletMarkerPinMap.jsx
index 6acf4aa4d00..60377b919bf 100644
--- a/frontend/src/metabase/visualizations/components/LeafletMarkerPinMap.jsx
+++ b/frontend/src/metabase/visualizations/components/LeafletMarkerPinMap.jsx
@@ -98,57 +98,64 @@ export default class LeafletMarkerPinMap extends LeafletMap {
_createMarker = (rowIndex) => {
const marker = L.marker([0, 0], { icon: this.pinMarkerIcon });
- const { onHoverChange, onVisualizationClick, settings } = this.props;
- if (onHoverChange) {
- marker.on("mousemove", (e) => {
- const {
- series: [
- {
- data: { cols, rows },
- },
- ],
- } = this.props;
- const hover = {
- dimensions: cols.map((col, colIndex) => ({
- value: rows[rowIndex][colIndex],
- column: col,
- })),
- element: marker._icon,
- };
- onHoverChange(hover);
- });
- marker.on("mouseout", () => {
- onHoverChange(null);
- });
- }
- if (onVisualizationClick) {
- marker.on("click", () => {
- const {
- series: [
- {
- data: { cols, rows },
- },
- ],
- } = this.props;
- // if there is a primary key then associate a pin with it
- const pkIndex = _.findIndex(cols, isPK);
- const hasPk = pkIndex >= 0;
-
- const data = cols.map((col, index) => ({
- col,
- value: rows[rowIndex][index],
- }));
-
- onVisualizationClick({
- value: hasPk ? rows[rowIndex][pkIndex] : null,
- column: hasPk ? cols[pkIndex] : null,
- element: marker._icon,
- origin: { row: rows[rowIndex], cols },
- settings,
- data,
- });
+ marker.on("mousemove", () => {
+ const { onHoverChange } = this.props;
+ if (!onHoverChange) {
+ return;
+ }
+ const {
+ series: [
+ {
+ data: { cols, rows },
+ },
+ ],
+ } = this.props;
+ const hover = {
+ dimensions: cols.map((col, colIndex) => ({
+ value: rows[rowIndex][colIndex],
+ column: col,
+ })),
+ element: marker._icon,
+ };
+ onHoverChange(hover);
+ });
+
+ marker.on("mouseout", () => {
+ const { onHoverChange } = this.props;
+ onHoverChange?.(null);
+ });
+
+ marker.on("click", () => {
+ const { onVisualizationClick, settings } = this.props;
+ if (!onVisualizationClick) {
+ return;
+ }
+ const {
+ series: [
+ {
+ data: { cols, rows },
+ },
+ ],
+ } = this.props;
+ // if there is a primary key then associate a pin with it
+ const pkIndex = _.findIndex(cols, isPK);
+ const hasPk = pkIndex >= 0;
+
+ const data = cols.map((col, index) => ({
+ col,
+ value: rows[rowIndex][index],
+ }));
+
+ onVisualizationClick({
+ value: hasPk ? rows[rowIndex][pkIndex] : null,
+ column: hasPk ? cols[pkIndex] : null,
+ element: marker._icon,
+ origin: { row: rows[rowIndex], cols },
+ settings,
+ data,
});
- }
+ });
+
return marker;
};
}
diff --git a/frontend/src/metabase/visualizations/components/PinMap.jsx b/frontend/src/metabase/visualizations/components/PinMap.jsx
index 79cf77c42a2..405171f4b04 100644
--- a/frontend/src/metabase/visualizations/components/PinMap.jsx
+++ b/frontend/src/metabase/visualizations/components/PinMap.jsx
@@ -226,6 +226,13 @@ export default class PinMap extends Component {
binWidth={binWidth}
binHeight={binHeight}
onFiltering={(filtering) => this.setState({ filtering })}
+ zoomControl={!isEditing}
+ onHoverChange={
+ isDashboard && isEditing ? null : mapProps.onHoverChange
+ }
+ onVisualizationClick={
+ isDashboard && isEditing ? null : mapProps.onVisualizationClick
+ }
/>
) : null}
<div
diff --git a/frontend/src/metabase/visualizations/components/PinMap.module.css b/frontend/src/metabase/visualizations/components/PinMap.module.css
index ffbcc7f6255..3fcd7abbef2 100644
--- a/frontend/src/metabase/visualizations/components/PinMap.module.css
+++ b/frontend/src/metabase/visualizations/components/PinMap.module.css
@@ -1,4 +1,5 @@
.pinMapButton {
opacity: 0.9;
margin-bottom: 0.5rem;
+ pointer-events: all;
}
diff --git a/frontend/src/metabase/visualizations/visualizations/Map/Map.jsx b/frontend/src/metabase/visualizations/visualizations/Map/Map.jsx
index 6a3591fedc2..08ce8607594 100644
--- a/frontend/src/metabase/visualizations/visualizations/Map/Map.jsx
+++ b/frontend/src/metabase/visualizations/visualizations/Map/Map.jsx
@@ -309,7 +309,8 @@ export class Map extends Component {
this.props.width === nextProps.width &&
this.props.height === nextProps.height;
const sameSeries = isSameSeries(this.props.series, nextProps.series);
- return !(sameSize && sameSeries);
+ const sameIsEditing = this.props.isEditing === nextProps.isEditing;
+ return !(sameSize && sameSeries && sameIsEditing);
}
render() {