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

Fix BB-768 : Unset Author Credit leads to bugs #1051

Draft
wants to merge 18 commits into
base: master
Choose a base branch
from

Conversation

Tarunmeena0901
Copy link
Contributor

@Tarunmeena0901 Tarunmeena0901 commented Jan 10, 2024

Problem

BB-768

refer to this discussion for more details

Solution

  • In edition.js and edition-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 group

  • The 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

  • ./entities/edition.js
  • ./entities/edition-group.js
  • redux reducers.ts for edition and edition-groups
  • actions.ts in author-credit-editor

@Tarunmeena0901 Tarunmeena0901 changed the title Fix BB-768 : Unset Author Credit leads to bugs Fix BB-768 & BB-767: Unset Author Credit leads to bugs Jan 10, 2024
@Tarunmeena0901 Tarunmeena0901 changed the title Fix BB-768 & BB-767: Unset Author Credit leads to bugs Fix BB-768 : Unset Author Credit leads to bugs Jan 30, 2024
@Tarunmeena0901
Copy link
Contributor Author

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

@Tarunmeena0901
Copy link
Contributor Author

so there was two cases when authorCreditEnable was being undefined whenever the page loads

  1. when we try to create an edition
  2. when we try to edit an edition group

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

editionSEc

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

groupSec

after fix for case1 :

Screenshot 2024-02-01 155737

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) {
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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

  1. when someone as set that there is no author credit

  2. 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

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh i see now

@MonkeyDo
Copy link
Contributor

MonkeyDo commented Feb 1, 2024

Thanks for looking into this issue again, I appreciate your efforts!
I will review this very soon, thanks for your continued patience.

@MonkeyDo
Copy link
Contributor

MonkeyDo commented Feb 2, 2024

Thanks again for working on this.
I realized there is a crucial piece missing in this puzzle, and the feature won't work properly until it is resolved.

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).
I'll get back to you when I'm able to work on this, hopefully next week.

@Tarunmeena0901
Copy link
Contributor Author

Tarunmeena0901 commented Feb 3, 2024

Thanks again for working on this. I realized there is a crucial piece missing in this puzzle, and the feature won't work properly until it is resolved.

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). I'll get back to you when I'm able to work on this, hopefully next week.

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. ✅✅

@Tarunmeena0901
Copy link
Contributor Author

Tarunmeena0901 commented Feb 7, 2024

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.

Screenshot 2024-02-08 014248

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
@Tarunmeena0901
Copy link
Contributor Author

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 .
Thank you for your patience.

@Tarunmeena0901
Copy link
Contributor Author

Tarunmeena0901 commented Feb 25, 2024

i was having a look at it again and after all this time i noticed that unified-form is crying in the corner and i haven't made any changes there , so i did it this time and i noticed two view in bookbrainz.sql file which were not present in my local postgres setup
whenever i tried to do \dv , so i am not sure if those needs the the new credit_section field.

in edition and edition-group pages rather than displaying nothing if the author credits are not provide while creating the entity i thought it would be better to display something like Author Credits: N/A so if someone see it and remember the credits they may edit the entity accordingly

Screenshot 2024-02-25 195620

Tarunmeena0901 and others added 2 commits March 6, 2024 20:14
…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 )
@MonkeyDo
Copy link
Contributor

it means that the author_credits section exists but with empty author credits

While re-reading this comment, a lightbulb turned on above my head:
I suppose all we really need is to modify the entity creation code to allow creating an empty author_credit (i.e. an AC without any author_credit_name attached to it) when the "empty author credit" checkbox is checked.

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.

@Tarunmeena0901
Copy link
Contributor Author

Tarunmeena0901 commented Apr 7, 2024

While re-reading this comment, a lightbulb turned on above my head: I suppose all we really need is to modify the entity creation code to allow creating an empty author_credit (i.e. an AC without any author_credit_name attached to it) when the "empty author credit" checkbox is checked.

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?
This doesn't seem feasible as we have over 2000 editions and edition groups.

like you said here
#1051 (comment)

@Tarunmeena0901 Tarunmeena0901 marked this pull request as draft May 21, 2024 18:15
Copy link
Contributor

@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.

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;
Copy link
Contributor

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;
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above

Comment on lines +283 to +284
authorCreditEnable: editionGroup.creditSection,
creditSection: editionGroup.creditSection,
Copy link
Contributor

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.

Comment on lines +114 to +119
else if (!entity.deleted && hasAuthorCredits === false) {
authorCreditSection = (
<div className="alert alert-warning">
Author Credits : N/A
</div>);
}
Copy link
Contributor

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.

Comment on lines +134 to +139
else if (!entity.deleted && hasAuthorCredits === false) {
authorCreditSection = (
<div className="alert alert-warning">
Author Credits : N/A
</div>);
}
Copy link
Contributor

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,
Copy link
Contributor

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!

Comment on lines +15 to +16
UPDATE bookbrainz.edition_data SET credit_section = true;
UPDATE bookbrainz.edition_group_data SET credit_section = true;
Copy link
Contributor

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
Copy link
Contributor

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;

Copy link
Contributor

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 --
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
-- 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 --

@MonkeyDo
Copy link
Contributor

One thing I'll need to figure out on the heels of this fix is a good way to allow users to keep an Edition and its Edition Group in sync. In MusicBrainz it's a simple checkbox which only appears when the author credit has been modified:

image

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