Skip to content

Commit 7631054

Browse files
authored
add permsiions and only show unresolved comments (codesandbox#3835)
1 parent ea192fa commit 7631054

File tree

2 files changed

+38
-26
lines changed
  • packages/app/src/app
    • overmind/namespaces/comments
    • pages/Sandbox/Editor/Workspace/screens/Comments/Dialog

2 files changed

+38
-26
lines changed

packages/app/src/app/overmind/namespaces/comments/state.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const state: State = {
5252
return {};
5353
}
5454
const rootComments = Object.values(comments[currentSandbox.id]).filter(
55-
comment => comment.parentComment == null
55+
comment => comment.parentComment == null && !comment.isResolved
5656
);
5757

5858
return rootComments.reduce<{

packages/app/src/app/pages/Sandbox/Editor/Workspace/screens/Comments/Dialog/index.tsx

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
Text,
99
Textarea,
1010
} from '@codesandbox/components';
11+
import { hasPermission } from '@codesandbox/common/lib/utils/permission';
1112
import css from '@styled-system/css';
1213
import {
1314
DIALOG_TRANSITION_DURATION,
@@ -254,9 +255,15 @@ const DragHandle: React.FC<{
254255
);
255256

256257
const DialogHeader = ({ comment, hasShadow }) => {
257-
const { actions } = useOvermind();
258+
const {
259+
state: { editor, user },
260+
actions: { comments },
261+
} = useOvermind();
258262

259-
const closeDialog = () => actions.comments.closeComment();
263+
const closeDialog = () => comments.closeComment();
264+
const canResolve =
265+
hasPermission(editor.currentSandbox.authorization, 'write_project') ||
266+
comment.user.id === user.id;
260267

261268
return (
262269
<Stack
@@ -278,25 +285,27 @@ const DialogHeader = ({ comment, hasShadow }) => {
278285
Comment
279286
</Text>
280287
<Stack align="center">
281-
<IconButton
282-
onClick={() =>
283-
actions.comments.resolveComment({
284-
commentId: comment.id,
285-
isResolved: !comment.isResolved,
286-
})
287-
}
288-
name="check"
289-
size={14}
290-
title={comment.isResolved ? 'Unresolve Comment' : 'Resolve Comment'}
291-
css={css({
292-
transition: 'color',
293-
transitionDuration: theme => theme.speeds[1],
294-
color: comment.isResolved ? 'green' : 'mutedForeground',
295-
':hover:not(:disabled), :focus:not(:disabled)': {
296-
color: comment.isResolved ? 'green' : 'foreground',
297-
},
298-
})}
299-
/>
288+
{canResolve && (
289+
<IconButton
290+
onClick={() =>
291+
comments.resolveComment({
292+
commentId: comment.id,
293+
isResolved: !comment.isResolved,
294+
})
295+
}
296+
name="check"
297+
size={14}
298+
title={comment.isResolved ? 'Unresolve Comment' : 'Resolve Comment'}
299+
css={css({
300+
transition: 'color',
301+
transitionDuration: theme => theme.speeds[1],
302+
color: comment.isResolved ? 'green' : 'mutedForeground',
303+
':hover:not(:disabled), :focus:not(:disabled)': {
304+
color: comment.isResolved ? 'green' : 'foreground',
305+
},
306+
})}
307+
/>
308+
)}
300309
<IconButton
301310
name="cross"
302311
size={10}
@@ -309,7 +318,10 @@ const DialogHeader = ({ comment, hasShadow }) => {
309318
};
310319

311320
const CommentBody = ({ comment, editing, setEditing, hasReplies }) => {
312-
const { state, actions } = useOvermind();
321+
const {
322+
state,
323+
actions: { comments },
324+
} = useOvermind();
313325

314326
return (
315327
<Stack direction="vertical" gap={4}>
@@ -330,8 +342,8 @@ const CommentBody = ({ comment, editing, setEditing, hasReplies }) => {
330342
</Menu.Item>
331343
<Menu.Item
332344
onSelect={() => {
333-
actions.comments.closeComment();
334-
actions.comments.deleteComment({
345+
comments.closeComment();
346+
comments.deleteComment({
335347
commentId: comment.id,
336348
});
337349
}}
@@ -360,7 +372,7 @@ const CommentBody = ({ comment, editing, setEditing, hasReplies }) => {
360372
<EditComment
361373
initialValue={comment.content}
362374
onSave={async newValue => {
363-
await actions.comments.updateComment({
375+
await comments.updateComment({
364376
commentId: comment.id,
365377
content: newValue,
366378
});

0 commit comments

Comments
 (0)