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

Display and preserve annotation of imported entities #1107

Merged
merged 7 commits into from
Aug 6, 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
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 @@
'EditionGroupImport',
[
'editionGroupType',
'editions.defaultAlias',
'editions.disambiguation',
'editions.releaseEventSet.releaseEvents'
// TODO: Reenable edition rels once imports have BBIDs

Check warning on line 35 in src/server/routes/import-entity/edition-group.js

View workflow job for this annotation

GitHub Actions / ESLint

src/server/routes/import-entity/edition-group.js#L35

Unexpected 'todo' comment: 'TODO: Reenable edition rels once imports...' (no-warning-comments)
// 'editions.defaultAlias',
// 'editions.disambiguation',
// 'editions.releaseEventSet.releaseEvents'
Comment on lines 34 to +38
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected trailing comma (comma-dangle)

Sigh, one more example why this ESLint rule is stupid... it often forces you to pointlessly edit neighbouring lines. Can we just disable this rule or migrate to always using dangling commas?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have my blessing to disable the rule. I've never seen it as a relevant code styling rule.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, I've dropped the rule in 2fc11a2. We might want to do the same across all repos, but I better won't do that now or I will find some more rules which should be changed or turned off 🤐

],
'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
Loading