opencaesar / oml-vision

A VS Code extension providing UI viewpoints for OML models
Other
4 stars 2 forks source link

Cannot generate a view when there are more than 2 sets of layouts objects that contain the "children" attribute #36

Closed pogi7 closed 5 months ago

pogi7 commented 5 months ago

Checklist before submitting a bug report

Context

I cannot generate a view when there are more than 2 sets of layouts objects that contain the "children" attribute in the pages.json file.

Steps to reproduce the bug

  1. Add this JSON to the pages.json file in any OML model. For example https://github.com/pogi7/kepler16b-example/blob/main/src/vision/layouts/pages.json
    
    [
    { "title": "Home", "path": "/", "type": "home" },
    {
    "title": "Kepler16b",
    "type": "group",
    "iconUrl": "https://nasa-jpl.github.io/stellar/icons/satellite.svg",
    "children": [
      { 
        "title": "Objectives",
        "type": "table",
        "path": "objectives"
      },
      {
        "title": "Missions",
        "type": "tree",
        "path": "missions"
      },
      {
        "title": "Components",
        "type": "diagram",
        "path": "components"
      },
      {
        "title": "Connections",
        "type": "table",
        "path": "connections"
      }
    ]
    },
    {
    "title": "Test",
    "type": "group",
    "iconUrl": "https://nasa-jpl.github.io/stellar/icons/satellite.svg",
    "children": [
      {
        "title": "Requirements",
        "type": "tree",
        "path": "requirements"
      }
    ]
    }
    ]
2. Verify that there is a src/vision/layouts/trees folder with a requirements.json file with the following JSON object.

```json
{
  "requirements": {
    "name": "Requirements Diagram",
    "diagrams": {
      "all-rows": "requirements-diagram"
    },
    "queries": {
      "req-query": "requirements.sparql"
    },
    "rowMapping": {
      "id": "req-query",
      "name": "Requirements",
      "labelFormat": "{r_id}",
      "subRowMappings": [
        {
          "id": "req-query",
          "name": "Components",
          "labelFormat": "C Name: {c_name}"
        }
      ]
    }
  }
}
  1. Try to open the requirements tree view.

Current result

It will not render properly and an error will show.

Expected result

All views with defined layout/viewpoint in the pages.json file and has an appropriate layout/viewpoint JSON specification file should render with no errors.

Additional context

[Any additional context. If applicable, you may provide screenshots and/or error logs.]

Possible fix

It seems that the bug is being caused in the this code in the TableView.tsx, TreeView.tsx, and DiagramView.tsx.

layouts[LayoutPaths.Pages][1]["children"].forEach((diagram: any) => {
      if (diagram.type === "diagram") {
        // Locally scoped variable which is used to set the key of the JSON object
        let _path = "";
        // Path comes from the pages.json file with the .json file identifier
        _path = diagram.path + ".json";
        // Use object spread to merge all diagrams into diagramLayouts object
        diagramLayouts = {...diagramLayouts, ...layouts[_path]};
      }
    });

It looks like the code is only getting the first element in the JSON array when it should loop through all JSON objects that have the "children" JSON attribute.

Technical data