Skip to content

Commit

Permalink
Annotations: accept possibly undefined lastRevision
Browse files Browse the repository at this point in the history
  • Loading branch information
MonkeyDo committed Jul 17, 2024
1 parent c484187 commit b6b933e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
44 changes: 35 additions & 9 deletions src/client/components/pages/entities/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,47 @@ class EntityAnnotation extends React.Component {
if (!annotation || !annotation.content) {
return null;
}
const lastModifiedDate = new Date(annotation.lastRevision.createdAt);
const lastModifiedDate =
annotation.lastRevision?.createdAt &&
new Date(annotation.lastRevision.createdAt);
return (
<Row>
<Col lg={12}>
<h2>Annotation</h2>
<Collapse in={this.state.open}>
<pre className="annotation-content" ref={this.annotationContentRef} >{stringToHTMLWithLinks(annotation.content)}</pre>
<pre
className="annotation-content"
ref={this.annotationContentRef}
>
{stringToHTMLWithLinks(annotation.content)}
</pre>
</Collapse>
{this.state.showButton &&
<Button variant="link" onClick={this.handleToggleCollapse}>
Show {this.state.open ? 'less' : 'more…'}
</Button>}
<p className="text-muted">Last modified: <span title={formatDate(lastModifiedDate, true)}>{formatDate(lastModifiedDate)}</span>
<span className="small"> (revision <a href={`/revision/${annotation.lastRevisionId}`}>#{annotation.lastRevisionId}</a>)</span>
</p>
{this.state.showButton && (
<Button
variant="link"
onClick={this.handleToggleCollapse}
>
Show {this.state.open ? 'less' : 'more…'}
</Button>
)}
{lastModifiedDate && (
<p className="text-muted">
Last modified:{' '}
<span title={formatDate(lastModifiedDate, true)}>
{formatDate(lastModifiedDate)}
</span>
<span className="small">
{' '}
(revision{' '}
<a
href={`/revision/${annotation.lastRevisionId}`}
>
#{annotation.lastRevisionId}
</a>
)
</span>
</p>
)}
</Col>
</Row>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {faQuestionCircle} from '@fortawesome/free-solid-svg-icons';
*
* @param {Object} props - The properties passed to the component.
* @param {Object} props.annotation - The annotation object containing
* its content and lastRevision info
* its content and lastRevision info. lastRevision can be undefined
* @param {Function} props.onAnnotationChange - A function to be called when the
* annotation is changed.
* @returns {ReactElement} React element containing the rendered
Expand Down Expand Up @@ -84,7 +84,7 @@ function AnnotationSection({
/>
</Form.Group>
{
annotation && annotation.lastRevision &&
annotation?.lastRevision?.createdAt &&
<p className="small text-muted">Last modified: {formatDate(new Date(annotation.lastRevision.createdAt))}</p>
}
<p className="text-muted">
Expand Down

0 comments on commit b6b933e

Please sign in to comment.