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

Project aliases #2644

Draft
wants to merge 39 commits into
base: main
Choose a base branch
from
Draft

Project aliases #2644

wants to merge 39 commits into from

Conversation

mo-nathan
Copy link
Member

This implements a feature where project admins can define a set of "aliases" for users and locations. E.g., NJW represents the user nathan or Walk 10 represents the location USA, Massachusetts, Wellfleet, Marconi Beach. The aliases only work in the context of the project (specifically when filling in field slip forms).

config/routes.rb Outdated Show resolved Hide resolved
@mo-nathan
Copy link
Member Author

Thanks Nimmo! This is much better. More work to go, but this feels like a good first cut.

@mo-nathan
Copy link
Member Author

mo-nathan commented Jan 12, 2025

  • Add Project header
  • Add autocomplete to form
  • CRUD tests
  • Apply the aliases when they get saved to the field slip
  • Update Members and Locations tabs to show aliases and allow adding
  • Translate alias on the field slip form
  • Remove Show action?
  • Tests

@JoeCohen
Copy link
Member

Will this PR:

  • accommodate uploading a list of foray registrants, with aliases (if any) to be completed later? (If the foray organizers ask for it on the registration form, the upload could include MO login. Maybe also iNat login.)
  • allow for a future (pie-in-the-sky) PR which does type-ahead in the Collector, ID By, and Location fields of the Field Slip form?

@mo-nathan
Copy link
Member Author

@JoeCohen This PR is just going to do the basic CRUD for ProjectAliases and apply them to values in project field slips when they get saved. Once we're sure they are reasonable, then adding a facility for bulk creation of users with aliases for a specific project makes sense. I'm not sure about whether it's worth doing the type ahead bit since the point is to make these aliases short enough that they are really easy to type. For example, if the walks at "1", "2", ... "15" and the users are "NJW", "JDC", and "NS" is there any need for type ahead?

@JoeCohen
Copy link
Member

JoeCohen commented Jan 18, 2025 via email

@coveralls
Copy link
Collaborator

coveralls commented Jan 18, 2025

Coverage Status

coverage: 93.52% (+0.02%) from 93.5%
when pulling d9fd3a0 on njw-project-aliases
into 4cbb226 on main.

@coveralls
Copy link
Collaborator

Coverage Status

coverage: 93.515% (+0.01%) from 93.501%
when pulling 12a46ed on njw-project-aliases
into 76fbbc1 on main.

test/models/project_alias_test.rb Outdated Show resolved Hide resolved
app/views/controllers/projects/aliases/_form.html.erb Outdated Show resolved Hide resolved
app/views/controllers/projects/aliases/edit.html.erb Outdated Show resolved Hide resolved
app/views/controllers/projects/aliases/new.html.erb Outdated Show resolved Hide resolved
app/views/controllers/projects/aliases/_form.html.erb Outdated Show resolved Hide resolved
action: "autocompleter#swap" }) %>
</div>

<%= autocompleter_hidden_field(form:, type:) %>
Copy link
Contributor

Choose a reason for hiding this comment

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

this needs the arg hidden_value: @project.location_id or whichever should be prefilled.

I anticipate an issue here, because if I understand correctly you're asking for the stimulus controller to do something magical that it does not yet have the ability to do. There is only ever one hidden field and one field in the HTML, and although the type can swap only the initial values can be prefilled.

If you want each type's default option (whether Location or User) to be prefilled if the user changes back and forth in the select, it seems we will need to store both of these hidden prefill values as data attributes on the Stimulus root autocompleter element, as something like data-hidden-value-location and data-hidden-value-user.

Then we will need to add a mechanism to the Stimulus autocompleter controller swap function that checks for the appropriate prefill value of the new autocompleter type when swapping, and fills it in the hidden field.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm using:

<%= autocompleter_hidden_field(form:, type:, hidden_value: project_alias.target_id) %>

which seems to be working fine. If you think there's still an issue, let me know how to see it.

@mo-nathan
Copy link
Member Author

@JoeCohen I don't understand your "Richard Bingl" case. Are there two users? Or are you saying that the completed names shows somehow? For example if I type "NJW" somewhere it shows "Nathan Wilson". My worry about adding complexity here is that my own experience and the experience from Jess Evans is that the UI is already too slow. I've been thinking about how to speed it up. It might work out since one of my thoughts is to send the browser the info all the aliases when the page loads so the browser side could display the full name/login without a round trip to the server. Nimmo and I did look at this at the current autocompleter is not behaving as expected since it does a server round trip every time you add a letter. I think this is the main source of slowness on this form.

Regarding adding "aliases on the fly", that's a good idea. I need to think about how that would work in the UI. I am thinking about listing the aliases on the Members and Locations tabs. I've realized that users and locations can and may often have more than one alias.

@JoeCohen
Copy link
Member

"Richard Bing" case.

  • Field Slip hard copy has the Collector's full name, rather than an alias.
  • It's not very legible, and appears to be "Richard Bingly"
  • Recorder discovers the true alias/full name upon typing the first 12 (or fewer) characters of "Richard Bingly"

@mo-nathan
Copy link
Member Author

I think the described "Richard Bing" behavior is already implemented now that the default user format is "Full Name (login)". However, the problem this creates is that now you cannot autocomplete using the login. For example Bill Yule is "Bill (boletebill)". To get the autocompleter to find him you need to type "Bill (bol" and it is unlikely that that info is going to be on the field slip. Aliases at least help with this since we could create aliases for him for "BY" and "Bill Yule". It turns out that his login already operates as an alias. I do think the translation of an alias should show up in the UI via JavaScript, but I haven't implemented that yet. Is there more to your suggestion that I'm missing?

@@ -212,6 +212,7 @@ export default class extends Controller {
// to refresh the primer (as with location_containing a changed lat/lng).
//
swap({ detail }) {
console.log("swap called");
Copy link
Contributor

@nimmolo nimmolo Jan 23, 2025

Choose a reason for hiding this comment

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

Note that this Stimulus controller has a method verbose. If you switch your

console.log("swap called")

to

this.verbose("swap called")

and then uncomment the actual method body of verbose, it will log a whole trace of what it's executing (as defined by wherever Jason and I left lines that say this.verbose("Say something");

However that may give you more info than you want.

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.

4 participants