enhancement
major
minor
defect
critical
major
minor
major
#30120
View layer: options of a string attribute cannot have display labels
A model attribute of type tl.core:String whose options come from <options-by-expression> is edited by the view layer (FieldControlService) as a selection whose options are labeled through MetaLabelProvider; for a string, the label is the string itself. There is no way to show a display label for an option value that differs from the stored value.
Example (control application tl-factory): the attribute providerType of a git connection stores the key of a registered provider type (gitea, git), options factoryGitProviderTypes(). The dialog lists gitea / git instead of "Gitea" / "Git-Server (ohne Hosting-Funktionen)". The value must stay the key (it is a configuration key of a registry, not a model enumeration, so tl.core:Enum classifiers do not fit).
Proposal: an optional label function for the options of an attribute, e.g. <options-by-expression function="..." label="value -> ..."/> or a separate annotation <option-label function="value -> ..."/> evaluated by the view layer's select control (and the classic form layer where it is cheap), defaulting to MetaLabelProvider. The read-only display of the field uses the same label.
Lösung
Labels of the options source (default for the whole application). <options-by-expression> has the optional property option-labels, a label provider (in-app classifier label-provider), typically LabelProviderByExpression:
{{{#!xml <options-by-expression function="t -> 'phone', 'portal'"> <option-labels class="com.top_logic.model.search.providers.LabelProviderByExpression" label="key -> switch ($key) { 'email': #('E-mail'@en, 'E-Mail'@de); ... default: $key; }"/> </options-by-expression> }}}
The labels are exposed as Generator#getOptionLabels() and apply wherever the attribute is shown as a selection: edit field, selected value and read-only display of a view-layer field (FieldSpec#getOptionLabels()), the table column of the attribute (sorted and searched by the labels), and the classic form fields (StringFieldProvider, LongFieldProvider, FloatFieldProvider). alphabetic-order sorts by these labels. The images stay those of the options.
Override for a single field. The SelectControlProvider of a <field> has the property option-labels as well; stated there, the labels hold for this field alone (also for an option-provider configured at the control), while table columns and other forms keep the labels of the options source:
{{{#!xml <field attribute="channel"> <input-control class="com.top_logic.layout.view.form.SelectControlProvider"> <option-labels class="com.top_logic.model.search.providers.LabelProviderByExpression" label="key -> switch ($key) { 'email': #('Mail'@en, 'Mail'@de); default: $key; }"/> </input-control> </field> }}}
Order by label. Any order by label of a field - order="by-label" at the control, or the alphabetic-order of the source - sorts by the labels the field actually displays.
Demo (tl-demo-react): attribute demo.tickets:Ticket#channel; the Tickets list column "Channel" shows the model labels, the Channel field of the ticket form the short labels of its control.