From c02a33a74cbc460dfaf7768faa98db0f19614438 Mon Sep 17 00:00:00 2001 From: "codegen-sh[bot]" <131295404+codegen-sh[bot]@users.noreply.github.com> Date: Sat, 24 May 2025 18:35:50 -0400 Subject: [PATCH] feat: Disable commenting per collection (#9295) * Address PR feedback: Move commenting logic to Collection model - Update openDocumentComments action to use collection.canCreateComment - Update AuthenticatedLayout to check collection-level commenting setting - Update DocumentMeta to use collection commenting preference - Add commenting field to CollectionForm with proper UI - Maintain backward compatibility with team-level preferences * Applied automatic fixes * Disable comment creation UI when collection commenting is disabled - Update Editor component to use collection-level commenting setting - Pass onCreateCommentMark as undefined when commenting is disabled - This removes the shortcut and toolbar icon for comment creation - Maintains backward compatibility with team-level preferences * Fix TypeScript error in Editor component - Fix props destructuring to avoid variable shadowing - Ensure all required props are properly destructured - Maintain correct property order from original implementation * Fix TypeScript error: add missing activeCollectionId parameter - Add activeCollectionId to import document action perform function - This parameter was being used but not declared in the function signature - Fixes TS2304 error: Cannot find name 'activeCollectionId' * fix form * docs --------- Co-authored-by: codegen-sh[bot] <131295404+codegen-sh[bot]@users.noreply.github.com> Co-authored-by: Tom Moor --- app/actions/definitions/documents.tsx | 11 ++++++--- app/components/AuthenticatedLayout.tsx | 6 +++-- app/components/Collection/CollectionForm.tsx | 13 ++++++++++- app/models/Collection.ts | 23 +++++++++++++++++++ .../Document/components/DocumentMeta.tsx | 11 +++++++-- app/scenes/Document/components/Editor.tsx | 15 +++++++++--- ...0250429130521-add-collection-commenting.js | 17 ++++++++++++++ server/models/Collection.ts | 6 +++++ server/presenters/collection.ts | 1 + server/routes/api/collections/collections.ts | 7 ++++++ server/routes/api/collections/schema.ts | 2 ++ shared/i18n/locales/en_US/translation.json | 3 ++- 12 files changed, 103 insertions(+), 12 deletions(-) create mode 100644 server/migrations/20250429130521-add-collection-commenting.js diff --git a/app/actions/definitions/documents.tsx b/app/actions/definitions/documents.tsx index 019297d976..60bf342902 100644 --- a/app/actions/definitions/documents.tsx +++ b/app/actions/definitions/documents.tsx @@ -750,7 +750,7 @@ export const importDocument = createAction({ return false; }, - perform: ({ activeCollectionId, activeDocumentId, stores }) => { + perform: ({ activeDocumentId, activeCollectionId, stores }) => { const { documents } = stores; const input = document.createElement("input"); input.type = "file"; @@ -1081,12 +1081,17 @@ export const openDocumentComments = createAction({ analyticsName: "Open comments", section: ActiveDocumentSection, icon: , - visible: ({ activeDocumentId, stores }) => { + visible: ({ activeCollectionId, activeDocumentId, stores }) => { const can = stores.policies.abilities(activeDocumentId ?? ""); + const collection = activeCollectionId + ? stores.collections.get(activeCollectionId) + : undefined; + return ( !!activeDocumentId && can.comment && - !!stores.auth.team?.getPreference(TeamPreference.Commenting) + (collection?.canCreateComment ?? + !!stores.auth.team?.getPreference(TeamPreference.Commenting)) ); }, perform: ({ activeDocumentId, stores }) => { diff --git a/app/components/AuthenticatedLayout.tsx b/app/components/AuthenticatedLayout.tsx index c167fa42af..405400bbfa 100644 --- a/app/components/AuthenticatedLayout.tsx +++ b/app/components/AuthenticatedLayout.tsx @@ -49,7 +49,7 @@ type Props = { }; const AuthenticatedLayout: React.FC = ({ children }: Props) => { - const { ui, auth } = useStores(); + const { ui, auth, collections } = useStores(); const location = useLocation(); const layoutRef = React.useRef(null); const can = usePolicy(ui.activeDocumentId); @@ -108,7 +108,9 @@ const AuthenticatedLayout: React.FC = ({ children }: Props) => { can.comment && ui.activeDocumentId && ui.commentsExpanded && - team.getPreference(TeamPreference.Commenting); + (ui.activeCollectionId + ? collections.get(ui.activeCollectionId)?.canCreateComment + : !!team.getPreference(TeamPreference.Commenting)); const sidebarRight = ( { @@ -83,6 +84,7 @@ export const CollectionForm = observer(function CollectionForm_({ icon: collection?.icon, sharing: collection?.sharing ?? true, permission: collection?.permission, + commenting: collection?.commenting ?? true, color: iconColor, }, }); @@ -190,6 +192,15 @@ export const CollectionForm = observer(function CollectionForm_({ /> )} + {team.getPreference(TeamPreference.Commenting) && ( + + )} +