Problem/Motivation

There is a mismatch between EnumListPropType and its default source: CheckboxesWidget

Checkboxes widget allows an unique occurrence of each enum value, but the EnumListPropType schema allows multiple occurence.

Proposed resolution

  1. Introduce a new EnumSetPropType with is identical to EnumListPropType but with uniqueItems: true
  2. Make CheckboxesWidget the default widget of this new prop type
  3. Add a new SelectsWidget for EnumListPropType which will show a select element with the enum values for each array value.

Remaining tasks

Tell current users of UIP2 Beta4 they may need to change their current enum_list props by enum_set.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

pdureau created an issue. See original summary.

pdureau’s picture

Status: Active » Needs work

Work in progress. Remaining work to do:

pdureau’s picture

Current status.

OOS:

  • Test SelectsWidget with #3485201: [1.1.0] ⚠️ From Layout Options to UI Patterns 2.x >> DONE
  • Do we put select title only when minItems? >> NO, we always print it, for accessibility
  • If possible: Dynamic number of selects elements when no maxItems >> NO, let's keep thing simple
  • Update schema compatibility checker? >> Not now

TODO:

  • Update the management of enumeration in both widgets and prop types
  • Unit tests?
pdureau’s picture

Assigned: pdureau » just_like_good_vibes
Status: Needs work » Needs review

Update the management of enumeration in both widgets and prop types

DONE

just_like_good_vibes’s picture

Assigned: just_like_good_vibes » pdureau
Status: Needs review » Needs work

- the function getAllowedValues does not live well in PropTypePluginBase and SourcePluginBase with the name getEnumOptions, let's rather put this in a trait,
and use that trait in enum prop types and appropriate sources.
- there is a typo in "mixItems" in CompatibilityChecker

otherwise i think this is quite a bold move.

pdureau’s picture

Assigned: pdureau » just_like_good_vibes
Status: Needs work » Needs review

Thanks you. Changes done.

I was not sure about the naming of the trait, so I did "EnumTrait"

pdureau’s picture

just_like_good_vibes’s picture

Status: Needs review » Needs work

in CompatibilityChecker,
please change line 165 to

if (($reference_schema["uniqueItems"] ?? FALSE) && (!isset($checked_schema["uniqueItems"]) || !$checked_schema["uniqueItems"])) {
      return FALSE;
    }

and put priority: 1 to EnumList prop type in its attributes

just_like_good_vibes’s picture

pdureau’s picture

Assigned: pdureau » just_like_good_vibes
Status: Needs work » Needs review

I don't reproduce this on my environment. This is an enum_list:

    offset_xl:
      title: "Columns offset (extra large)"
      type: array
      maxItems: 3
      items:
        type: integer
        enum: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]

This is an enum_set:

    test:
      title: "Test"
      type: array
      uniqueItems: true
      maxItems: 3
      items:
        type: integer
        enum: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] 
and put priority: 1 to EnumList prop type in its attributes

But we need to do some changes because it is better and safer to set priority attribute instead of relying on plugin discovery order, but 1 is already the default value and let's update both enum_set and enum_list:

  • Each enum (priority: 10) is also a string (priority: 1) or a number (priority: 1)
  • Each identifier (priority: 100) is also a string (priority: 1)
  • Each url (priority: 10) is also a string (priority: 1)
  • So, each enum_set (priority: 10) is also a enum_list (priority: 1)

Once the change done, CompatibilityChecker must also be updated. Thanks for your proposal, it works well.

just_like_good_vibes’s picture

Assigned: just_like_good_vibes » Unassigned
Status: Needs review » Fixed

pdureau’s picture

Let's fix that in an otehr issue:

Each enum_set (priority: 10) is also a enum_list (priority: 5) which is also a list (priority: 1)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.