Skip to content

Commit 7e40314

Browse files
45330 refactor(editor): lift mentions computation to WorkflowLog parent component
1 parent b87fcb4 commit 7e40314

3 files changed

Lines changed: 22 additions & 25 deletions

File tree

frontend/src/public/components/Workflows/WorkflowLog/PopupCommentField/PopupCommentField.tsx

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,30 @@
11
import * as React from 'react';
2-
import { useMemo } from 'react';
32
import { useIntl } from 'react-intl';
4-
import { useSelector } from 'react-redux';
53

64
import { RichEditor, type IRichEditorHandle } from '../../../RichEditor';
7-
import { getMentionData } from '../../../RichEditor/utils/getMentionData';
5+
import { type TMentionData } from '../../../RichEditor/types';
86
import { Avatar } from '../../../UI/Avatar';
97
import { IAuthUser } from '../../../../types/redux';
108
import { TUploadedFile } from '../../../../utils/uploadFiles';
119
import { ISendWorkflowLogComment } from '../../../../redux/workflows/types';
1210
import { useStatePromise } from '../../../../hooks/useStatePromise';
1311
import { isArrayWithItems } from '../../../../utils/helpers';
14-
import { getUsers } from '../../../../redux/selectors/user';
15-
import { getNotDeletedUsers } from '../../../../utils/users';
1612

1713
import styles from './PopupCommentField.css';
1814

1915
export interface IPopupCommentFieldProps {
2016
user: IAuthUser;
17+
mentions: TMentionData[];
2118
sendComment({ text, attachments, taskId }: ISendWorkflowLogComment): void;
2219
taskId?: number;
2320
}
2421

2522
export type TPopupCommentFieldProps = IPopupCommentFieldProps;
2623

27-
export function PopupCommentField({ user, sendComment, taskId }: TPopupCommentFieldProps) {
24+
export function PopupCommentField({ user, mentions, sendComment, taskId }: TPopupCommentFieldProps) {
2825
const { formatMessage } = useIntl();
2926
const editorRef = React.useRef<IRichEditorHandle>(null);
3027

31-
const users = useSelector(getUsers);
32-
const mentions = useMemo(
33-
() => getMentionData(getNotDeletedUsers(users)),
34-
[users],
35-
);
36-
3728
const [commentText, setCommentText] = useStatePromise('');
3829
const [filesToUpload, setFilesToUpload] = useStatePromise<TUploadedFile[]>([]);
3930

frontend/src/public/components/Workflows/WorkflowLog/WorkflowLog.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from 'react';
2-
import { useEffect } from 'react';
2+
import { useEffect, useMemo } from 'react';
3+
import { useSelector } from 'react-redux';
34
import classnames from 'classnames';
45
import { useIntl } from 'react-intl';
56
import Switch from 'rc-switch';
@@ -41,6 +42,9 @@ import { WorkflowLogRemovedPerformerGroup } from './WorkflowLogEvents/WorkflowLo
4142

4243
import styles from './WorkflowLog.css';
4344
import { IChangeWorkflowLogViewSettingsPayload, ISendWorkflowLogComment } from '../../../redux/workflows/types';
45+
import { getUsers } from '../../../redux/selectors/user';
46+
import { getNotDeletedUsers } from '../../../utils/users';
47+
import { getMentionData } from '../../RichEditor/utils/getMentionData';
4448

4549
export const WorkflowLog = ({
4650
theme,
@@ -69,6 +73,12 @@ export const WorkflowLog = ({
6973
}: IWorkflowLogProps) => {
7074
const { formatMessage } = useIntl();
7175

76+
const users = useSelector(getUsers);
77+
const mentions = useMemo(
78+
() => getMentionData(getNotDeletedUsers(users)),
79+
[users],
80+
);
81+
7282
useEffect(() => {
7383
return () => {
7484
if (onUnmount) {
@@ -213,7 +223,7 @@ export const WorkflowLog = ({
213223

214224
return (
215225
<div className={styles['comment-field']}>
216-
<PopupCommentFieldContainer sendComment={sendComment} taskId={taskId} />
226+
<PopupCommentFieldContainer sendComment={sendComment} taskId={taskId} mentions={mentions} />
217227
</div>
218228
);
219229
};
@@ -270,6 +280,7 @@ export const WorkflowLog = ({
270280
<WorkflowLogTaskCommentContainer
271281
workflowStatus={workflowStatus}
272282
isOnlyAttachmentsShown={isOnlyAttachmentsShown}
283+
mentions={mentions}
273284
{...event}
274285
/>
275286
),

frontend/src/public/components/Workflows/WorkflowLog/WorkflowLogEvents/WorkflowLogTaskComment/WorkflowLogTaskComment.tsx

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import React, { useEffect, useMemo, useRef, useState } from 'react';
1+
import React, { useEffect, useRef, useState } from 'react';
22
import { useIntl } from 'react-intl';
3-
import { useSelector } from 'react-redux';
43
import classnames from 'classnames';
54
import { InView } from 'react-intersection-observer';
65
import data from '@emoji-mart/data';
@@ -10,7 +9,7 @@ import { useClickOutside } from '../../../../../hooks/useClickOutside';
109
import { IDeleteComment } from '../../../../../api/workflows/deleteComment';
1110
import { Avatar } from '../../../../UI/Avatar';
1211
import { EWorkflowStatus, IWorkflowLogItem } from '../../../../../types/workflow';
13-
import { getUserFullName , getNotDeletedUsers } from '../../../../../utils/users';
12+
import { getUserFullName } from '../../../../../utils/users';
1413
import { RichText } from '../../../../RichText';
1514
import { Attachments } from '../../../../Attachments';
1615
import { UserData } from '../../../../UserData';
@@ -23,7 +22,7 @@ import {
2322
CommentWatchedIcon,
2423
} from '../../../../icons';
2524
import { RichEditor } from '../../../../RichEditor';
26-
import { getMentionData } from '../../../../RichEditor/utils/getMentionData';
25+
import { type TMentionData } from '../../../../RichEditor/types';
2726
import { IAccount, TUserListItem } from '../../../../../types/user';
2827
import { useStatePromise } from '../../../../../hooks/useStatePromise';
2928
import { TUploadedFile } from '../../../../../utils/uploadFiles';
@@ -32,7 +31,7 @@ import { IWatchedComment } from '../../../../../api/workflows/watchedComment';
3231
import { Tooltip } from '../../../../UI';
3332
import { ICreateReaction } from '../../../../../api/workflows/createReactionComment';
3433
import { IDeleteReaction } from '../../../../../api/workflows/deleteReactionComment';
35-
import { getUsers } from '../../../../../redux/selectors/user';
34+
3635

3736

3837
import styles from './WorkflowLogTaskComment.css';
@@ -57,15 +56,10 @@ export function WorkflowLogTaskComment({
5756
watchedComment,
5857
createReactionComment,
5958
deleteReactionComment,
59+
mentions,
6060
}: TWorkflowLogTaskCommentProps) {
6161
const { formatMessage } = useIntl();
6262

63-
const allUsers = useSelector(getUsers);
64-
const mentions = useMemo(
65-
() => getMentionData(getNotDeletedUsers(allUsers)),
66-
[allUsers],
67-
);
68-
6963
const clickRef = useRef<HTMLButtonElement>(null);
7064
const [isShowTooltipEmoji, setIsShowTooltipEmoji] = useState(false);
7165
const [isShowEmoji, setIsShowEmoji] = useState(false);
@@ -397,6 +391,7 @@ export type TWorkflowLogTaskCommentProps = Pick<
397391
currentUserId: number;
398392
workflowModal: boolean;
399393
workflowStatus: EWorkflowStatus;
394+
mentions: TMentionData[];
400395
isOnlyAttachmentsShown?: boolean;
401396
editComment(payload: IEditComment): void;
402397
deleteComment(payload: IDeleteComment): void;

0 commit comments

Comments
 (0)