Skip to content

Commit

Permalink
TASK: convert CR/Nodes reducer to TS
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaip committed Nov 14, 2018
1 parent f2036f1 commit 9898ca7
Show file tree
Hide file tree
Showing 14 changed files with 983 additions and 747 deletions.
2 changes: 1 addition & 1 deletion packages/neos-ui-guest-frame/src/InlineUI/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default class InlineUI extends PureComponent {
};

render() {
const focused = this.props.focused.toJS();
const {focused} = this.props;
const focusedNodeContextPath = focused.contextPath;
const {nodeTypesRegistry, focusedNode, shouldScrollIntoView, requestScrollIntoView, destructiveOperationsAreDisabled, clipboardMode, clipboardNodeContextPath} = this.props;
const isDocument = nodeTypesRegistry.hasRole($get('nodeType', focusedNode), 'document');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
import {$get} from 'plow-js';
import {Node, NodeContextPath} from './index';

//
// Helper function to determine allowed node types
//
export const getAllowedNodeTypesTakingAutoCreatedIntoAccount = (baseNode, parentOfBaseNode, nodeTypesRegistry) => {
export const getAllowedNodeTypesTakingAutoCreatedIntoAccount = (baseNode: Node, parentOfBaseNode: Node, nodeTypesRegistry: any) => {
if (!baseNode) {
return [];
}
if ($get('isAutoCreated', baseNode)) {
if (baseNode.isAutoCreated) {
if (!parentOfBaseNode) {
return [];
}
return nodeTypesRegistry.getAllowedGrandChildNodeTypes(
$get('nodeType', parentOfBaseNode),
$get('name', baseNode)
parentOfBaseNode.nodeType,
baseNode.name
);
}

// Not auto created
return nodeTypesRegistry.getAllowedChildNodeTypes($get('nodeType', baseNode));
return nodeTypesRegistry.getAllowedChildNodeTypes(baseNode.nodeType);
};

//
// Helper function to get parent contextPath from current contextPath
//
export const parentNodeContextPath = contextPath => {
export const parentNodeContextPath = (contextPath: NodeContextPath) => {
if (typeof contextPath !== 'string') {
console.error('`contextPath` must be a string!'); // tslint:disable-line
return null;
}

const [path, context] = contextPath.split('@');

if (path.length === 0) {
// We are at top level; so there is no parent anymore!
return false;
return null;
}

return `${path.substr(0, path.lastIndexOf('/'))}@${context}`;
Expand All @@ -42,7 +42,7 @@ export const parentNodeContextPath = contextPath => {
//
// Helper function to check if the node is collapsed
//
export const isNodeCollapsed = (node, isToggled, rootNode, loadingDepth) => {
const isCollapsedByDefault = loadingDepth === 0 ? false : $get('depth', node) - $get('depth', rootNode) >= loadingDepth;
export const isNodeCollapsed = (node: Node, isToggled: boolean, rootNode: Node, loadingDepth: number) => {
const isCollapsedByDefault = loadingDepth === 0 ? false : node.depth - rootNode.depth >= loadingDepth;
return (isCollapsedByDefault && !isToggled) || (!isCollapsedByDefault && isToggled);
};
Loading

0 comments on commit 9898ca7

Please sign in to comment.