From fee3b97326198ff0d0829f117c2677201d786ecb Mon Sep 17 00:00:00 2001 From: ilkin-overleaf <100852799+ilkin-overleaf@users.noreply.github.com> Date: Tue, 4 Jul 2023 14:05:12 +0300 Subject: [PATCH] Merge pull request #13641 from overleaf/ii-review-panel-migration-overview-view [web] Create overview view shell for review panel GitOrigin-RevId: 21cc8a744253aec53f089ec6e6c1221d7153f3a4 --- .../components/review-panel/container.tsx | 8 -- .../review-panel/current-file-container.tsx | 106 +++++++++-------- .../review-panel/entries/comment-entry.tsx | 13 ++- .../review-panel/hooks/use-collapse-height.ts | 26 +++++ .../review-panel/overview-container.tsx | 72 ++++++------ .../components/review-panel/overview-file.tsx | 109 ++++++++++++++++++ .../components/review-panel/review-panel.tsx | 9 +- .../toolbar/resolved-comments-dropdown.tsx | 2 +- .../review-panel/toolbar/toggle-menu.tsx | 19 +-- .../hooks/use-angular-review-panel-state.ts | 5 + .../review-panel/types/review-panel-state.ts | 9 +- .../stylesheets/app/editor/review-panel.less | 15 +-- .../editor-left-menu.spec.tsx | 4 +- .../settings/settings-document.test.tsx | 2 +- .../review-panel/review-panel.spec.tsx | 8 ++ services/web/types/project-settings.ts | 4 +- services/web/types/review-panel/entry.ts | 2 +- .../web/types/review-panel/review-panel.ts | 2 +- 18 files changed, 274 insertions(+), 141 deletions(-) create mode 100644 services/web/frontend/js/features/source-editor/components/review-panel/hooks/use-collapse-height.ts create mode 100644 services/web/frontend/js/features/source-editor/components/review-panel/overview-file.tsx diff --git a/services/web/frontend/js/features/source-editor/components/review-panel/container.tsx b/services/web/frontend/js/features/source-editor/components/review-panel/container.tsx index bba2364bc0..21f4dd32ab 100644 --- a/services/web/frontend/js/features/source-editor/components/review-panel/container.tsx +++ b/services/web/frontend/js/features/source-editor/components/review-panel/container.tsx @@ -1,6 +1,3 @@ -import Toggler from './toggler' -import Toolbar from './toolbar/toolbar' -import Nav from './nav' import classnames from 'classnames' const reviewPanelClasses = ['ol-cm-review-panel'] @@ -18,11 +15,6 @@ function Container({ children, classNames, ...rest }: ContainerProps) { {...rest} data-testid="review-panel" > -
- -
- {children} ) diff --git a/services/web/frontend/js/features/source-editor/components/review-panel/current-file-container.tsx b/services/web/frontend/js/features/source-editor/components/review-panel/current-file-container.tsx index 6ecb25e170..bfb01124ba 100644 --- a/services/web/frontend/js/features/source-editor/components/review-panel/current-file-container.tsx +++ b/services/web/frontend/js/features/source-editor/components/review-panel/current-file-container.tsx @@ -1,4 +1,8 @@ import { useMemo } from 'react' +import Container from './container' +import Toolbar from './toolbar/toolbar' +import Nav from './nav' +import Toggler from './toggler' import ChangeEntry from './entries/change-entry' import AggregateChangeEntry from './entries/aggregate-change-entry' import CommentEntry from './entries/comment-entry' @@ -26,54 +30,62 @@ function CurrentFileContainer() { }, [currentDocEntries]) return ( -
-
- {openDocId && - objectEntries.map(([id, entry]) => { - if (!entry.visible) { - return null - } - - if (entry.type === 'insert' || entry.type === 'delete') { - return - } - - if (entry.type === 'aggregate-change') { - return - } - - if (entry.type === 'comment' && !loadingThreads) { - return ( - - ) - } - - if (entry.type === 'add-comment' && permissions.comment) { - return - } - - if (entry.type === 'bulk-actions') { - return - } - - return null - })} + +
+ +
-
+ +
+
+ {openDocId && + objectEntries.map(([id, entry]) => { + if (!entry.visible) { + return null + } + + if (entry.type === 'insert' || entry.type === 'delete') { + return + } + + if (entry.type === 'aggregate-change') { + return + } + + if (entry.type === 'comment' && !loadingThreads) { + return ( + + ) + } + + if (entry.type === 'add-comment' && permissions.comment) { + return + } + + if (entry.type === 'bulk-actions') { + return + } + + return null + })} +
+
+ ) } diff --git a/services/web/frontend/js/features/source-editor/components/review-panel/entries/comment-entry.tsx b/services/web/frontend/js/features/source-editor/components/review-panel/entries/comment-entry.tsx index a01cac81a6..9871b37c3b 100644 --- a/services/web/frontend/js/features/source-editor/components/review-panel/entries/comment-entry.tsx +++ b/services/web/frontend/js/features/source-editor/components/review-panel/entries/comment-entry.tsx @@ -14,22 +14,29 @@ import { import classnames from 'classnames' import { ReviewPanelCommentEntry } from '../../../../../../../types/review-panel/entry' import { - DocId, ReviewPanelCommentThreads, + ReviewPanelPermissions, ThreadId, } from '../../../../../../../types/review-panel/review-panel' +import { DocId } from '../../../../../../../types/project-settings' type CommentEntryProps = { docId: DocId entry: ReviewPanelCommentEntry entryId: ThreadId + permissions: ReviewPanelPermissions threads: ReviewPanelCommentThreads } -function CommentEntry({ docId, entry, entryId, threads }: CommentEntryProps) { +function CommentEntry({ + docId, + entry, + entryId, + permissions, + threads, +}: CommentEntryProps) { const { t } = useTranslation() const { - permissions, gotoEntry, toggleReviewPanel, resolveComment, diff --git a/services/web/frontend/js/features/source-editor/components/review-panel/hooks/use-collapse-height.ts b/services/web/frontend/js/features/source-editor/components/review-panel/hooks/use-collapse-height.ts new file mode 100644 index 0000000000..431ce8ac96 --- /dev/null +++ b/services/web/frontend/js/features/source-editor/components/review-panel/hooks/use-collapse-height.ts @@ -0,0 +1,26 @@ +import { useEffect } from 'react' + +function useCollapseHeight( + elRef: React.MutableRefObject, + shouldCollapse: boolean +) { + useEffect(() => { + if (elRef.current) { + const neededHeight = elRef.current.scrollHeight + + if (neededHeight > 0) { + const height = shouldCollapse ? 0 : neededHeight + // This might result in a too big height if the element has css prop of + // `box-sizing` set to `content-box`. To fix that, values of props such as + // box-sizing, padding and border could be extracted from `height` to compensate. + elRef.current.style.height = `${height}px` + } else { + if (shouldCollapse) { + elRef.current.style.height = '0' + } + } + } + }, [elRef, shouldCollapse]) +} + +export default useCollapseHeight diff --git a/services/web/frontend/js/features/source-editor/components/review-panel/overview-container.tsx b/services/web/frontend/js/features/source-editor/components/review-panel/overview-container.tsx index 9122163bb8..32bdb3f628 100644 --- a/services/web/frontend/js/features/source-editor/components/review-panel/overview-container.tsx +++ b/services/web/frontend/js/features/source-editor/components/review-panel/overview-container.tsx @@ -1,41 +1,41 @@ +import Container from './container' +import Toggler from './toggler' +import Toolbar from './toolbar/toolbar' +import Nav from './nav' +import Icon from '../../../../shared/components/icon' +import OverviewFile from './overview-file' +import { useReviewPanelValueContext } from '../../context/review-panel/review-panel-context' + function OverviewContainer() { + const { loading, docs } = useReviewPanelValueContext() + return ( -
- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod - tempor incididunt ut labore et dolore magna aliqua. Et malesuada fames ac - turpis egestas integer eget aliquet nibh. Et leo duis ut diam quam nulla - porttitor massa id. Risus quis varius quam quisque id diam vel quam - elementum. Nibh venenatis cras sed felis. Sit amet commodo nulla facilisi - nullam vehicula ipsum a arcu. Dui ut ornare lectus sit amet est placerat - in. Aliquam ultrices sagittis orci a. Leo a diam sollicitudin tempor id eu - nisl nunc mi. Quis ipsum suspendisse ultrices gravida dictum fusce. Ut - etiam sit amet nisl purus in mollis nunc sed. Rhoncus est pellentesque - elit ullamcorper dignissim cras. Faucibus turpis in eu mi bibendum. Proin - libero nunc consequat interdum. Ac placerat vestibulum lectus mauris - ultrices eros in cursus turpis. Ac felis donec et odio. Nullam ac tortor - vitae purus faucibus. Consectetur lorem donec massa sapien faucibus et - molestie. Praesent elementum facilisis leo vel fringilla est ullamcorper - eget nulla. Adipiscing vitae proin sagittis nisl rhoncus mattis rhoncus - urna. Cursus metus aliquam eleifend mi in nulla posuere sollicitudin - aliquam. Eget nullam non nisi est sit amet facilisis magna. Donec - adipiscing tristique risus nec feugiat in fermentum posuere. Gravida - rutrum quisque non tellus orci ac auctor augue. Euismod in pellentesque - massa placerat duis ultricies lacus. Pellentesque diam volutpat commodo - sed egestas. Tempus iaculis urna id volutpat lacus laoreet. Lorem ipsum - dolor sit amet consectetur. Tincidunt id aliquet risus feugiat in ante - metus. Risus ultricies tristique nulla aliquet enim tortor at auctor urna. - Purus in mollis nunc sed. In ante metus dictum at. Magna eget est lorem - ipsum dolor sit. Fusce id velit ut tortor pretium viverra. Augue neque - gravida in fermentum et sollicitudin ac. Et malesuada fames ac turpis. - Felis bibendum ut tristique et egestas quis ipsum suspendisse ultrices. - Varius vel pharetra vel turpis nunc eget. -
+ + + +
+ {loading ? ( +
+ +
+ ) : ( + docs?.map(doc => ( + + )) + )} +
+