You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by GitBox <gi...@apache.org> on 2021/06/01 13:09:00 UTC

[GitHub] [brooklyn-ui] algairim commented on a change in pull request #209: WIP Make relationship view processing completely generic in app inspector

algairim commented on a change in pull request #209:
URL: https://github.com/apache/brooklyn-ui/pull/209#discussion_r643086669



##########
File path: ui-modules/app-inspector/app/components/entity-tree/entity-tree.directive.js
##########
@@ -141,52 +134,60 @@ export function entityTreeDirective() {
             }
 
             /**
-             * Extends entity tree with 'host_for/hosted_on' view mode. Moves entities (creates copies) if their host is
-             * not a parent and labels them to display under 'host_for/hosted_on' view mode only.
+             * Extends entity tree with other view modes. Moves entities (creates copies) if their host is
+             * not a parent and labels them to display under other view modes only.
              *
              * @param {Array.<Object>} entities The entity tree converted to array.
              * @param {Array.<Object>} relationships The relationships of entities.
              */
-            function addHostForHostedOnView(entities, relationships) {
-
-                // Look through all entities found in the entity tree
-                entities.forEach(entity => {
-
-                    // Check if entity has 'host_for/hosted_on' relationship.
-                    let relationship = relationships.find(r => r.id === entity.id);
-                    if (relationship && relationship.name === RELATIONSHIP_HOST_FOR) {
-
-                        // Label every 'host_for' entity to display and highlight in 'host_for/hosted_on' view mode.
-                        displayEntityInView(entity, VIEW_HOST_FOR_HOSTED_ON);
-                        highlightEntityInView(entity, VIEW_HOST_FOR_HOSTED_ON);
-
-                        // Look for 'hosted_on' entities under 'host_for', flip of move them and label to display in
-                        // 'host_for/hosted_on' view mode respectively.
-                        relationship.targets.forEach(target => {
-                            let relatedEntity = entities.find(e => e.id === target);
-                            if (relatedEntity) {
-                                highlightEntityInView(relatedEntity, VIEW_HOST_FOR_HOSTED_ON);
-                                displayParentsInView(entities, relatedEntity.parentId, VIEW_HOST_FOR_HOSTED_ON);
-
-                                // Re-arrange the tree if related 'hosted_on' entity is not a child of 'host_for'.
-                                if (relatedEntity.parentId !== entity.id) {
-
-                                    if (relatedEntity.id === entity.parentId) {
-                                        // 4.1. Flip 'hosted_on' parent with a 'host_for' child.
-                                        flipParentAndChild(relatedEntity, entity, entities, VIEW_HOST_FOR_HOSTED_ON);
-                                    } else {
-                                        // 4.2. Move 'hosted_on' entity to a new 'host_for' parent.
-                                        moveEntityToParent(relatedEntity, entity, entities, VIEW_HOST_FOR_HOSTED_ON);
+            function addOtherViews(entities, relationships) {
+                let otherViews = Array.from($scope.viewModes).filter(r => r !== VIEW_PARENT_CHILD);
+                otherViews.forEach(view => {
+
+                    // Define parent and child identifiers
+                    const otherParentChildIdentifiers = view.split(RELATIONSHIP_VIEW_DELIMITER);
+                    const OTHER_PARENT = otherParentChildIdentifiers[0];
+                    const OTHER_CHILD = otherParentChildIdentifiers[1];

Review comment:
       This is the new code.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org