Skip to content

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

rework comments sidebar (#63636)

Uladzimir Havenchyk18b9ae17c7d4
diff --git a/e2e/support/helpers/e2e-comment-helpers.ts b/e2e/support/helpers/e2e-comment-helpers.ts
index 554d644fe5c..d19bbac3a39 100644
--- a/e2e/support/helpers/e2e-comment-helpers.ts
+++ b/e2e/support/helpers/e2e-comment-helpers.ts
@@ -1,7 +1,5 @@
import type { DocumentId } from "metabase-types/api";
-import { modal } from "./e2e-ui-elements-helpers";
-
export const Comments = {
getDocumentNodeButton,
getDocumentNodeButtons,
@@ -15,6 +13,8 @@ export const Comments = {
reopenCommentByText,
openAllComments,
reactToComment,
+ getSidebar,
+ closeSidebar,
};
function getDocumentNodeButton({
@@ -59,7 +59,7 @@ function getCommentByText(text: string | RegExp) {
function openAllComments() {
cy.findByRole("link", { name: "Show all comments" }).click();
- cy.findByRole("dialog").should("contain.text", "All comments");
+ getSidebar().should("contain.text", "All comments");
}
function getEmojiPicker() {
@@ -89,7 +89,7 @@ function reopenCommentByText(text: string | RegExp) {
}
function reactToComment(comment: string | RegExp, emoji: string) {
- modal().within(() => {
+ getSidebar().within(() => {
getCommentByText(comment)
.realHover()
.within(() => {
@@ -101,3 +101,11 @@ function reactToComment(comment: string | RegExp, emoji: string) {
cy.findByText(emoji).click();
});
}
+
+function getSidebar() {
+ return cy.findByTestId("comments-sidebar");
+}
+
+function closeSidebar() {
+ cy.icon("close").click();
+}
diff --git a/e2e/test/scenarios/documents/comments.cy.spec.ts b/e2e/test/scenarios/documents/comments.cy.spec.ts
index ff6e0877f55..492c841f053 100644
--- a/e2e/test/scenarios/documents/comments.cy.spec.ts
+++ b/e2e/test/scenarios/documents/comments.cy.spec.ts
@@ -72,7 +72,7 @@ H.describeWithSnowplowEE("document comments", () => {
.should("be.visible")
.click();
- H.modal().within(() => {
+ Comments.getSidebar().within(() => {
cy.findByRole("heading", { name: "Comments about this" }).should(
"be.visible",
);
@@ -101,7 +101,7 @@ H.describeWithSnowplowEE("document comments", () => {
cy.log("can close the sidebar with a keyboard shortcut");
cy.realPress("Escape");
- H.modal().should("not.exist");
+ Comments.getSidebar().should("not.exist");
getNodeElement()
.closest("[data-node-view-wrapper]")
@@ -125,7 +125,7 @@ H.describeWithSnowplowEE("document comments", () => {
Comments.getNewThreadInput().within(() => {
Comments.getPlaceholder().should("be.visible");
});
- cy.findByLabelText("Close").click();
+ Comments.closeSidebar();
H.documentContent().click();
cy.realType("{leftarrow}".repeat("lor sit amet.".length));
@@ -150,7 +150,7 @@ H.describeWithSnowplowEE("document comments", () => {
.should("not.contain.text", "1")
.click();
- H.modal().within(() => {
+ Comments.getSidebar().within(() => {
cy.findByRole("heading", { name: "Comments about this" }).should(
"be.visible",
);
@@ -203,7 +203,7 @@ H.describeWithSnowplowEE("document comments", () => {
it("allows to create / update / delete comments", () => {
startNewCommentIn1ParagraphDocument();
- H.modal().within(() => {
+ Comments.getSidebar().within(() => {
cy.log("does not allow to send empty comments");
cy.realPress([META_KEY, "Enter"]);
cy.findByLabelText("Send").should("be.disabled");
@@ -250,7 +250,7 @@ H.describeWithSnowplowEE("document comments", () => {
H.popover().findByText("Delete").click();
- H.modal().within(() => {
+ Comments.getSidebar().within(() => {
cy.findByText("Reply A").should("not.exist");
cy.findByText("This comment was deleted.").should("not.exist");
@@ -263,7 +263,7 @@ H.describeWithSnowplowEE("document comments", () => {
H.popover().findByText("Delete").click();
- H.modal().within(() => {
+ Comments.getSidebar().within(() => {
cy.findByText("1st thread").should("not.exist");
cy.findByText("This comment was deleted.").should("be.visible");
cy.findByText("Reply 1").should("be.visible");
@@ -281,7 +281,7 @@ H.describeWithSnowplowEE("document comments", () => {
cy.realType("My ");
cy.realPress([META_KEY, "Enter"]);
- H.modal().within(() => {
+ Comments.getSidebar().within(() => {
Comments.getCommentByText("My Reply 1").should("be.visible");
Comments.getCommentByText("My Reply 1")
.findByRole("textbox")
@@ -303,11 +303,11 @@ H.describeWithSnowplowEE("document comments", () => {
Comments.getCommentByText("Reply 2")
.findByRole("textbox")
.should("have.attr", "contenteditable", "false");
- H.modal().should("be.visible");
+ Comments.getSidebar().should("be.visible");
cy.log("subsequent Esc should close the modal");
cy.realPress("Escape");
- H.modal().should("not.exist");
+ Comments.getSidebar().should("not.exist");
});
it("shows comment button with unresolved, undeleted comments count", () => {
@@ -384,7 +384,7 @@ H.describeWithSnowplowEE("document comments", () => {
.click();
});
- H.modal().within(() => {
+ Comments.getSidebar().within(() => {
cy.findByRole("heading", { name: "Comments about this" }).should(
"be.visible",
);
@@ -507,7 +507,7 @@ H.describeWithSnowplowEE("document comments", () => {
},
);
- H.modal().within(() => {
+ Comments.getSidebar().within(() => {
Comments.getCommentByText("Test 1")
.should("contain.text", "Bobby Tables")
.and("contain.text", "BT");
@@ -547,7 +547,7 @@ H.describeWithSnowplowEE("document comments", () => {
.and("contain.text", "1")
.click();
- H.modal().within(() => {
+ Comments.getSidebar().within(() => {
cy.findByText("Test X").should("be.visible");
cy.findByText("Test 1").should("not.exist");
cy.findByText("Test 2").should("not.exist");
@@ -604,12 +604,12 @@ H.describeWithSnowplowEE("document comments", () => {
cy.findByLabelText("Comments")
.should("be.disabled")
.click({ force: true });
- H.modal().should("not.exist");
+ Comments.getSidebar().should("not.exist");
cy.findByLabelText("Show all comments")
.should("be.disabled")
.click({ force: true });
- H.modal().should("not.exist");
+ Comments.getSidebar().should("not.exist");
});
});
@@ -748,12 +748,12 @@ H.describeWithSnowplowEE("document comments", () => {
H.documentSuggestionDialog().should("be.visible");
cy.realPress("Escape");
H.documentSuggestionDialog().should("not.exist");
- H.modal().should("be.visible");
+ Comments.getSidebar().should("be.visible");
cy.realType("{backspace}{backspace}{backspace}@none");
H.documentSuggestionDialog().findByText("None Tableton").click();
- H.modal().within(() => {
+ Comments.getSidebar().within(() => {
Comments.getNewThreadInput()
.findByText("@Bobby Tables")
.should("be.visible");
@@ -799,13 +799,13 @@ H.describeWithSnowplowEE("document comments", () => {
cy.realType(":eg");
cy.realPress("Escape");
Comments.getEmojiPicker().should("not.exist");
- H.modal().should("be.visible");
+ Comments.getSidebar().should("be.visible");
cy.log("can use mouse to select emoji");
cy.realType("{backspace}{backspace}{backspace}:egg");
Comments.getEmojiPicker().findByText("🥚").click();
- H.modal().within(() => {
+ Comments.getSidebar().within(() => {
Comments.getNewThreadInput()
.should("contain.text", "😊")
.and("contain.text", "🍆")
@@ -1021,7 +1021,7 @@ H.describeWithSnowplowEE("document comments", () => {
H.visitDocumentComment("@documentId", HEADING_1_ID, commentId);
});
- H.modal().within(() => {
+ Comments.getSidebar().within(() => {
cy.findByRole("heading", { name: "All comments" }).should("not.exist");
cy.findByRole("heading", { name: "Comments about this" }).should(
"be.visible",
@@ -1043,7 +1043,7 @@ H.describeWithSnowplowEE("document comments", () => {
H.visitDocumentComment("@documentId", HEADING_1_ID, commentId);
});
- H.modal().within(() => {
+ Comments.getSidebar().within(() => {
cy.findByTestId("comments-resolved-tab").should("be.visible");
cy.findAllByTestId("discussion-comment").should("have.length", 1);
Comments.getCommentByText("Foo").should(
@@ -1059,13 +1059,19 @@ H.describeWithSnowplowEE("document comments", () => {
H.visitDocumentComment("@documentId", HEADING_1_ID, commentId);
});
- H.modal().findByTestId("comments-resolved-tab").should("not.exist");
+ Comments.getSidebar()
+ .findByTestId("comments-resolved-tab")
+ .should("not.exist");
Comments.resolveCommentByText("Foo");
- H.modal().findByTestId("comments-resolved-tab").should("be.visible");
+ Comments.getSidebar()
+ .findByTestId("comments-resolved-tab")
+ .should("be.visible");
Comments.reopenCommentByText("Foo");
- H.modal().findByTestId("comments-resolved-tab").should("not.exist");
+ Comments.getSidebar()
+ .findByTestId("comments-resolved-tab")
+ .should("not.exist");
});
});
@@ -1075,7 +1081,7 @@ H.describeWithSnowplowEE("document comments", () => {
cy.realType("thread 1");
cy.realPress([META_KEY, "Enter"]);
- H.modal().within(() => {
+ Comments.getSidebar().within(() => {
Comments.getNewThreadInput().type("thread 2");
cy.realPress([META_KEY, "Enter"]);
});
@@ -1105,7 +1111,7 @@ H.describeWithSnowplowEE("document comments", () => {
cy.location().then((loc) => {
cy.visit(`${loc.pathname}/comments/all`);
- H.modal()
+ Comments.getSidebar()
.should("contain", "All comments")
.should("contain", "No comments");
});
@@ -1123,7 +1129,7 @@ H.describeWithSnowplowEE("document comments", () => {
Comments.resolveCommentByText("Test 1");
Comments.openAllComments();
- H.modal()
+ Comments.getSidebar()
.should("contain", "All comments")
.should("contain", "No comments");
});
@@ -1140,7 +1146,7 @@ H.describeWithSnowplowEE("document comments", () => {
Comments.reactToComment("Test 1", FIRST_REACTION_EMOJI);
Comments.reactToComment("Test 1", SECOND_REACTION_EMOJI);
- H.modal().within(() => {
+ Comments.getSidebar().within(() => {
cy.findByTestId("discussion-reactions").within((el) => {
cy.wrap(el).should("contain", `${FIRST_REACTION_EMOJI}1`);
cy.wrap(el).should("contain", `${SECOND_REACTION_EMOJI}1`);
@@ -1158,7 +1164,7 @@ H.describeWithSnowplowEE("document comments", () => {
Comments.reactToComment("Test 1", FIRST_REACTION_EMOJI);
Comments.reactToComment("Test 1", SECOND_REACTION_EMOJI);
- H.modal().within(() => {
+ Comments.getSidebar().within(() => {
cy.findByTestId("discussion-reactions").within(() => {
cy.findByText(`${FIRST_REACTION_EMOJI}`).should("exist");
cy.findByText(`${FIRST_REACTION_EMOJI}`).click();
@@ -1183,7 +1189,7 @@ H.describeWithSnowplowEE("document comments", () => {
Comments.reactToComment("Test 1", FIRST_REACTION_EMOJI);
Comments.reactToComment("Test 1", SECOND_REACTION_EMOJI);
- H.modal().within(() => {
+ Comments.getSidebar().within(() => {
cy.findByTestId("discussion-reactions").within((el) => {
cy.wrap(el).should("contain", `${FIRST_REACTION_EMOJI}2`);
cy.wrap(el).should("contain", `${SECOND_REACTION_EMOJI}2`);
@@ -1208,7 +1214,7 @@ H.describeWithSnowplowEE("document comments", () => {
Comments.reactToComment("Test 1", FIRST_REACTION_EMOJI);
Comments.reactToComment("Test 1", SECOND_REACTION_EMOJI);
- H.modal().within(() => {
+ Comments.getSidebar().within(() => {
cy.findByTestId("discussion-reactions").within((el) => {
cy.wrap(el).should("contain", `${FIRST_REACTION_EMOJI}1`);
cy.wrap(el).should("contain", `${SECOND_REACTION_EMOJI}1`);
@@ -1227,7 +1233,7 @@ H.describeWithSnowplowEE("document comments", () => {
H.visitDocumentComment("@documentId", PARAGRAPH_ID);
- H.modal().within(() => {
+ Comments.getSidebar().within(() => {
cy.findByTestId("discussion-comment-deleted")
.realHover()
.within(() => {
@@ -1247,11 +1253,11 @@ H.describeWithSnowplowEE("document comments", () => {
cy.log("verify blockquote is rendered during typing");
cy.realType("> blockquote");
- getBlockquote("blockquote", H.modal()).should("be.visible");
+ getBlockquote("blockquote", Comments.getSidebar()).should("be.visible");
cy.log("verify blockquote is rendered after submitting");
cy.realPress([META_KEY, "Enter"]);
- getBlockquote("blockquote", H.modal()).should("be.visible");
+ getBlockquote("blockquote", Comments.getSidebar()).should("be.visible");
});
it("should support ordered lists", () => {
@@ -1261,14 +1267,14 @@ H.describeWithSnowplowEE("document comments", () => {
cy.realPress("Enter");
cy.realType("two");
cy.log("verify ordered list is rendered during typing");
- getOrderedList("one", H.modal()).should("be.visible");
- getOrderedList("two", H.modal()).should("be.visible");
+ getOrderedList("one", Comments.getSidebar()).should("be.visible");
+ getOrderedList("two", Comments.getSidebar()).should("be.visible");
cy.log("verify ordered list is rendered after submitting");
cy.realPress([META_KEY, "Enter"]);
- getOrderedList("one", H.modal()).should("be.visible");
- getOrderedList("two", H.modal()).should("be.visible");
+ getOrderedList("one", Comments.getSidebar()).should("be.visible");
+ getOrderedList("two", Comments.getSidebar()).should("be.visible");
});
it("should support unordered lists", () => {
@@ -1278,14 +1284,14 @@ H.describeWithSnowplowEE("document comments", () => {
cy.realPress("Enter");
cy.realType("b");
cy.log("verify bullet list is rendered during typing");
- getBulletList("a", H.modal()).should("be.visible");
- getBulletList("b", H.modal()).should("be.visible");
+ getBulletList("a", Comments.getSidebar()).should("be.visible");
+ getBulletList("b", Comments.getSidebar()).should("be.visible");
cy.log("verify bullet list is rendered after submitting");
cy.realPress([META_KEY, "Enter"]);
- getBulletList("a", H.modal()).should("be.visible");
- getBulletList("b", H.modal()).should("be.visible");
+ getBulletList("a", Comments.getSidebar()).should("be.visible");
+ getBulletList("b", Comments.getSidebar()).should("be.visible");
});
it("should support code blocks", () => {
@@ -1295,12 +1301,12 @@ H.describeWithSnowplowEE("document comments", () => {
cy.realPress("Enter");
cy.log("verify code block is rendered during typing");
cy.realType("code");
- getCodeBlock("code", H.modal()).should("be.visible");
+ getCodeBlock("code", Comments.getSidebar()).should("be.visible");
cy.log("verify code block is rendered after submitting");
cy.realPress([META_KEY, "Enter"]);
- getCodeBlock("code", H.modal()).should("be.visible");
+ getCodeBlock("code", Comments.getSidebar()).should("be.visible");
});
});
@@ -1311,7 +1317,7 @@ H.describeWithSnowplowEE("document comments", () => {
cy.realType("ol");
cy.realPress([META_KEY, "Shift", "7"]);
- getOrderedList("ol", H.modal()).should("be.visible");
+ getOrderedList("ol", Comments.getSidebar()).should("be.visible");
});
it("should support bullet list", () => {
@@ -1320,7 +1326,7 @@ H.describeWithSnowplowEE("document comments", () => {
cy.realType("ul");
cy.realPress([META_KEY, "Shift", "8"]);
- getBulletList("ul", H.modal()).should("be.visible");
+ getBulletList("ul", Comments.getSidebar()).should("be.visible");
});
it("should support code block", () => {
@@ -1329,7 +1335,7 @@ H.describeWithSnowplowEE("document comments", () => {
cy.realType("code");
cy.realPress([META_KEY, "Alt", "c"]);
- getCodeBlock("code", H.modal()).should("be.visible");
+ getCodeBlock("code", Comments.getSidebar()).should("be.visible");
});
// explicitly disabled in CustomStarterKit to keep default browser behavior
@@ -1339,7 +1345,7 @@ H.describeWithSnowplowEE("document comments", () => {
cy.realType("blockquote");
cy.realPress([META_KEY, "Shift", "k"]);
- getBlockquote("blockquote", H.modal()).should("be.visible");
+ getBlockquote("blockquote", Comments.getSidebar()).should("be.visible");
});
});
@@ -1366,10 +1372,10 @@ H.describeWithSnowplowEE("document comments", () => {
cy.reload();
- getBlockquote("blockquote", H.modal()).should("be.visible");
- getOrderedList("ol", H.modal()).should("be.visible");
- getBulletList("ul", H.modal()).should("be.visible");
- getCodeBlock("code", H.modal()).should("be.visible");
+ 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");
});
});
@@ -1566,7 +1572,7 @@ function startNewCommentIn1ParagraphDocument() {
.click();
});
- H.modal().within(() => {
+ Comments.getSidebar().within(() => {
cy.findByRole("heading", { name: "Comments about this" }).should(
"be.visible",
);
@@ -1973,14 +1979,14 @@ function verifyEmail({
cy.log("Metabase company name");
const hasCompanyName = [...document.querySelectorAll("*")].some((element) => {
- return element.textContent.trim() === "Metabase, Inc.";
+ return element.textContent?.trim() === "Metabase, Inc.";
});
expect(hasCompanyName).to.be.true;
cy.log("Metabase company address");
const hasCompanyAddress = [...document.querySelectorAll("*")].some(
(element) =>
- element.textContent.trim() ===
+ element.textContent?.trim() ===
"9740 Campo Rd., Suite 1029, Spring Valley, CA 91977",
);
expect(hasCompanyAddress).to.be.true;
diff --git a/enterprise/frontend/src/metabase-enterprise/comments/components/CommentEditor/CommentEditor.tsx b/enterprise/frontend/src/metabase-enterprise/comments/components/CommentEditor/CommentEditor.tsx
index f30599ae87d..f4aa8e85915 100644
--- a/enterprise/frontend/src/metabase-enterprise/comments/components/CommentEditor/CommentEditor.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/comments/components/CommentEditor/CommentEditor.tsx
@@ -85,6 +85,7 @@ export const CommentEditor = ({
trailingNode: false,
heading: false,
horizontalRule: false,
+ paragraph: { editorContext: "comments" },
}),
SmartLink.configure({
HTMLAttributes: { class: "smart-link" },
diff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/CommentsSidesheet/CommentsSidesheet.module.css b/enterprise/frontend/src/metabase-enterprise/documents/components/CommentsSidesheet/CommentsSidesheet.module.css
index dcfe1b80d47..1b5ce9f4a46 100644
--- a/enterprise/frontend/src/metabase-enterprise/documents/components/CommentsSidesheet/CommentsSidesheet.module.css
+++ b/enterprise/frontend/src/metabase-enterprise/documents/components/CommentsSidesheet/CommentsSidesheet.module.css
@@ -27,3 +27,8 @@
z-index: 2;
background-color: var(--mb-color-bg-white);
}
+
+.tabPanel {
+ height: calc(100dvh - 160px);
+ overflow-y: auto;
+}
diff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/CommentsSidesheet/CommentsSidesheet.tsx b/enterprise/frontend/src/metabase-enterprise/documents/components/CommentsSidesheet/CommentsSidesheet.tsx
index 0cef056ce8a..88db278a12d 100644
--- a/enterprise/frontend/src/metabase-enterprise/documents/components/CommentsSidesheet/CommentsSidesheet.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/documents/components/CommentsSidesheet/CommentsSidesheet.tsx
@@ -1,5 +1,4 @@
import { useWindowEvent } from "@mantine/hooks";
-import cx from "classnames";
import { useCallback, useEffect, useMemo, useState } from "react";
import { useLatest, useLocation } from "react-use";
import { t } from "ttag";
@@ -8,7 +7,16 @@ import noResultsSource from "assets/img/no_results.svg";
import { useToast } from "metabase/common/hooks";
import Animation from "metabase/css/core/animation.module.css";
import { useDispatch, useSelector } from "metabase/lib/redux";
-import { Box, Flex, Image, Modal, Tabs, Text, rem } from "metabase/ui";
+import {
+ ActionIcon,
+ Box,
+ Flex,
+ Icon,
+ Image,
+ Tabs,
+ Text,
+ Title,
+} from "metabase/ui";
import {
useCreateCommentMutation,
useListCommentsQuery,
@@ -145,11 +153,6 @@ export const CommentsSidesheet = ({ params, onClose }: Props) => {
}
}, [hash, activeTabRef, isHashCommentResolved, isHashCommentUnresolved]);
- // Mantine modal, at least in v8 listens to `window` events in capture mode (before bubbling up),
- // so the modal closes before the event reaches the comment editor
- // See: https://github.com/mantinedev/mantine/blob/master/packages/%40mantine/core/src/components/ModalBase/use-modal.ts#L43
- // Therefore we need to listen for escape events during the bubbling phase, not the capture phase
- const closeOnEscape = false;
useWindowEvent("keydown", (event) => {
if (event.key === "Escape" && !event.defaultPrevented) {
closeSidebar();
@@ -185,99 +188,92 @@ export const CommentsSidesheet = ({ params, onClose }: Props) => {
}
return (
- <Modal.Root
- h="100dvh"
- lockScroll={false}
- opened
- variant="sidesheet"
- onClose={closeSidebar}
- closeOnEscape={closeOnEscape}
+ <Box
+ component="aside"
+ pos="relative"
+ mah="100dvh"
+ w="30rem"
+ className={Animation.slideLeft}
+ style={{
+ borderLeft: "1px solid var(--mb-color-border)",
+ }}
+ data-testid="comments-sidebar"
>
- <Modal.Content
- classNames={{
- content: cx(S.content, Animation.slideLeft),
+ <Flex px="xl" pt="1.25rem" pb="sm" justify="space-between" align="center">
+ <Title order={3}>
+ {childTargetId === "all" ? t`All comments` : t`Comments about this`}
+ </Title>
+ <ActionIcon onClick={closeSidebar}>
+ <Icon name="close" c="text-primary" />
+ </ActionIcon>
+ </Flex>
+
+ <Tabs
+ value={activeTab}
+ onChange={(value) => {
+ setActiveTab(value as SidesheetTab);
}}
- data-testid="sidesheet"
- px="none"
- transitionProps={{ duration: 0 }}
- w={rem(400)}
>
- <Modal.Header px="xl">
- <Modal.Title>
- {childTargetId === "all" ? t`All comments` : t`Comments about this`}
- </Modal.Title>
- <Modal.CloseButton onClick={closeSidebar} />
- </Modal.Header>
-
- <Modal.Body className={S.body} p={0}>
- <Tabs
- value={activeTab}
- onChange={(value) => {
- setActiveTab(value as SidesheetTab);
- }}
- >
- {availableTabs.length > 0 && (
- <Tabs.List px="1.625rem" className={S.tabsList}>
- <Tabs.Tab value="open" data-testid="comments-open-tab">
- {t`Open`}
- </Tabs.Tab>
- <Tabs.Tab value="resolved" data-testid="comments-resolved-tab">
- {t`Resolved (${resolvedCommentsCount})`}
- </Tabs.Tab>
- </Tabs.List>
- )}
-
- <Tabs.Panel value="open">
- {activeComments.length > 0 && (
- <Discussions
- childTargetId={childTargetId === "all" ? null : childTargetId}
- comments={activeComments}
- enableHoverHighlight={childTargetId === "all"}
- targetId={document.id}
- targetType="document"
- />
- )}
-
- {activeComments.length === 0 && childTargetId === "all" && (
- <Flex
- p="xl"
- pt="5rem"
- align="center"
- color="muted"
- direction="column"
- gap="md"
- >
- <Image w={120} h={120} src={noResultsSource} />
-
- <Text fw="700" c="text-light">{t`No comments`}</Text>
- </Flex>
- )}
-
- {childTargetId !== "all" && (
- <Box px="lg" py={activeComments.length === 0 ? "lg" : "xs"}>
- <CommentEditor
- autoFocus={shouldAutoOpenNewComment}
- data-testid="new-thread-editor"
- placeholder={t`Add a comment…`}
- onChange={(document) => setNewComment(document)}
- onSubmit={handleSubmit}
- />
- </Box>
- )}
- </Tabs.Panel>
-
- <Tabs.Panel value="resolved">
- <Discussions
- childTargetId={childTargetId === "all" ? null : childTargetId}
- comments={resolvedComments}
- targetId={document.id}
- targetType="document"
+ {availableTabs.length > 0 && (
+ <Tabs.List px="1.625rem" className={S.tabsList}>
+ <Tabs.Tab value="open" data-testid="comments-open-tab">
+ {t`Open`}
+ </Tabs.Tab>
+ <Tabs.Tab value="resolved" data-testid="comments-resolved-tab">
+ {t`Resolved (${resolvedCommentsCount})`}
+ </Tabs.Tab>
+ </Tabs.List>
+ )}
+
+ <Tabs.Panel value="open" className={S.tabPanel}>
+ {activeComments.length > 0 && (
+ <Discussions
+ childTargetId={childTargetId === "all" ? null : childTargetId}
+ comments={activeComments}
+ enableHoverHighlight={childTargetId === "all"}
+ targetId={document.id}
+ targetType="document"
+ />
+ )}
+
+ {activeComments.length === 0 && childTargetId === "all" && (
+ <Flex
+ p="xl"
+ pt="5rem"
+ align="center"
+ color="muted"
+ direction="column"
+ gap="md"
+ >
+ <Image w={120} h={120} src={noResultsSource} />
+
+ <Text fw="700" c="text-light">{t`No comments`}</Text>
+ </Flex>
+ )}
+
+ {childTargetId !== "all" && (
+ <Box px="lg" py={activeComments.length === 0 ? "lg" : "xs"}>
+ <CommentEditor
+ autoFocus={shouldAutoOpenNewComment}
+ data-testid="new-thread-editor"
+ placeholder={t`Add a comment…`}
+ onChange={(document) => setNewComment(document)}
+ onSubmit={handleSubmit}
/>
- </Tabs.Panel>
- </Tabs>
- </Modal.Body>
- </Modal.Content>
- </Modal.Root>
+ </Box>
+ )}
+ </Tabs.Panel>
+
+ <Tabs.Panel value="resolved" className={S.tabPanel}>
+ <Discussions
+ childTargetId={childTargetId === "all" ? null : childTargetId}
+ comments={resolvedComments}
+ targetId={document.id}
+ targetType="document"
+ />
+ </Tabs.Panel>
+ </Tabs>
+ </Box>
);
};
diff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentPage.module.css b/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentPage.module.css
index 6be1284ec52..18445228a5e 100644
--- a/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentPage.module.css
+++ b/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentPage.module.css
@@ -3,10 +3,6 @@
flex-direction: column;
height: 100%;
background-color: var(--mb-color-bg-white);
-
- &.commentsOpened {
- width: calc(100% - 25rem);
- }
}
.header {
@@ -32,7 +28,7 @@
display: flex;
flex-direction: column;
overflow-y: auto;
- padding: 0 2rem;
+ padding: 0 3rem 0 2rem;
scroll-padding-top: 32px;
}
diff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentPage.tsx b/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentPage.tsx
index e188582945e..5f95ca67d1a 100644
--- a/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentPage.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentPage.tsx
@@ -1,7 +1,6 @@
import { useForceUpdate } from "@mantine/hooks";
import type { JSONContent, Editor as TiptapEditor } from "@tiptap/core";
import type { Node as ProseMirrorNode } from "@tiptap/pm/model";
-import cx from "classnames";
import dayjs from "dayjs";
import type { Location } from "history";
import { type ReactNode, useCallback, useEffect, useState } from "react";
@@ -397,105 +396,98 @@ export const DocumentPage = ({
);
return (
- <>
- <Box
- className={cx(styles.documentPage, {
- [styles.commentsOpened]: commentSidebarOpen,
- })}
- >
- <SetTitle title={documentData?.name || t`New document`} />
- {documentData?.archived && <DocumentArchivedEntityBanner />}
- <Box className={styles.contentArea}>
- <Box className={styles.mainContent}>
- <Box className={styles.documentContainer}>
- <DocumentHeader
- document={documentData}
- documentTitle={documentTitle}
- isNewDocument={isNewDocument}
- canWrite={canWrite ?? false}
- showSaveButton={showSaveButton ?? false}
- isBookmarked={isBookmarked}
- onTitleChange={setDocumentTitle}
- onSave={() => {
- if (isNewDocument) {
- setCollectionPickerMode("save");
- } else {
- handleSave();
- }
- }}
- onMove={() => setCollectionPickerMode("move")}
- onToggleBookmark={handleToggleBookmark}
- onArchive={() => handleUpdate({ archived: true })}
- hasComments={hasComments}
- />
- <Editor
- onEditorReady={setEditorInstance}
- onCardEmbedsChange={updateCardEmbeds}
- onQuestionSelect={handleQuestionSelect}
- initialContent={documentContent}
- onChange={handleChange}
- editable={canWrite}
- isLoading={isDocumentLoading}
- />
- </Box>
- </Box>
-
- {selectedQuestionId &&
- selectedEmbedIndex !== null &&
- editorInstance && (
- <Box
- className={styles.sidebar}
- data-testid="document-card-sidebar"
- >
- <EmbedQuestionSettingsSidebar
- cardId={selectedQuestionId}
- editorInstance={editorInstance}
- />
- </Box>
- )}
-
- {collectionPickerMode && (
- <CollectionPickerModal
- title={t`Where should we save this document?`}
- onClose={() => setCollectionPickerMode(null)}
- value={{ id: "root", model: "collection" }}
- options={{
- showPersonalCollections: true,
- showRootCollection: true,
- }}
- onChange={async (collection) => {
- if (collectionPickerMode === "save") {
- handleSave(canonicalCollectionId(collection.id));
- setCollectionPickerMode(null);
- } else if (collectionPickerMode === "move") {
- handleUpdate({
- collection_id: canonicalCollectionId(collection.id),
- });
+ <Box className={styles.documentPage}>
+ <SetTitle title={documentData?.name || t`New document`} />
+ {documentData?.archived && <DocumentArchivedEntityBanner />}
+ <Box className={styles.contentArea}>
+ <Box className={styles.mainContent}>
+ <Box className={styles.documentContainer}>
+ <DocumentHeader
+ document={documentData}
+ documentTitle={documentTitle}
+ isNewDocument={isNewDocument}
+ canWrite={canWrite ?? false}
+ showSaveButton={showSaveButton ?? false}
+ isBookmarked={isBookmarked}
+ onTitleChange={setDocumentTitle}
+ onSave={() => {
+ if (isNewDocument) {
+ setCollectionPickerMode("save");
+ } else {
+ handleSave();
}
}}
+ onMove={() => setCollectionPickerMode("move")}
+ onToggleBookmark={handleToggleBookmark}
+ onArchive={() => handleUpdate({ archived: true })}
+ hasComments={hasComments}
+ />
+ <Editor
+ onEditorReady={setEditorInstance}
+ onCardEmbedsChange={updateCardEmbeds}
+ onQuestionSelect={handleQuestionSelect}
+ initialContent={documentContent}
+ onChange={handleChange}
+ editable={canWrite}
+ isLoading={isDocumentLoading}
/>
+ </Box>
+ </Box>
+
+ {selectedQuestionId &&
+ selectedEmbedIndex !== null &&
+ editorInstance && (
+ <Box className={styles.sidebar} data-testid="document-card-sidebar">
+ <EmbedQuestionSettingsSidebar
+ cardId={selectedQuestionId}
+ editorInstance={editorInstance}
+ />
+ </Box>
)}
- <LeaveRouteConfirmModal
- // `key` remounts this modal when navigating between different documents or to a new document.
- // The `route` doesn't change in that scenario which prevents the modal from closing when you confirm you want to discard your changes.
- key={location.key}
- isEnabled={hasUnsavedChanges() && !isNavigationScheduled}
- route={route}
- />
- <LeaveConfirmModal
- // only applies when going from /new -> /new
- opened={
- hasUnsavedChanges() &&
- isNewDocument &&
- location.key !== previousLocationKey
- }
- onConfirm={resetDocument}
- onClose={() => forceUpdate()}
+ {collectionPickerMode && (
+ <CollectionPickerModal
+ title={t`Where should we save this document?`}
+ onClose={() => setCollectionPickerMode(null)}
+ value={{ id: "root", model: "collection" }}
+ options={{
+ showPersonalCollections: true,
+ showRootCollection: true,
+ }}
+ onChange={async (collection) => {
+ if (collectionPickerMode === "save") {
+ handleSave(canonicalCollectionId(collection.id));
+ setCollectionPickerMode(null);
+ } else if (collectionPickerMode === "move") {
+ handleUpdate({
+ collection_id: canonicalCollectionId(collection.id),
+ });
+ }
+ }}
/>
- </Box>
+ )}
+
+ {children}
+
+ <LeaveRouteConfirmModal
+ // `key` remounts this modal when navigating between different documents or to a new document.
+ // The `route` doesn't change in that scenario which prevents the modal from closing when you confirm you want to discard your changes.
+ key={location.key}
+ isEnabled={hasUnsavedChanges() && !isNavigationScheduled}
+ route={route}
+ />
+
+ <LeaveConfirmModal
+ // only applies when going from /new -> /new
+ opened={
+ hasUnsavedChanges() &&
+ isNewDocument &&
+ location.key !== previousLocationKey
+ }
+ onConfirm={resetDocument}
+ onClose={() => forceUpdate()}
+ />
</Box>
- {children}
- </>
+ </Box>
);
};
diff --git a/enterprise/frontend/src/metabase-enterprise/documents/index.ts b/enterprise/frontend/src/metabase-enterprise/documents/index.ts
index bab2bd77684..7c6b72a5e49 100644
--- a/enterprise/frontend/src/metabase-enterprise/documents/index.ts
+++ b/enterprise/frontend/src/metabase-enterprise/documents/index.ts
@@ -8,13 +8,18 @@ import { hasPremiumFeature } from "metabase-enterprise/settings";
import { documentsReducer } from "./documents.slice";
import { getRoutes } from "./routes";
-import { getCurrentDocument, getSidebarOpen } from "./selectors";
+import {
+ getCommentSidebarOpen,
+ getCurrentDocument,
+ getSidebarOpen,
+} from "./selectors";
if (hasPremiumFeature("documents")) {
PLUGIN_DOCUMENTS.getRoutes = getRoutes;
PLUGIN_DOCUMENTS.shouldShowDocumentInNewItemMenu = () => true;
PLUGIN_DOCUMENTS.getCurrentDocument = getCurrentDocument;
PLUGIN_DOCUMENTS.getSidebarOpen = getSidebarOpen;
+ PLUGIN_DOCUMENTS.getCommentSidebarOpen = getCommentSidebarOpen;
PLUGIN_REDUCERS.documents = documentsReducer;
diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CustomStarterKit/CustomStarterKit.tsx b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CustomStarterKit/CustomStarterKit.tsx
index 04c56b8aace..07bca9ef78e 100644
--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CustomStarterKit/CustomStarterKit.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CustomStarterKit/CustomStarterKit.tsx
@@ -39,10 +39,16 @@ const replaceExtension = <T extends AnyExtension>(
return clone;
};
+interface CustomStarterKitOptions extends StarterKitOptions {
+ paragraph: StarterKitOptions["paragraph"] & {
+ editorContext?: "comments" | "document";
+ };
+}
+
/**
* Modified StarterKit so it doesn't hijack browsers' cmd/ctrl+shift+b behavior
*/
-export const CustomStarterKit = StarterKit.extend<StarterKitOptions>({
+export const CustomStarterKit = StarterKit.extend<CustomStarterKitOptions>({
name: "customStarterKit",
addExtensions() {
let extensions = this.parent?.() || [];
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.tsx
index f8c80e7a028..78bb4ca5503 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
@@ -41,7 +41,14 @@ export const CustomParagraph = Paragraph.extend({
},
});
-export const ParagraphNodeView = ({ node, editor, getPos }: NodeViewProps) => {
+export const ParagraphNodeView = ({
+ node,
+ editor,
+ getPos,
+ extension,
+}: NodeViewProps) => {
+ const editorContext = extension?.options?.editorContext || "document";
+ const shouldHideCommentMenu = editorContext === "comments";
const childTargetId = useSelector(getChildTargetId);
const hoveredChildTargetId = useSelector(getHoveredChildTargetId);
const document = useSelector(getCurrentDocument);
@@ -86,17 +93,20 @@ export const ParagraphNodeView = ({ node, editor, getPos }: NodeViewProps) => {
<NodeViewContent<"p"> as="p" />
</NodeViewWrapper>
- {document && rendered && isTopLevel({ editor, getPos }) && (
- <CommentsMenu
- active={isOpen}
- disabled={hasUnsavedChanges}
- href={`/document/${document.id}/comments/${_id}`}
- ref={refs.setFloating}
- show={isOpen || hovered}
- threads={threads}
- style={floatingStyles}
- />
- )}
+ {document &&
+ rendered &&
+ !shouldHideCommentMenu &&
+ isTopLevel({ editor, getPos }) && (
+ <CommentsMenu
+ active={isOpen}
+ disabled={hasUnsavedChanges}
+ href={`/document/${document.id}/comments/${_id}`}
+ ref={refs.setFloating}
+ show={isOpen || hovered}
+ threads={threads}
+ style={floatingStyles}
+ />
+ )}
</>
);
};
diff --git a/frontend/src/metabase/nav/components/AppBar/AppBar.tsx b/frontend/src/metabase/nav/components/AppBar/AppBar.tsx
index a1c1308f0f4..4978a727e70 100644
--- a/frontend/src/metabase/nav/components/AppBar/AppBar.tsx
+++ b/frontend/src/metabase/nav/components/AppBar/AppBar.tsx
@@ -16,6 +16,7 @@ export interface AppBarProps {
isNavBarOpen?: boolean;
isNavBarEnabled?: boolean;
isMetabotVisible?: boolean;
+ isCommentSidebarOpen?: boolean;
isDocumentSidebarOpen?: boolean;
isLogoVisible?: boolean;
isSearchVisible?: boolean;
diff --git a/frontend/src/metabase/nav/components/AppBar/AppBarLarge.tsx b/frontend/src/metabase/nav/components/AppBar/AppBarLarge.tsx
index 5f8d2293dea..f10fefec435 100644
--- a/frontend/src/metabase/nav/components/AppBar/AppBarLarge.tsx
+++ b/frontend/src/metabase/nav/components/AppBar/AppBarLarge.tsx
@@ -29,6 +29,7 @@ export interface AppBarLargeProps {
isNavBarEnabled?: boolean;
isMetabotVisible?: boolean;
isDocumentSidebarOpen?: boolean;
+ isCommentSidebarOpen?: boolean;
isLogoVisible?: boolean;
isSearchVisible?: boolean;
isEmbeddingIframe?: boolean;
@@ -47,6 +48,7 @@ const AppBarLarge = ({
isNavBarEnabled,
isMetabotVisible,
isDocumentSidebarOpen,
+ isCommentSidebarOpen,
isLogoVisible,
isSearchVisible,
isEmbeddingIframe,
@@ -62,7 +64,10 @@ const AppBarLarge = ({
return (
<AppBarRoot
hasSidebarOpen={
- isNavBarVisible || isMetabotVisible || isDocumentSidebarOpen
+ isNavBarVisible ||
+ isMetabotVisible ||
+ isDocumentSidebarOpen ||
+ isCommentSidebarOpen
}
>
<AppBarLeftContainer>
diff --git a/frontend/src/metabase/nav/containers/AppBar/AppBar.tsx b/frontend/src/metabase/nav/containers/AppBar/AppBar.tsx
index 54c60dcc6e2..fba5bef6e64 100644
--- a/frontend/src/metabase/nav/containers/AppBar/AppBar.tsx
+++ b/frontend/src/metabase/nav/containers/AppBar/AppBar.tsx
@@ -31,6 +31,7 @@ const mapStateToProps = (state: State, props: RouterProps) => ({
isNavBarEnabled: getIsNavBarEnabled(state, props),
isMetabotVisible: PLUGIN_METABOT.getMetabotVisible(state),
isDocumentSidebarOpen: PLUGIN_DOCUMENTS.getSidebarOpen(state),
+ isCommentSidebarOpen: PLUGIN_DOCUMENTS.getCommentSidebarOpen(state),
isLogoVisible: getIsLogoVisible(state),
isSearchVisible: getIsSearchVisible(state),
isEmbeddingIframe: getIsEmbeddingIframe(state),
diff --git a/frontend/src/metabase/plugins/index.ts b/frontend/src/metabase/plugins/index.ts
index f684583c02a..0115cb49aee 100644
--- a/frontend/src/metabase/plugins/index.ts
+++ b/frontend/src/metabase/plugins/index.ts
@@ -817,6 +817,7 @@ export const PLUGIN_DOCUMENTS = {
shouldShowDocumentInNewItemMenu: () => false,
getCurrentDocument: (_state: any) => null as Document | null,
getSidebarOpen: (_state: any) => false,
+ getCommentSidebarOpen: (_state: any) => false,
};
export const PLUGIN_ENTITIES = {