Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to change placeholder text for comment/tag, and make comment replies optional #113

Merged
merged 2 commits into from
Oct 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 27 additions & 21 deletions src/editor/widgets/comment/CommentWidget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ import PurposeSelect, { PURPOSES } from './PurposeSelect';
const validPurposes = PURPOSES.map(p => p.value);

/**
* Comments are TextualBodies where the purpose field is either
* Comments are TextualBodies where the purpose field is either
* blank or 'commenting' or 'replying'
*/
const isComment = (body, matchAllPurposes) => {
const hasMatchingPurpose = matchAllPurposes ?
const hasMatchingPurpose = matchAllPurposes ?
validPurposes.indexOf(body.purpose) > -1 : body.purpose == 'commenting' || body.purpose == 'replying';

return body.type === 'TextualBody' && (
!body.hasOwnProperty('purpose') || hasMatchingPurpose
);
}

/**
/**
/* A comment should be read-only if:
/* - the global read-only flag is set
/* - the current rule is 'MINE_ONLY' and the creator ID differs
/* - the current rule is 'MINE_ONLY' and the creator ID differs
/* The 'editable' config flag overrides the global setting, if any
*/
const isReadOnlyComment = (body, props) => {
Expand Down Expand Up @@ -56,18 +56,18 @@ const getDraftReply = (existingDraft, isReply) => {
};
};

/**
/**
* Renders a list of comment bodies, followed by a 'reply' field.
*/
const CommentWidget = props => {

// All comments
const all = props.annotation ?
const all = props.annotation ?
props.annotation.bodies.filter(body => isComment(body, props.purposeSelector)) : [];

// Add a draft reply if there isn't one already
const draftReply = getDraftReply(all.find(b => b.draft == true), all.length > 1);

// All except draft reply
const comments = all.filter(b => b != draftReply);

Expand All @@ -87,38 +87,44 @@ const CommentWidget = props => {
const onChangeReplyPurpose = purpose =>
props.onUpdateBody(draftReply, { ...draftReply, purpose: purpose.value });

// Pre-condition: will be true if the annotation exists, and Annotorious is not in read-only mode
const isReadable = (!props.readOnly && props.annotation);

// Extra condtion to: reply field exists if there is no comment yet, or disableReply is false.
const hasReply = comments.length === 0 || !props.disableReply;

return (
<>
{ comments.map((body, idx) =>
<Comment
key={idx}
{ comments.map((body, idx) =>
ahammouda marked this conversation as resolved.
Show resolved Hide resolved
<Comment
key={idx}
env={props.env}
purposeSelector={props.purposeSelector}
readOnly={isReadOnlyComment(body, props)}
body={body}
readOnly={isReadOnlyComment(body, props)}
body={body}
onUpdate={props.onUpdateBody}
onDelete={props.onRemoveBody}
onSaveAndClose={props.onSaveAndClose} />
)}

{ !props.readOnly && props.annotation &&
{ isReadable && hasReply &&
<div className="r6o-widget comment editable">
<TextEntryField
focus={props.focus}
content={draftReply.value}
editable={true}
placeholder={comments.length > 0 ? i18n.t('Add a reply...') : i18n.t('Add a comment...')}
placeholder={comments.length > 0 ? i18n.t('Add a reply...') : (props.textPlaceHolder || i18n.t('Add a comment...'))}
onChange={onEditReply}
onSaveAndClose={() => props.onSaveAndClose()}
/>
{ props.purposeSelector && draftReply.value.length > 0 &&
<PurposeSelect
/>
{ props.purposeSelector && draftReply.value.length > 0 &&
<PurposeSelect
editable={true}
content={draftReply.purpose}
onChange={onChangeReplyPurpose}
onChange={onChangeReplyPurpose}
onSaveAndClose={() => props.onSaveAndClose()}
/>
}
}
</div>
}
</>
Expand All @@ -127,9 +133,9 @@ const CommentWidget = props => {
}

CommentWidget.disableDelete = (annotation, props) => {
const commentBodies =
const commentBodies =
annotation.bodies.filter(body => isComment(body, props.purposeSelector));

return commentBodies.some(comment => isReadOnlyComment(comment, props));
}

Expand Down
10 changes: 5 additions & 5 deletions src/editor/widgets/tag/TagWidget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ const getDraftTag = existingDraft =>
const TagWidget = props => {

// All tags (draft + non-draft)
const all = props.annotation ?
const all = props.annotation ?
props.annotation.bodies.filter(b => b.purpose === 'tagging') : [];

// Last draft tag goes into the input field
const draftTag = getDraftTag(all.slice().reverse().find(b => b.draft));
const draftTag = getDraftTag(all.slice().reverse().find(b => b.draft));

// All except draft tag
const tags = all.filter(b => b != draftTag);
Expand Down Expand Up @@ -66,7 +66,7 @@ const TagWidget = props => {
if (draftTag.value.trim().length === 0) {
props.onAppendBody(toSubmit);
} else {
props.onUpdateBody(draftTag, toSubmit);
props.onUpdateBody(draftTag, toSubmit);
}
}

Expand Down Expand Up @@ -96,9 +96,9 @@ const TagWidget = props => {
}

{!props.readOnly &&
<Autocomplete
<Autocomplete
focus={props.focus}
placeholder={i18n.t('Add tag...')}
placeholder={props.textPlaceHolder || i18n.t('Add tag...')}
vocabulary={props.vocabulary || []}
onChange={onDraftChange}
onSubmit={onSubmit}/>
Expand Down