Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: FEATURE: Add nodeMove strategy configuration to nodetypes #5314

Open
wants to merge 14 commits into
base: 9.0
Choose a base branch
from

Conversation

pKallert
Copy link
Contributor

@pKallert pKallert commented Oct 23, 2024

In order to mimic the behavior of 8.3 we decided to introduce a setting for move strategies on NodeType level.

In 8.3 when moving a document node, we (try to) move it in all dimensions. When moving a content node in 8.3 we do not try to move it in all dimensions.

Currently the move strategy is hard-coded in the Neos UI. With this PR we load the move strategy from the NodyType if no "override" move strategy is given.

This gives us the flexibility in the future to implement some custom move strategies in the UI but lets us keep the 8.3 behavior for now.

Review instructions

Checklist

  • Code follows the PSR-2 coding style
  • Tests have been created, run and adjusted as needed
  • The PR is created against the lowest maintained branch
  • Reviewer - PR Title is brief but complete and starts with FEATURE|TASK|BUGFIX
  • Reviewer - The first section explains the change briefly for change-logs
  • Reviewer - Breaking Changes are marked with !!! and have upgrade-instructions

Copy link
Member

@skurfuerst skurfuerst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, only two nitpicks :)

@mhsdesign
Copy link
Member

Huuch i remember having created an issue for this once neos/neos-ui#3587 and funnily there was even a pr from Bernhard both for neos and the ui #4994 but that seems to be superseded then ...

@bwaidelich
Copy link
Member

In order to mimic the behavior of 9.0 we decided to introduce a setting for move strategies on NodeType level.

is that correct? I'm confused as to what this PR is supposed to solve (by just reading the description)

@pKallert
Copy link
Contributor Author

pKallert commented Nov 1, 2024

In order to mimic the behavior of 9.0 we decided to introduce a setting for move strategies on NodeType level.

is that correct? I'm confused as to what this PR is supposed to solve (by just reading the description)

Sorry, of course I meant 8.3 😄

This is for differentiating between document and content nodes when moving nodes.
For example: When moving a document node in the UI the node should be moved in all dimensions. When moving a content node (like in 8.3) the node should perhaps not be moved in all dimensions.
This is now a setting that can be set for each node type with the behavior from 8.3 set as the default.

We also talked about implementing a query window in the UI, but that could get annoying really fast especially if you move nodes very often. This can be further enhanced in future iterations but for now we landed on setting it in the node type.

There are still some edge cases that I have to have a look at and think about(when I get my local environment running again) to fix the failing test.
I updated the description accordingly and set the PR to draft since the tests are failing and my local env keeps giving errors

@pKallert pKallert changed the title FEATURE: Add nodeMove strategy configuration to nodetypes Draft: FEATURE: Add nodeMove strategy configuration to nodetypes Nov 1, 2024
@bwaidelich
Copy link
Member

Thanks a lot for the great explanation! 🤩

Comment on lines +45 to +53
{
if (str_starts_with($name, 'RelationDistributionStrategy::')) {
$name = substr($name, strpos($name, '::') + 2);
foreach (self::cases() as $status) {
if ($name === $status->name) {
return $status;
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this complex logic, every backed enum has a built-in from and tryFrom

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, we want to get the value from key.
Enum ->from gets the key from a value, as far as I understand. So I could pass gatherSpecializations and would get RelationDistributionStrategy::STRATEGY_GATHER_SPECIALIZATIONS.
Here, we have RelationDistributionStrategy::STRATEGY_SCATTER
Basically we need to cast the string RelationDistributionStrategy::STRATEGY_GATHER_ALL into an actual enum. Not sure if there is a way to do it that is not ugly?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized that we use a different value for name and value.
btw that's IMO a limitation of PHP enums, it would make things much easier if enums without backed type would just serialize to string and have (try)from to avoid that confusion.
But, anyways, when using backed enums we should probably always refer to the value instead of the key when (de)serializing the enum

@@ -3,6 +3,8 @@
'Neos.Neos:Node': true
'Neos.Neos:Hidable': true
abstract: true
strategy:
moveNode: RelationDistributionStrategy::STRATEGY_SCATTER
Copy link
Member

@bwaidelich bwaidelich Nov 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's the root cause. Why not

Suggested change
moveNode: RelationDistributionStrategy::STRATEGY_SCATTER
moveNode: scatter

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This format is what we decided during the sprint when discussing the new setting. It is a lot clearer than only using the key

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing is: If it is clearer, we should change the values of those enums to reflect this, i.e. change

case STRATEGY_SCATTER = 'scatter';

to

case STRATEGY_SCATTER = 'STRATEGY_SCATTER';

(like we did for many other enums exactly to avoid that confusion).

But without that change, having a different serialization format wether it's in the database (or a JSON representation) from the YAML representation is just error prone in my eyes.

Anyways, I don't want to block this PR of course – feel free to ignore me, just my 2ct :)

@@ -7,6 +7,8 @@
'Neos.Neos:Hidable': true
abstract: true
aggregate: true
strategy:
moveNode: RelationDistributionStrategy::STRATEGY_GATHER_ALL
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

..and

Suggested change
moveNode: RelationDistributionStrategy::STRATEGY_GATHER_ALL
moveNode: gatherAll

Comment on lines +45 to +53
{
if (str_starts_with($name, 'RelationDistributionStrategy::')) {
$name = substr($name, strpos($name, '::') + 2);
foreach (self::cases() as $status) {
if ($name === $status->name) {
return $status;
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized that we use a different value for name and value.
btw that's IMO a limitation of PHP enums, it would make things much easier if enums without backed type would just serialize to string and have (try)from to avoid that confusion.
But, anyways, when using backed enums we should probably always refer to the value instead of the key when (de)serializing the enum

}
}
}
return self::STRATEGY_GATHER_ALL;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, one more addition:
If we decide to keep the value based serialization we should at least fail if referring to an invalid value, rather than falling back to some strategy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants