## Description
#### Goals
* [ ] Allow easy creation and edition of lightweight enum types in Wikifunctions (Default View)
* [ ] Guarantee that lightweight enum types created or edited through the Wikifunctions UI are wellformed, which means than:
* [ ] The key Z6884K3 should always be the same as the Zid of the persisted object.
* [ ] The typed list Z6884K2 should be typed as the type specified in Z6884K1
* [ ] All the items in the typed list Z6884K2 should be items of the type specified in Z6884K1
* [ ] The type selected in Z6884K1 should only be a Wikidata reference type (Z6091-6)
#### Technical details:
* Depends on: {https://phabricator.wikimedia.org/T391221}
* Once the function Z6884 is available, the basic behavior (Default View) should work out of the box.
* The only missing things are the restrictions to guarantee instances are wellformed, which includes:
* disable field Z6884K3
* set field Z6884K3 of new objects to Z0
* disable field Z6884K2[ 0 ] (typed list type)
* enforce same value in the field Z6884K2[ 0 ] as the one selected in Z6884K1
* the type selected in Z6884K1 should only be a Wikidata reference type (Z6091-6). We can suggest that by using the lookup suggestions for now. We do not enforce it for now because the rights are just for maintainers/staff
* This might just involve changes in:
* some initialization or object factory logic: for setting Z0
* `ZObjectKeyValue`: for disabling fields and setting ZTypedList type when receiving Z6884K1 updates
Example type:
```
{
"Z1K1": "Z2",
"Z2K1": { "Z1K1": "Z6", "Z6K1": "Z23772" },
"Z2K2": {
"Z1K1": "Z7",
"Z7K1": "Z6884",
"Z6884K1": "Z6091",
"Z6884K2": [ "Z6091",
{ "Z1K1": "Z6091", "Z6091K1": "Q499327" },
{ "Z1K1": "Z6091", "Z6091K1": "Q1775415" },
{ "Z1K1": "Z6091", "Z6091K1": "Q1775461" }
],
"Z6884K3": { "Z1K1": "Z6", "Z6K1": "Z23772" }
},
"Z2K3": {
"Z1K1": "Z12",
"Z12K1": [ "Z11",
{
"Z1K1": "Z11",
"Z11K1": "Z1002",
"Z11K2": "Enumeration of grammatical genders"
}
]
},
"Z2K4": {
"Z1K1": "Z32",
"Z32K1": [ "Z31" ]
},
"Z2K5": {
"Z1K1": "Z12",
"Z12K1": [ "Z11" ]
}
}
```
---
## Example User Flows
#### Flow 1: Create a new Lightweight Enum type
**Step 1: Create a new object of type "Enum"**
# Go to Special page CreateObject https://www.wikifunctions.org/wiki/Special:CreateObject
# To select Typed Enum:
# Under "type", search and select "Function Call"
# Under "function", search and select "Typed Enum of Wikidata references"
{F59361410}
Expected outcome:
* [ ] The key "Z6884K1/Wikidata reference type":
* [ ] Should only allow selection of Wikidata reference types (Z6091-6)
* [ ] On selection, the same type selected for "Z6884K1" should be set as the value of the type of the list "Z6884K2[ 0 ]"
* [ ] The key "Z6884K2/list of Wikidata references":
* [ ] The type of the typed list should not be directly editable (disabled field)
* [ ] The type of the typed list should be kept in sync with the type selected as "Z6884K1"
* [ ] The key "Z6884K3/ZID of result type":
* [ ] Should be set to "Z0"
* [ ] Should not be editable (disabled field)
---
**Step 2: Set a type for the enum items**
# Under "Wikidata reference type", select an eligible type.
# Interact with the typed list component:
# Expand to see the typed list type
# Add items to the typed list
Expected outcome:
* [ ] Upon expansion of the "Z6884K2/list of Wikidata references" key, the type of the typed list is set to the selected type above
* [ ] Upon adding items to the list, the items added are of the selected type
* [ ] On changing the type "Z6884K1", the typed list type will be updated
|{F59361437}|{F59361438}|{F59361443}|
|1. Z6884K1 type is set|2.a. Z6884K2 list is expanded| 2.b. Z6884K2 list items are added|
---
**Step 3: Add items and publish**
# Under "list of Wikidata references", add N items and select their values:
# Click [+] to add one item
# Search and select "masculine (grammatical gender)"
# Click [+] to add another item
# Search and select "feminine (grammatical gender)"
# Set label in the About widget "Enumeration of grammatical genders"
# Click "Publish"
{F59361642}
**Expected outcome**
* [ ] The object is successfully saved
* [ ] The user is redirected to the read page of the new Zid
* [ ] The Z6884K3/ZID of result type has been replaced with the new Zid
|Collapsed enum (read)|Expanded enum (read)|
|{F59361683}|{F59361686}|
---
#### Flow 2: Edit an existing Lightweight Enum type
**Step 1: Go to the Edit page of an Enum type**
# Go to the enum type page created before
# Click on "Edit source"
|Collapsed enum (edit)|Expanded enum (edit)|
|{F59361960}|{F59361959}|
Expected outcome:
* [ ] A user can now change the "Wikidata reference type" or add/remove items from the "list of Wikidata references"
* [ ] A user **can't** change the value of "ZID of result type"
* [ ] On "Publish" a user will be able to submit changes successfully if they have the appropriate rights (T391913)
---
**Step 2: Edit list items**
# Click [+] button under the typed list to add new elements
# Search and select "neuter (grammatical gender)"
# Click "Publish"
Expected outcome:
* [ ] The new item is added successfully
* [ ] The user is redirected to the read page, where they can see the new item
{F59362061}
---
**Step 3: Edit enum type**
# Go to the enum type page created before
# Click on "Edit source"
# Change the value of "Wikidata reference type" to "Wikidata lexeme reference"
# Add more items to the list, for example:
# Click [+] to add a new item
# Select Wikidata lexeme for "masculine (English, adjective)"
# Click "Publish"
Expected outcome:
* [ ] After changing the "Wikidata reference type", the typed list of the "list of Wikidata references" must be updated to the same value (screenshot 1)
* [ ] Any new items added to the list must be of the new type (screenshot 2 and 3)
* [ ] When publishing, the typed list component must clear the non applicable types (current behavior) (screenshots 4 and 5)
|{F59362148}|{F59362160}|{F59362164}|{F59362175}|{F59362184}|
|screenshot 1|screenshot 2|screenshot 3|screenshot 4|screenshot 5|
## Completion checklist
* [ ] Before closing this task, review one by one the checklist available here: https://www.mediawiki.org/wiki/Abstract_Wikipedia_team/Definition_of_Done#Front-end_Task/Bug_Completion_Checklist