Skip to content

Commit

Permalink
fix: show 'no url/binding' node, use async leafstate for component (r…
Browse files Browse the repository at this point in the history
…edhat-developer#687)

Signed-off-by: Andre Dietisheim <[email protected]>
  • Loading branch information
adietish committed Feb 2, 2024
1 parent 929dcea commit 6b7332e
Showing 1 changed file with 39 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ public Object getApplicationsRoot() {

@Override
public @NotNull LeafState getLeafState(@NotNull Object element) {
if (element instanceof ComponentNode) {
return LeafState.ALWAYS;
} else if (element instanceof ChartReleaseNode) {
if (element instanceof ChartReleaseNode) {
return LeafState.ALWAYS;
} else if (element instanceof MessageNode<?>) {
return LeafState.ALWAYS;
Expand All @@ -111,8 +109,8 @@ private Object[] createComponentChildren(ComponentNode componentNode) {
if (odo == null) {
return new Object[] { new MessageNode<>(root, componentNode, "Could not get components") };
}
List<URLNode> urls = getURLs(componentNode);
List<BindingNode> bindings = getBindings(componentNode, odo);
List<BaseNode<ComponentNode>> urls = getURLs(componentNode, odo);
List<BaseNode<ComponentNode>> bindings = getBindings(componentNode, odo);
return Stream.of(urls, bindings)
.filter(item -> !item.isEmpty())
.flatMap(Collection::stream)
Expand Down Expand Up @@ -221,34 +219,47 @@ private List<BaseNode<?>> load(Callable<List<BaseNode<?>>> callable, NamespaceNo
return Collections.singletonList(new MessageNode<>(namespace.getRoot(), namespace, errorMessage));
}
}
private List<URLNode> getURLs(ComponentNode element) {
List<URLNode> results = new ArrayList<>();
Odo odo = element.getRoot().getOdo().getNow(null);
if (odo == null) {
return Collections.emptyList();
}

private List<BaseNode<ComponentNode>> getURLs(ComponentNode componentNode, @NotNull Odo odo) {
List<BaseNode<ComponentNode>> nodes = new ArrayList<>();
try {
odo.listURLs(element.getParent().getName(),
element.getComponent().getPath(), element.getName()).forEach(url ->
results.add(new URLNode(element, url))
);
List<URLNode> urls = odo.listURLs(
componentNode.getParent().getName(),
componentNode.getComponent().getPath(),
componentNode.getName())
.stream()
.map(url -> new URLNode(componentNode, url))
.collect(Collectors.toList());
if (!urls.isEmpty()) {
nodes.addAll(urls);
} else {
nodes.add(new MessageNode<>(root, componentNode, "<No URLS>"));
}
} catch (IOException e) {
LOGGER.warn(e.getLocalizedMessage(), e);
}
return results;
return nodes;
}

private List<BindingNode> getBindings(ComponentNode element, @NotNull Odo odo) {
List<BindingNode> results = new ArrayList<>();
private List<BaseNode<ComponentNode>> getBindings(ComponentNode componentNode, @NotNull Odo odo) {
List<BaseNode<ComponentNode>> nodes = new ArrayList<>();
try {
odo.listBindings(element.getParent().getName(),
element.getComponent().getPath(), element.getName()).forEach(binding ->
results.add(new BindingNode(element, binding))
);
List<BindingNode> bindings = odo.listBindings(
componentNode.getParent().getName(),
componentNode.getComponent().getPath(),
componentNode.getName())
.stream()
.map(binding -> new BindingNode(componentNode, binding))
.collect(Collectors.toList());
if (!bindings.isEmpty()) {
nodes.addAll(bindings);
} else {
nodes.add(new MessageNode<>(root, componentNode, "<No Bindings>"));
}
} catch (IOException e) {
LOGGER.warn(e.getLocalizedMessage(), e);
}
return results;
return nodes;
}

private Object[] getRegistries(ApplicationsRootNode root) {
Expand Down Expand Up @@ -318,6 +329,11 @@ public Object getParentElement(@NotNull Object element) {
public void commit() {
}

@Override
public boolean isToBuildChildrenInBackground(@NotNull Object element) {
return true;
}

@Override
public boolean hasSomethingToCommit() {
return false;
Expand Down

0 comments on commit 6b7332e

Please sign in to comment.