slate-entity-labeler
slate-entity-labeler copied to clipboard
Make labeling of selected text to new entity more reliable.
Problem: The button to add a new entity is on the entity picker. This invokes a callback back out to the parent component which contains the editor and it is responsible for creating the new entity, updating its state which then updates the editor with a new available option. The editor naively assumes any new option must have been added due to the button from within itself and assumes whatever text was selected should be labeled as the newly added entity. This is an assumption that's may not be true if new entity is added from outside while the user is interacting with the control.
It would be better if this entity was created and assigned to the selected text in more reliable manner.
Solution? There might be a better pattern, but one way is to make the new entity prop callback return the new entity that is created. Instead of invoking as fire/forget it will await the creation of the new entity and then assign the selected text to it while still maintain internal execution context.