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

chore: Allow annotation revision ids to be null (rebased) #1106

Merged
merged 2 commits into from
Jul 17, 2024
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
6 changes: 6 additions & 0 deletions sql/migrations/2024-07-17-annotation-revision-id/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

BEGIN;

ALTER TABLE bookbrainz.annotation ALTER COLUMN last_revision_id SET NOT NULL;

COMMIT;
7 changes: 7 additions & 0 deletions sql/migrations/2024-07-17-annotation-revision-id/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Allow NULL values for annotation.last_revision_id (foreing key to revision table)
-- so that we can use annotations for entities pending import, which do not have revisions.
BEGIN;

ALTER TABLE bookbrainz.annotation ALTER COLUMN last_revision_id DROP NOT NULL;

COMMIT;
2 changes: 1 addition & 1 deletion sql/schemas/bookbrainz.sql
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ ALTER TABLE bookbrainz.work_revision ADD FOREIGN KEY (data_id) REFERENCES bookbr
CREATE TABLE bookbrainz.annotation (
id SERIAL PRIMARY KEY,
content TEXT NOT NULL,
last_revision_id INT NOT NULL
last_revision_id INT
);
ALTER TABLE bookbrainz.annotation ADD FOREIGN KEY (last_revision_id) REFERENCES bookbrainz.revision (id);
ALTER TABLE bookbrainz.author_data ADD FOREIGN KEY (annotation_id) REFERENCES bookbrainz.annotation (id);
Expand Down
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
Loading