-
-
Notifications
You must be signed in to change notification settings - Fork 285
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,13 +16,14 @@ | |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
|
||
import {Alert, Col, ListGroup, Row} from 'react-bootstrap'; | ||
import {Alert, Col, Form, ListGroup, Row} from 'react-bootstrap'; | ||
import { | ||
checkIfNameExists, | ||
debouncedUpdateDisambiguationField, | ||
debouncedUpdateNameField, | ||
debouncedUpdateSortNameField, | ||
searchName, | ||
updateCheckbox, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And one last name change request :) |
||
updateLanguageField | ||
} from './actions'; | ||
import {isAliasEmpty, isRequiredDisambiguationEmpty} from '../helpers'; | ||
|
@@ -63,6 +64,7 @@ import {getEntityDisambiguation} from '../../helpers/entity'; | |
* @param {string} props.nameValue - The name currently set for this entity. | ||
* @param {string} props.sortNameValue - The sort name currently set for this | ||
* entity. | ||
* @param {Function} props.onCheckboxToggle - A function to be called when toggle copy name to EG checkbox | ||
* @param {Function} props.onLanguageChange - A function to be called when a | ||
* different language type is selected. | ||
* @param {Function} props.onNameChange - A function to be called when the name | ||
|
@@ -129,13 +131,15 @@ class NameSection extends React.Component { | |
|
||
render() { | ||
const { | ||
action, | ||
disambiguationDefaultValue, | ||
entityType, | ||
exactMatches, | ||
languageOptions, | ||
languageValue, | ||
nameValue, | ||
sortNameValue, | ||
onCheckboxToggle, | ||
onLanguageChange, | ||
onSortNameChange, | ||
onDisambiguationChange, | ||
|
@@ -172,6 +176,17 @@ class NameSection extends React.Component { | |
onChange={this.handleNameChange} | ||
/> | ||
</Col> | ||
{action === 'edit' && entityType === 'edition' && | ||
<Col className="md-2" lg={{offset: 3, span: 6}}> | ||
<Form.Check | ||
className="margin-bottom-d8" | ||
id="name" | ||
label="Copy the edition name to edition-group" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This does sound like a reasonable place for checkbox |
||
type="checkbox" | ||
onChange={onCheckboxToggle} | ||
/> | ||
</Col> | ||
} | ||
<Col lg={{offset: 3, span: 6}}> | ||
{isRequiredDisambiguationEmpty( | ||
warnIfExists, | ||
|
@@ -271,6 +286,7 @@ NameSection.propTypes = { | |
languageOptions: PropTypes.array.isRequired, | ||
languageValue: PropTypes.number, | ||
nameValue: PropTypes.string.isRequired, | ||
onCheckboxToggle: PropTypes.func.isRequired, | ||
onDisambiguationChange: PropTypes.func.isRequired, | ||
onLanguageChange: PropTypes.func.isRequired, | ||
onNameChange: PropTypes.func.isRequired, | ||
|
@@ -314,6 +330,7 @@ function mapStateToProps(rootState) { | |
function mapDispatchToProps(dispatch, {entity, entityType}) { | ||
const entityBBID = entity && entity.bbid; | ||
return { | ||
onCheckboxToggle: (event) => dispatch(updateCheckbox(event.target.checked)), | ||
onDisambiguationChange: (event) => | ||
dispatch(debouncedUpdateDisambiguationField(event.target.value)), | ||
onLanguageChange: (value) => | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,6 +73,7 @@ function transformNewForm(data) { | |
return { | ||
aliases, | ||
annotation: data.annotationSection.content, | ||
copyToEG: data.nameSection.copyToEG ?? false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's rename this property to |
||
depth: data.editionSection.depth && | ||
parseInt(data.editionSection.depth, 10), | ||
disambiguation: data.nameSection.disambiguation, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1020,6 +1020,7 @@ export function handleCreateOrEditEntity( | |
aliasSet: {id: number} | null | undefined, | ||
annotation: {id: number} | null | undefined, | ||
bbid: string, | ||
editionGroup:any | undefined, | ||
disambiguation: {id: number} | null | undefined, | ||
identifierSet: {id: number} | null | undefined, | ||
type: EntityTypeString | ||
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's make this a separate |
||
const currentEditionGroup = currentEntity.editionGroup; | ||
const entityDefaultAlias = body.aliases.find((alias) => alias.default); | ||
if (currentEditionGroup.defaultAlias.name !== entityDefaultAlias.name) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
const tempBody = {aliases: [{...currentEditionGroup.defaultAlias, default: true, name: entityDefaultAlias.name}]}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. I don't think we have access to the aliases array on currentEditionGroup and so the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. About that last detail: I've suggested removing the 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 If none of this works then we'll want to keep an alias comparison condition, but make it similar to what There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, I think that's what's happening here: |
||
const aliasSet = await getNextAliasSet(orm, transacting, currentEditionGroup, tempBody); | ||
const EGEntity = await fetchOrCreateMainEntity( | ||
orm, transacting, false, currentEditionGroup.bbid, 'EditionGroup' | ||
); | ||
EGEntity.set('aliasSetId', aliasSet.id); | ||
EGEntity.shouldInsert = false; | ||
allEntities.push(EGEntity); | ||
} | ||
} | ||
if (isMergeOperation) { | ||
allEntities = await processMergeOperation(orm, transacting, req.session, | ||
mainEntity, allEntities, relationshipSets); | ||
|
There was a problem hiding this comment.
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
orUPDATE_COPY_NAME_TO_EDITION_GROUP
to make way forUPDATE_COPY_AUTHOR_CREDIT_…