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

Generic Json API #3

Open
MostafaZeinali opened this issue Dec 27, 2022 · 6 comments
Open

Generic Json API #3

MostafaZeinali opened this issue Dec 27, 2022 · 6 comments

Comments

@MostafaZeinali
Copy link

MostafaZeinali commented Dec 27, 2022

I have a tree represented in json that I would like to visualize in this component. I have managed to do so up until a certain level before I faced an issue. My tree is not "complete" meaning, one path has children that the other path does not. And a JSONPath selector such as [?(@.items)] does not solve the issue. Is this intended? My question is, if I define a "child level" for a certain "level" do "all nodes" at that level have to have that child?
Imagine this:

A
    B
        C
D
   E

As you can see, E does not have a level 3 child, but B does. Can this be represented with this component?
Here's my full json,:

{
	"data": {
		"items": [
			{
				"items": [
					{
						"items": [
							{
								"items": [
									{
										"items": [
											{
												"items": [
													{
														"items": [
															{
																"items": [
																	{
																		"items": [
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "23",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "8",
																				"type": "Well",
																				"name": "WELL_1"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "24",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "10",
																				"type": "Well",
																				"name": "WELL_2"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "25",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "11",
																				"type": "Well",
																				"name": "WELL_3"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "26",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "12",
																				"type": "Well",
																				"name": "WELL_4"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "27",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "13",
																				"type": "Well",
																				"name": "WELL_5"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "28",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "14",
																				"type": "Well",
																				"name": "WELL_6"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "29",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "15",
																				"type": "Well",
																				"name": "WELL_7"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "30",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "16",
																				"type": "Well",
																				"name": "WELL_8"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "31",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "17",
																				"type": "Well",
																				"name": "WELL_9"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "32",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "18",
																				"type": "Well",
																				"name": "WELL_10"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "33",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "19",
																				"type": "Well",
																				"name": "WELL_11"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "34",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "20",
																				"type": "Well",
																				"name": "WELL_12"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "35",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "21",
																				"type": "Well",
																				"name": "WELL_13"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "36",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "22",
																				"type": "Well",
																				"name": "WELL_14"
																			}
																		],
																		"operated": false,
																		"id": "9",
																		"type": "Reservoir",
																		"name": "DEMO_FIELD__DEFAULT_Reservoir"
																	}
																],
																"operated": false,
																"id": "7",
																"type": "Field",
																"name": "DEMO_FIELD"
															}
														],
														"operated": false,
														"id": "5",
														"type": "ProductionStation",
														"name": "Station 1"
													}
												],
												"operated": false,
												"id": "6",
												"type": "Block",
												"name": "SOUTH__DEFAULT_Block"
											},
											{
												"items": [
													{
														"items": [
															{
																"items": [
																	{
																		"items": [
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "63",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "49",
																				"type": "Well",
																				"name": "WELL_1"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "64",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "50",
																				"type": "Well",
																				"name": "WELL_2"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "65",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "51",
																				"type": "Well",
																				"name": "WELL_3"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "66",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "52",
																				"type": "Well",
																				"name": "WELL_4"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "67",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "53",
																				"type": "Well",
																				"name": "WELL_5"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "68",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "54",
																				"type": "Well",
																				"name": "WELL_6"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "69",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "55",
																				"type": "Well",
																				"name": "WELL_7"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "70",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "56",
																				"type": "Well",
																				"name": "WELL_8"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "71",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "57",
																				"type": "Well",
																				"name": "WELL_9"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "72",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "58",
																				"type": "Well",
																				"name": "WELL_10"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "73",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "59",
																				"type": "Well",
																				"name": "WELL_11"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "74",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "60",
																				"type": "Well",
																				"name": "WELL_12"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "75",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "61",
																				"type": "Well",
																				"name": "WELL_13"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "76",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "62",
																				"type": "Well",
																				"name": "WELL_14"
																			}
																		],
																		"operated": false,
																		"id": "40",
																		"type": "Reservoir",
																		"name": "Reservoir 1"
																	}
																],
																"operated": false,
																"id": "39",
																"type": "Field",
																"name": "Field 1"
															},
															{
																"items": [
																	{
																		"items": [
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "91",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "77",
																				"type": "Well",
																				"name": "WELL_1"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "92",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "78",
																				"type": "Well",
																				"name": "WELL_2"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "93",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "79",
																				"type": "Well",
																				"name": "WELL_3"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "94",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "80",
																				"type": "Well",
																				"name": "WELL_4"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "95",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "81",
																				"type": "Well",
																				"name": "WELL_5"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "96",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "82",
																				"type": "Well",
																				"name": "WELL_6"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "97",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "83",
																				"type": "Well",
																				"name": "WELL_7"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "98",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "84",
																				"type": "Well",
																				"name": "WELL_8"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "99",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "85",
																				"type": "Well",
																				"name": "WELL_9"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "100",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "86",
																				"type": "Well",
																				"name": "WELL_10"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "101",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "87",
																				"type": "Well",
																				"name": "WELL_11"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "102",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "88",
																				"type": "Well",
																				"name": "WELL_12"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "103",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "89",
																				"type": "Well",
																				"name": "WELL_13"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "104",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "90",
																				"type": "Well",
																				"name": "WELL_14"
																			}
																		],
																		"operated": false,
																		"id": "42",
																		"type": "Reservoir",
																		"name": "Reservoir 2"
																	}
																],
																"operated": false,
																"id": "41",
																"type": "Field",
																"name": "Field 2"
															}
														],
														"operated": false,
														"id": "38",
														"type": "ProductionStation",
														"name": "Station 2"
													}
												],
												"operated": false,
												"id": "37",
												"type": "Block",
												"name": "Block 1"
											},
											{
												"items": [
													{
														"items": [
															{
																"items": [
																	{
																		"items": [
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "119",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "105",
																				"type": "Well",
																				"name": "WELL_1"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "120",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "106",
																				"type": "Well",
																				"name": "WELL_2"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "121",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "107",
																				"type": "Well",
																				"name": "WELL_3"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "122",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "108",
																				"type": "Well",
																				"name": "WELL_4"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "123",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "109",
																				"type": "Well",
																				"name": "WELL_5"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "124",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "110",
																				"type": "Well",
																				"name": "WELL_6"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "125",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "111",
																				"type": "Well",
																				"name": "WELL_7"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "126",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "112",
																				"type": "Well",
																				"name": "WELL_8"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "127",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "113",
																				"type": "Well",
																				"name": "WELL_9"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "128",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "114",
																				"type": "Well",
																				"name": "WELL_10"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "129",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "115",
																				"type": "Well",
																				"name": "WELL_11"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "130",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "116",
																				"type": "Well",
																				"name": "WELL_12"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "131",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "117",
																				"type": "Well",
																				"name": "WELL_13"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "132",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "118",
																				"type": "Well",
																				"name": "WELL_14"
																			}
																		],
																		"operated": false,
																		"id": "46",
																		"type": "Reservoir",
																		"name": "Reservoir 3"
																	}
																],
																"operated": false,
																"id": "45",
																"type": "Field",
																"name": "Field 3"
															},
															{
																"items": [
																	{
																		"items": [
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "147",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "133",
																				"type": "Well",
																				"name": "WELL_1"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "148",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "134",
																				"type": "Well",
																				"name": "WELL_2"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "149",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "135",
																				"type": "Well",
																				"name": "WELL_3"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "150",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "136",
																				"type": "Well",
																				"name": "WELL_4"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "151",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "137",
																				"type": "Well",
																				"name": "WELL_5"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "152",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "138",
																				"type": "Well",
																				"name": "WELL_6"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "153",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "139",
																				"type": "Well",
																				"name": "WELL_7"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "154",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "140",
																				"type": "Well",
																				"name": "WELL_8"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "155",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "141",
																				"type": "Well",
																				"name": "WELL_9"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "156",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "142",
																				"type": "Well",
																				"name": "WELL_10"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "157",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "143",
																				"type": "Well",
																				"name": "WELL_11"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "158",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "144",
																				"type": "Well",
																				"name": "WELL_12"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "159",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "145",
																				"type": "Well",
																				"name": "WELL_13"
																			},
																			{
																				"well_info": null,
																				"items": [
																					{
																						"operated": false,
																						"id": "160",
																						"type": "Completion",
																						"name": "COMP_1_20"
																					}
																				],
																				"operated": false,
																				"id": "146",
																				"type": "Well",
																				"name": "WELL_14"
																			}
																		],
																		"operated": false,
																		"id": "48",
																		"type": "Reservoir",
																		"name": "Reservoir 4"
																	}
																],
																"operated": false,
																"id": "47",
																"type": "Field",
																"name": "Field 4"
															}
														],
														"operated": false,
														"id": "44",
														"type": "ProductionStation",
														"name": "Station 3"
													}
												],
												"operated": false,
												"id": "43",
												"type": "Block",
												"name": "Block 2"
											}
										],
										"operated": false,
										"id": "3",
										"type": "Region",
										"name": "SOUTH"
									}
								],
								"id": "1",
								"type": "Company",
								"name": "Target Oilfield Services"
							}
						],
						"id": "154",
						"type": "Country",
						"name": "Oman"
					}
				],
				"id": "1",
				"type": "Continent",
				"name": "Asia"
			},
			{
				"items": [
					{
						"items": [
							{
								"items": [
									{
										"items": null,
										"operated": false,
										"id": "2",
										"type": "Region",
										"name": "Muntenia"
									}
								],
								"id": "2",
								"type": "Company",
								"name": "Mazarine Energy Romania S.R.L."
							}
						],
						"id": "169",
						"type": "Country",
						"name": "Romania"
					}
				],
				"id": "3",
				"type": "Continent",
				"name": "Europe"
			}
		]
	}
}
@MostafaZeinali
Copy link
Author

I can provide more details if you need.

@pgillich
Copy link
Owner

pgillich commented Dec 31, 2022

The plugin expects an array with objects, it cannot process a deep tree. So, you have to transform the original schema.
You can change your service source code of or you can transform it in JSONata on-the-fly, for example: https://try.jsonata.org/5iqrLPmdA
Most probable, you wouldn't like to show all the records, so you should add filtering to the JSONata expression.
You can read more details about the used functions here:

@pgillich
Copy link
Owner

I just tested the plugin with above on-the-fly example. It does not work, because of a JSONata 1.8.5 bug: jsonata-js/jsonata#547
The JSONata version should be updated and a new plugin version must be build and published.
Please be patient. The issue describes a workaround, you may try it.

@MostafaZeinali
Copy link
Author

Hello dear. Thanks for the reply. I will be patient as advised, but just to make sure we are on the same page and I have gotten my message fully across, I'll add some more details.
I have already built the tree with the json data I posted above with the following JSON selectors:
tree1

The problem starts when I add one more level:
tree2

Inspecting my data brought me to this conclusion that the code expects the tree to be "full" meaning all paths must be the same.

The exact error I get is:
"Fields have different lengths"

Here's my panel json for testing and debugging:

{
  "id": 12,
  "gridPos": {
    "h": 21,
    "w": 5,
    "x": 0,
    "y": 0
  },
  "type": "pgillich-tree-panel",
  "title": "Asset Tree",
  "datasource": {
    "uid": "Eq8gmtt4z",
    "type": "marcusolsson-json-datasource"
  },
  "options": {
    "rootName": "Assets",
    "treeFieldTemplateEngine": "simple",
    "treeFields": "${Continent}\n${Country}\n${Company}\n${Region}\n${Block}",
    "serieColumn": "serieColumn",
    "expandLevel": 5,
    "showItemCount": true,
    "orderLevels": "asc"
  },
  "targets": [
    {
      "datasource": {
        "type": "marcusolsson-json-datasource",
        "uid": "Eq8gmtt4z"
      },
      "body": "",
      "cacheDurationSeconds": 300,
      "fields": [
        {
          "jsonPath": "$.data.items[*].name",
          "language": "jsonpath",
          "name": "Continent"
        },
        {
          "jsonPath": "$.data.items[*].items[*].name",
          "language": "jsonpath",
          "name": "Country"
        },
        {
          "jsonPath": "$.data.items[*].items[*].items[*].name",
          "language": "jsonpath",
          "name": "Company"
        },
        {
          "jsonPath": "$.data.items[*].items[*].items[*].items[*].name",
          "language": "jsonpath",
          "name": "Region"
        },
        {
          "name": "Block",
          "jsonPath": "$.data.items[*].items[*].items[*].items[*].items[*].name",
          "language": "jsonpath"
        }
      ],
      "method": "GET",
      "params": [],
      "queryParams": "",
      "refId": "A",
      "urlPath": "/api/v1/tree"
    }
  ]
}

@pgillich
Copy link
Owner

pgillich commented Jan 1, 2023

I just tested the plugin with above on-the-fly example. It does not work, because of a JSONata 1.8.5 bug: jsonata-js/jsonata#547 The JSONata version should be updated and a new plugin version must be build and published. Please be patient. The issue describes a workaround, you may try it.

The old JSONata version is used by the datasource. It's a known issue and we have to wait for upgrading it: grafana/grafana-json-datasource#307

@pgillich
Copy link
Owner

pgillich commented Jan 1, 2023

Hello dear. Thanks for the reply. I will be patient as advised, but just to make sure we are on the same page and I have gotten my message fully across, I'll add some more details. I have already built the tree with the json data I posted above with the following JSON selectors:

I see. So, the situation is more simple, because each field (Continent, Country, Company, Region, ...) has a dedicated level. The cause of "Fields have different lengths" error message is, a value is missing (because of not enough deep level) and must be substituted with a static string.

The JsonPath is not enough flexible for it, so JSONata expression must be used, see ( ? ... : ... expressions): https:/pgillich/grafana-tree-panel#datasource

The number of values in fields must be same, so missing values must be substituted. JSON API supports JSONata, so it's possible.

You can use jfq to work out the expressions: https:/pgillich/grafana-kubernetes#sample-grafana-dashboards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants