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 18:15:59 UTC

[GitHub] [brooklyn-ui] algairim commented on a change in pull request #209: Improvements for relationship view processing in app inspector

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



##########
File path: ui-modules/app-inspector/app/components/entity-tree/entity-tree.directive.js
##########
@@ -141,55 +134,106 @@ 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) {
+            function addOtherViews(entities, relationships) {
+                let otherViews = Array.from($scope.viewModes).filter(r => r !== VIEW_PARENT_CHILD);
+                otherViews.forEach(view => {
 
-                // Look through all entities found in the entity tree
-                entities.forEach(entity => {
+                    // Get 'OTHER_PARENT' and 'OTHER_CHILD' identifiers.
+                    const {OTHER_PARENT, OTHER_CHILD} = getRelationshipViewIdentifiers(view);
+
+                    // Phase 1. Look through all entities found in the entity tree: process entity with 'OTHER_PARENT'
+                    //          roles and entities without roles.
+                    entities.forEach(entity => {
+
+                        // Get relationship roles for an entity.
+                        const {parentRole, childRole} = getRelationshipRoles(relationships, entity.id, OTHER_PARENT, OTHER_CHILD);
+
+                        if (parentRole) {
 
-                    // 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);
+                            // Label every 'OTHER_PARENT' entity to display and highlight in 'OTHER_PARENT/OTHER_CHILD'
+                            // view mode, only if it does not play the role of 'OTHER_CHILD' at the same time.
+                            if (!childRole) {
+                                displayEntityInView(entity, view);
+                                highlightEntityInView(entity, view);
+                            }

Review comment:
       This is the new bit in the code block refactored above.




-- 
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