Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Classes/Application/Shared/TreeNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public function __construct(
public readonly bool $isMatchedByFilter,
public readonly bool $isDisabled,
public readonly bool $isHiddenInMenu,
public readonly bool $isCreated,
public readonly bool $isModified,
public readonly bool $isRemoved,
// todo rename to hasTimeableNodeVisibility?
public readonly bool $hasScheduledDisabledState,
public readonly bool $hasUnloadedChildren,
Expand All @@ -48,6 +51,9 @@ public function jsonSerialize(): mixed
'isMatchedByFilter' => $this->isMatchedByFilter,
'isDisabled' => $this->isDisabled,
'isHiddenInMenu' => $this->isHiddenInMenu,
'isCreated' => $this->isCreated,
'isModified' => $this->isModified,
'isRemoved' => $this->isRemoved,
'hasScheduledDisabledState' => $this->hasScheduledDisabledState,
'hasUnloadedChildren' => $this->hasUnloadedChildren,
'children' => $this->children,
Expand Down
6 changes: 6 additions & 0 deletions Classes/Application/Shared/TreeNodeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public function __construct(
private bool $isMatchedByFilter,
private readonly bool $isDisabled,
private readonly bool $isHiddenInMenu,
private bool $isCreated,
private bool $isModified,
private bool $isRemoved,
private readonly bool $hasScheduledDisabledState,
private bool $hasUnloadedChildren,
) {
Expand Down Expand Up @@ -89,6 +92,9 @@ public function build(): TreeNode
isMatchedByFilter: $this->isMatchedByFilter,
isDisabled: $this->isDisabled,
isHiddenInMenu: $this->isHiddenInMenu,
isCreated: $this->isCreated,
isModified: $this->isModified,
isRemoved: $this->isRemoved,
hasScheduledDisabledState: $this->hasScheduledDisabledState,
hasUnloadedChildren: $this->hasUnloadedChildren,
children: $this->buildChildren(),
Expand Down
50 changes: 50 additions & 0 deletions Classes/Infrastructure/ESCR/NodeChangeState.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/*
* This file is part of the Neos.Neos.Ui package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/

declare(strict_types=1);

namespace Neos\Neos\Ui\Infrastructure\ESCR;

use Neos\Neos\PendingChangesProjection\Change;

readonly class NodeChangeState
{
public function __construct(
public bool $isCreated,
public bool $isChanged,
public bool $isDeleted,
) {
}

public static function create(): self
{
return new self(false, false, false);
}

public static function fromChange(Change $change): self
{
return new self(
$change->created,
$change->changed || $change->deleted,
$change->deleted,
);
}

public function withAppliedAdditionalChange(Change $change): self
{
return new self(
$change->created || $this->isCreated,
($change->changed || $change->moved) || $this->isChanged,
$change->deleted || $this->isDeleted,
);
}
}
58 changes: 58 additions & 0 deletions Classes/Infrastructure/ESCR/NodeChangeStateCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

/*
* This file is part of the Neos.Neos.Ui package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/

declare(strict_types=1);

namespace Neos\Neos\Ui\Infrastructure\ESCR;

use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePoint;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\Flow\Annotations as Flow;
use Neos\Neos\PendingChangesProjection\Changes;

#[Flow\Proxy(false)]
final readonly class NodeChangeStateCollection
{
/**
* @param array<string, NodeChangeState> $changesByNodeAggregateId
*/
private function __construct(
private array $changesByNodeAggregateId,
) {
}

public static function create(Changes $changes, DimensionSpacePoint $dimensionSpacePoint): self
{
/**
* @var array<string, NodeChangeState> $changesByNodeAggregateId
*/
$changesByNodeAggregateId = [];

foreach ($changes as $change) {
if ($change->originDimensionSpacePoint === null || $change->originDimensionSpacePoint->equals($dimensionSpacePoint)) {
if ($pendingChange = $changesByNodeAggregateId[$change->nodeAggregateId->value] ?? null) {
$changesByNodeAggregateId[$change->nodeAggregateId->value] = $pendingChange->withAppliedAdditionalChange($change);
} else {
$changesByNodeAggregateId[$change->nodeAggregateId->value] = NodeChangeState::fromChange($change);
}
}
}
return new self(
$changesByNodeAggregateId
);
}

public function findByNodeAggreqateId(NodeAggregateId $nodeAggregateId): ?NodeChangeState
{
return $this->changesByNodeAggregateId[$nodeAggregateId->value] ?? null;
}
}
48 changes: 40 additions & 8 deletions Classes/Infrastructure/ESCR/NodeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@
use Neos\Flow\Annotations as Flow;
use Neos\Neos\Domain\NodeLabel\NodeLabelGeneratorInterface;
use Neos\Neos\Domain\SubtreeTagging\NeosSubtreeTag;
use Neos\Neos\PendingChangesProjection\Changes;
use Neos\Neos\Ui\Application\Shared\NodeTypeWasNotFound;
use Neos\Neos\Ui\Application\Shared\NodeWasNotFound;
use Neos\Neos\Ui\Application\Shared\TreeNodeBuilder;
use Neos\Workspace\Ui\ViewModel\PendingChanges;

/**
* @internal
Expand All @@ -46,7 +48,8 @@ final class NodeService
public function __construct(
private readonly ContentRepository $contentRepository,
public readonly ContentSubgraphInterface $subgraph,
private readonly NodeLabelGeneratorInterface $nodeLabelGenerator
private readonly NodeLabelGeneratorInterface $nodeLabelGenerator,
public readonly NodeChangeStateCollection $pendingChanges,
) {
}

Expand Down Expand Up @@ -88,26 +91,30 @@ public function getLabelForNode(Node $node): string

public function findParentNode(Node $node): ?Node
{
return $this->subgraph->findParentNode($node->aggregateId);
$parent = $this->subgraph->findParentNode($node->aggregateId);
return $parent && $this->filterRemovedNodes($parent) ? $parent : null;
}

public function findPrecedingSiblingNodes(Node $node): Nodes
{
$filter = FindPrecedingSiblingNodesFilter::create();

return $this->subgraph->findPrecedingSiblingNodes($node->aggregateId, $filter);
return $this->subgraph->findPrecedingSiblingNodes($node->aggregateId, $filter)
->filter(fn (Node $node) => $this->filterRemovedNodes($node));
}

public function findSucceedingSiblingNodes(Node $node): Nodes
{
$filter = FindSucceedingSiblingNodesFilter::create();

return $this->subgraph->findSucceedingSiblingNodes($node->aggregateId, $filter);
return $this->subgraph->findSucceedingSiblingNodes($node->aggregateId, $filter)
->filter(fn (Node $node) => $this->filterRemovedNodes($node));
}

public function findNodeByAbsoluteNodePath(AbsoluteNodePath $path): ?Node
{
return $this->subgraph->findNodeByAbsolutePath($path);
$node = $this->subgraph->findNodeByAbsolutePath($path);
return $node && $this->filterRemovedNodes($node) ? $node : null;
}

public function search(Node $rootNode, string $searchTerm, NodeTypeFilter $nodeTypeFilter): Nodes
Expand All @@ -117,7 +124,8 @@ public function search(Node $rootNode, string $searchTerm, NodeTypeFilter $nodeT
searchTerm: $searchTerm
);

return $this->subgraph->findDescendantNodes($rootNode->aggregateId, $filter);
return $this->subgraph->findDescendantNodes($rootNode->aggregateId, $filter)
->filter(fn (Node $node) => $this->filterRemovedNodes($node));
}

public function createTreeBuilderForRootNode(
Expand All @@ -135,6 +143,7 @@ public function createTreeBuilderForRootNode(
public function createTreeNodeBuilderForNode(Node $node): TreeNodeBuilder
{
$nodeType = $this->requireNodeTypeByName($node->nodeTypeName);
$pendingChange = $this->pendingChanges->findByNodeAggreqateId($node->aggregateId);

return new TreeNodeBuilder(
nodeAddress: NodeAddress::fromNode($node),
Expand All @@ -147,7 +156,10 @@ public function createTreeNodeBuilderForNode(Node $node): TreeNodeBuilder
hasScheduledDisabledState:
$node->getProperty('enableAfterDateTime') instanceof \DateTimeInterface
|| $node->getProperty('disableAfterDateTime') instanceof \DateTimeInterface,
hasUnloadedChildren: false
hasUnloadedChildren: false,
isCreated: $pendingChange ? $pendingChange->isCreated : false,
isModified: $pendingChange ? $pendingChange->isChanged : false,
isRemoved: $pendingChange ? $pendingChange->isDeleted : false,
);
}

Expand All @@ -157,7 +169,8 @@ public function findChildNodes(Node $parentNode, NodeTypeCriteria $nodeTypeCrite
nodeTypes: $nodeTypeCriteria,
);

return $this->subgraph->findChildNodes($parentNode->aggregateId, $filter);
return $this->subgraph->findChildNodes($parentNode->aggregateId, $filter)
->filter(fn (Node $node) => $this->filterRemovedNodes($node));
}

public function getNumberOfChildNodes(Node $parentNode, NodeTypeCriteria $nodeTypeCriteria): int
Expand All @@ -175,4 +188,23 @@ public function findAncestorNodes(Node $node): Nodes

return $this->subgraph->findAncestorNodes($node->aggregateId, $filter);
}

/**
* Filter function to remove all nodes that are tagged as removed
* AND do not have the tag assigned directly (deleted as children)
* AND are not in the current changes (other workspaces)
*/
public function filterRemovedNodes(Node $node): bool
{
if (!$node->tags->contain(NeosSubtreeTag::removed())) {
return true;
}
if ($node->tags->withoutInherited()->contain(NeosSubtreeTag::removed())) {
$changeState = $this->pendingChanges->findByNodeAggreqateId($node->aggregateId);
if ($changeState instanceof NodeChangeState && $changeState->isDeleted) {
return true;
}
}
return false;
}
}
17 changes: 14 additions & 3 deletions Classes/Infrastructure/ESCR/NodeServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@
namespace Neos\Neos\Ui\Infrastructure\ESCR;

use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePoint;
use Neos\ContentRepository\Core\Projection\ContentGraph\VisibilityConstraints;
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Flow\Annotations as Flow;
use Neos\Neos\Domain\NodeLabel\NodeLabelGeneratorInterface;
use Neos\Neos\Domain\SubtreeTagging\NeosVisibilityConstraints;
use Neos\Neos\PendingChangesProjection\ChangeFinder;
use Neos\Neos\PendingChangesProjection\ChangeProjection;

/**
* @internal
Expand All @@ -41,17 +44,25 @@ public function create(
): NodeService {
$contentRepository = $this->contentRepositoryRegistry
->get($contentRepositoryId);
$subgraph = $contentRepository
->getContentGraph($workspaceName)
$contentGraph = $contentRepository->getContentGraph($workspaceName);
$subgraph = $contentGraph
->getSubgraph(
$dimensionSpacePoint,
NeosVisibilityConstraints::excludeRemoved()
VisibilityConstraints::createEmpty()
);

$changeFinder = $contentRepository->projectionState(ChangeFinder::class);
$changes = $changeFinder->findByContentStreamId($contentGraph->getContentStreamId());
$pendingChanges = NodeChangeStateCollection::create(
$changes,
$dimensionSpacePoint,
);

return new NodeService(
contentRepository: $contentRepository,
subgraph: $subgraph,
nodeLabelGenerator: $this->nodeLabelGenerator,
pendingChanges: $pendingChanges,
);
}
}
Loading