-
Notifications
You must be signed in to change notification settings - Fork 326
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
TagInput - Functional component for tag-like inputs #3735
Open
Gazook89
wants to merge
20
commits into
naturalcrit:master
Choose a base branch
from
Gazook89:Functional-Tag-Editor
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+113
−155
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
No actual functionality implemented yet, just renames the component from "StringArrayEditor" to "TagInput", for brevity at the possible cost of clarity. For now, the original StringArrayEditor is kept and named "TagInput-class.jsx" so that I can reference it as I work on the functional component.
Take an array of values from props, load it into valueContext state with an "editing" boolean for each value. Then, when rendering the component, take each value in the valueContext array and create a div for each -- at this point, if the value is "being edited", it returns a div with text "editing". If not being edited, it returns a div with the value as text. Nothing is being edited at this point since that functionality doesn't exist yet.
Tags are now either "readTag" or "writeTag", with the former being a div with the tag value and the latter a text input with the value. Minor class name change in LESS.
Clicking on a readTag now converts that tag to a text input, and maintains the tag value. It also closes any other open text inputs amongst the tags (but leaves the "new tag" input open).
Currently uses uncontrolled inputs with a `defaultValue` attribute set to the values passed in via props. The input can then be edited, and when `Enter` is pressed, it updates the stored value state. Later, this can be updated to be trigger with `Tab` or clicking outside the active input element.
Now brew metadata is actually updated and preserved across reloads to match updated tag values. useEffect calls the props.onChange event from the parent component on every change to the valueContext state of this component (right now, after hitting Enter in a tag input).
Component now accepts new tags entered in the always-present input field. Entering a value and hitting Enter submits the tag, and it appears as a new tag. Updated the tag list keys to be unique (via `index`). To-Do: empty 'new tag' input after submitting.
New button that triggers `submitTag()` method directly (rather than throw onKeyDown event) and passes `null` as the newValue. New `if` condition checks for null on newValue and if true, removes the tag that matches the originalValue. This *does* currently delete all duplicate tags if they match the one you are deleting. Not sure when you'd ever want duplicate tags, but regardless i'll likely switch this to work via Index, not value.
Fixes issue in last commit, so removing a tag that has duplicate value of other tags only removes the correct one, not the others as well.
Now whenever a new tag is submitted, the input element is cleared and ready for the next tag. Whitespace cleanup.
Now comma (`,`) submits a tag, like `Enter`
Updated initial comment to actually have the list to copy |
Begin work on setting a better html structure for the component. Create a .less file for the component, which I may not actually use.
Fixes an issue where tags with duplicate values would all update to the same value after editing just one. Also an adjustment to the parameters that are passed to handleInputKeyDown-- they are now one object. This helps handle an "options" object where more optional features can be turned on and off.
5e-Cleric
reviewed
Sep 20, 2024
5e-Cleric
reviewed
Sep 20, 2024
5e-Cleric
reviewed
Sep 20, 2024
This file was just the old StringArrayEditor that I kept around for easy reference. Can be deleted now.
calculuschild
approved these changes
Sep 23, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems functional and clean enough to me for a start. Just some variable naming suggestions.
Just nobody merge this yet until I can deploy the latest master branch live.
- Verify new features are functional
- add new tags, remove existing tags, edit existing tags
- changes to tags are saved to brew, and are rendered on reload
- loads existing tags (from brews that existed prior to this PR)
- Test for edge cases / try to break things
- Identify opportunities for simplification and refactoring
- Check for code legibility and appropriate comments
Followed suggestions on the PR.
5e-Cleric
added
UI/UX
User Interface, user experience
🔍 R4 - Reviewed - Fixed! Awaiting final review⭐
PR review comments addressed
labels
Oct 23, 2024
3 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
🔍 R4 - Reviewed - Fixed! Awaiting final review⭐
PR review comments addressed
UI/UX
User Interface, user experience
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This supersedes PR #3469. This PR is just the very basic functionality of tags: add, remove, update. Subsequent PRs will layer on additional features/functionality in discrete chunks and descriptions are below. Each of the additional features is a branch on the previous PR-- they build on each other. As such, they can merged in order, or the last PR can be merged in and it will contain everything prior to it. Here is the breakdown:
#3735 - Part 1 - Basic Functions
The PR removes the current StringArrayEditor.jsx entirely, and replaces it with tagInput.jsx which creates a functional component called TagInput. Obviously it doesn't have to be limited to only "tags" as we called them in HB-- it can be used for the Author list as well and where you might want a *string array editor*. I just prefer the shorter name for brevity.[No PR yet] - Part 2 - Keyboard Navigation
Part 2 focuses on adding keyboard navigation to the tag input. Things like using
Enter
,,
, orTab
to submit a new value, or tabbing/shift+tabbing to move around the tags.Here is the branch on my remote.
[No PR yet] - Part 3 - Validations
Part 3 adds methods to validate the tag inputs so that we can control what values are input. It differs from the original StringArrayEditor by having the validator functions centralized with other inputs in
validations.js
, rather than declaring the functions directly in props or asvaluePatterns
.Here is the branch on my remote.
[No PR yet] - Part 4 - Uniqueness
Part 4 is basically a supplement to Part 3-- it adds a check to see if the new value is unique from the existing tags before submitting it. By default, it must be unique, but via props the component could accept duplicate values.
Here is the branch on my remote.
Quick Overview of TagInput
Click to expand
The component is called by the parent, MetadataEditor, which passes in an array of strings which represent the values of each tag (tag can be any data type, like Tags or Authors). Additional props can be passed in, such as validation regexes, a boolean "unique?" prop, "non-editable" tags, etc-- though right now, most of those features aren't in this PR yet.
With the array of strings, TagInput creates a new array of objects. Each object has two properties:
value
andediting
. The latter is set tofalse
by default. Each tag is rendered as a list of divs that are "read only", or in the code,renderReadTag()
. These elements have a click event that changes theediting
property of the tag totrue
, and converts them to "write" tags (renderWriteTag()
), which are text inputs that allow you to edit the tag.TagInput passes an array of strings back up to MetadataEditor which the processes it with it's own
handleFieldChange
handler.Related Issues or Discussions
Related discussion on previous PR StringArrayEditor revision and update #3469. Most of the "good discussion" on the topic of tag inputs.
fixes Tweak tags schemas #2333
fixes The StringArrayEditor component returns error if you
ESC
out of it #3462QA Instructions, Screenshots, Recordings
This is the visual design for THIS PR, Part 1:
For reference, here is a screenshot from Part 4:
Reviewer Checklist
*Reviewers, refer to this list when testing features, or suggest new items *
Copy this list