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
Fix BB-768 : Unset Author Credit leads to bugs #1051
base: master
Are you sure you want to change the base?
Conversation
src/client/entity-editor/author-credit-editor/author-credit-section.tsx
Outdated
Show resolved
Hide resolved
well..... I was just reviewing my own PR today and find out that my solution for this problem was so naive 😆 , so I had another look at this issue and fixed it in a better way in my upcoming commit |
so there was two cases when authorCreditEnable was being undefined whenever the page loads
the reason behind this in first case was that the rootstate had an empty edition section with no authorCreditEnable field to set the default state with and the reason behind the second case was we were not sending any default authorCreditEnable field in enditionGroupSection rootstate to set the default state from after fix for case1 : same the bug is fixed for edition-group edit routes |
@@ -79,7 +79,7 @@ EditionGroupAttributes.propTypes = { | |||
}; | |||
|
|||
|
|||
function EditionGroupDisplayPage({entity, identifierTypes, user, wikipediaExtract}) { | |||
function EditionGroupDisplayPage({entity, identifierTypes, user, wikipediaExtract}, authorCreditEnable) { |
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.
This parameter and its usage below are probably a leftover from your previous attempt to solve the issue. Modern React components have no second function parameter as far as I know.
Same goes for the EditionDisplayPage
component.
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.
YES ! you are correct, Kell. React components do not have a second function parameter. Thank you for pointing this out. This is indeed something I overlooked in my previous solution, where I attempted to prevent the warning about unset author credits from displaying on the edition and edition group pages. However, it's clear now that this approach won't work , i will fix this
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.
but now as I think that when we are creating a edition or an edition group we don't allow to submit the form until the author credit is filled or "No author credit" checkbox is checked
so we have two cases here while creating
-
when someone as set that there is no author credit
-
author credits are provided while creating
in both the cases after creating the edition or edition group , the main page should not show any warning then why do we even have the warning ???
maybe we should remove it completely
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.
we have two cases here while creating
You are right about this, but the warning is not there only for new entities.
We do want to show the warning for existing entites that are missing that information.
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.
Oh i see now
Thanks for looking into this issue again, I appreciate your efforts! |
Thanks again for working on this. In short, I think we do not currently have a a way to store in the database that an edition has been set as "no author credit". The web page works fine, but we don't have a has_author_credit boolean column in the edition_data table, which is required if we want the checkbox to actually do something and being able to hide the warning. Some modifications need to be done on the bookbrainz-site repo, and others on the bookbrainz-data-js repo (our ORM). |
Yesss, exactly! Currently, I was trying to do just that—saving a boolean variable in the database to indicate whether author credits are set or unset for an edition or edition group. I made some schema changes to the edition_data table and edition_group_data table yesterday. I would have completed it today, but I got a little busy. I'll surely figure out the next part; give me some time, and I'll be back with a fix. ✅✅ |
In my last commit, I added a credit_section boolean column to our edition_data and edition_group_data tables. I also added the same column to our views. The purpose is to set credit_section to false if author credits are disabled. This signifies that the entity does not require author credits, thus no warning will be shown. If credit_section for an entity is true, along with other pre-existing checks, it means that the author_credits section exists but with empty author credits, and a warning will be displayed. The next step is to use the credit_section state in the frontend. Until then, any suggestions for improvement or a better approach to solving this aspect of the issue ?. 😊 |
…ontend to set or unset warning on entity page and enable or disable credit state whenever edit page loads
My apologies for finalizing this PR later than expected. I was occupied with my college responsibilities. With this commit, consider this issue resolved. In my latest commit, I utilized the saved state of author credits in both the edition and edition_group in the frontend to determine whether to display the "Unset author credit warning." Additionally, the "Author credit enable" checkbox in the edit page is no longer set to true by default; instead, it utilizes the previously saved state of the credit section to determine whether it should be checked or unchecked. this commit fix BB-768 as well as fix BB-767 . The only remaining task is to address the failing test and make changes in bookbrainz-data-js . |
…unified form and added the edition_data.credit_section state in bb.edition_import view
i was having a look at it again and after all this time i noticed that in |
…t think were correct cause mocha test fail so maybe we should leave the test part for another pr ( truth is i am not good at writing test )
While re-reading this comment, a lightbulb turned on above my head: Similarly, when loading an existing entity from the database, if it has an author_credit but the author_credit has no author_credit_name attached to it we can consider it's on purpose, and we don't show the "author credit unset" warning. And if we try editing that entity, the "no author credit" checkbox will be pre-checked. There is also an author_count (INT) column in the author_credit table, which we don't currently use anywhere as far as I can tell. Perhaps manually setting it to 0 could serve the same purpose? Or maybe as a secondary check that the entity has "no AC" set on purpose? Not sure it's necessary. |
I should have asked this question earlier, but since I've started working on this now, I'm not able to comprehend that by using this method, how do we handle entities that are already present . Since they didn't have empty author credits, are we gonna edit each entity and check the 'don't have author credit' checkbox? like you said here |
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.
Sorry for the delay in reviewing this!
I had to get in deep and try some things myself to ensure everything works as expected.
You did a really nice job of it!
I do have comments and suggestions to improve the code, it might look like a lot but it's a lot of repeating the same things since we have code for editions and edition groups.
There is one piece of code to be added at the very top of the processAuthorCredit function in src/server/routes/entity/entity.tsx
It gets the value of creditSection that we return in transformNewForm, and uses that to set the author credit id to null on the database model if the user checked the box:
const authorCreditEnabled = _.get(currentEntity, ['creditSection']);
if (!authorCreditEnabled) {
return {
authorCreditId: null
};
}
); | ||
UPDATE bookbrainz.edition_data SET credit_section = true; |
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.
This update statement is not required considering we have a default already, and probably not wanted
); | ||
|
||
UPDATE bookbrainz.edition_group_data SET credit_section = true; |
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 as above
authorCreditEnable: editionGroup.creditSection, | ||
creditSection: editionGroup.creditSection, |
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 comment as above here, we don't need to send creditSection to the redux state as it duplicates authorCreditEnable.
else if (!entity.deleted && hasAuthorCredits === false) { | ||
authorCreditSection = ( | ||
<div className="alert alert-warning"> | ||
Author Credits : N/A | ||
</div>); | ||
} |
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.
I don't think the banner here improves anything, it makes it look like something is wrong when in fact a user ticked a box to clarify it doesn't have an author, so everything is good.
I don't think we need to display anything in this case.
else if (!entity.deleted && hasAuthorCredits === false) { | ||
authorCreditSection = ( | ||
<div className="alert alert-warning"> | ||
Author Credits : N/A | ||
</div>); | ||
} |
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 as above
@@ -476,7 +479,8 @@ export function editionToFormState(edition) { | |||
const editionGroup = utils.entityToOption(edition.editionGroup); | |||
|
|||
const editionSection = { | |||
authorCreditEnable: true, | |||
authorCreditEnable: edition.creditSection, | |||
creditSection: edition.creditSection, |
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.
And I think that's our final creditSection to remove from the state!
UPDATE bookbrainz.edition_data SET credit_section = true; | ||
UPDATE bookbrainz.edition_group_data SET credit_section = true; |
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.
These are not wanted, we do not want to set the value to true for ALL records!
This is what these lines do, without a WHERE clause. If this was the intent, updating all records in a DB is in The Danger Zone and should always be treated with care :)
UPDATE bookbrainz.edition_data SET credit_section = true; | ||
UPDATE bookbrainz.edition_group_data SET credit_section = true; | ||
|
||
-- Recreate the view with the new definition |
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.
We want to drop the two views we're about to recreate:
-- Drop the existing view if it exists
DROP VIEW IF EXISTS
bookbrainz.edition,
bookbrainz.edition_group;
DROP VIEW IF EXISTS | ||
bookbrainz.edition, | ||
bookbrainz.edition_group; | ||
|
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.
The down file is supposed to allow you to return to the previous version of the schema.
In this case, that means deleting the new credit_section column for the edition_data and edition_group_data tables, as well as dropping and recreating the views as they were before which you can copy directly from master: https://github.com/metabrainz/bookbrainz-site/blob/master/sql/schemas/bookbrainz.sql#L869C1-L883C27
@@ -0,0 +1,90 @@ | |||
----------------------------------------------------------------------- | |||
-- Rename entities Creator -> Author and Publication -> Edition Group -- |
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.
-- Rename entities Creator -> Author and Publication -> Edition Group -- | |
-- Adds a credit_section boolean column to edition_data and edition_group_data to make author credits optional -- |
Problem
BB-768
refer to this discussion for more details
Solution
In
edition.js
andedition-group.js
I added a check before displaying a warning of unset credit . this will not show any warning on created edition or edition-group page, if we click the checkbox while creating the edition or edition groupThe checkbox was not getting checked and was needed to be clicked two times before disabling the edition credit , the reason was the redux initial state of
authorCreditEnable
was undefined rather than being true .Areas of Impact