-
Notifications
You must be signed in to change notification settings - Fork 4
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
Human readable choice labels #5
Open
jjonek
wants to merge
1
commit into
WithSecureOpenSource:dev
Choose a base branch
from
jjonek:choice_labels
base: dev
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.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
3.2.0 2015-07-20 | ||
|
||
[Jouni Kuusisto <[email protected]>] | ||
* MINOR: Implemented choice labels for IdexableField subclasses. | ||
|
||
3.1.1 2015-03-23 | ||
|
||
[Anton Berezin <[email protected]>] | ||
|
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
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
Oops, something went wrong.
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.
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.
I like the idea with human readable labels. But make it a dict then - not two list parameters. Cause I already foresee the situation when someone adds a choice somewhere in the middle of the list and forgets to add the label exactly at the same spot of another list - and WOOOHA! a month passes and no one has a clue why the data that was coming from the UI is so inappropriate.
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.
However, for the primitive cases it would also make sense to have just a list of choices that would internally be transformed from [val1, val2, val3] into {val1:val1, val2:val2, val3:val3}
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.
I see your point and actually I had thought about it myself. My concern regarding the dict is the correct ordering of the choices: how can we guarantee correct ordering of the items? For some use cases like UI automation the correct ordering of choices could be crucial.
Order of items in python dict seems to be implementation specific. I see two options to address this issue:
In both cases choices and labels would be split to separate lists in schema output, in order to preserve correct ordering (also on client side) and especially to maintain backward compatibility.
Somehow I dislike the idea of interpreting the contents of the choice list to guess whether it should include labels or not. Enum would support ordering and also deal with duplicate values.
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.
Then again, enum name as a label may be quite limiting. These values could be extended with extra label field, but meh..
Using OrderedDict would solve ordering but allow e.g. spaces in the label.
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.
I gave your idea another thought.
Human labels just do not make sense with respect to Resource API. The choices that are mentioned in the current "choices" field must be the values that make sense for the client (including a human client).
The only scenario where you would hypothetically need both: short values and human readable title is in case if you want to "optimize bandwidth" so to say. If performance is to be kept in mind - Resource API is not an option. That has never been its design goal.
In case if you want to implement something like:
Please don't.
Do like:
And internally - i.e. in the implementation (not definition) of the individual resource do the mapping from the string values to the integers.
On the other hand, if in the example above you really need to expose both the size and a corresponding group type as human readable string - it is a clear indication that you should use a read-only Resource with a Link field.
Sth like:
Thus I do not approve this commit :)
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.
I gave your idea another thought.
Human labels just do not make sense with respect to Resource API. The choices that are mentioned in the current "choices" field must be the values that make sense for the client (including a human client).
The only scenario where you would hypothetically need both: short values and human readable title is in case if you want to "optimize bandwidth" so to say. If performance is to be kept in mind - Resource API is not an option. That has never been its design goal.
In case if you want to implement something like:
Please don't.
Do like:
And internally - i.e. in the implementation (not definition) of the individual resource do the mapping from the string values to the integers.
On the other hand, if in the example above you really need to expose both the size and a corresponding group type as human readable string - it is a clear indication that you should use a read-only Resource with a Link field.
Sth like:
Thus I do not approve this commit :)