Page MenuHomePhabricator

[MEX] M3.1.2 - use wbparsevalue API to normalize string values
Closed, ResolvedPublic

Description

As a follow-up from T401405, we should use the wbparsevalue API before sending the value to wbeditentity. This way, the API can already normalize the value (specifically: trim whitespace); this, in turn, lets us detect if the value was actually changed or not. (TODO: Task needs polishing.)

Specifically:

  • the “statement being edited” store (T405723) should primarily contain the values in a form that can be directly bound to the text inputs, i.e. not yet in parsed data value form
  • separately, there should be a store (cache?) of parsed data values (property ID → string input → Promise for parsed response); when the user types into the input, we send out the wbparsevalue request and put it in this store
  • the publish button should be enabled if the parsed data value store contains resolved responses for all the currently used text inputs (and at that point we can then also check if it’s actually different from the currently saved value in the statementsStore, and disable the button if the user’s input results in no change to the saved value, e.g. only adding surrounding whitespace)
  • publishing the edit pulls the corresponding parsed data values out of that cache (for the main value, qualifiers, and references) and then assembles the entity in the format we send to wbeditentity

A WIP patch for this has some more useful comments.

Question for UX: How should the user interface behave while it’s waiting for the wbparsevalue API request to respond? And also, what should happen if the value wasn’t actually changed (e.g. the user just added a space at the end)? The desktop UI always disables the “publish” button until the value has finished parsing and is known to be different from the previous value. (There have been occasional complaints about this slowing down editors. I suspect a lot of editors, yours truly included, at this point have some deeply ingrained muscle memory for waiting a moment between entering a value and pressing Enter to save it.)

Answer: The publish button will remain greyed out until it has been parsed by the server

This is blocked by: T405723

Acceptance Criteria

  • The publish button will remain greyed out until it has been parsed by the server
  • When adding spaces to an existing value the publish button will remain greyed out

Event Timeline

Change #1190229 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/Wikibase@master] WIP: Use wbparsevalue when editing statement

https://gerrit.wikimedia.org/r/1190229

Might be effectively a duplicate of T404695: [MEX] M3.1.2 add live input validation to edit formwbparsevalue is how we’re going to do the input validation, I expect.

Change #1190229 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] Use wbparsevalue when editing statement

https://gerrit.wikimedia.org/r/1190229

when the user types into the input, we send out the wbparsevalue request and put it in this store

I had a look at how exactly the desktop UI does this: it listens to input events (strictly speaking it listens to jQuery eachchange events, which basically delegate to input) and delays the parse via setTimout(), with a default parseDelay of 300 ms; each subsequent input event first cancels the previous setTimeout() and then kicks off a new one. (In lodash terms, I think that’s a debounce with a 300 ms wait, trailing edge only, no maxWait.) I think it makes sense to copy this behavior for now.

Change #1194235 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/Wikibase@master] Parse values after 300 ms without waiting for publish

https://gerrit.wikimedia.org/r/1194235

I think the above patch is already okay to review – I’ll keep working on the task in parallel.

Change #1194636 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/Wikibase@master] WIP: Disable edit button until statement value is parsed

https://gerrit.wikimedia.org/r/1194636

the publish button should be enabled if the parsed data value store contains resolved responses for all the currently used text inputs (and at that point we can then also check if it’s actually different from the currently saved value in the statementsStore, and disable the button if the user’s input results in no change to the saved value, e.g. only adding surrounding whitespace)

Important: but the button should be enabled if the user made any other changes, e.g. changing the statement’s rank!

Change #1194675 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/Wikibase@master] Change parsedValueStore getter to action

https://gerrit.wikimedia.org/r/1194675

Change #1194961 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/Wikibase@master] Populate parsedValueStore with initial statements

https://gerrit.wikimedia.org/r/1194961

Change #1195237 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/Wikibase@master] WIP: Check if there are changes before saving statement

https://gerrit.wikimedia.org/r/1195237

Change #1194675 abandoned by Lucas Werkmeister (WMDE):

[mediawiki/extensions/Wikibase@master] Change parsedValueStore getter to action

Reason:

squashed into the parent changes (I decided I preferred this version after all, and also needed a version of it in an earlier change already)

https://gerrit.wikimedia.org/r/1194675

Change #1194235 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] Parse values after 300 ms without waiting for publish

https://gerrit.wikimedia.org/r/1194235

Change #1194961 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] Populate parsedValueStore with initial statements

https://gerrit.wikimedia.org/r/1194961

Change #1194636 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] Disable edit button until statement value is parsed

https://gerrit.wikimedia.org/r/1194636

Change #1195237 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] Check if there are changes before saving statement

https://gerrit.wikimedia.org/r/1195237