www.fgks.org   »   [go: up one dir, main page]

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

add identifiers to author edit page #5093

Merged

Conversation

RayBB
Copy link
Collaborator
@RayBB RayBB commented Apr 25, 2021

Closes #853

I am addressing the PR in the minimum way following this comment.

To me, that means for this PR to be a success only the following need to be true:

  • A user can add a new identifier to an author
  • A user can modify an existing identifier on an author
  • A user can remove an existing identifier from an author

All three of these are possible using this minimal code.
Some possible future enhancements:

  • parsing a url to get identifier
  • validating identifiers
  • more listed in the original ticket

Enhancements with bigger scope:

  • dynamically render identifiers on author view page (right now they are hard coded)

Technical

From what I can see, this is one of the first implementation of Vue as an addition to an existing page. I'd really love feedback for how to make it better since I imagine others may be following this as an example.

I tried to keep things as simple as possible to meet the criteria.

For editions, the identifiers are setup as a list. However, for authors identifiers seem to be setup as dictionary. I'm not sure why this is but I figure for the scope of this PR I should just deal with it since I imagine doing a data conversion is not trivial.

I'm using template with the v-for because it allows me to have two root elements for each item in the list and that is need to use css grid.

Testing

Try adding and removing some identifiers from an author.

Setup

In order for this to work the appropriate config must be added to your environment by going to http://localhost:8080/config/author.yml?m=edit and setting:

identifiers:
-   label: ISNI
    name: isni
    notes: ''
    url: http://www.isni.org/@@@
    website: http://www.isni.org/
-   label: VIAF
    name: viaf
    notes: ''
    url: https://viaf.org/viaf/@@@
    website: https://viaf.org
-   label: Wikidata
    name: wikidata
    notes: ''
    url: https://tools.wmflabs.org/reasonator/?q=@@@
    website: https://wikidata.org
key: /config/author
type:
    key: /type/object

Screenshot

Screen.Recording.2021-05-04.at.8.42.27.PM.mov

Stakeholders

@mekarpeles
Copy link
Member

@RayBB this is great that we're pushing the frontier on vue. This PR is useful as proof of concept even if we decide some changes may be required. Here's my first batch of opinionated feedback:

  1. Especially for core features of the website (wiki, borrowing, reading log, lists, search) things should work with javascript disabled. This often makes a big difference when we're discussing website accessibility and this similarly also helps ensure under the hood we have very simple APIs which are GET/POST'able and can be automated for admin tasks. This doesn't mean we can't use vue, but I think this page in particular should probably work without it.
  2. I think @jdlrobson may rightfully push for any of our js code to be outside of our templates and instead in /openlibrary/plugins/openlibrary/js/

@jdlrobson
Copy link
Collaborator

think @jdlrobson may rightfully push for any of our js code to be outside of our templates and instead in /openlibrary/plugins/openlibrary/js/

Yes please. Out of interest foes Python have any linting tools we could use to detect when that happens to assist volunteer contributors?

@RayBB
Copy link
Collaborator Author
RayBB commented Apr 28, 2021

As far as I can tell editing links on authors already requires JS and so does editing identifiers on editions (which this is based on). If the idea is that JS shouldn't be used for editing going lets add that to the Vue documentation and clarify where it is appropriate to use Vue.

It is possible to avoid JS all together if we require the users to save and reload the page after adding each identifier but I imagine that would feel quite cumbersome.

@jdlrobson It is possible to run a script that checks if any .vue or .js files were added outside of the /openlibrary/plugins/openlibrary/js/ . It could be a simple bash script but I don't know of any python specific linting tools that would do the job. If you make a separate issue goals for this I can look at it later.

Please let me know how to move forward. Since @cdrini initially setup the Vue work perhaps he has thought on this.

@jdlrobson
Copy link
Collaborator

As far as I can tell editing links on authors already requires JS and so does editing identifiers on editions (which this is based on). If the idea is that JS shouldn't be used for editing going lets add that to the Vue documentation and clarify where it is appropriate to use Vue.

I defer to Mek on this one but my belief about this is that without javascript it should be possible to read any page, search, and navigate to any page that can be rendered. Basic editing should be possible using a form submission, but its okay if it's a limited experience. For JavaScript enabled clients we can and should give the best experience possible. Using Vue.js on the editor seems perfectly sensible to me.

I do think we should adopt a storybook instance (#4179) and document our components before building too many things in Vue. That remains a high priority on my side for the frontend if we are going to maintain these Vue based components going forward. If we don't we may be destined to repeat the same mistakes of the past

@jdlrobson It is possible to run a script that checks if any .vue or .js files were added outside of the /openlibrary/plugins/openlibrary/js/ . It could be a simple bash script but I don't know of any python specific linting tools that would do the job. If you make a separate issue goals for this I can look at it later.

Sorry I should have looked at the pull request rather than done a drive by comment on my phone. Sorry about that.

This patch is fine Mek. We can and should use inline script tags inside Vue files. The only issue is inside python rendered templates. Sorry for the confusion here. #4474 captures that.

@RayBB
Copy link
Collaborator Author
RayBB commented May 4, 2021

@cdrini could you help me with the two things I wrote under Where I need help?

@cdrini
Copy link
Collaborator
cdrini commented May 4, 2021

Discussed on call:

  • Will need to create /config/authors (we'll copy it over to prod once it's created).
  • Fetching /config/authors from JS seems ok for now.
  • Not adding deletion right now seems reasonable, since there is already a pretty substantial contribution here.

@RayBB
Copy link
Collaborator Author
RayBB commented May 6, 2021

@cdrini If there is anything I should change let me know and I'll work on it this weekend.

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.

Nice work @RayBB ! A number of style/naming things, and a few suggestions on how to get the author_config working and make the logic a little simpler. Great work on testing the tires of the Vue flow!

openlibrary/components/AuthorIdentifiers.vue Outdated Show resolved Hide resolved
openlibrary/components/AuthorIdentifiers.vue Outdated Show resolved Hide resolved
openlibrary/components/AuthorIdentifiers.vue Outdated Show resolved Hide resolved
openlibrary/components/AuthorIdentifiers.vue Outdated Show resolved Hide resolved
openlibrary/components/AuthorIdentifiers.vue Outdated Show resolved Hide resolved
openlibrary/components/AuthorIdentifiers.vue Outdated Show resolved Hide resolved
openlibrary/components/AuthorIdentifiers.vue Outdated Show resolved Hide resolved
openlibrary/plugins/upstream/utils.py Outdated Show resolved Hide resolved
openlibrary/plugins/upstream/utils.py Show resolved Hide resolved
openlibrary/plugins/upstream/utils.py Outdated Show resolved Hide resolved
@cdrini
Copy link
Collaborator
cdrini commented May 6, 2021

Created the page here: https://openlibrary.org/config/author

Note I used a different link for Wikidata.

@RayBB RayBB requested a review from cdrini May 13, 2021 05:45
@RayBB
Copy link
Collaborator Author
RayBB commented May 13, 2021

@cdrini ready for another review. Thanks for the great comments!

These are the only two issues you raised that need a second look:
#5093 (comment)
#5093 (comment)

openlibrary/components/AuthorIdentifiers.vue Show resolved Hide resolved
openlibrary/components/AuthorIdentifiers.vue Outdated Show resolved Hide resolved
openlibrary/components/AuthorIdentifiers.vue Outdated Show resolved Hide resolved
openlibrary/components/AuthorIdentifiers.vue Show resolved Hide resolved
openlibrary/components/AuthorIdentifiers.vue Outdated Show resolved Hide resolved
openlibrary/components/AuthorIdentifiers.vue Outdated Show resolved Hide resolved
openlibrary/templates/type/author/edit.html Outdated Show resolved Hide resolved
openlibrary/components/AuthorIdentifiers.vue Outdated Show resolved Hide resolved
openlibrary/components/AuthorIdentifiers.vue Outdated Show resolved Hide resolved
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.

Looking great! A few small final changes. I think those 3 vars will be clearer if we dissolve assignedIdentifiersWithConfigs ; that's the piece that's making this a little harder to read for me. Let me know if you have any questions!

<button class="form-control" type="button" name="set" :disabled="!setButtonEnabled" @click=setIdentifier>Set</button>
</th>
</tr>
<tr :key="identifier.name" v-for="identifier in assignedIdentifiersWithConfigs">
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also add a v-if="value"; we don't want rows without identifiers to show up.

Copy link
Collaborator Author
@RayBB RayBB May 15, 2021

Choose a reason for hiding this comment

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

I don't think that we can do that using Vue 2 https://v3.vuejs.org/guide/migration/v-if-v-for.html#_2-x-syntax

Since this is only assigned identifiers, the only time rows with blank values will show up is if a user clicks remove.

That seems ok to me and lets us avoid more computed properties (the vue recommended solution).

Copy link
Collaborator
@cdrini cdrini May 17, 2021

Choose a reason for hiding this comment

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

The way they've written the docs there is super confusing :P But I think in Vue 3 this will no longer be possible; Vue 2 should support it: https://vuejs.org/v2/guide/list.html#v-for-with-v-if

Grrr, that's an annoying change in Vue 3 :/ Let's use it here for now, since we're still on Vue 2. I use this pattern profusely throughout library explorer 😅

@RayBB
Copy link
Collaborator Author
RayBB commented May 15, 2021

@cdrini your code reviews are amazing and I'm so impressed by how much you simplified this!

Ready for another review now

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.

Code lgtm! Two small fixes, and then I'll toss the latest code on testing for some... testing!

openlibrary/components/AuthorIdentifiers.vue Outdated Show resolved Hide resolved
openlibrary/components/AuthorIdentifiers.vue Outdated Show resolved Hide resolved
openlibrary/components/AuthorIdentifiers.vue Show resolved Hide resolved
@cdrini
Copy link
Collaborator
cdrini commented May 17, 2021

Tested on testing:

Tested locally:

  • ✅ Adding IDs + saving
  • ✅ Removing previous ID
  • ✅ Removing all identifiers - Doesn't seem to work; but can fix in a future issue/PR

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.

Add a UI for adding identifiers to authors
4 participants