diff --git a/services/web/frontend/js/features/review-panel-new/components/review-panel-change.tsx b/services/web/frontend/js/features/review-panel-new/components/review-panel-change.tsx index c5807dc4c5..b2097ad61d 100644 --- a/services/web/frontend/js/features/review-panel-new/components/review-panel-change.tsx +++ b/services/web/frontend/js/features/review-panel-new/components/review-panel-change.tsx @@ -15,15 +15,7 @@ import { useChangesUsersContext } from '../context/changes-users-context' import { ReviewPanelChangeUser } from './review-panel-change-user' import { ReviewPanelEntry } from './review-panel-entry' import { useModalsContext } from '@/features/ide-react/context/modals-context' - -const TEXT_CHAR_LIMIT = 50 - -const truncateText = (text: string) => { - if (text.length > TEXT_CHAR_LIMIT) { - return text.slice(0, TEXT_CHAR_LIMIT) + '...' - } - return text -} +import { ExpandableContent } from './review-panel-expandable-content' export const ReviewPanelChange = memo<{ change: Change @@ -172,18 +164,27 @@ export const ReviewPanelChange = memo<{ {t('aggregate_changed')}:{' '} - {truncateText(aggregate.op.d)} + {' '} {t('aggregate_to')}{' '} - - {truncateText(change.op.i)} - + ) : ( {t('tracked_change_added')}:  - {truncateText(change.op.i)} + )} @@ -200,7 +201,10 @@ export const ReviewPanelChange = memo<{ {t('tracked_change_deleted')}:  - {truncateText(change.op.d)} + diff --git a/services/web/frontend/js/features/review-panel-new/components/review-panel-expandable-content.tsx b/services/web/frontend/js/features/review-panel-new/components/review-panel-expandable-content.tsx index ed8f837826..f16556a049 100644 --- a/services/web/frontend/js/features/review-panel-new/components/review-panel-expandable-content.tsx +++ b/services/web/frontend/js/features/review-panel-new/components/review-panel-expandable-content.tsx @@ -1,24 +1,34 @@ -import { FC, useCallback, useEffect, useRef, useState } from 'react' -import classNames from 'classnames' +import { FC, useCallback, useRef, useState } from 'react' import OLButton from '@/features/ui/components/ol/ol-button' import { useTranslation } from 'react-i18next' +import classNames from 'classnames' -export const ExpandableContent: FC<{ className?: string }> = ({ - children, +export const ExpandableContent: FC<{ + className?: string + content: string + contentLimit?: number + newLineCharsLimit?: number + checkNewLines?: boolean + inline?: boolean +}> = ({ + content, className, + contentLimit = 50, + newLineCharsLimit = 3, + checkNewLines = true, + inline = false, }) => { const { t } = useTranslation() const contentRef = useRef(null) const [isExpanded, setIsExpanded] = useState(false) - const [isOverflowing, setIsOverflowing] = useState(false) - - useEffect(() => { - if (contentRef.current) { - setIsOverflowing( - contentRef.current.scrollHeight > contentRef.current.clientHeight + const limit = checkNewLines + ? Math.min( + contentLimit, + indexOfNthLine(content, newLineCharsLimit) ?? Infinity ) - } - }, []) + : contentLimit + + const isOverflowing = content.length > limit const handleShowMore = useCallback(() => { setIsExpanded(true) @@ -35,38 +45,54 @@ export const ExpandableContent: FC<{ className?: string }> = ({ }, []) return ( -
+ <>
- {children} + {isExpanded ? content : content.slice(0, limit)} + {isOverflowing && !isExpanded && '...'}
- {isExpanded ? ( - - {t('show_less')} - - ) : ( - isOverflowing && ( +
+ {isExpanded ? ( - {t('show_more')} + {t('show_less')} - ) - )} -
+ ) : ( + isOverflowing && ( + + {t('show_more')} + + ) + )} +
+ ) } + +function indexOfNthLine(content: string, n: number) { + if (n < 1) return null + + let line = 0 + for (let i = 0; i < content.length; i++) { + if (content[i] === '\n') { + line++ + if (line === n) { + return i + } + } + } + return null +} diff --git a/services/web/frontend/js/features/review-panel-new/components/review-panel-message.tsx b/services/web/frontend/js/features/review-panel-new/components/review-panel-message.tsx index 2104c8af8f..403903d7f4 100644 --- a/services/web/frontend/js/features/review-panel-new/components/review-panel-message.tsx +++ b/services/web/frontend/js/features/review-panel-new/components/review-panel-message.tsx @@ -112,9 +112,11 @@ export const ReviewPanelMessage: FC<{ autoFocus // eslint-disable-line jsx-a11y/no-autofocus /> ) : ( - - {message.content} - + )} {deleting && ( diff --git a/services/web/frontend/js/features/review-panel-new/components/review-panel-resolved-thread.tsx b/services/web/frontend/js/features/review-panel-new/components/review-panel-resolved-thread.tsx index 30b9d84ccd..937cabc59d 100644 --- a/services/web/frontend/js/features/review-panel-new/components/review-panel-resolved-thread.tsx +++ b/services/web/frontend/js/features/review-panel-new/components/review-panel-resolved-thread.tsx @@ -97,9 +97,11 @@ export const ReviewPanelResolvedThread: FC<{
{t('quoted_text')}
- - {comment?.op.c} - + diff --git a/services/web/frontend/stylesheets/app/editor/review-panel-new.less b/services/web/frontend/stylesheets/app/editor/review-panel-new.less index e45ea94225..42a6e04926 100644 --- a/services/web/frontend/stylesheets/app/editor/review-panel-new.less +++ b/services/web/frontend/stylesheets/app/editor/review-panel-new.less @@ -361,19 +361,26 @@ font-size: @font-size-02; color: @content-primary; overflow-wrap: anywhere; + white-space: pre-wrap; } - .review-panel-content-expandable { - display: -webkit-box; - text-overflow: ellipsis; - -webkit-box-orient: vertical; - -webkit-line-clamp: 3; - line-clamp: 3; - overflow: hidden; + .review-panel-expandable-content { + display: inline; + padding-right: var(--spacing-02); } - .review-panel-content-expanded { - display: block; + .review-panel-expandable-inline { + display: inline; + } + + .review-panel-expandable-links { + .btn-inline-link { + text-decoration: none; + line-height: 1; + } + .btn-inline-link:hover { + text-decoration: underline; + } } .review-panel-comment-input { diff --git a/services/web/frontend/stylesheets/bootstrap-5/pages/editor/review-panel-new.scss b/services/web/frontend/stylesheets/bootstrap-5/pages/editor/review-panel-new.scss index 71f5f77722..ecc54c1aaa 100644 --- a/services/web/frontend/stylesheets/bootstrap-5/pages/editor/review-panel-new.scss +++ b/services/web/frontend/stylesheets/bootstrap-5/pages/editor/review-panel-new.scss @@ -366,19 +366,27 @@ font-size: var(--font-size-02); color: var(--content-primary); overflow-wrap: anywhere; + white-space: pre-wrap; } - .review-panel-content-expandable { - display: -webkit-box; - text-overflow: ellipsis; - -webkit-box-orient: vertical; - -webkit-line-clamp: 3; - line-clamp: 3; - overflow: hidden; + .review-panel-expandable-content { + display: inline; + padding-right: var(--spacing-02); } - .review-panel-content-expanded { - display: block; + .review-panel-expandable-inline { + display: inline; + } + + .review-panel-expandable-links { + .btn-inline-link { + text-decoration: none; + line-height: 1; + } + + .btn-inline-link:hover { + text-decoration: underline; + } } .review-panel-comment-input {