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

Hide "Show all editions" link in edition table when appropriate #10017

Conversation

Spaarsh
Copy link
Contributor

@Spaarsh Spaarsh commented Nov 10, 2024

The issue#9946 was occurring due to "?mode=ebooks" being default at some point in time earlier. Since that is not the case anymore, according to the openlibrary/openlibrary/templates/type/edition/view.html, the editions_limit was being assigned the value 10 always. This prevented the default value of editions_limit to be None (which is then used in openlibrary/openlibrary/templates/type/work/editions_database.html).

The change includes the 'None' to be one of the acceptable states, restoring the originally intended logic.

Closes #9946

fix

Technical

The implementations simply adds None into the set of acceptable states of the query parameter 'mode'.

Testing

  1. Go to the homepage and search for any book.
  2. Click upon any book in the results.
  3. Scroll down and look at the editions table.
  4. If the "Showing X featured editions. View all Y editions?" text doesn't show anymore for cases where X is equal to Y (Img. 1), the issue has been fixed. And otherwise, it should show the aforementioned text (Img. 2).

Screenshot

image
Img. 1(when X==Y)

image
Img. 2 (when X!=Y)

Stakeholders

@SivanC @jimchamp @cdrini

The issue#9946 was occurring due to "?mode=ebooks" being default at some point in time earlier. Since that is not the case anymore, according to the openlibrary/openlibrary/templates/type/edition/view.html, the editions_limit was being assigned the value 10 always. This prevented the default value of editions_limit to be None (which is then used in  openlibrary/openlibrary/templates/type/work/editions_database.html).

The change includes the 'None' to be one of the acceptable states, restoring the originally intended logic.
@cdrini
Copy link
Collaborator

cdrini commented Nov 12, 2024

@SivanC would you be able to give this one a code review and QA?

@SivanC
Copy link
Contributor

SivanC commented Nov 12, 2024

@SivanC would you be able to give this one a code review and QA?

@cdrini Yes! Sorry should've realized that's my jurisdiction 😅

@cdrini
Copy link
Collaborator

cdrini commented Nov 12, 2024

Sweet ty! Haha, I needed you to leave a comment, otherwise GitHub won't let me assign you 😁

@SivanC
Copy link
Contributor

SivanC commented Nov 13, 2024

@cdrini @Spaarsh Looks good to me! No text in ?mode=foo/?mode=all or by default, showed in ?mode=ebooks when there was 1/3 ebook editions.

@Spaarsh
Copy link
Contributor Author

Spaarsh commented Dec 3, 2024

@SivanC waiting for it to be merged!

@SivanC
Copy link
Contributor

SivanC commented Dec 3, 2024

@Spaarsh Thanks for reaching out! Unfortunately I'm not in a position to be able to merge your PR, but I will contact those who can again and see that it gets merged soon.

@jimchamp jimchamp self-assigned this Dec 3, 2024
@jimchamp jimchamp self-requested a review December 4, 2024 00:00
Copy link
Collaborator

@jimchamp jimchamp left a comment

Choose a reason for hiding this comment

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

Thanks for your patience, @Spaarsh!

When I deployed this to our testing environment today, I noticed that the featured edition counts and the table entries for some book pages were different in production.

OL77764W_prod
Work OL77764W in production environment

OL77764W_testing_with_changes
Work OL77764W in testing environment

If mode exists, then we expect it to be either all or ebooks. Because of this, these changes effectively set limit to None every time the page is loaded (the exception being when mode is manually set to an unexpected value, like baz).

Limiting the number of editions that we fetch for a book page is very important, especially when the work has several hundred editions. Page rendering is blocked by the get_sorted_editions call, and waiting for this method to return can take tens of seconds in the worst case.

Can you roll this change back, and instead update this condition in editions_datatable.html? I think that something like this would work:
(editions_limit and len(editions) < editions_limit) or (len(editions) < work.edition_count)

@jimchamp jimchamp added the Needs: Submitter Input Waiting on input from the creator of the issue/pr [managed] label Dec 5, 2024
…editions-in-editions-table-when-not-necessary
@github-actions github-actions bot removed the Needs: Submitter Input Waiting on input from the creator of the issue/pr [managed] label Dec 7, 2024
@Spaarsh
Copy link
Contributor Author

Spaarsh commented Dec 8, 2024

Sorry for the delay! The change suggested by you didn't work, so made one small change, I flipped the less than sign to a greater sign:

(editions_limit and len(editions) > editions_limit) or (len(editions) < work.edition_count)

Explanation:

The editions_limit is set to None if the mode is ebooks or all, otherwise, it is set to be 10 as per this line in view.html.

Mode not set or unexpected mode selected

So, when there is no mode, 10 is the editions_limit, hence the first part of the statement is:
10 and len(editions)>10

Now, if the editions themselves are 8 (as in the case of this work), there is no need to display the "view all editions" part. And accordingly, the statement len(editions) > editions_limit resolves to False resulting in the first to be False.

Moving on to the next part len(edtions) < work.edition_count, when no mode is selected, the len(editions) is equal to the work.edition_count. So the condition return False and accordingly, we get the entire condition to be False.

False or False which resolves to False. Thus, the "view all editions" is not displayed.
image
Mode set to 'foo' for this work

image
No mode set for this work

image
No mode set for this work

Mode set to "all" or "ebooks"

When the mode is selected to be ebooks or all, the editions_limit is set to None so the first part resolves to a False.

Mode set to "all"

Moving to the next part, if the mode==all then len(editions) is equal work.edition_count. Hence the entire condition returns a False. So the "view all editions" shall not be displayed.
image
All mode set for this work

Mode set to "ebooks"

While for the ebooks mode, the len(editions) is less than work.edition_count. Thus the second part of the condition returns True and hence, the entire condition is True so the "view all editions" is displayed.
image
ebooks mode set for this work

@Spaarsh Spaarsh requested a review from jimchamp December 8, 2024 13:35
Copy link
Collaborator

@jimchamp jimchamp left a comment

Choose a reason for hiding this comment

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

Thanks @Spaarsh! Lgtm.

@jimchamp jimchamp merged commit ae0da2e into internetarchive:master Dec 10, 2024
2 checks passed
@jimchamp jimchamp changed the title Fixed the issue#9946 Hide "Show all editions" link in edition table when appropriate Dec 10, 2024
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.

Hide link to all editions in edition table when number of featured editions is equal to total editions
4 participants