Skip to content

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

WRK 905 Allow commenting on unsaved documents (#64237)

Stas Gavrylovb71caeacdf6b
diff --git a/e2e/test/scenarios/documents/comments.cy.spec.ts b/e2e/test/scenarios/documents/comments.cy.spec.ts
index 50c52999813..fe86173fab5 100644
--- a/e2e/test/scenarios/documents/comments.cy.spec.ts
+++ b/e2e/test/scenarios/documents/comments.cy.spec.ts
@@ -570,7 +570,7 @@ H.describeWithSnowplowEE("document comments", () => {
});
});
- it("prevents editing the document when comments are open", () => {
+ it("allows editing the document when comments are open", () => {
create1ParagraphDocument();
cy.get<DocumentId>("@documentId").then((documentId) => {
@@ -580,17 +580,17 @@ H.describeWithSnowplowEE("document comments", () => {
H.documentContent().click();
cy.realType("test");
- cy.findByRole("button", { name: "Save" }).should("not.exist");
+ cy.findByRole("button", { name: "Save" }).should("exist");
H.documentContent()
- .get('[contenteditable="false"]')
+ .get('[contenteditable="true"]')
.should("be.visible");
H.documentFormattingMenu().should("not.exist");
});
});
});
- it("prevents opening comments when document has changes", () => {
+ it("allows opening comments when document has changes", () => {
create1ParagraphDocument();
cy.get<DocumentId>("@documentId").then((documentId) => {
@@ -614,15 +614,11 @@ H.describeWithSnowplowEE("document comments", () => {
getParagraph("Lorem ipsum dolor sit amet.xyz").realHover();
- cy.findByLabelText("Comments")
- .should("be.disabled")
- .click({ force: true });
- Comments.getSidebar().should("not.exist");
+ cy.findByLabelText("Comments").should("not.be.disabled").click();
+ Comments.getSidebar().should("be.visible");
- cy.findByLabelText("Show all comments")
- .should("be.disabled")
- .click({ force: true });
- Comments.getSidebar().should("not.exist");
+ cy.findByLabelText("Show all comments").should("not.be.disabled").click();
+ Comments.getSidebar().should("be.visible");
});
});
diff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentHeader.tsx b/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentHeader.tsx
index ad3fac8f7a3..0a3e35e6e65 100644
--- a/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentHeader.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentHeader.tsx
@@ -134,20 +134,7 @@ export const DocumentHeader = ({
{!isNewDocument && hasComments && (
<Tooltip label={t`Show all comments`}>
<Box>
- {showSaveButton && (
- <ActionIcon
- className={S.commentsIcon}
- disabled
- variant="subtle"
- size="md"
- aria-label={t`Show all comments`}
- data-hide-on-print
- >
- <Icon name="comment" />
- </ActionIcon>
- )}
-
- {!showSaveButton && document && (
+ {document && (
<ActionIcon
className={S.commentsIcon}
component={Link}
diff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentPage.tsx b/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentPage.tsx
index d5e4f7c861c..82fff427f7b 100644
--- a/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentPage.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentPage.tsx
@@ -58,7 +58,6 @@ import {
import { useDocumentState } from "../hooks/use-document-state";
import { useRegisterDocumentMetabotContext } from "../hooks/use-register-document-metabot-context";
import {
- getCommentSidebarOpen,
getDraftCards,
getHasUnsavedChanges,
getSelectedEmbedIndex,
@@ -92,7 +91,6 @@ export const DocumentPage = ({
const dispatch = useDispatch();
const selectedQuestionId = useSelector(getSelectedQuestionId);
const selectedEmbedIndex = useSelector(getSelectedEmbedIndex);
- const commentSidebarOpen = useSelector(getCommentSidebarOpen);
const draftCards = useSelector(getDraftCards);
const [editorInstance, setEditorInstance] = useState<TiptapEditor | null>(
null,
@@ -140,8 +138,7 @@ export const DocumentPage = ({
const hasComments =
!!commentsData?.comments && commentsData.comments.length > 0;
- const canWrite =
- (isNewDocument || documentData?.can_write) && !commentSidebarOpen;
+ const canWrite = isNewDocument || documentData?.can_write;
useEffect(() => {
if (error) {
diff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/Editor/CommentsMenu/CommentsMenu.tsx b/enterprise/frontend/src/metabase-enterprise/documents/components/Editor/CommentsMenu/CommentsMenu.tsx
index b3453298b45..2a089670289 100644
--- a/enterprise/frontend/src/metabase-enterprise/documents/components/Editor/CommentsMenu/CommentsMenu.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/documents/components/Editor/CommentsMenu/CommentsMenu.tsx
@@ -11,7 +11,7 @@ import S from "./CommentsMenu.module.css";
interface Props {
active: boolean;
- disabled: boolean;
+ disabled?: boolean;
href: string;
show: boolean;
style: CSSProperties;
@@ -29,10 +29,7 @@ export const getUnresolvedComments = (
};
export const CommentsMenu = forwardRef<HTMLDivElement, Props>(
- function CommentsMenu(
- { active, disabled, href, show, style, threads }: Props,
- ref,
- ) {
+ function CommentsMenu({ active, href, show, style, threads }: Props, ref) {
const unresolvedCommentsCount = useMemo(
() => getUnresolvedComments(threads).length,
[threads],
@@ -42,9 +39,7 @@ export const CommentsMenu = forwardRef<HTMLDivElement, Props>(
return createPortal(
<Box
className={cx(S.commentsMenu, {
- [S.visible]: disabled
- ? hasUnresolvedComments
- : show || hasUnresolvedComments,
+ [S.visible]: show || hasUnresolvedComments,
})}
contentEditable={false}
draggable={false}
@@ -53,17 +48,11 @@ export const CommentsMenu = forwardRef<HTMLDivElement, Props>(
ref={ref}
style={style}
>
- <CommentsButton
- disabled={disabled}
+ <CommentsButton<typeof ForwardRefLink>
variant={active ? "filled" : "default"}
unresolvedCommentsCount={unresolvedCommentsCount}
- {...(disabled
- ? undefined
- : {
- component: ForwardRefLink,
- // If no existing unresolved comments comments, add query param to auto-open new comment form
- to: unresolvedCommentsCount > 0 ? href : `${href}?new=true`,
- })}
+ component={ForwardRefLink}
+ to={unresolvedCommentsCount > 0 ? href : `${href}?new=true`}
/>
</Box>,
document.body,
diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/components/CommentsButton.tsx b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/components/CommentsButton.tsx
index 7e0d2d53578..6ab08216587 100644
--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/components/CommentsButton.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/components/CommentsButton.tsx
@@ -1,15 +1,17 @@
+import type { ComponentPropsWithoutRef, ElementType } from "react";
import { t } from "ttag";
import { Button, type ButtonProps, Icon } from "metabase/ui";
-interface Props extends ButtonProps {
+type Props<C extends ElementType = "button"> = ButtonProps & {
unresolvedCommentsCount: number;
-}
+ component?: C;
+} & Omit<ComponentPropsWithoutRef<C>, keyof ButtonProps | "component">;
-export const CommentsButton = ({
+export const CommentsButton = <C extends ElementType = "button">({
unresolvedCommentsCount,
...props
-}: Props) => {
+}: Props<C>) => {
return (
<Button
aria-label={t`Comments`}
@@ -19,7 +21,7 @@ export const CommentsButton = ({
}
px="sm"
size="xs"
- {...props}
+ {...(props as ButtonProps)}
>
{unresolvedCommentsCount > 0 ? unresolvedCommentsCount : null}
</Button>
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.tsx
index 55c328c5d80..752c7534522 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
@@ -16,7 +16,6 @@ import { CommentsMenu } from "metabase-enterprise/documents/components/Editor/Co
import {
getChildTargetId,
getCurrentDocument,
- getHasUnsavedChanges,
getHoveredChildTargetId,
} from "metabase-enterprise/documents/selectors";
import { getListCommentsQuery } from "metabase-enterprise/documents/utils/api";
@@ -52,7 +51,6 @@ export const BlockquoteNodeView = ({ node }: NodeViewProps) => {
getListCommentsQuery(document),
);
const comments = commentsData?.comments;
- const hasUnsavedChanges = useSelector(getHasUnsavedChanges);
const [hovered, setHovered] = useState(false);
const [rendered, setRendered] = useState(false); // floating ui wrongly positions things without this
const { _id } = node.attrs;
@@ -92,7 +90,6 @@ export const BlockquoteNodeView = ({ node }: NodeViewProps) => {
{document && rendered && (
<CommentsMenu
active={isOpen}
- disabled={hasUnsavedChanges}
href={`/document/${document.id}/comments/${_id}`}
ref={refs.setFloating}
show={isOpen || hovered}
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.tsx
index 2ec23de8b45..1afb0cd8f20 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
@@ -16,7 +16,6 @@ import { CommentsMenu } from "metabase-enterprise/documents/components/Editor/Co
import {
getChildTargetId,
getCurrentDocument,
- getHasUnsavedChanges,
getHoveredChildTargetId,
} from "metabase-enterprise/documents/selectors";
import { getListCommentsQuery } from "metabase-enterprise/documents/utils/api";
@@ -49,7 +48,6 @@ export const BulletListNodeView = ({ node, editor, getPos }: NodeViewProps) => {
getListCommentsQuery(document),
);
const comments = commentsData?.comments;
- const hasUnsavedChanges = useSelector(getHasUnsavedChanges);
const [hovered, setHovered] = useState(false);
const [rendered, setRendered] = useState(false); // floating ui wrongly positions things without this
const { _id } = node.attrs;
@@ -90,7 +88,6 @@ export const BulletListNodeView = ({ node, editor, getPos }: NodeViewProps) => {
{document && rendered && isTopLevel({ editor, getPos }) && (
<CommentsMenu
active={isOpen}
- disabled={hasUnsavedChanges}
href={`/document/${document.id}/comments/${_id}`}
ref={refs.setFloating}
show={isOpen || hovered}
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.tsx
index 62f5203d9a7..1103ade7316 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
@@ -17,7 +17,6 @@ import { CommentsMenu } from "metabase-enterprise/documents/components/Editor/Co
import {
getChildTargetId,
getCurrentDocument,
- getHasUnsavedChanges,
getHoveredChildTargetId,
} from "metabase-enterprise/documents/selectors";
import { getListCommentsQuery } from "metabase-enterprise/documents/utils/api";
@@ -128,7 +127,6 @@ export const CodeBlockNodeView = ({ node }: NodeViewProps) => {
getListCommentsQuery(document),
);
const comments = commentsData?.comments;
- const hasUnsavedChanges = useSelector(getHasUnsavedChanges);
const [hovered, setHovered] = useState(false);
const [rendered, setRendered] = useState(false); // floating ui wrongly positions things without this
const { _id } = node.attrs;
@@ -177,7 +175,6 @@ export const CodeBlockNodeView = ({ node }: NodeViewProps) => {
{document && rendered && (
<CommentsMenu
active={isOpen}
- disabled={hasUnsavedChanges}
href={`/document/${document.id}/comments/${_id}`}
ref={refs.setFloating}
show={isOpen || hovered}
diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/FlexContainer/FlexContainer.tsx b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/FlexContainer/FlexContainer.tsx
index a1a20c003cd..bdacb30f405 100644
--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/FlexContainer/FlexContainer.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/FlexContainer/FlexContainer.tsx
@@ -9,9 +9,7 @@ import cx from "classnames";
import type React from "react";
import { useCallback, useMemo, useRef, useState } from "react";
-import { useSelector } from "metabase/lib/redux";
import { Box } from "metabase/ui";
-import { getCommentSidebarOpen } from "metabase-enterprise/documents/selectors";
import styles from "./FlexContainer.module.css";
@@ -88,8 +86,6 @@ const FlexContainerComponent: React.FC<NodeViewProps> = ({
const containerRef = useRef<HTMLDivElement>(null);
const [isResizing, setIsResizing] = useState(false);
- const shouldDisableResizing = useSelector(getCommentSidebarOpen);
-
// Get column count and current widths
const columnCount = node.content.childCount;
const currentWidths = node.attrs.columnWidths;
@@ -196,7 +192,7 @@ const FlexContainerComponent: React.FC<NodeViewProps> = ({
);
const renderResizeHandles = () => {
- if (columnCount <= 1 || shouldDisableResizing) {
+ if (columnCount <= 1) {
return null;
}
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.tsx
index 4d187ada0a4..f036d2274eb 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
@@ -16,7 +16,6 @@ import { CommentsMenu } from "metabase-enterprise/documents/components/Editor/Co
import {
getChildTargetId,
getCurrentDocument,
- getHasUnsavedChanges,
getHoveredChildTargetId,
} from "metabase-enterprise/documents/selectors";
import { getListCommentsQuery } from "metabase-enterprise/documents/utils/api";
@@ -65,7 +64,6 @@ export const HeadingNodeView = ({ node }: NodeViewProps) => {
getListCommentsQuery(document),
);
const comments = commentsData?.comments;
- const hasUnsavedChanges = useSelector(getHasUnsavedChanges);
const [hovered, setHovered] = useState(false);
const [rendered, setRendered] = useState(false); // floating ui wrongly positions things without this
const { _id, level } = node.attrs;
@@ -107,7 +105,6 @@ export const HeadingNodeView = ({ node }: NodeViewProps) => {
{document && rendered && (
<CommentsMenu
active={isOpen}
- disabled={hasUnsavedChanges}
href={`/document/${document.id}/comments/${_id}`}
ref={refs.setFloating}
show={isOpen || hovered}
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.tsx
index 054b6f64669..e521d1f4760 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
@@ -16,7 +16,6 @@ import { CommentsMenu } from "metabase-enterprise/documents/components/Editor/Co
import {
getChildTargetId,
getCurrentDocument,
- getHasUnsavedChanges,
getHoveredChildTargetId,
} from "metabase-enterprise/documents/selectors";
import { getListCommentsQuery } from "metabase-enterprise/documents/utils/api";
@@ -65,7 +64,6 @@ export const OrderedListNodeView = ({
getListCommentsQuery(document),
);
const comments = commentsData?.comments;
- const hasUnsavedChanges = useSelector(getHasUnsavedChanges);
const [hovered, setHovered] = useState(false);
const [rendered, setRendered] = useState(false); // floating ui wrongly positions things without this
const { _id } = node.attrs;
@@ -106,7 +104,6 @@ export const OrderedListNodeView = ({
{document && rendered && isTopLevel({ editor, getPos }) && (
<CommentsMenu
active={isOpen}
- disabled={hasUnsavedChanges}
href={`/document/${document.id}/comments/${_id}`}
ref={refs.setFloating}
show={isOpen || hovered}
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 78bb4ca5503..cde95e04dd0 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
@@ -16,7 +16,6 @@ import { CommentsMenu } from "metabase-enterprise/documents/components/Editor/Co
import {
getChildTargetId,
getCurrentDocument,
- getHasUnsavedChanges,
getHoveredChildTargetId,
} from "metabase-enterprise/documents/selectors";
import { getListCommentsQuery } from "metabase-enterprise/documents/utils/api";
@@ -56,7 +55,6 @@ export const ParagraphNodeView = ({
getListCommentsQuery(document),
);
const comments = commentsData?.comments;
- const hasUnsavedChanges = useSelector(getHasUnsavedChanges);
const [hovered, setHovered] = useState(false);
const [rendered, setRendered] = useState(false); // floating ui wrongly positions things without this
const { _id } = node.attrs;
@@ -99,7 +97,6 @@ export const ParagraphNodeView = ({
isTopLevel({ editor, getPos }) && (
<CommentsMenu
active={isOpen}
- disabled={hasUnsavedChanges}
href={`/document/${document.id}/comments/${_id}`}
ref={refs.setFloating}
show={isOpen || hovered}
diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/ResizeNode/ResizeNode.tsx b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/ResizeNode/ResizeNode.tsx
index db2d9fca2be..509135981bb 100644
--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/ResizeNode/ResizeNode.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/ResizeNode/ResizeNode.tsx
@@ -7,9 +7,7 @@ import {
import type React from "react";
import { useRef, useState } from "react";
-import { useSelector } from "metabase/lib/redux";
import { Box, Flex } from "metabase/ui";
-import { getCommentSidebarOpen } from "metabase-enterprise/documents/selectors";
import S from "./ResizeNode.module.css";
@@ -86,8 +84,6 @@ const ResizeNodeView = ({
const [height, setHeight] = useState(attrs.height);
const _height = useRef(attrs.height);
- const shouldDisableResizing = useSelector(getCommentSidebarOpen);
-
const computeHeight = (delta: number) => {
const newHeight = _height.current + delta;
@@ -114,9 +110,7 @@ const ResizeNodeView = ({
data-type="resizeNode"
>
<NodeViewContent className={S.content} />
- {!shouldDisableResizing && (
- <DragHandle onDrag={handleDrag} onDragEnd={handleDragEnd} />
- )}
+ <DragHandle onDrag={handleDrag} onDragEnd={handleDragEnd} />
</NodeViewWrapper>
);
};