Skip to content
This repository has been archived by the owner on Mar 31, 2022. It is now read-only.

Introduce TagField #167

Closed
7 tasks done
glebfox opened this issue Nov 9, 2020 · 1 comment
Closed
7 tasks done

Introduce TagField #167

glebfox opened this issue Nov 9, 2020 · 1 comment
Assignees
Milestone

Comments

@glebfox
Copy link
Contributor

glebfox commented Nov 9, 2020

Description

Introduce TagField as a replacement for deprecated TokenList.

Reflect functionality of TokenList:

  • Lookup action
  • ClearAll action

Examples:

Progress

  • Create base component structure
  • implement client-side tags
  • Handle enter key press
  • Backend search logic
  • Work with entity
  • Clear all button
  • Styling

Changes

TagField is based on SuggestionField, so it supports searching values while typing a text. TagField works both with entities and datatypes. It shows values as separated tags:
image
and has a popup with suggestions:
image

Searching values

TagField has all features of SuggestionField, including searching values. For more information, see SuggestionField documentation.

Declarative way:

<tagField id="tagField">
    <query entityClass="io.jmix.samples.ui.entity.SampleUser"
           searchStringFormat="%${searchString}%">
        select e from sample_User e where e.username like :searchString
    </query>
</tagField>

Programming way:

tagField.setSearchExecutor((searchString, searchParams) -> {
    return dataManager.load(SampleUser.class)
            .query("select e from sample_User e where e.username like :name")
            .parameter("name", "%" + searchString + "%")
            .list();
});

Create items

TagField inherits the ability to set ENTER keypress handler. Extending this functionality, TagField provides a predefined class NewTagProvider for converting entered text to tag. For instance, we will convert entered text to entity:

tagFieldDatatype.setEnterPressHandler(new TagField.NewTagProvider<OrderLine>() {
    @Override
    public OrderLine create(String text) {
        OrderLine orderLine = metadata.create(OrderLine.class);
        orderLine.setName(text);
        return orderLine;
    }
});

Tags API

TagField has API for configuring displayed tags.

  1. setTagStyleProvider() - generates stylename and adds it to tags.
  2. setTagCaptionProvider() - enables to change displayed caption of tags.
  3. setTagComparator() - sets comporator for sorting displayed tags.
  4. addTagClickListener() - enables to handle clicks on tags.
  5. setClearAllVisible() - displays the button for removing tags from the field. It also has an attribute in the XML configuration. The default value is false.
    <tagField id="tagField"
              clearAllVisible="true"/>
    

QA

  1. Check that component works with entity: suggestions are shown and can be selected, component value can be changed.
  2. Check that clearAllVisible="true"removes all tags from the field;
  3. Check Java API:
    • tagStyleProvider();
    • tagCaptionProvider(); // it changes caption only for tags
    • tagComporator(); // sets sorting for tags
    • addTagClickListener();
  4. TagField can create new values from entered text by pressing ENTER key. Check that works:
    <tagField id="tagField"
              clearAllVisible="true"/>
    
    @Autowired
    private DatatypeRegistry datatypeRegistry;
    @Autowired
    private Notifications notifications;
    
    tagField.setEnterPressHandler(new TagField.NewTagProvider<Integer>() {
     @Override
     public Integer create(String search) {
         try {
             return datatypeRegistry.get(Integer.class).parse(search);
         } catch (ParseException e) {
             notifications.create(Notifications.NotificationType.TRAY)
                     .withCaption(e.getMessage())
                     .show();
         }
         return null;
     }
    });
    
  5. Check that TagField looks pretty under Halo, Hover themes in browsers: Chrome, Safari, Edge, IE11
    Check Helium theme in Chrome, Safari, Edge. Also check predefined sizes: small, large;
  6. Try any your cases;
@glebfox glebfox added this to the 0.2.0 milestone Nov 9, 2020
@glebfox glebfox assigned glebfox and Flaurite and unassigned glebfox Nov 9, 2020
@knstvk knstvk modified the milestones: 0.2.0, 0.3.0 Dec 7, 2020
Flaurite added a commit to jmix-projects/jmix-cuba that referenced this issue Jan 28, 2021
Flaurite added a commit that referenced this issue Jan 28, 2021
Flaurite added a commit that referenced this issue Jan 28, 2021
@natfirst natfirst assigned owlet1997 and unassigned natfirst Feb 15, 2021
@owlet1997
Copy link

owlet1997 commented Feb 15, 2021

Tag <query> is highlighted as a mistake by Idea in XML descriptor:
image

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants