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

Displays author name on merge #9920

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

Conversation

DanielleInkster
Copy link

@DanielleInkster DanielleInkster commented Oct 1, 2024

Closes #9811

Displaying the author’s name next to the OL...A identifier making it easier to distinguish between works by different authors.

Technical

utils.js
Added get_author_name function to fetch the name of the author associated with the id and append to the record.

AuthorRoleTable.vue
Added p tag to display authors name, as well as class to formate with CSS.

MergeTable.vue
Created enhancedRecords to include author name and added to template in order to display. Added CSS to display name next to ID.

*** I've not added enhancedRecords to the merge function in this file as I couldn't verify if this would impact what is saved when merging works. Can someone please clarify?***

Testing

  1. Run command npm run serve --component=MergeUI.
  2. Open merge view (http://localhost:8080/static/components/?records=OL1233242W,OL12312W)
  3. Verify merge view now displays the author names next to the ids
  4. Verify merging works as expected.

*** I was not able to find any JS tests for the files associated with this ticket. If needed, I can create if directed to the correct directory.***

Screenshot

Screenshot 2024-10-01 at 17 23 46

Stakeholders

@cdrini

@cdrini cdrini added the On testing.openlibrary.org This PR has been deployed to testing.openlibrary.org for testing label Oct 2, 2024
Copy link
Collaborator

@cdrini cdrini left a comment

Choose a reason for hiding this comment

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

Awesome @DanielleInkster ! A few small fixes but looking great so far 😊 Note I noticed this in my testing erroring:

https://testing.openlibrary.org/works/merge?records=OL6151392W,OL31613496W

Some sort of error is happening and only the result row is getting rendered!

{{role[field].key.slice("/authors/".length)}}
</a>
<p class="author-author-children"><b>{{role[field].name}}</b></p>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's put this in a new <td> element so it appears as its own column on the nested author roles table.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh actually, if we attach the author name to entry (eg the thing that has the author field) instead of to the entry.author, it should automatically show up! That might be easier.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Eg

entry.name = author_names[entry.author.key];

instead of

entry.author.name = author_names[entry.author.key];

Copy link
Author

Choose a reason for hiding this comment

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

I'm pretty sure I understand why this should work (should be captured under the else statement) but I couldn't get the name to render without making an else-if branch for it.

Comment on lines 123 to 124
enhanced_records.flatMap(record =>
record.authors.map(entry=> {
Copy link
Collaborator

@cdrini cdrini Oct 2, 2024

Choose a reason for hiding this comment

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

Since we're not returning anything, we can use forEach instead. Actually a for loop here might be the cleanest approach!

We can also avoid the extra loop by change the get_author_names method to return the full key with the /authors/ prefix.

Suggested change
enhanced_records.flatMap(record =>
record.authors.map(entry=> {
for (const record of enhanced_records) {
for (entry of record.authors) {
entry.author.name = author_names[entry.author.key];
}
}

fields: 'key,name',
})

const response = await fetch(`${CONFIGS.OL_BASE_BOOKS}/search/authors.json?${queryParams}`)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
const response = await fetch(`${CONFIGS.OL_BASE_BOOKS}/search/authors.json?${queryParams}`)
const response = await fetch(`${CONFIGS.OL_BASE_SEARCH}/search/authors.json?${queryParams}`)


const response = await fetch(`${CONFIGS.OL_BASE_BOOKS}/search/authors.json?${queryParams}`)

if (!response.ok) return {error: true};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's have this throw a new error, and then in the place we call it, wrap the call to this method in a try catch that...

async enhancedRecords(){
if (!this.records) return null;

const author_names = await get_author_names(this.records)
Copy link
Collaborator

Choose a reason for hiding this comment

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

...to a try catch that just returns the clone without any modifications. Otherwise an error here will cause the entire UI to fail!

@cdrini
Copy link
Collaborator

cdrini commented Oct 2, 2024

*** I've not added enhancedRecords to the merge function in this file as I couldn't verify if this would impact what is saved when merging works. Can someone please clarify?***

Yes that's exactly correct! We don't want to use enhanced_records during merging since then it'll try to save the author names in a weird place :P

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 17.12%. Comparing base (ce16a79) to head (2253ae3).
Report is 467 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9920      +/-   ##
==========================================
+ Coverage   16.06%   17.12%   +1.06%     
==========================================
  Files          90       89       -1     
  Lines        4769     4752      -17     
  Branches      832      831       -1     
==========================================
+ Hits          766      814      +48     
+ Misses       3480     3428      -52     
+ Partials      523      510      -13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -113,6 +113,26 @@ export default {
return records;
},

async enhancedRecords(){
Copy link
Collaborator

@cdrini cdrini Oct 2, 2024

Choose a reason for hiding this comment

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

To avoid someone in the future accidentally saving!

Suggested change
async enhancedRecords(){
/** The records, with extra helpful metadata attached for display. Should NOT be saved to Open Library */
async enhancedRecords(){

@cdrini cdrini added the Needs: Submitter Input Waiting on input from the creator of the issue/pr [managed] label Oct 2, 2024
@DanielleInkster DanielleInkster force-pushed the 9811/feature/display-author-name-on-merge branch from 2253ae3 to 9474056 Compare October 5, 2024 13:18
@github-actions github-actions bot removed the Needs: Submitter Input Waiting on input from the creator of the issue/pr [managed] label Oct 5, 2024
@DanielleInkster
Copy link
Author

https://testing.openlibrary.org/works/merge?records=OL6151392W,OL31613496W

@cdrini - I'm not able to access this unfortunately.
Screenshot 2024-10-05 at 14 22 13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
On testing.openlibrary.org This PR has been deployed to testing.openlibrary.org for testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

When merging works, display author names
3 participants