diff --git a/Classes/Domain/Model/Changes/MoveAfter.php b/Classes/Domain/Model/Changes/MoveAfter.php index fadb9bc50d..6ad3e5c504 100644 --- a/Classes/Domain/Model/Changes/MoveAfter.php +++ b/Classes/Domain/Model/Changes/MoveAfter.php @@ -91,6 +91,11 @@ public function apply(): void ); $contentRepository->handle($command); + if (!$hasEqualParentNode) { + // Remove the node at the old location of moving across nodes; so that we can insert it again at the new location + $this->feedbackCollection->add(new RemoveNode($subject, $parentNode)); + } + $updateParentNodeInfo = new UpdateNodeInfo(); $updateParentNodeInfo->setNode($parentNodeOfPreviousSibling); $this->feedbackCollection->add($updateParentNodeInfo); diff --git a/Classes/Domain/Model/Changes/MoveBefore.php b/Classes/Domain/Model/Changes/MoveBefore.php index d71d2c7566..96ef393a68 100644 --- a/Classes/Domain/Model/Changes/MoveBefore.php +++ b/Classes/Domain/Model/Changes/MoveBefore.php @@ -90,6 +90,11 @@ public function apply(): void ) ); + if (!$hasEqualParentNode) { + // Remove the node at the old location of moving across nodes; so that we can insert it again at the new location + $this->feedbackCollection->add(new RemoveNode($subject, $parentNode)); + } + $updateParentNodeInfo = new UpdateNodeInfo(); $updateParentNodeInfo->setNode($succeedingSiblingParent); diff --git a/Classes/Domain/Model/Changes/MoveInto.php b/Classes/Domain/Model/Changes/MoveInto.php index 95dad1c83e..990c8e7c2d 100644 --- a/Classes/Domain/Model/Changes/MoveInto.php +++ b/Classes/Domain/Model/Changes/MoveInto.php @@ -15,6 +15,7 @@ use Neos\ContentRepository\Core\Feature\NodeMove\Command\MoveNodeAggregate; use Neos\ContentRepository\Core\Feature\NodeMove\Dto\RelationDistributionStrategy; use Neos\ContentRepository\Core\Projection\ContentGraph\Node; +use Neos\Neos\Ui\Domain\Model\Feedback\Operations\RemoveNode; use Neos\Neos\Ui\Domain\Model\Feedback\Operations\UpdateNodeInfo; /** @@ -96,6 +97,11 @@ public function apply(): void ) ); + if (!$hasEqualParentNode) { + // Remove the node at the old location of moving across nodes; so that we can insert it again at the new location + $this->feedbackCollection->add(new RemoveNode($subject, $parentNode)); + } + $updateParentNodeInfo = new UpdateNodeInfo(); $updateParentNodeInfo->setNode($parentNode); $this->feedbackCollection->add($updateParentNodeInfo); diff --git a/Classes/Domain/Model/Feedback/Operations/UpdateNodePath.php b/Classes/Domain/Model/Feedback/Operations/UpdateNodePath.php deleted file mode 100644 index 50538adeee..0000000000 --- a/Classes/Domain/Model/Feedback/Operations/UpdateNodePath.php +++ /dev/null @@ -1,123 +0,0 @@ -oldContextPath = $contextPath; - } - - /** - * Set the new context path after a node was moved - * - * @param string $contextPath - * @return void - */ - public function setNewContextPath(string $contextPath): void - { - $this->newContextPath = $contextPath; - } - - /** - * Get the original context path of the moved node - * - * @return string - */ - public function getOldContextPath(): string - { - return $this->oldContextPath; - } - - /** - * Get the new context path of the moved node - * - * @return string - */ - public function getNewContextPath(): string - { - return $this->newContextPath; - } - - /** - * Get the type identifier - * - * @return string - */ - public function getType() - { - return 'Neos.Neos.Ui:UpdateNodePath'; - } - - /** - * Get the description - * - * @return string - */ - public function getDescription() - { - return sprintf('Updated path for node context path "%s" is available.', $this->getOldContextPath()); - } - - /** - * Checks whether this feedback is similar to another - * - * @param FeedbackInterface $feedback - * @return boolean - */ - public function isSimilarTo(FeedbackInterface $feedback) - { - if (!$feedback instanceof self) { - return false; - } - - return $this->getOldContextPath() === $feedback->getOldContextPath(); - } - - /** - * Serialize the payload for this feedback - * - * @param ControllerContext $controllerContext - * @return mixed - */ - public function serializePayload(ControllerContext $controllerContext) - { - return [ - 'oldContextPath' => $this->getOldContextPath(), - 'newContextPath' => $this->getNewContextPath(), - ]; - } -} diff --git a/packages/neos-ui-redux-store/src/CR/Nodes/helpers.ts b/packages/neos-ui-redux-store/src/CR/Nodes/helpers.ts index dfa8dcb35d..25ac5f0960 100644 --- a/packages/neos-ui-redux-store/src/CR/Nodes/helpers.ts +++ b/packages/neos-ui-redux-store/src/CR/Nodes/helpers.ts @@ -21,27 +21,6 @@ export const getAllowedNodeTypesTakingAutoCreatedIntoAccount = (baseNode: Node, return nodeTypesRegistry.getAllowedChildNodeTypes(baseNode.nodeType); }; -// -// Helper function to get parent contextPath from current contextPath -// -// IMPORTANT: The function is used just by the old CR and the can be removed, -// when the event sourced CR is the only way -// -export const parentNodeContextPath = (contextPath: NodeContextPath) => { - if (typeof contextPath !== 'string') { - console.error('`contextPath` must be a string!'); - return null; - } - const [path, context] = contextPath.split('@'); - - if (path.length === 0) { - // We are at top level; so there is no parent anymore! - return null; - } - - return `${path.substr(0, path.lastIndexOf('/'))}@${context}`; -}; - // // Helper function to check if the node is collapsed // diff --git a/packages/neos-ui/src/manifest.js b/packages/neos-ui/src/manifest.js index 216e16b420..88c028b132 100644 --- a/packages/neos-ui/src/manifest.js +++ b/packages/neos-ui/src/manifest.js @@ -2,8 +2,6 @@ import uuid from 'uuid'; import {actions, selectors} from '@neos-project/neos-ui-redux-store'; -import {parentNodeContextPath} from '@neos-project/neos-ui-redux-store/src/CR/Nodes/helpers'; - import manifest from '@neos-project/neos-ui-extensibility'; import {SynchronousRegistry, SynchronousMetaRegistry} from '@neos-project/neos-ui-extensibility/src/registry'; @@ -265,69 +263,12 @@ manifest('main', {}, (globalRegistry, {routes}) => { store.dispatch(actions.CR.Nodes.merge(feedbackPayload.byContextPath)); }); - // - // When the server has updated node path, apply it to the store - // - serverFeedbackHandlers.set('Neos.Neos.Ui:UpdateNodePath/Main', ({oldContextPath, newContextPath}, {store}) => { - let currentDocumentNodeMoved = false; - const parentContextPath = parentNodeContextPath(oldContextPath); - - const state = store.getState(); - if (state?.cr?.nodes?.focused?.contextPath === oldContextPath) { - store.dispatch(actions.CR.Nodes.unFocus()); - } - - if (state?.ui?.pageTree?.isFocused === oldContextPath) { - store.dispatch(actions.UI.PageTree.focus(parentContextPath)); - } - - // If we are moving the current document node or one of its parents... - const [oldPath] = oldContextPath.split('@'); - const currentDocumentNodePath = state?.cr?.nodes?.documentNode; - if (currentDocumentNodePath && (currentDocumentNodePath === oldContextPath || currentDocumentNodePath.split('@')[0].startsWith(oldPath + '/'))) { - currentDocumentNodeMoved = true; - let redirectContextPath = oldContextPath; - let redirectUri = null; - // Determine closest parent that is not being moved - while (!redirectUri) { - redirectContextPath = parentNodeContextPath(redirectContextPath); - // This is an extreme case when even the top node does not exist in the given dimension - // TODO: still find a nicer way to break out of this situation - if (redirectContextPath === false) { - window.location.href = routes?.core?.modules?.defaultModule; - break; - } - redirectUri = state?.cr?.nodes?.byContextPath?.[redirectContextPath]?.uri; - } - - // Temporarily set the document node to the moved nodes parent before updating its path - store.dispatch(actions.CR.Nodes.setDocumentNode(redirectContextPath)); - } - - store.dispatch(actions.CR.Nodes.updatePath(oldContextPath, newContextPath)); - - // If we moved the current node we have to read the preview uri again and then redirect the content frame - // and also update the selected document node - if (currentDocumentNodeMoved) { - const newState = store.getState(); - store.dispatch(actions.UI.ContentCanvas.setSrc(newState?.cr?.nodes?.byContextPath?.[newContextPath]?.uri)); - store.dispatch(actions.CR.Nodes.setDocumentNode(newContextPath)); - } - - // Remove the node from the old position in the dom - if (state?.cr?.nodes?.documentNode !== oldContextPath) { - findAllOccurrencesOfNodeInGuestFrame(oldContextPath).forEach(el => { - const closestContentCollection = el.closest('.neos-contentcollection'); - el.remove(); - - createEmptyContentCollectionPlaceholderIfMissing(closestContentCollection); - - dispatchCustomEvent('Neos.NodeRemoved', 'Node was removed.', { - element: el - }); - }); - } - }); + // TODO + /*if (currentDocumentNodeMoved) { + const newState = store.getState(); + store.dispatch(actions.UI.ContentCanvas.setSrc(newState?.cr?.nodes?.byContextPath?.[newContextPath]?.uri)); + store.dispatch(actions.CR.Nodes.setDocumentNode(newContextPath)); + }*/ // // When the server has removed a node, remove it as well from the store amd the dom