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

Clean up and rename computed variables #10307

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

Conversation

schu96
Copy link
Contributor

@schu96 schu96 commented Jan 9, 2025

Closes #10301

Refactor

Technical

Remove computed isEdition variable and use saveIdentifiersAsList to ensure component still functions properly when saving Author identifiers vs Edition/Work identifiers.

Removes props initially used to create an ordered dropdown list for identifiers, add a popular identifier list within the IdentifiersInput.vue for easier future maintenance.

Testing

Run docker compose up -d and then docker-compose run --rm home npx vue-cli-service build --watch --no-clean --mode production --dest static/build/components/production --target wc --name ol-IdentifiersInput openlibrary/components/IdentifiersInput.vue

Sign in using the OpenLibrary dev account or as a patron

Navigate to an edition and click on the edit button. Click on the identifiers component and check that the identifiers dropdown list contains two sets of identifiers separated by a non-selectable option with three dashes.

Within the same edit page, select the Work Details tab. Click on the identifiers component and verify that the work identifiers dropdown list contains only one set of identifiers without the three dashes option.

Navigate to an author page and click on the edit button. The dropdown list should also have one set of identifiers without the three dashes option.

Screenshot

Editions dropdown

image
Work dropdown

image
Author dropdown

image

Stakeholders

@cdrini

@codecov-commenter
Copy link

codecov-commenter commented Jan 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 17.59%. Comparing base (3025f5d) to head (38de33a).
Report is 141 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #10307      +/-   ##
==========================================
+ Coverage   17.44%   17.59%   +0.14%     
==========================================
  Files          89       88       -1     
  Lines        4792     4769      -23     
  Branches      848      847       -1     
==========================================
+ Hits          836      839       +3     
+ Misses       3436     3411      -25     
+ Partials      520      519       -1     

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

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, thanks for tackling @schu96 !! I think we can do a bit more to making this component less aware of the isEdition logic; by making it less tightly coupled to this notion, we should be able to DRY up a few of these methods, since there are a number of shared patterns. A few spots of feedback for you! Let me know if you have any questions 😊

openlibrary/components/IdentifiersInput.vue Outdated Show resolved Hide resolved
openlibrary/components/IdentifiersInput.vue Outdated Show resolved Hide resolved
openlibrary/components/IdentifiersInput.vue Outdated Show resolved Hide resolved
openlibrary/components/IdentifiersInput.vue Outdated Show resolved Hide resolved
openlibrary/components/IdentifiersInput.vue Outdated Show resolved Hide resolved
openlibrary/components/IdentifiersInput.vue Outdated Show resolved Hide resolved
@cdrini cdrini self-assigned this Jan 10, 2025
@cdrini cdrini added the Needs: Submitter Input Waiting on input from the creator of the issue/pr [managed] label Jan 10, 2025
@github-actions github-actions bot removed the Needs: Submitter Input Waiting on input from the creator of the issue/pr [managed] label Jan 11, 2025
@schu96 schu96 changed the title Clean up computed variables and move popular identifier logic Clean up and rename computed variables Jan 13, 2025
@schu96 schu96 requested a review from cdrini January 15, 2025 20:58
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.

Niiice this is cleaning up very nicely! A few last spots to tighten up the screws!

if (this.secondary_identifiers) {
const secondConfigs = JSON.parse(decodeURIComponent(this.secondary_identifiers));
return Object.fromEntries(secondConfigs.map(e => [e.name, e]));
popularIdDict: function() {
Copy link
Collaborator

@cdrini cdrini Feb 18, 2025

Choose a reason for hiding this comment

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

Ok, looking great! This can now just be a list, since we never have to do a look-up by identifier name, which makes this code much tighter!

        popularIds: function() {
            const popularIdNames = JSON.parse(decodeURIComponent(this.popular_ids));
            return this.parsedConfig
                .filter((config) => popularConfig.includes(config.name));
        },

if (this.secondary_identifiers) {
const secondConfigs = JSON.parse(decodeURIComponent(this.secondary_identifiers));
return Object.fromEntries(secondConfigs.map(e => [e.name, e]));
popularIdDict: function() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

And to keep the naming consistent, let's renaming the property to popular_ids_string ; that way any time we have a JSON/string input, it ends with foo_string, and then the parsed non-string version is just foo.

return Object.fromEntries(popularConfigs.map(e => [e.name, e]));
}
return {};
parsedConfig: function() {
Copy link
Collaborator

@cdrini cdrini Feb 18, 2025

Choose a reason for hiding this comment

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

So this can then be renamed to idConfig, and we don't specify parsed

return Object.fromEntries(betterConfigs.map(e => [e.name, e]));
}
return Object.fromEntries(parsedConfigs['identifiers'].map(e => [e.name, e]));
identifierConfigsByKey: function() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This now also looks un-needed and can be removed ; we can replace where this is used with the parsedConfig computed.

@cdrini cdrini added the Needs: Submitter Input Waiting on input from the creator of the issue/pr [managed] label Feb 18, 2025
@@ -447,7 +447,7 @@
$ set1 = [id_dict[name] for name in popular if name in id_dict and name not in exclude]
$ set2 = sorted([id for id in edition_config.identifiers if id.name not in popular and id.name not in exclude], key=lambda id:id.label)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh and set1 and set2 might now no longer be used!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Submitter Input Waiting on input from the creator of the issue/pr [managed]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor IdentifiersInput Vue component to not need isEdition checks
3 participants