Skip to content

Commit

Permalink
Merge pull request #1107 from kellnerd/import-annotation
Browse files Browse the repository at this point in the history
Display and preserve annotation of imported entities
  • Loading branch information
MonkeyDo authored Aug 6, 2024
2 parents b32213d + 2fc11a2 commit 4ee6307
Show file tree
Hide file tree
Showing 15 changed files with 36 additions and 13 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ const stylisticIssuesRules = {
properties: 'always'
}
],
'comma-dangle': ERROR,
'comma-spacing': ERROR,
'comma-style': ERROR,
'computed-property-spacing': ERROR,
Expand Down
3 changes: 3 additions & 0 deletions sql/migrations/import/up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ CREATE OR REPLACE VIEW bookbrainz.edition_import AS
SELECT
import.id AS import_id,
edition_data.id as data_id,
edition_data.annotation_id,
edition_data.disambiguation_id,
alias_set.default_alias_id,
edition_data.width,
Expand All @@ -146,6 +147,7 @@ CREATE OR REPLACE VIEW bookbrainz.publisher_import AS
SELECT
import.id AS import_id,
publisher_data.id as data_id,
publisher_data.annotation_id,
publisher_data.disambiguation_id,
alias_set.default_alias_id,
publisher_data.begin_year,
Expand All @@ -171,6 +173,7 @@ CREATE OR REPLACE VIEW bookbrainz.edition_group_import AS
SELECT
import.id AS import_id,
edition_group_data.id as data_id,
edition_group_data.annotation_id,
edition_group_data.disambiguation_id,
alias_set.default_alias_id,
edition_group_data.type_id,
Expand Down
3 changes: 3 additions & 0 deletions sql/schemas/bookbrainz.sql
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,7 @@ CREATE VIEW bookbrainz.edition_import AS
SELECT
import.id AS import_id,
edition_data.id as data_id,
edition_data.annotation_id,
edition_data.disambiguation_id,
alias_set.default_alias_id,
edition_data.width,
Expand All @@ -1007,6 +1008,7 @@ CREATE VIEW bookbrainz.publisher_import AS
SELECT
import.id AS import_id,
publisher_data.id as data_id,
publisher_data.annotation_id,
publisher_data.disambiguation_id,
alias_set.default_alias_id,
publisher_data.begin_year,
Expand All @@ -1032,6 +1034,7 @@ CREATE VIEW bookbrainz.edition_group_import AS
SELECT
import.id AS import_id,
edition_group_data.id as data_id,
edition_group_data.annotation_id,
edition_group_data.disambiguation_id,
alias_set.default_alias_id,
edition_group_data.type_id,
Expand Down
2 changes: 2 additions & 0 deletions src/client/components/pages/import-entities/author.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import * as importHelper from '../../../helpers/import-entity';

import {AuthorAttributes} from '../entities/author';
import {ENTITY_TYPE_ICONS} from '../../../helpers/entity';
import EntityAnnotation from '../entities/annotation';
import EntityImage from '../entities/image';
import EntityLinks from '../entities/links';
import ImportFooter from './footer';
Expand Down Expand Up @@ -49,6 +50,7 @@ function ImportAuthorDisplayPage({importEntity, identifierTypes}) {
<AuthorAttributes author={importEntity}/>
</Col>
</Row>
<EntityAnnotation entity={importEntity}/>
<EntityLinks
entity={importEntity}
identifierTypes={identifierTypes}
Expand Down
2 changes: 2 additions & 0 deletions src/client/components/pages/import-entities/edition-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import * as importHelper from '../../../helpers/import-entity';

import {ENTITY_TYPE_ICONS} from '../../../helpers/entity';
import {EditionGroupAttributes} from '../entities/edition-group';
import EntityAnnotation from '../entities/annotation';
import EntityImage from '../entities/image';
import EntityLinks from '../entities/links';
import ImportFooter from './footer';
Expand Down Expand Up @@ -49,6 +50,7 @@ function ImportEditionGroupDisplayPage({importEntity, identifierTypes}) {
<EditionGroupAttributes editionGroup={importEntity}/>
</Col>
</Row>
<EntityAnnotation entity={importEntity}/>
<EntityLinks
entity={importEntity}
identifierTypes={identifierTypes}
Expand Down
2 changes: 2 additions & 0 deletions src/client/components/pages/import-entities/edition.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import * as importHelper from '../../../helpers/import-entity';

import {ENTITY_TYPE_ICONS} from '../../../helpers/entity';
import {EditionAttributes} from '../entities/edition';
import EntityAnnotation from '../entities/annotation';
import EntityImage from '../entities/image';
import EntityLinks from '../entities/links';
import ImportFooter from './footer';
Expand Down Expand Up @@ -50,6 +51,7 @@ function ImportEditionDisplayPage({importEntity, identifierTypes}) {
<EditionAttributes edition={importEntity}/>
</Col>
</Row>
<EntityAnnotation entity={importEntity}/>
<EntityLinks
entity={importEntity}
identifierTypes={identifierTypes}
Expand Down
2 changes: 2 additions & 0 deletions src/client/components/pages/import-entities/publisher.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import * as bootstrap from 'react-bootstrap';
import * as importHelper from '../../../helpers/import-entity';

import {ENTITY_TYPE_ICONS} from '../../../helpers/entity';
import EntityAnnotation from '../entities/annotation';
import EntityImage from '../entities/image';
import EntityLinks from '../entities/links';
import ImportFooter from './footer';
Expand Down Expand Up @@ -50,6 +51,7 @@ function ImportPublisherDisplayPage({importEntity, identifierTypes}) {
<PublisherAttributes publisher={importEntity}/>
</Col>
</Row>
<EntityAnnotation entity={importEntity}/>
<EntityLinks
entity={importEntity}
identifierTypes={identifierTypes}
Expand Down
2 changes: 2 additions & 0 deletions src/client/components/pages/import-entities/work.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import * as bootstrap from 'react-bootstrap';
import * as importHelper from '../../../helpers/import-entity';

import {ENTITY_TYPE_ICONS} from '../../../helpers/entity';
import EntityAnnotation from '../entities/annotation';
import EntityImage from '../entities/image';
import EntityLinks from '../entities/links';
import ImportFooter from './footer';
Expand Down Expand Up @@ -49,6 +50,7 @@ function ImportWorkDisplayPage({importEntity, identifierTypes}) {
<WorkAttributes work={importEntity}/>
</Col>
</Row>
<EntityAnnotation entity={importEntity}/>
<EntityLinks
entity={importEntity}
identifierTypes={identifierTypes}
Expand Down
6 changes: 3 additions & 3 deletions src/client/helpers/import-entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

import {get} from 'lodash';
import {get, kebabCase} from 'lodash';


export function getImportLabel(importEntity) {
return `${get(importEntity, 'defaultAlias.name', '(unnamed)')} `;
}

export function getImportUrl(importEntity) {
const type = importEntity.type.toLowerCase();
const type = kebabCase(importEntity.type);
const id = importEntity.importId;
return `/imports/${type}/${id}`;
}

export function getImportDiscardUrl(importEntity) {
const type = importEntity.type.toLowerCase();
const type = kebabCase(importEntity.type);
const id = importEntity.importId;
return `/imports/${type}/${id}/discard/handler`;
}
6 changes: 3 additions & 3 deletions src/server/helpers/importEntityRouteUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
// @flow

import * as utils from './utils';
import {camelCase, kebabCase, partialRight} from 'lodash';
import type express from 'express';
import {generateProps} from './props';
import {partialRight} from 'lodash';


/**
Expand All @@ -39,7 +39,7 @@ export function generateImportEntityProps(
) {
const {importEntity} = res.locals;
const {type: importEntityName} = importEntity;
const importEntityType = importEntityName.toLowerCase();
const importEntityType = camelCase(importEntityName);

const getFilteredIdentifierTypes =
partialRight(utils.filterIdentifierTypesByEntity, importEntity);
Expand All @@ -48,7 +48,7 @@ export function generateImportEntityProps(
);

const submissionUrl =
`/imports/${importEntityType}/${importEntity.importId}/edit/approve`;
`/imports/${kebabCase(importEntityType)}/${importEntity.importId}/edit/approve`;

const props = Object.assign({
entityType: importEntityType,
Expand Down
1 change: 1 addition & 0 deletions src/server/helpers/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ export function makeEntityLoader(modelName: string, additionalRels: Array<string
export function makeImportLoader(modelName, additionalRels, errMessage) {
const relations = [
'aliasSet.aliases.language',
'annotation',
'defaultAlias',
'disambiguation',
'identifierSet.identifiers.type'
Expand Down
7 changes: 4 additions & 3 deletions src/server/routes/import-entity/edition-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ router.param(
'EditionGroupImport',
[
'editionGroupType',
'editions.defaultAlias',
'editions.disambiguation',
'editions.releaseEventSet.releaseEvents'
// TODO: Reenable edition rels once imports have BBIDs
// 'editions.defaultAlias',
// 'editions.disambiguation',
// 'editions.releaseEventSet.releaseEvents'
],
'Edition Group Import not found'
)
Expand Down
2 changes: 1 addition & 1 deletion src/server/routes/import-entity/import-routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export async function approveImportPostEditing(req, res) {
const {importId, type} = importEntity;
const formData = req.body;

const validateForm = getValidator(type.toLowerCase());
const validateForm = getValidator(type);

if (!validateForm(formData)) {
const err = new error.FormSubmissionError();
Expand Down
5 changes: 5 additions & 0 deletions src/server/routes/import-entity/transform-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export function formToAuthorState(data) {

return {
aliases,
annotation: data.annotationSection.content,
beginAreaId: data.authorSection.beginArea &&
data.authorSection.beginArea.id,
beginDate: data.authorSection.beginDate,
Expand Down Expand Up @@ -55,6 +56,7 @@ export function formToEditionState(data) {

return {
aliases,
annotation: data.annotationSection.content,
depth: data.editionSection.depth &&
parseInt(data.editionSection.depth, 10),
disambiguation: data.nameSection.disambiguation,
Expand Down Expand Up @@ -88,6 +90,7 @@ export function formToEditionGroupState(data) {

return {
aliases,
annotation: data.annotationSection.content,
disambiguation: data.nameSection.disambiguation,
identifiers,
note: data.submissionSection.note,
Expand All @@ -102,6 +105,7 @@ export function formToPublisherState(data) {

return {
aliases,
annotation: data.annotationSection.content,
areaId: data.publisherSection.area && data.publisherSection.area.id,
beginDate: data.publisherSection.beginDate,
disambiguation: data.nameSection.disambiguation,
Expand All @@ -122,6 +126,7 @@ export function formToWorkState(data) {

return {
aliases,
annotation: data.annotationSection.content,
disambiguation: data.nameSection.disambiguation,
identifiers,
languages,
Expand Down
5 changes: 3 additions & 2 deletions src/server/routes/import-entity/transform-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
the form layout as described in the `client/entity-editor`
*/

import {isEmpty, isNull} from 'lodash';
import {camelCase, isEmpty, isNull} from 'lodash';


export function areaToOption(area) {
Expand Down Expand Up @@ -181,9 +181,10 @@ export const entitySectionMap = {
};

export function entityToFormState(importEntity) {
const entitySection = `${importEntity.type.toLowerCase()}Section`;
const entitySection = `${camelCase(importEntity.type)}Section`;
return {
aliasEditor: getAliasEditor(importEntity),
annotationSection: importEntity.annotation ?? {},
buttonBar: getButtonBar(importEntity),
[entitySection]: entitySectionMap[importEntity.type](importEntity),
identifierEditor: getIdentifierEditor(importEntity),
Expand Down

0 comments on commit 4ee6307

Please sign in to comment.