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

BUGFIX: only allow to create nodes of the same role as the reference node #906

Merged
merged 2 commits into from
Sep 8, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
BUGFIX: only allow to create nodes of the same role as the reference …
…node
  • Loading branch information
dimaip committed Sep 7, 2017
commit 9ca09aa6d80bfd2b45ca61684dc5f15bbe585a48
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,19 @@ export default class NodeTypesRegistry extends SynchronousRegistry {
return Object.keys(result || []).filter(key => result[key]);
}

getAllowedNodeTypesTakingAutoCreatedIntoAccount(isSubjectNodeAutocreated, referenceParentName, referenceParentNodeType, referenceGrandParentNodeType) {
getAllowedNodeTypesTakingAutoCreatedIntoAccount(isSubjectNodeAutocreated, referenceParentName, referenceParentNodeType, referenceGrandParentNodeType, role) {
let result;
if (isSubjectNodeAutocreated) {
if (!referenceGrandParentNodeType) {
return [];
}
return this.getAllowedGrandChildNodeTypes(referenceGrandParentNodeType, referenceParentName);
result = this.getAllowedGrandChildNodeTypes(referenceGrandParentNodeType, referenceParentName);
}

return this.getAllowedChildNodeTypes(referenceParentNodeType);
result = this.getAllowedChildNodeTypes(referenceParentNodeType);
// If role is provided, filter by role, e.g. only "content" or "document" ndoetypes
console.log(role);
return role ? result.filter(nodeTypeName => this.hasRole(nodeTypeName, role)) : result;
}

getGroupedNodeTypeList(nodeTypeFilter) {
Expand Down
5 changes: 3 additions & 2 deletions packages/neos-ui-redux-store/src/CR/Nodes/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export const clipboardIsEmptySelector = createSelector(
clipboardNodePath => Boolean(clipboardNodePath)
);

const getPathInNode = (state, contextPath, propertyPath) => {
export const getPathInNode = (state, contextPath, propertyPath) => {
const node = $get(['cr', 'nodes', 'byContextPath', contextPath], state);

return $get(propertyPath, node);
Expand All @@ -188,7 +188,8 @@ export const makeGetAllowedChildNodeTypesSelector = (nodeTypesRegistry, elevator
(state, {reference}) => getPathInNode(state, elevator(reference), 'isAutoCreated'),
(state, {reference}) => getPathInNode(state, elevator(reference), 'name'),
(state, {reference}) => getPathInNode(state, elevator(reference), 'nodeType'),
(state, {reference}) => getPathInNode(state, elevator(parentNodeContextPath(reference)), 'nodeType')
(state, {reference}) => getPathInNode(state, elevator(parentNodeContextPath(reference)), 'nodeType'),
(state, {role}) => role
],
(...args) => nodeTypesRegistry.getAllowedNodeTypesTakingAutoCreatedIntoAccount(...args)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ const calculateInitialMode = (allowedSiblingNodeTypes, allowedChildNodeTypes) =>

return state => {
const reference = $get('ui.selectNodeTypeModal.referenceNodeContextPath', state);
const allowedSiblingNodeTypes = nodeTypesRegistry.getGroupedNodeTypeList(getAllowedSiblingNodeTypesSelector(state, {reference}));
const allowedChildNodeTypes = nodeTypesRegistry.getGroupedNodeTypeList(getAllowedChildNodeTypesSelector(state, {reference}));
const referenceNodeType = selectors.CR.Nodes.getPathInNode(state, reference, 'nodeType');
const role = nodeTypesRegistry.hasRole(referenceNodeType, 'document') ? 'document' : 'content';
const allowedSiblingNodeTypes = nodeTypesRegistry.getGroupedNodeTypeList(getAllowedSiblingNodeTypesSelector(state, {reference, role}));
const allowedChildNodeTypes = nodeTypesRegistry.getGroupedNodeTypeList(getAllowedChildNodeTypesSelector(state, {reference, role}));

return {
isOpen: $get('ui.selectNodeTypeModal.isOpen', state),
Expand Down