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

Subject tag changes #10138

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

Conversation

jimchamp
Copy link
Collaborator

@jimchamp jimchamp commented Dec 9, 2024

Supplants #9843

General Tag Changes

  • Only two general tag types are now defined:
    • Collection tags
      • Tag type: collection
    • Subject tags
      • Tag types: subject, person, place, time
    • work-type tags have been removed
  • All tag types now have a body property
    • This will be rendered both on tag views and subject pages.

Tag model

  • Tag.find() updated to return multiple values

    • Now returns a list of matching tag keys
    • tag_type no longer a required parameter
  • Tag.create() updated to take a dict representation of a Tag

    • Tag dict validations are expected to occur before create is called
    • Tag.create() now returns the newly created Tag object (instead of a key)
      • Prevents redundant calls to Infogami

Tag page templates

General Tag view - /templates/type/tag/view.html

  • Updated means of deriving a related subject_key
  • Renders Tag.body to the page (if the tag is a subject tag)
  • Sanitizes and formats the tag's description and body before rendering

Tag edit and add views have been consolidated as /templates/type/tag/form.html

Subject page

  • Disambiguation section added
    • Included links to the Tag views of subject tags with a similar name

addtag.py

  • unflatten calls on patron input have been removed
    • unflatten is used specifically for book edit form data
  • Added type-specific validation functions
  • Added handler for type-specific edits

Missing from this PR

  • Subject tag body is not automatically generated
    • Attempted to add the same components that are used by the subject page, but HTML becomes malformed after sanitize and format calls
  • Types in URLs (/tags/OL123T/{tag_type}/{tag_label})
    • Requires refactor of ReadableUrlProcessor

Technical

Testing

Screenshot

Stakeholders

Removes `work` tag type, and adds four distinct subject types.

Adds `body` input to the "add tag" form.

Fixes bug where incorrect subject page link is rendered on tag page.

Replace subject page "Edit" button with "Tag" button, when no associated tag is found.  If there is a tag, a link to the tag page is included beneath the tag description.

Update the Tag.create method to take a `tag` dictionary, and to return the newly created tag.
Creates handler for paths like `/tag/{tag_type}/add`, and new templates for adding and editing
specific tag types.

The generic "Add Tag" form template has been updated to show and hide the appropriate form
elements whenever the selected tag type is changed.  Additionally, existing tag form templates
have been updated to take a `page` object (instead of one parameter for each property a `Tag` may
have).

The subject page "Tag" link has been updated to point to `/tag/{tag_type}/add`, where `tag_type`
is one of our four subject types.  Patron's who follow the link will be served the form for
adding subject tags (instead of the generalized add tag form, available at `/tag/add`).
The subject page handler now makes a call to fetch related
tags after the subject has been returned from Solr.  Data
fetched from the `/subjects` `json` endpoint are no longer
decorated with tag data.
Adds new `validate_subject_tag` and `create_tag`
functions.  Updates existing `create_subject_tag`
function to take a dictionary.

Updates existing handlers to use the correct tag
validation and creation methods.
Form would fail to submit when `collection` type was chosen and all fields filled.
The issue was the required subject tag body, which is only required for subject tags.
Inputs specific to a tag sub-type are now removed if that tag type is not selected.
- Sanitize tag description in tag view
- Update subject key derivation in tag view
- Reduce number of DB calls required to decorate a subject page with tags
- Tag edit `GET` handler returns edit form specific to the existing tag's type
- Use correct sub-type validations on tag edit
- Remove `utils.unflatten` call when creating tag
  - `utils.unflatten` is made specifically for processing the book edit form
@jimchamp jimchamp force-pushed the subject-tag-changes branch from e52b1fe to 1c17c70 Compare December 9, 2024 18:44
@codecov-commenter
Copy link

codecov-commenter commented Dec 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 17.44%. Comparing base (347bff9) to head (0ed861a).
Report is 170 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #10138      +/-   ##
==========================================
+ Coverage   17.12%   17.44%   +0.31%     
==========================================
  Files          89       89              
  Lines        4752     4792      +40     
  Branches      831      848      +17     
==========================================
+ Hits          814      836      +22     
- Misses       3428     3436       +8     
- Partials      510      520      +10     

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

@jimchamp jimchamp force-pushed the subject-tag-changes branch from 01aaaf0 to 7f45814 Compare December 9, 2024 18:54
@jimchamp jimchamp force-pushed the subject-tag-changes branch 4 times, most recently from 53a99e9 to 7e861fd Compare December 9, 2024 19:58
@jimchamp jimchamp force-pushed the subject-tag-changes branch from fe8c8a4 to 12fca88 Compare December 9, 2024 21:34
@jimchamp jimchamp force-pushed the subject-tag-changes branch from c6dc94f to 0d81650 Compare December 9, 2024 21:55
- Disambiguation links now point to subject pages
- Disambiguation link for current page is no longer included
- Move disambiguation section
- Add tag body to top of `contentBody` div
- Require `body` for all tag types
- Add duplicate tag validations
- Reload page with flash message when duplicate tag exists
- Update flash messages to render hyperlinks
@jimchamp jimchamp marked this pull request as draft December 13, 2024 23:43
@jimchamp jimchamp marked this pull request as ready for review December 13, 2024 23:43
@jimchamp jimchamp added the Needs: Submitter Input Waiting on input from the creator of the issue/pr [managed] label Dec 13, 2024
@mekarpeles mekarpeles self-assigned this Dec 16, 2024
@mekarpeles mekarpeles added the Priority: 1 Do this week, receiving emails, time sensitive, . [managed] label Dec 16, 2024
@jimchamp jimchamp force-pushed the subject-tag-changes branch from 0f30126 to 2b2e593 Compare December 17, 2024 00:21
@github-actions github-actions bot removed the Needs: Submitter Input Waiting on input from the creator of the issue/pr [managed] label Dec 17, 2024
@jimchamp jimchamp force-pushed the subject-tag-changes branch from 0370a6d to 860a95e Compare December 17, 2024 22:21
@jimchamp
Copy link
Collaborator Author

Outstanding tasks:

  • Subject type localization
  • Add history table to Tag view

Comment on lines +26 to +27
SUBJECT_SUB_TYPES = ["subject", "person", "place", "time"]
TAG_TYPES = SUBJECT_SUB_TYPES + ["collection"]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This are being used as display strings. get_subject_tag_types and get_tag_types will need to be updated such that they return lists of localized tag type strings.

@jimchamp jimchamp added the On testing.openlibrary.org This PR has been deployed to testing.openlibrary.org for testing label Dec 18, 2024
match = list(web.ctx.site.things(q))
return match[0] if match else None
def find(cls, tag_name, tag_type=None):
"""Returns a Tag key for a given tag name."""
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Suggested change
"""Returns a Tag key for a given tag name."""
"""Returns a list of keys for Tags that match the search criteria."""

@jimchamp jimchamp force-pushed the subject-tag-changes branch from 4468b30 to 5ba6a4b Compare December 20, 2024 23:41
Copy link

@accesslint accesslint bot left a comment

Choose a reason for hiding this comment

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

There are accessibility issues in these changes.

<div class="formElement">
<div class="label"><label for="tag_type">$_("Tag type")</label></div>
<div class="input">
<select name="tag_type" id="tag_type" required>
<select name="tag_type" required>
Copy link

Choose a reason for hiding this comment

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

Looks like this element is missing an accessible name or label. That makes it hard for people using screen readers or voice control to use the control.

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 Priority: 1 Do this week, receiving emails, time sensitive, . [managed]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants