neos-ui icon indicating copy to clipboard operation
neos-ui copied to clipboard

Inspector Edit allow to unset value via `commit(undefined)`

Open mhsdesign opened this issue 2 years ago • 1 comments

Description

When implementing an editor one might have a reset option. To reset the value, one likely thinks that props.commit(null) or props.commit(undefined) would do the job, but they wont work as expected.

  • null will be filtered out by the reducer: https://github.com/neos/neos-ui/blob/2597ffef66f7901569b865e35ea634a941b50a7b/packages/neos-ui-redux-store/src/UI/Inspector/index.ts#L94 - the event shows up in redux but null is intended to be a noop (and used sometimes that way)
  • undefined can be used to unset the current value, but only if there are pending changes to it. When there are no pending changes in the editor the current transient value will be undefined as well as the "new" value too, so this diff check fails, and we noop: https://github.com/neos/neos-ui/blob/8d5e7c9d4859384950d510f54d7daa34633785d0/packages/neos-ui/src/Containers/RightSideBar/Inspector/InspectorEditorEnvelope/index.js#L54

Currently the most unset way is to use commit('') but this sets the value actually to an empty string.

Alternative workarounds:

props.commit("")
setTimeout(() => props.commit(undefined))

or set the hooks to an empty array, so the diffcheck is ignored:

props.commit(undefined, [])

or use the raw commit function directly actions.UI.Inspector.commit (that we often augment):

export function commit(propertyId: string, value: any, hooks: HookMap | null = null, focusedNode: Node): void;

UI: since always. 7.3 ... 8.3 and also 9.0-dev

mhsdesign avatar Oct 23 '23 18:10 mhsdesign

I would like to help with that topic at the upcoming sprint in Hamburg :)

laurahaenel avatar Mar 01 '24 10:03 laurahaenel