-
Notifications
You must be signed in to change notification settings - Fork 358
Support for display name in Select prompts #105
Comments
Hey @frodgesh! Thanks for opening this issue. Do you mind adding some more information as to why you think the API should be changed this way? since it's a breaking change, id like to think through this throughly before changing anything. Currently, select and multi select return the value the user chose so that options can themselves be ints. Also, if the selects return ints, we'll have to add of logic to prevent the casting of the return value since it doesn't make a lot of sense to convert the index into a string. |
@AlecAivazis, thanks for the feedback! Of course, user can convert string answer to int, but that's not the point. If we send []string to the quiz, certainly we do have the array, so why do we have to get string as a return? Would be much likely to get an index of this string to find it in the array, I guess. In example, we got a struct array of food with two fields: name and calories. We'll send to the quiz a string[] copy of this array, but how do we know, how much calories in chosen food if we get a string? Probably, indexing the whole array would not be the safer idea. |
@frodgesh So I thought about this last night, I think the right approach would be something very similar to the |
@AlecAivazis It is even more acceptable based on the idea that a function should return the answer, not a reference. I hope, it would be possible to choose a field as an option. |
Hi! In my case, i'm feeding a slice of string 'questions' into the select, which may contain duplicates. In this situation, the returned string does not really help to get a reference to the right question metadata that i'm also storing. A returned int, as well as being able to pass structs as options, would be of great help. |
Hey, I made a few changes to make it work with the I can open a proper PR if you guys think that this is a good approach. The idea basically is to keep the current API, creating the |
Thanks for working on this @gregoriokusowski! I have been meaning to start implementing this but have gotten completely swamped with getting some work out for a client as quickly as possible. I think this is a great start. I really like the use of the Please feel free to reach out to me here or on the gophers slack channel if you need any guidance. |
I updated that branch, so you can check it. I didn't have to touch the writer (yet?!), but I'll play more with other types. Since it's doing some meta-programming, I'm not sure if it worth to have a single implementation that works with both, or have 2 implementations (one for |
Hey, first just wanted to say great library! We also find this to be a bit of a usability issue with select/multi-select. Slice of indices would suffice, getting the actual of struct(s) directly would be fine as well. Just thinking out loud: It seems for select/multi-select you want to be able to control the output string for each item. What about instead of requiring the user pass strings, let them pass the items directly and provide the function for formatting the list of options
|
@aajtodd - thanks for the kind words. It sounds like what you are suggesting is exactly what @gregoriokusowski has been working on. Instead of defining our own interface, he is using |
@AlecAivazis I haven't taken the time to review the work he has been doing but yes the end result is close to what I am thinking. There are some potential downsides with an interface approach though (
Both of these result in the same solution, the user would be forced to alias the type and override the
Thoughts? |
I'd really like to see a solution to this as well. It seems to me a very common practice to have a human-readable label that is distinct and different from the underlying value. (think ID vs Name) In my case, the labels I want to present to my users are actually a composite possibly several bits of metadata that add more context for a human. The actual value I want to get at is the unique ID that corresponds to that value.
What I ultimately want to return here is the string ID. (same would apply to |
I looked at this recently and tried to find the right API for the user to specify the result. I wanted to keep only one field for setting either a list of strings, or a list of the interfaces, but it would cause us to lose a lot of type safety, since i would have to change I will take another stab at this this weekend and just add a field that takes in a list of the specific interface for structs to act as options. So now the question is - does anyone have an opinion on using tl;dr1 - I hear you. I hope to have a solution for doing this very soon. cc @coryb |
Thanks for the ping @AlecAivazis. I spent some time looking into this and testing out various options and I don't see any feasible way that will not break the API. The We could change Maybe it is time to think about adding a new prompt for this purpose? We could deprecate Anyway, I am wondering if we should just take a step back and play around with a few different abstractions that might more coherently address these issues. |
Have you considered a function that wraps the existing select and select multi. Submit a slice of interface{} to the function, use a template to format the fields you require to the existing select and multi select, on completion return the current selected option id so you can then select your item out of your own slice. |
I like your approach, @AlecAivazis. The spike I implemented is very similar to the idea of using the interface, but dirtier because of the backward compatibility. Quick review, IMHO the I would say we have enough available solutions to make a choice. The two dilemmas are Stringer vs Renderer and backward compatible vs new version. |
I just wanted to let this thread know that we're about to merge a PR as part of the I think this is as far as I'm going to take this issue/feature in |
@AlecAivazis Thank you for taking the time to address this |
Hi, |
No description provided.
The text was updated successfully, but these errors were encountered: