Skip to content

Add Code Template Library to search results#2

Open
jbeckers wants to merge 1 commit into
diridium-com:mainfrom
jbeckers:show-code-template-libraries-in-search-results
Open

Add Code Template Library to search results#2
jbeckers wants to merge 1 commit into
diridium-com:mainfrom
jbeckers:show-code-template-libraries-in-search-results

Conversation

@jbeckers
Copy link
Copy Markdown

@jbeckers jbeckers commented Mar 24, 2026

Looking at

the Code Template Library name is already added to the search results, in the location field.

This PR adds the location tot the search result tree for Code Templates (just like it's done for Channels)

@jbeckers
Copy link
Copy Markdown
Author

Fixes #1

@pacmano1
Copy link
Copy Markdown
Contributor

pacmano1 commented Apr 24, 2026

(This is partially AI written w/my guidance after doing a larger refactor and backing away from that).

Thanks for catching this, and good call noticing the library name is already in the location field. I was heading toward a bigger refactor before I saw this approach, and your instinct to fix it client-side is the right one.

One thought on the tree shape. As written, the tree ends up as:

Code Templates
  TemplateName
    Library X > TemplateName
      Line 1: ...

A couple of things about that:

  1. The hierarchy is Template → Library, but I think the issue is asking for Library → Template (libraries as the grouping, templates nested underneath). That way two same-named templates in different libraries are cleanly separated at the top of the code-templates branch.
  2. The template name ends up printed twice, once as its own node and once inside the location string on the child node.
  3. For a template that isn't in any library, the server sets location to just the template name, so you'd get a duplicate node (TemplateName → TemplateName → Line). Orphan templates are uncommon but reachable: DefaultCodeTemplateController.updateLibraries does not cascade-delete templates when a library is removed, so a REST call or import that removes a library without also listing its templates leaves them in the cache with no library reference.

Would you be open to splitting the location string on " > " and rendering the library and template as separate tree levels? Something like:

String location = match.getLocation();
int sep = location.indexOf(" > ");
String libraryLabel = sep > 0 ? location.substring(0, sep) : "(No Library)";
String templateLabel = sep > 0 ? location.substring(sep + 3) : location;
DefaultMutableTreeNode libNode = findOrCreateChild(codeTemplatesNode, libraryLabel);
DefaultMutableTreeNode tmplNode = findOrCreateChild(libNode, templateLabel);
tmplNode.add(new DefaultMutableTreeNode(lineLabel));

That gives:

Code Templates
  Library X
    TemplateName
      Line 1: ...
  (No Library)
    OrphanTemplate
      Line 1: ...

Happy to push the change to your branch if easier, or you can update the PR. Either works.

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

Successfully merging this pull request may close these issues.

2 participants