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

Feat(EG): Copy Edition name to Edition Group #842

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

tr1ten
Copy link
Collaborator

@tr1ten tr1ten commented May 3, 2022

Problem

BB-663: Add option to copy Edition name to Edition Group

Solution

Added checkbox for copying edition name to edition-group

Areas of Impact

nameSection component, createOrEditEnity function

Copy link
Member

@MonkeyDo MonkeyDo left a comment

Choose a reason for hiding this comment

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

Nice going !
Thanks a lot, that's going to be very useful now that I have to implement a similar checkboc for copying Author Credits.
I might just copy your homework :p

When I first tried the feature, I got an error on submission: Submission Error: No Updated Field.
Having the checkbox as the only change in the form isn't considered a change to the Edition, which sort of makes sense, but I think we should allow this workflow.

<Form.Check
className="margin-bottom-d8"
id="name"
label="Copy the edition name to edition-group"
Copy link
Member

@MonkeyDo MonkeyDo Jun 9, 2022

Choose a reason for hiding this comment

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

Should be "Edition" and "the Edition Group".

I'm not fully convinced by the placement, but I can't think of a better way right now :/
Maybe below the disambiguation?
image

Or in the Edition Group section below?
image

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe below the disambiguation?

This does sound like a reasonable place for checkbox

if (!isNew && entityType === 'Edition' && body.copyToEG) {
const currentEditionGroup = currentEntity.editionGroup;
const entityDefaultAlias = body.aliases.find((alias) => alias.default);
if (currentEditionGroup.defaultAlias.name !== entityDefaultAlias.name) {
Copy link
Member

Choose a reason for hiding this comment

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

We probably also want to make sure the sort name and language are the same. The getNextAliasSet function takes care of that, and returns the existing alias if unchanged, which shouldn't result in any changes on the EG.
So you should be able to remove this if condition.

@@ -1085,6 +1086,21 @@ export function handleCreateOrEditEntity(
let allEntities = [...otherEntities, mainEntity]
.filter(entity => entity.get('dataId') !== null);

// copy name to the edition group
if (!isNew && entityType === 'Edition' && body.copyToEG) {
Copy link
Member

Choose a reason for hiding this comment

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

Let's make this a separate copyNameToEditionGroup function in an effort to keep handleCreateOrEditEntity more readable

const currentEditionGroup = currentEntity.editionGroup;
const entityDefaultAlias = body.aliases.find((alias) => alias.default);
if (currentEditionGroup.defaultAlias.name !== entityDefaultAlias.name) {
const tempBody = {aliases: [{...currentEditionGroup.defaultAlias, default: true, name: entityDefaultAlias.name}]};
Copy link
Member

Choose a reason for hiding this comment

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

Reading this aliases array, I think if the EG before modification has multiple aliases, this tempBody will always be a different array of aliases, since it onyl contains one item.
You'll have to use the whole currentEditionGroup.aliases and modify the default alias (I guess by filtering by id).

I don't think we have access to the aliases array on currentEditionGroup and so the const EGEntity = await fetchOrCreateMainEntity call should probably be done beforehand.

Copy link
Member

Choose a reason for hiding this comment

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

About that last detail: I've suggested removing the currentEditionGroup.defaultAlias.name !== entityDefaultAlias.name check and letting getNextAliasSet do the comparison, but now I realize this adds some DB calls if we have to fetch the Edition Group first to get the aliases (and we don't want that).

I think we can get away with fetching all the aliases for the EG in makeEntityLoader: https://github.com/metabrainz/bookbrainz-site/blob/master/src/server/routes/entity/edition.js#L299
'editionGroup.defaultAlias' -> 'editionGroup.aliases' probably does the trick?

If none of this works then we'll want to keep an alias comparison condition, but make it similar to what updateAliasSet ORM function uses: https://github.com/metabrainz/bookbrainz-data-js/blob/master/src/func/alias.ts#L41-L48

Copy link
Member

Choose a reason for hiding this comment

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

Reading this aliases array, I think if the EG before modification has multiple aliases, this tempBody will always be a different array of aliases, since it onyl contains one item.

Yes, I think that's what's happening here:
The Edition Group diff shows three removed aliases while copying the name from the Edition:
image

@@ -73,6 +73,7 @@ function transformNewForm(data) {
return {
aliases,
annotation: data.annotationSection.content,
copyToEG: data.nameSection.copyToEG ?? false,
Copy link
Member

Choose a reason for hiding this comment

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

Let's rename this property to copyNameToEditionGroup for clarity; I know it's long, but I think it leaves less guesswork.
I'll build on your solution in a separate PR to add a copyAuthorCreditToEditionGroup so the distinction will be important.

@@ -26,7 +26,7 @@ export const UPDATE_NAME_FIELD = 'UPDATE_NAME_FIELD';
export const UPDATE_SORT_NAME_FIELD = 'UPDATE_SORT_NAME_FIELD';
export const UPDATE_WARN_IF_EXISTS = 'UPDATE_WARN_IF_EXISTS';
export const UPDATE_SEARCH_RESULTS = 'UPDATE_SEARCH_RESULTS';

export const UPDATE_COPY_CHECKBOX = 'UPDATE_COPY_CHECKBOX';
Copy link
Member

Choose a reason for hiding this comment

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

Same remark as my other comment, let's rename this UPDATE_COPY_NAME_CHECKBOX or UPDATE_COPY_NAME_TO_EDITION_GROUP to make way for UPDATE_COPY_AUTHOR_CREDIT_…

import {
checkIfNameExists,
debouncedUpdateDisambiguationField,
debouncedUpdateNameField,
debouncedUpdateSortNameField,
searchName,
updateCheckbox,
Copy link
Member

Choose a reason for hiding this comment

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

And one last name change request :) updateCopyNameCheckbox or updateCopyNameToEditionGroup

@tr1ten
Copy link
Collaborator Author

tr1ten commented Jun 9, 2022

I think we should allow this workflow.

Not sure about this, if only thing user wants is to change EG's default name wouldn't it be better to do it directly?
else we would have to deal with cases like if they already have same default name? should we throw error or let them submit?
also if EG is the only thing that got changed, should we include Edition in the revision as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants