Skip to content

Commit 23353be

Browse files
committed
feat: add actions in review
1 parent 59befe4 commit 23353be

File tree

4 files changed

+67
-17
lines changed

4 files changed

+67
-17
lines changed

src/components/codeReview/CodeReviewBody.tsx

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ import React, { FC, Fragment } from 'react';
77
import { Add } from '@mui/icons-material';
88
import { IconButton, styled } from '@mui/material';
99

10+
import { APP_ACTIONS_TYPES } from '../../config/appActionsTypes';
1011
import { APP_DATA_TYPES, APP_DATA_VISIBILITY } from '../../config/appDataTypes';
1112
import { GENERAL_SETTINGS_NAME } from '../../config/appSettingsTypes';
1213
import { REVIEW_MODE_INDIVIDUAL } from '../../config/constants';
1314
import { SMALL_BORDER_RADIUS } from '../../config/layout';
15+
import { MUTATION_KEYS, useMutation } from '../../config/queryClient';
1416
import {
1517
CODE_REVIEW_ADD_BUTTON_CYPRESS,
1618
CODE_REVIEW_LINE_CONTENT_CYPRESS,
@@ -94,6 +96,11 @@ const CodeReviewBody: FC<Props> = () => {
9496
const allowComments = settings[GeneralSettingsKeys.AllowComments];
9597
const reviewMode = settings[GeneralSettingsKeys.ReviewMode];
9698
const { postAppData, comments } = useAppDataContext();
99+
const { mutate: postAction } = useMutation<
100+
unknown,
101+
unknown,
102+
{ data: unknown; type: string }
103+
>(MUTATION_KEYS.POST_APP_ACTION);
97104

98105
const versionComments = comments?.filter((c) => c.data.codeId === codeId);
99106

@@ -174,25 +181,30 @@ const CodeReviewBody: FC<Props> = () => {
174181
<CommentEditor
175182
onCancel={closeComment}
176183
onSend={(text) => {
184+
const data = {
185+
content: text,
186+
line: i,
187+
// codeId corresponding to current code version
188+
codeId,
189+
// comment on top level has no parent
190+
parent: null,
191+
...(multilineRange?.start &&
192+
multilineRange?.end && {
193+
multiline: multilineRange,
194+
}),
195+
};
177196
postAppData({
178-
data: {
179-
content: text,
180-
line: i,
181-
// codeId corresponding to current code version
182-
codeId,
183-
// comment on top level has no parent
184-
parent: null,
185-
...(multilineRange?.start &&
186-
multilineRange?.end && {
187-
multiline: multilineRange,
188-
}),
189-
},
197+
data,
190198
type: APP_DATA_TYPES.COMMENT,
191199
visibility:
192200
reviewMode === REVIEW_MODE_INDIVIDUAL
193201
? APP_DATA_VISIBILITY.MEMBER
194202
: APP_DATA_VISIBILITY.ITEM,
195203
});
204+
postAction({
205+
data,
206+
type: APP_ACTIONS_TYPES.CREATE_COMMENT,
207+
});
196208
closeComment();
197209
}}
198210
/>

src/components/common/CommentActions.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { useTranslation } from 'react-i18next';
44
import { Delete, Edit, Flag } from '@mui/icons-material';
55
import { ListItemIcon, ListItemText, Menu, MenuItem } from '@mui/material';
66

7+
import { APP_ACTIONS_TYPES } from '../../config/appActionsTypes';
8+
import { MUTATION_KEYS, useMutation } from '../../config/queryClient';
79
import { useAppDataContext } from '../context/AppDataContext';
810
import { useCommentContext } from '../context/CommentContext';
911
import { useReviewContext } from '../context/ReviewContext';
@@ -31,6 +33,11 @@ const CommentActions: FC<Props> = ({
3133
const comment = useCommentContext();
3234
const { editComment } = useReviewContext();
3335
const { deleteAppData } = useAppDataContext();
36+
const { mutate: postAction } = useMutation<
37+
unknown,
38+
unknown,
39+
{ data: unknown; type: string }
40+
>(MUTATION_KEYS.POST_APP_ACTION);
3441

3542
return (
3643
<Menu
@@ -52,6 +59,10 @@ const CommentActions: FC<Props> = ({
5259
<MenuItem
5360
onClick={() => {
5461
editComment(comment.id);
62+
postAction({
63+
data: { comment },
64+
type: APP_ACTIONS_TYPES.EDIT_COMMENT,
65+
});
5566
onClose();
5667
}}
5768
>
@@ -65,6 +76,10 @@ const CommentActions: FC<Props> = ({
6576
<MenuItem
6677
onClick={() => {
6778
deleteAppData({ id: comment.id });
79+
postAction({
80+
data: { comment },
81+
type: APP_ACTIONS_TYPES.DELETE_COMMENT,
82+
});
6883
onClose();
6984
}}
7085
>
@@ -78,6 +93,10 @@ const CommentActions: FC<Props> = ({
7893
<MenuItem
7994
onClick={() => {
8095
onClickFlag?.();
96+
postAction({
97+
data: { comment },
98+
type: APP_ACTIONS_TYPES.REPORT_COMMENT,
99+
});
81100
onClose();
82101
}}
83102
>

src/components/common/CommentThread.tsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import { useTranslation } from 'react-i18next';
55

66
import { TextField, styled } from '@mui/material';
77

8+
import { APP_ACTIONS_TYPES } from '../../config/appActionsTypes';
89
import { APP_DATA_TYPES } from '../../config/appDataTypes';
910
import { BIG_BORDER_RADIUS } from '../../config/layout';
11+
import { MUTATION_KEYS, useMutation } from '../../config/queryClient';
1012
import { COMMENT_THREAD_CONTAINER_CYPRESS } from '../../config/selectors';
1113
import { CommentType } from '../../interfaces/comment';
1214
import { buildThread } from '../../utils/comments';
@@ -51,6 +53,11 @@ const CommentThread: FC<Props> = ({ children, hiddenState }) => {
5153
closeEditingComment,
5254
} = useReviewContext();
5355
const { patchAppData, postAppData } = useAppDataContext();
56+
const { mutate: postAction } = useMutation<
57+
unknown,
58+
unknown,
59+
{ data: unknown; type: string }
60+
>(MUTATION_KEYS.POST_APP_ACTION);
5461

5562
const isEdited = (id: string): boolean => id === currentEditedCommentId;
5663
const isReplied = (id: string): boolean => id === currentRepliedCommentId;
@@ -108,14 +115,19 @@ const CommentThread: FC<Props> = ({ children, hiddenState }) => {
108115
<CommentEditor
109116
onCancel={closeComment}
110117
onSend={(content) => {
118+
const data = {
119+
...c.data,
120+
parent: c.id,
121+
content,
122+
};
111123
postAppData({
112-
data: {
113-
...c.data,
114-
parent: c.id,
115-
content,
116-
},
124+
data,
117125
type: APP_DATA_TYPES.COMMENT,
118126
});
127+
postAction({
128+
data,
129+
type: APP_ACTIONS_TYPES.RESPOND_COMMENT,
130+
});
119131
closeComment();
120132
}}
121133
comment={{ ...c, data: { ...c.data, content: '' } }}

src/config/appActionsTypes.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,11 @@ export enum APP_ACTIONS_TYPES {
99
CANCEL_PROMPT = 'cancel_prompt',
1010
INITIALIZE_EXECUTION = 'initialize_execution',
1111
NEW_FIGURE = 'new_figure',
12+
13+
// Review actions
14+
CREATE_COMMENT = 'create_comment',
15+
EDIT_COMMENT = 'edit_comment',
16+
REPORT_COMMENT = 'report_comment',
17+
DELETE_COMMENT = 'delete_comment',
18+
RESPOND_COMMENT = 'respond_comment',
1219
}

0 commit comments

Comments
 (0)