The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
disable comments in an iframe (#64098)
Oleksandr Solovyov7ff28228118e
diff --git a/.clj-kondo/config/modules/config.edn b/.clj-kondo/config/modules/config.ednindex c6fbe42c077..2f3d34a2bbb 100644--- a/.clj-kondo/config/modules/config.edn+++ b/.clj-kondo/config/modules/config.edn@@ -1655,7 +1655,8 @@{:team "Workflows":api #{metabase-enterprise.comments.apimetabase-enterprise.comments.init}- :uses #{api+ :uses #{analytics+ apichanneleventsmodelsdiff --git a/e2e/support/helpers/e2e-document-helpers.ts b/e2e/support/helpers/e2e-document-helpers.tsindex 029e507f3f2..0a1640c6c85 100644--- a/e2e/support/helpers/e2e-document-helpers.ts+++ b/e2e/support/helpers/e2e-document-helpers.ts@@ -235,3 +235,58 @@ export function getFlexContainerForCard(name: string) {export function getResizeHandlesForFlexContianer(element: Cypress.Chainable) {return element.findAllByTestId("flex-container-drag-handle");}++// Document nodes+export function getHeading1(name = "Heading 1") {+ return documentContent().findByRole("heading", {+ name,+ level: 1,+ });+}++export function getHeading2(name = "Heading 2") {+ return documentContent().findByRole("heading", {+ name,+ level: 2,+ });+}++export function getHeading3(name = "Heading 3") {+ return documentContent().findByRole("heading", {+ name,+ level: 3,+ });+}++export function getParagraph(text = "Lorem ipsum dolor sit amet.") {+ return documentContent().findByText(text).parent();+}++export function getBulletList(+ text = "Bullet A",+ container = documentContent(),+) {+ return container.findByText(text).closest("ul");+}++export function getBlockquote(+ text = "A famous quote",+ container = documentContent(),+) {+ return container.findByText(text).closest("blockquote");+}++export function getOrderedList(text = "Item 1", container = documentContent()) {+ return container.findByText(text).closest("ol");+}++export function getCodeBlock(+ text = "while (true) {}",+ container = documentContent(),+) {+ return container.findByText(text).closest("pre");+}++export function getEmbed() {+ return documentContent().findByTestId("document-card-embed");+}diff --git a/e2e/test/scenarios/documents/comments.cy.spec.ts b/e2e/test/scenarios/documents/comments.cy.spec.tsindex fe86173fab5..7903051e010 100644--- a/e2e/test/scenarios/documents/comments.cy.spec.ts+++ b/e2e/test/scenarios/documents/comments.cy.spec.ts@@ -42,15 +42,15 @@ H.describeWithSnowplowEE("document comments", () => {cy.findByRole("link", { name: "All comments" }).should("not.exist");cy.get<DocumentId>("@documentId").then((documentId) => {- testCommentingOnNode(documentId, HEADING_1_ID, getHeading1);- testCommentingOnNode(documentId, HEADING_2_ID, getHeading2);- testCommentingOnNode(documentId, HEADING_3_ID, getHeading3);- testCommentingOnNode(documentId, PARAGRAPH_ID, getParagraph);- testCommentingOnNode(documentId, BULLET_LIST_ID, getBulletList);- testCommentingOnNode(documentId, BLOCKQUOTE_ID, getBlockquote);- testCommentingOnNode(documentId, ORDERED_LIST_ID, getOrderedList);- testCommentingOnNode(documentId, CODE_BLOCK_ID, getCodeBlock);- testCommentingOnNode(documentId, CARD_EMBED_ID, getEmbed, {+ testCommentingOnNode(documentId, HEADING_1_ID, H.getHeading1);+ testCommentingOnNode(documentId, HEADING_2_ID, H.getHeading2);+ testCommentingOnNode(documentId, HEADING_3_ID, H.getHeading3);+ testCommentingOnNode(documentId, PARAGRAPH_ID, H.getParagraph);+ testCommentingOnNode(documentId, BULLET_LIST_ID, H.getBulletList);+ testCommentingOnNode(documentId, BLOCKQUOTE_ID, H.getBlockquote);+ testCommentingOnNode(documentId, ORDERED_LIST_ID, H.getOrderedList);+ testCommentingOnNode(documentId, CODE_BLOCK_ID, H.getCodeBlock);+ testCommentingOnNode(documentId, CARD_EMBED_ID, H.getEmbed, {isCardEmbedNode: true,});});@@ -155,7 +155,7 @@ H.describeWithSnowplowEE("document comments", () => {Comments.getDocumentNodeButtons().filter(":visible").should("have.length", 1);- getParagraph("lor sit amet.").realHover();+ H.getParagraph("lor sit amet.").realHover();Comments.getDocumentNodeButtons().filter(":visible").should("have.length", 2)@@ -600,7 +600,7 @@ H.describeWithSnowplowEE("document comments", () => {.should("be.visible").and("have.value", "Lorem ipsum");- getParagraph().realHover();+ H.getParagraph().realHover();Comments.getDocumentNodeButton({targetId: documentId,childTargetId: PARAGRAPH_ID,@@ -612,7 +612,7 @@ H.describeWithSnowplowEE("document comments", () => {H.documentContent().click();cy.realType("xyz");- getParagraph("Lorem ipsum dolor sit amet.xyz").realHover();+ H.getParagraph("Lorem ipsum dolor sit amet.xyz").realHover();cy.findByLabelText("Comments").should("not.be.disabled").click();Comments.getSidebar().should("be.visible");@@ -1270,11 +1270,15 @@ H.describeWithSnowplowEE("document comments", () => {cy.log("verify blockquote is rendered during typing");cy.realType("> blockquote");- getBlockquote("blockquote", Comments.getSidebar()).should("be.visible");+ H.getBlockquote("blockquote", Comments.getSidebar()).should(+ "be.visible",+ );cy.log("verify blockquote is rendered after submitting");cy.realPress([META_KEY, "Enter"]);- getBlockquote("blockquote", Comments.getSidebar()).should("be.visible");+ H.getBlockquote("blockquote", Comments.getSidebar()).should(+ "be.visible",+ );});it("should support ordered lists", () => {@@ -1284,14 +1288,14 @@ H.describeWithSnowplowEE("document comments", () => {cy.realPress("Enter");cy.realType("two");cy.log("verify ordered list is rendered during typing");- getOrderedList("one", Comments.getSidebar()).should("be.visible");- getOrderedList("two", Comments.getSidebar()).should("be.visible");+ H.getOrderedList("one", Comments.getSidebar()).should("be.visible");+ H.getOrderedList("two", Comments.getSidebar()).should("be.visible");cy.log("verify ordered list is rendered after submitting");cy.realPress([META_KEY, "Enter"]);- getOrderedList("one", Comments.getSidebar()).should("be.visible");- getOrderedList("two", Comments.getSidebar()).should("be.visible");+ H.getOrderedList("one", Comments.getSidebar()).should("be.visible");+ H.getOrderedList("two", Comments.getSidebar()).should("be.visible");});it("should support unordered lists", () => {@@ -1301,14 +1305,14 @@ H.describeWithSnowplowEE("document comments", () => {cy.realPress("Enter");cy.realType("b");cy.log("verify bullet list is rendered during typing");- getBulletList("a", Comments.getSidebar()).should("be.visible");- getBulletList("b", Comments.getSidebar()).should("be.visible");+ H.getBulletList("a", Comments.getSidebar()).should("be.visible");+ H.getBulletList("b", Comments.getSidebar()).should("be.visible");cy.log("verify bullet list is rendered after submitting");cy.realPress([META_KEY, "Enter"]);- getBulletList("a", Comments.getSidebar()).should("be.visible");- getBulletList("b", Comments.getSidebar()).should("be.visible");+ H.getBulletList("a", Comments.getSidebar()).should("be.visible");+ H.getBulletList("b", Comments.getSidebar()).should("be.visible");});it("should support code blocks", () => {@@ -1318,12 +1322,12 @@ H.describeWithSnowplowEE("document comments", () => {cy.realPress("Enter");cy.log("verify code block is rendered during typing");cy.realType("code");- getCodeBlock("code", Comments.getSidebar()).should("be.visible");+ H.getCodeBlock("code", Comments.getSidebar()).should("be.visible");cy.log("verify code block is rendered after submitting");cy.realPress([META_KEY, "Enter"]);- getCodeBlock("code", Comments.getSidebar()).should("be.visible");+ H.getCodeBlock("code", Comments.getSidebar()).should("be.visible");});});@@ -1334,7 +1338,7 @@ H.describeWithSnowplowEE("document comments", () => {cy.realType("ol");cy.realPress([META_KEY, "Shift", "7"]);- getOrderedList("ol", Comments.getSidebar()).should("be.visible");+ H.getOrderedList("ol", Comments.getSidebar()).should("be.visible");});it("should support bullet list", () => {@@ -1343,7 +1347,7 @@ H.describeWithSnowplowEE("document comments", () => {cy.realType("ul");cy.realPress([META_KEY, "Shift", "8"]);- getBulletList("ul", Comments.getSidebar()).should("be.visible");+ H.getBulletList("ul", Comments.getSidebar()).should("be.visible");});it("should support code block", () => {@@ -1352,7 +1356,7 @@ H.describeWithSnowplowEE("document comments", () => {cy.realType("code");cy.realPress([META_KEY, "Alt", "c"]);- getCodeBlock("code", Comments.getSidebar()).should("be.visible");+ H.getCodeBlock("code", Comments.getSidebar()).should("be.visible");});// explicitly disabled in CustomStarterKit to keep default browser behavior@@ -1362,7 +1366,9 @@ H.describeWithSnowplowEE("document comments", () => {cy.realType("blockquote");cy.realPress([META_KEY, "Shift", "k"]);- getBlockquote("blockquote", Comments.getSidebar()).should("be.visible");+ H.getBlockquote("blockquote", Comments.getSidebar()).should(+ "be.visible",+ );});});@@ -1389,10 +1395,10 @@ H.describeWithSnowplowEE("document comments", () => {cy.reload();- getBlockquote("blockquote", Comments.getSidebar()).should("be.visible");- getOrderedList("ol", Comments.getSidebar()).should("be.visible");- getBulletList("ul", Comments.getSidebar()).should("be.visible");- getCodeBlock("code", Comments.getSidebar()).should("be.visible");+ H.getBlockquote("blockquote", Comments.getSidebar()).should("be.visible");+ H.getOrderedList("ol", Comments.getSidebar()).should("be.visible");+ H.getBulletList("ul", Comments.getSidebar()).should("be.visible");+ H.getCodeBlock("code", Comments.getSidebar()).should("be.visible");});});@@ -1579,7 +1585,7 @@ function selectCharactersLeft(count: number) {function startNewCommentIn1ParagraphDocument() {createAndVisit1ParagraphDocument();- getParagraph().realHover();+ H.getParagraph().realHover();cy.get<DocumentId>("@documentId").then((targetId) => {Comments.getDocumentNodeButton({@@ -1911,57 +1917,6 @@ function createComment(});}-function getHeading1(name = "Heading 1") {- return H.documentContent().findByRole("heading", {- name,- level: 1,- });-}--function getHeading2(name = "Heading 2") {- return H.documentContent().findByRole("heading", {- name,- level: 2,- });-}--function getHeading3(name = "Heading 3") {- return H.documentContent().findByRole("heading", {- name,- level: 3,- });-}--function getParagraph(text = "Lorem ipsum dolor sit amet.") {- return H.documentContent().findByText(text).parent();-}--function getBulletList(text = "Bullet A", container = H.documentContent()) {- return container.findByText(text).closest("ul");-}--function getBlockquote(- text = "A famous quote",- container = H.documentContent(),-) {- return container.findByText(text).closest("blockquote");-}--function getOrderedList(text = "Item 1", container = H.documentContent()) {- return container.findByText(text).closest("ol");-}--function getCodeBlock(- text = "while (true) {}",- container = H.documentContent(),-) {- return container.findByText(text).closest("pre");-}--function getEmbed() {- return H.documentContent().findByTestId("document-card-embed");-}-function verifyEmail({email,expected,diff --git a/e2e/test/scenarios/embedding/interactive-embedding.cy.spec.js b/e2e/test/scenarios/embedding/interactive-embedding.cy.spec.jsindex 5be337cc704..3434889bf0e 100644--- a/e2e/test/scenarios/embedding/interactive-embedding.cy.spec.js+++ b/e2e/test/scenarios/embedding/interactive-embedding.cy.spec.js@@ -9,6 +9,7 @@ import {SECOND_COLLECTION_ID,THIRD_COLLECTION_ID,} from "e2e/support/cypress_sample_instance_data";+import { uuid } from "metabase/lib/uuid";import {createMockDashboardCard,createMockTextDashboardCard,@@ -1707,6 +1708,75 @@ describe("scenarios > embedding > full app", () => {cy.button("Save this").should("not.exist");});});++ describe("documents > comments", () => {+ it("should not display comments in an embedded app", () => {+ H.activateToken("bleeding-edge");+ const DOCUMENT_ID = 1;+ const PARAGRAPH_ID = "b7fa322a-964e-d668-8d30-c772ef4f0022";++ H.createDocument({+ idAlias: "documentId",+ name: "Lorem ipsum",+ document: {+ type: "doc",+ content: [+ {+ type: "paragraph",+ attrs: {+ _id: PARAGRAPH_ID,+ },+ content: [+ {+ type: "text",+ text: "Lorem ipsum dolor sit amet.",+ },+ ],+ },+ ],+ },+ });+ H.createComment({+ target_type: "document",+ target_id: DOCUMENT_ID,+ child_target_id: PARAGRAPH_ID,+ parent_comment_id: null,+ content: {+ type: "doc",+ content: [+ {+ type: "paragraph",+ attrs: { _id: uuid() },+ content: [{ type: "text", text: "Test comment" }],+ },+ ],+ },+ html: "<p>Test comment</p>",+ });++ cy.intercept({+ method: "GET",+ path: "/api/ee/document/*",+ }).as("documentGet");++ cy.intercept({+ method: "GET",+ path: "/api/ee/comment/*",+ }).as("commentGet");++ H.visitFullAppEmbeddingUrl({+ url: `/document/${DOCUMENT_ID}`,+ });++ cy.wait("@documentGet");++ cy.findByLabelText("Show all comments").should("not.exist");++ cy.findAllByRole("link", { name: "Comments" }).should("not.exist");++ cy.get("@commentGet.all").should("have.length", 0);+ });+ });});describe("scenarios > embedding > full app - jwt sso integration", () => {diff --git a/enterprise/backend/src/metabase_enterprise/comments/api.clj b/enterprise/backend/src/metabase_enterprise/comments/api.cljindex 3e0ef9072e5..f52b343ec69 100644--- a/enterprise/backend/src/metabase_enterprise/comments/api.clj+++ b/enterprise/backend/src/metabase_enterprise/comments/api.clj@@ -4,6 +4,7 @@[honey.sql.helpers :as sql.helpers][metabase-enterprise.comments.models.comment :as comment][metabase-enterprise.comments.models.comment-reaction :as comment-reaction]+ [metabase.analytics.core :as analytics][metabase.api.common :as api][metabase.api.macros :as api.macros][metabase.api.routes.common :refer [+auth]]@@ -91,15 +92,20 @@[_route-params{:keys [target_type target_id]} :- [:map[:target_type [:enum "document"]]- [:target_id ms/PositiveInt]]]- (let [_entity (api/read-check (TYPE->MODEL target_type) target_id)- comments (-> (t2/select :model/Comment- {:where [:and- [:= :target_type target_type]- [:= :target_id target_id]]- :order-by [[:created_at :asc]]})- (t2/hydrate :creator :reactions))]- {:comments (render-comments comments)}))+ [:target_id ms/PositiveInt]]+ _body+ req]+ (if (analytics/embedding-context? (get-in req [:headers "x-metabase-client"]))+ {:disabled true+ :comments []}+ (let [_entity (api/read-check (TYPE->MODEL target_type) target_id)+ comments (-> (t2/select :model/Comment+ {:where [:and+ [:= :target_type target_type]+ [:= :target_id target_id]]+ :order-by [[:created_at :asc]]})+ (t2/hydrate :creator :reactions))]+ {:comments (render-comments comments)})))(defn notify-comment!"Send a notification about comment"@@ -241,7 +247,10 @@(api.macros/defendpoint :get "/mentions""Get a list of entities suitable for mentions. NOTE: only users for now."- [_route-params _query-params]+ [_route _query _body req]+ ;; no access in embedding context+ (api/check-404 (not (analytics/embedding-context? (get-in req [:headers "x-metabase-client"]))))+(let [clauses (user/filter-clauses nil nil nil nil {:limit (request/limit):offset (request/offset)})];; returns nothing while we're trying to figure out how do we deal with sandboxes and tenants etcdiff --git a/enterprise/backend/test/metabase_enterprise/comments/api_test.clj b/enterprise/backend/test/metabase_enterprise/comments/api_test.cljindex c59accdf8fb..bb12000e4d8 100644--- a/enterprise/backend/test/metabase_enterprise/comments/api_test.clj+++ b/enterprise/backend/test/metabase_enterprise/comments/api_test.clj@@ -5,6 +5,7 @@[clojure.string :as str][clojure.test :refer :all][metabase-enterprise.test :as met]+ [metabase.analytics.sdk :as sdk][metabase.notification.seed :as notification.seed][metabase.test :as mt][metabase.util :as u]@@ -315,3 +316,23 @@:limit 50:offset 0}(mt/user-http-request :rasta :get 200 "ee/comment/mentions" :limit 50))))))++(deftest iframe-comments-test+ (testing "comments are disabled inside of an iframe"+ (mt/with-temp [:model/Document {doc-id :id} {}+ :model/Comment {comment-id :id} {:target_id doc-id}]+ (testing "Comments are not shown if in iframe"+ (is (=? {:comments [{:id comment-id}]}+ (mt/user-http-request :rasta :get 200 (str "ee/comment/")+ :target_type "document"+ :target_id doc-id)))+ (is (=? {:comments []+ :disabled true}+ (mt/user-http-request :rasta :get 200 (str "ee/comment/")+ {:request-options {:headers {"x-metabase-client" @#'sdk/embedding-iframe-client}}}+ :target_type "document"+ :target_id doc-id))))+ (testing "Users mentions are not available either"+ (is (= "Not found."+ (mt/user-http-request :rasta :get 404 (str "ee/comment/mentions")+ {:request-options {:headers {"x-metabase-client" @#'sdk/embedding-iframe-client}}})))))))diff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentHeader.tsx b/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentHeader.tsxindex 0a3e35e6e65..346ab2b7044 100644--- a/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentHeader.tsx+++ b/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentHeader.tsx@@ -5,6 +5,7 @@ import { t } from "ttag";import DateTime, {getFormattedTime,} from "metabase/common/components/DateTime";+import { isWithinIframe } from "metabase/lib/dom";import {ActionIcon,Box,@@ -131,7 +132,7 @@ export const DocumentHeader = ({</Box>)}</Transition>- {!isNewDocument && hasComments && (+ {!isNewDocument && hasComments && !isWithinIframe() && (<Tooltip label={t`Show all comments`}><Box>{document && (diff --git a/enterprise/frontend/src/metabase-enterprise/documents/utils/api.ts b/enterprise/frontend/src/metabase-enterprise/documents/utils/api.tsindex 209f162a753..5b3a1ff664d 100644--- a/enterprise/frontend/src/metabase-enterprise/documents/utils/api.ts+++ b/enterprise/frontend/src/metabase-enterprise/documents/utils/api.ts@@ -1,12 +1,13 @@import type { SkipToken } from "@reduxjs/toolkit/query";import { skipToken } from "metabase/api";+import { isWithinIframe } from "metabase/lib/dom";import type { Document, ListCommentsRequest } from "metabase-types/api";export function getListCommentsQuery(document: Document | null | undefined,): ListCommentsRequest | SkipToken {- if (!document) {+ if (!document || isWithinIframe()) {return skipToken;}diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Blockquote/Blockquote.tsx b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Blockquote/Blockquote.tsxindex 752c7534522..657a6db21f8 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Blockquote/Blockquote.tsx+++ b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Blockquote/Blockquote.tsx@@ -9,6 +9,7 @@ import {import cx from "classnames";import { useEffect, useMemo, useState } from "react";+import { isWithinIframe } from "metabase/lib/dom";import { useSelector } from "metabase/lib/redux";import { useListCommentsQuery } from "metabase-enterprise/api";import { getTargetChildCommentThreads } from "metabase-enterprise/comments/utils";@@ -87,7 +88,7 @@ export const BlockquoteNodeView = ({ node }: NodeViewProps) => {<NodeViewContent<"blockquote"> as="blockquote" /></NodeViewWrapper>- {document && rendered && (+ {document && rendered && !isWithinIframe() && (<CommentsMenuactive={isOpen}href={`/document/${document.id}/comments/${_id}`}diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/BulletList/BulletList.tsx b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/BulletList/BulletList.tsxindex 1afb0cd8f20..99c9ca8fa2b 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/BulletList/BulletList.tsx+++ b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/BulletList/BulletList.tsx@@ -9,6 +9,7 @@ import {import cx from "classnames";import { useEffect, useMemo, useState } from "react";+import { isWithinIframe } from "metabase/lib/dom";import { useSelector } from "metabase/lib/redux";import { useListCommentsQuery } from "metabase-enterprise/api";import { getTargetChildCommentThreads } from "metabase-enterprise/comments/utils";@@ -85,16 +86,19 @@ export const BulletListNodeView = ({ node, editor, getPos }: NodeViewProps) => {<NodeViewContent<"ul"> as="ul" /></NodeViewWrapper>- {document && rendered && isTopLevel({ editor, getPos }) && (- <CommentsMenu- active={isOpen}- href={`/document/${document.id}/comments/${_id}`}- ref={refs.setFloating}- show={isOpen || hovered}- threads={threads}- style={floatingStyles}- />- )}+ {document &&+ rendered &&+ isTopLevel({ editor, getPos }) &&+ !isWithinIframe() && (+ <CommentsMenu+ active={isOpen}+ href={`/document/${document.id}/comments/${_id}`}+ ref={refs.setFloating}+ show={isOpen || hovered}+ threads={threads}+ style={floatingStyles}+ />+ )}</>);};diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedNode.tsx b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedNode.tsxindex 7bac5a832cf..2214957a5eb 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedNode.tsx+++ b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedNode.tsx@@ -14,6 +14,7 @@ import { Ellipsified } from "metabase/common/components/Ellipsified";import { ForwardRefLink } from "metabase/common/components/Link";import { QuestionPickerModal } from "metabase/common/components/Pickers/QuestionPicker/components/QuestionPickerModal";import type { QuestionPickerValueItem } from "metabase/common/components/Pickers/QuestionPicker/types";+import { isWithinIframe } from "metabase/lib/dom";import { useDispatch, useSelector } from "metabase/lib/redux";import { getMetadata } from "metabase/selectors/metadata";import { Box, Flex, Icon, Loader, Menu, Text, TextInput } from "metabase/ui";@@ -646,26 +647,28 @@ export const CardEmbedComponent = memo(</Flex></Menu.Target><Menu.Dropdown>- <Menu.Item- leftSection={<Icon name="add_comment" size={14} />}- component={ForwardRefLink}- to={- // If no existing unresolved comments comments, add query param to auto-open new comment form- unresolvedCommentsCount > 0- ? commentsPath- : `${commentsPath}?new=true`- }- // actually stop the navigation from happening- onClick={(e) => {- if (!commentsPath || hasUnsavedChanges) {- e.preventDefault();+ {!isWithinIframe() && (+ <Menu.Item+ leftSection={<Icon name="add_comment" size={14} />}+ component={ForwardRefLink}+ to={+ // If no existing unresolved comments comments, add query param to auto-open new comment form+ unresolvedCommentsCount > 0+ ? commentsPath+ : `${commentsPath}?new=true`}- }}- // purely for presentation- disabled={!commentsPath || hasUnsavedChanges}- >- {t`Comment`}- </Menu.Item>+ // actually stop the navigation from happening+ onClick={(e) => {+ if (!commentsPath || hasUnsavedChanges) {+ e.preventDefault();+ }+ }}+ // purely for presentation+ disabled={!commentsPath || hasUnsavedChanges}+ >+ {t`Comment`}+ </Menu.Item>+ )}<Menu.ItemonClick={handleEditVisualizationSettings}disabled={!canWrite}diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CodeBlock/CodeBlock.tsx b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CodeBlock/CodeBlock.tsxindex 1103ade7316..80f45b6b5ea 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CodeBlock/CodeBlock.tsx+++ b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CodeBlock/CodeBlock.tsx@@ -10,6 +10,7 @@ import {import cx from "classnames";import { useEffect, useMemo, useState } from "react";+import { isWithinIframe } from "metabase/lib/dom";import { useSelector } from "metabase/lib/redux";import { useListCommentsQuery } from "metabase-enterprise/api";import { getTargetChildCommentThreads } from "metabase-enterprise/comments/utils";@@ -172,7 +173,7 @@ export const CodeBlockNodeView = ({ node }: NodeViewProps) => {</pre></NodeViewWrapper>- {document && rendered && (+ {document && rendered && !isWithinIframe() && (<CommentsMenuactive={isOpen}href={`/document/${document.id}/comments/${_id}`}diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Heading/Heading.tsx b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Heading/Heading.tsxindex f036d2274eb..cecb804be15 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Heading/Heading.tsx+++ b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Heading/Heading.tsx@@ -9,6 +9,7 @@ import {import cx from "classnames";import { useEffect, useMemo, useState } from "react";+import { isWithinIframe } from "metabase/lib/dom";import { useSelector } from "metabase/lib/redux";import { useListCommentsQuery } from "metabase-enterprise/api";import { getTargetChildCommentThreads } from "metabase-enterprise/comments/utils";@@ -102,7 +103,7 @@ export const HeadingNodeView = ({ node }: NodeViewProps) => {/></NodeViewWrapper>- {document && rendered && (+ {document && rendered && !isWithinIframe() && (<CommentsMenuactive={isOpen}href={`/document/${document.id}/comments/${_id}`}diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/OrderedList/OrderedList.tsx b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/OrderedList/OrderedList.tsxindex e521d1f4760..97861b8e6cc 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/OrderedList/OrderedList.tsx+++ b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/OrderedList/OrderedList.tsx@@ -9,6 +9,7 @@ import {import cx from "classnames";import { useEffect, useMemo, useState } from "react";+import { isWithinIframe } from "metabase/lib/dom";import { useSelector } from "metabase/lib/redux";import { useListCommentsQuery } from "metabase-enterprise/api";import { getTargetChildCommentThreads } from "metabase-enterprise/comments/utils";@@ -101,16 +102,19 @@ export const OrderedListNodeView = ({<NodeViewContent<"ol"> as="ol" /></NodeViewWrapper>- {document && rendered && isTopLevel({ editor, getPos }) && (- <CommentsMenu- active={isOpen}- href={`/document/${document.id}/comments/${_id}`}- ref={refs.setFloating}- show={isOpen || hovered}- threads={threads}- style={floatingStyles}- />- )}+ {document &&+ rendered &&+ !isWithinIframe() &&+ isTopLevel({ editor, getPos }) && (+ <CommentsMenu+ active={isOpen}+ href={`/document/${document.id}/comments/${_id}`}+ ref={refs.setFloating}+ show={isOpen || hovered}+ threads={threads}+ style={floatingStyles}+ />+ )}</>);};diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Paragraph/Paragraph.tsx b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Paragraph/Paragraph.tsxindex cde95e04dd0..3b2dfdf81d3 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Paragraph/Paragraph.tsx+++ b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Paragraph/Paragraph.tsx@@ -9,6 +9,7 @@ import {import cx from "classnames";import { useEffect, useMemo, useState } from "react";+import { isWithinIframe } from "metabase/lib/dom";import { useSelector } from "metabase/lib/redux";import { useListCommentsQuery } from "metabase-enterprise/api";import { getTargetChildCommentThreads } from "metabase-enterprise/comments/utils";@@ -47,7 +48,8 @@ export const ParagraphNodeView = ({extension,}: NodeViewProps) => {const editorContext = extension?.options?.editorContext || "document";- const shouldHideCommentMenu = editorContext === "comments";+ const shouldHideCommentMenu =+ editorContext === "comments" || isWithinIframe();const childTargetId = useSelector(getChildTargetId);const hoveredChildTargetId = useSelector(getHoveredChildTargetId);const document = useSelector(getCurrentDocument);diff --git a/src/metabase/analytics/core.clj b/src/metabase/analytics/core.cljindex c27d1d6bfe3..0285dc304e0 100644--- a/src/metabase/analytics/core.clj+++ b/src/metabase/analytics/core.clj@@ -35,6 +35,7 @@[metabase.analytics.sdk+ embedding-context?embedding-mwinclude-sdk-infowith-client! get-clientdiff --git a/src/metabase/analytics/sdk.clj b/src/metabase/analytics/sdk.cljindex f3b85bf9afb..e17297a90ad 100644--- a/src/metabase/analytics/sdk.clj+++ b/src/metabase/analytics/sdk.clj@@ -50,7 +50,7 @@"embedding-iframe" (prometheus/inc! :metabase-embedding-iframe/response {:status (str status)})(log/infof "Unknown client. client: %s" sdk-client)))-(defn- embedding-context?+(defn embedding-context?"Should we track this request as being made by an embedding client?"[client](or (= client embedding-sdk-client)