fix purpose when missing
This commit is contained in:
parent
2caf83083f
commit
71aa9c128e
|
@ -9,7 +9,6 @@ const purposes = ['assessing', 'bookmarking', 'classifying', 'commenting', 'desc
|
||||||
* Comments are TextualBodies where the purpose field is either
|
* Comments are TextualBodies where the purpose field is either
|
||||||
* blank or 'commenting' or 'replying'
|
* blank or 'commenting' or 'replying'
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const isComment = body =>
|
const isComment = body =>
|
||||||
body.type === 'TextualBody' && (
|
body.type === 'TextualBody' && (
|
||||||
!body.hasOwnProperty('purpose') || purposes.indexOf(body.purpose) > -1
|
!body.hasOwnProperty('purpose') || purposes.indexOf(body.purpose) > -1
|
||||||
|
@ -19,9 +18,11 @@ const isComment = body =>
|
||||||
* The draft reply is a comment body with a 'draft' flag
|
* The draft reply is a comment body with a 'draft' flag
|
||||||
*/
|
*/
|
||||||
const getDraftReply = (existingDraft, isReply) => {
|
const getDraftReply = (existingDraft, isReply) => {
|
||||||
return existingDraft ? existingDraft : {
|
let draft = existingDraft ? existingDraft : {
|
||||||
type: 'TextualBody', value: '', purpose: isReply ? 'replying' : 'commenting', draft: true
|
type: 'TextualBody', value: '', draft: true
|
||||||
};
|
};
|
||||||
|
draft.purpose = draft.purpose ? draft.purpose : isReply ? 'replying' : 'commenting';
|
||||||
|
return draft;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,13 +32,11 @@ const CommentWidget = props => {
|
||||||
// All comments (draft + non-draft)
|
// All comments (draft + non-draft)
|
||||||
const all = props.annotation ?
|
const all = props.annotation ?
|
||||||
props.annotation.bodies.filter(isComment) : [];
|
props.annotation.bodies.filter(isComment) : [];
|
||||||
|
|
||||||
// Last draft comment without a creator field goes into the reply field
|
// Last draft comment without a creator field goes into the reply field
|
||||||
const draftReply = getDraftReply(all.slice().reverse().find(b => b.draft && !b.creator), all.length > 1);
|
const draftReply = getDraftReply(all.slice().reverse().find(b => b.draft && !b.creator), all.length > 1);
|
||||||
|
|
||||||
// All except draft reply
|
// All except draft reply
|
||||||
const comments = all.filter(b => b != draftReply);
|
let comments = all.filter(b => b != draftReply);
|
||||||
|
comments = comments.map(elem => getDraftReply(elem));
|
||||||
const onEditReply = evt => {
|
const onEditReply = evt => {
|
||||||
const prev = draftReply.value;
|
const prev = draftReply.value;
|
||||||
const updated = evt.target.value;
|
const updated = evt.target.value;
|
||||||
|
@ -54,7 +53,12 @@ const CommentWidget = props => {
|
||||||
const onUpdatePurpose = evt => {
|
const onUpdatePurpose = evt => {
|
||||||
const prev = draftReply.purpose.trim();
|
const prev = draftReply.purpose.trim();
|
||||||
const updated = evt.value.trim();
|
const updated = evt.value.trim();
|
||||||
props.onUpdateBody(draftReply, { ...draftReply, purpose: updated });
|
if (draftReply.value == '' && updated.length > 0) {
|
||||||
|
draftReply.purpose = updated;
|
||||||
|
this.setState({purpose: updated});
|
||||||
|
} else {
|
||||||
|
props.onUpdateBody(draftReply, { ...draftReply, purpose: updated });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// A comment should be read-only if:
|
// A comment should be read-only if:
|
||||||
|
@ -108,7 +112,7 @@ const CommentWidget = props => {
|
||||||
{ props.purpose == true &&
|
{ props.purpose == true &&
|
||||||
<TypeDropdown
|
<TypeDropdown
|
||||||
editable={true}
|
editable={true}
|
||||||
content={draftReply.purpose ? draftReply.purpose : 'replying'}
|
content={draftReply.purpose}
|
||||||
onChange={onUpdatePurpose}
|
onChange={onUpdatePurpose}
|
||||||
onSaveAndClose={props.onSaveAndClose}
|
onSaveAndClose={props.onSaveAndClose}
|
||||||
/>
|
/>
|
||||||
|
|
Loading…
Reference in New Issue