Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

fix: OPTIC-354: Comment draft preserved between annotations #1652

Merged
6 changes: 3 additions & 3 deletions src/components/Comments/CommentForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { FF_DEV_3873, isFF } from '../../utils/feature-flags';

export type CommentFormProps = {
commentStore: any,
value?: string,
annotationStore: any,
onChange?: (value: string) => void,
inline?: boolean,
rows?: number,
Expand All @@ -19,7 +19,7 @@ export type CommentFormProps = {

export const CommentForm: FC<CommentFormProps> = observer(({
commentStore,
value = '',
annotationStore,
inline = true,
onChange,
rows = 1,
Expand Down Expand Up @@ -52,7 +52,6 @@ export const CommentForm: FC<CommentFormProps> = observer(({
commentStore.setCurrentComment(comment || '');
}, [commentStore]);


useEffect(() => {
if (!isFF(FF_DEV_3873)) {
commentStore.setAddedCommentThisSession(false);
Expand All @@ -72,6 +71,7 @@ export const CommentForm: FC<CommentFormProps> = observer(({
commentStore.setCommentFormSubmit(() => onSubmit());
}, [actionRef, commentStore]);

const value = commentStore.currentComment[annotationStore.selected.id] || '';

return (
<Block ref={formRef} tag="form" name="comment-form" mod={{ inline }} onSubmit={onSubmit}>
Expand Down
4 changes: 2 additions & 2 deletions src/components/Comments/Comments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { FF_DEV_3034, isFF } from '../../utils/feature-flags';
import './Comments.styl';


export const Comments: FC<{ commentStore: any, cacheKey?: string }> = observer(({ commentStore, cacheKey }) => {
export const Comments: FC<{ annotationStore: any; commentStore: any, cacheKey?: string }> = observer(({ annotationStore, commentStore, cacheKey }) => {
Travis1282 marked this conversation as resolved.
Show resolved Hide resolved
const mounted = useMounted();

const loadComments = async () => {
Expand Down Expand Up @@ -45,7 +45,7 @@ export const Comments: FC<{ commentStore: any, cacheKey?: string }> = observer((

return (
<Block name="comments">
<CommentForm commentStore={commentStore} inline />
<CommentForm commentStore={commentStore} annotationStore={annotationStore} inline />
<CommentsList commentStore={commentStore} />
</Block>
);
Expand Down
5 changes: 3 additions & 2 deletions src/components/SidePanels/DetailsPanel/DetailsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const CommentsTab: FC<any> = inject('store')(observer(({ store }) => {
<Block name="comments-panel">
<Elem name="section-tab">
<Elem name="section-content">
<CommentsComponent commentStore={store.commentStore} cacheKey={`task.${store.task.id}`} />
<CommentsComponent annotationStore={store.annotationStore} commentStore={store.commentStore} cacheKey={`task.${store.task.id}`} />
</Elem>
</Elem>
</Block>
Expand Down Expand Up @@ -132,7 +132,7 @@ const GeneralPanel: FC<any> = inject('store')(observer(({ store, currentEntity }
const { relationStore } = currentEntity;
const showAnnotationHistory = store.hasInterface('annotations:history');
const showDraftInHistory = isFF(FF_DEV_2290);

console.log(store)
Travis1282 marked this conversation as resolved.
Show resolved Hide resolved
return (
<>
{!showDraftInHistory ? (
Expand Down Expand Up @@ -169,6 +169,7 @@ const GeneralPanel: FC<any> = inject('store')(observer(({ store, currentEntity }
</Elem>
<Elem name="section-content">
<CommentsComponent
annotationStore={store.annotation}
Travis1282 marked this conversation as resolved.
Show resolved Hide resolved
commentStore={store.commentStore}
cacheKey={`task.${store.task.id}`}
/>
Expand Down
4 changes: 2 additions & 2 deletions src/stores/Comment/CommentStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const CommentStore = types
.volatile(() => ({
addedCommentThisSession: false,
commentFormSubmit: () => {},
currentComment: '',
currentComment: {},
inputRef: {},
tooltipMessage: '',
}))
Expand Down Expand Up @@ -75,7 +75,7 @@ export const CommentStore = types
}

function setCurrentComment(comment) {
self.currentComment = comment;
self.currentComment = {...self.currentComment, [self.annotation.id]: comment}
Travis1282 marked this conversation as resolved.
Show resolved Hide resolved
Travis1282 marked this conversation as resolved.
Show resolved Hide resolved
Travis1282 marked this conversation as resolved.
Show resolved Hide resolved
}

function setCommentFormSubmit(submitCallback) {
Expand Down
Loading