• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

knowledgepixels / nanodash / 27622721129

16 Jun 2026 01:55PM UTC coverage: 26.963% (+6.3%) from 20.697%
27622721129

Pull #483

github

web-flow
Merge 73a4d0fe1 into 663f14f46
Pull Request #483: Space/resource About pages, ref-aware spaces, and magic query params

1542 of 6717 branches covered (22.96%)

Branch coverage included in aggregate %.

3407 of 11638 relevant lines covered (29.27%)

4.31 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

27.03
src/main/java/com/knowledgepixels/nanodash/component/TitleBar.java
1
package com.knowledgepixels.nanodash.component;
2

3
import java.io.Serializable;
4
import java.util.ArrayList;
5
import java.util.List;
6

7
import org.apache.wicket.behavior.AttributeAppender;
8
import org.apache.wicket.markup.html.WebMarkupContainer;
9
import org.apache.wicket.markup.html.WebPage;
10
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
11
import org.apache.wicket.markup.html.panel.EmptyPanel;
12
import org.apache.wicket.markup.html.panel.Panel;
13
import org.apache.wicket.markup.repeater.Item;
14
import org.apache.wicket.markup.repeater.data.DataView;
15
import org.apache.wicket.markup.repeater.data.ListDataProvider;
16

17
import com.knowledgepixels.nanodash.NanodashPageRef;
18
import com.knowledgepixels.nanodash.NanodashPreferences;
19
import com.knowledgepixels.nanodash.page.NanodashPage;
20
import com.knowledgepixels.nanodash.page.PublishPage;
21
import com.knowledgepixels.nanodash.page.QueryListPage;
22
import com.knowledgepixels.nanodash.page.SpaceListPage;
23
import com.knowledgepixels.nanodash.page.UserListPage;
24

25
/**
26
 * TitleBar is the top bar of the Nanodash application, which contains
27
 * navigation elements such as profile, my channel, users, connectors,
28
 * publish, query, and breadcrumb navigation.
29
 */
30
public class TitleBar extends Panel {
31

32
    private String highlight;
33

34
    /**
35
     * The breadcrumb/tab strip row (the grey band just below the nav bar). Holds
36
     * the breadcrumb links on the left and, optionally, the resource tab strip on
37
     * the right (see {@link #setTabs(ResourceTabs)}).
38
     */
39
    private WebMarkupContainer breadcrumbPath;
40

41
    /**
42
     * Constructs a TitleBar with the specified id, page, highlight element,
43
     * and an array of path references for breadcrumb navigation.
44
     *
45
     * @param id        the component id
46
     * @param page      the current Nanodash page
47
     * @param highlight the id of the element to highlight
48
     * @param pathRefs  an array of NanodashPageRef for breadcrumb navigation
49
     */
50
    public TitleBar(String id, NanodashPage page, String highlight, NanodashPageRef... pathRefs) {
51
        super(id);
9✔
52
        this.highlight = highlight;
9✔
53
        add(new ProfileItem("profile", page));
39✔
54
        // Centered title-bar message: the post-publish confirmation and/or the
55
        // always-on "you haven't published an introduction yet" warning.
56
        add(new JustPublishedMessagePanel("justPublishedMessage", page.getPageParameters()));
42✔
57

58
        createNavLink("users", UserListPage.class);
15✔
59
        createNavLink("connectors", SpaceListPage.class);
15✔
60
        createNavLink("publish", PublishPage.class).setVisible(!NanodashPreferences.get().isReadOnlyMode());
33!
61
        createNavLink("query", QueryListPage.class);
15✔
62

63
        breadcrumbPath = new WebMarkupContainer("breadcrumbpath");
18✔
64
        WebMarkupContainer breadcrumbLinks = new WebMarkupContainer("breadcrumblinks");
15✔
65
        List<CrumbPart> crumbParts = buildCrumbParts(pathRefs);
9✔
66
        if (!crumbParts.isEmpty()) {
9!
67
            CrumbPart first = crumbParts.get(0);
×
68
            breadcrumbLinks.add(first.ref().createComponent("firstpathelement", first.label()));
×
69
            // Getting serialization exception if not using 'new ArrayList<...>(...)' here:
70
            List<CrumbPart> moreParts = new ArrayList<CrumbPart>(crumbParts.subList(1, crumbParts.size()));
×
71
            breadcrumbLinks.add(new DataView<CrumbPart>("morepathelements", new ListDataProvider<CrumbPart>(moreParts)) {
×
72

73
                @Override
74
                protected void populateItem(Item<CrumbPart> item) {
75
                    CrumbPart part = item.getModelObject();
×
76
                    item.add(part.ref().createComponent("furtherpathelement", part.label()));
×
77
                }
×
78

79
            });
80
        } else {
×
81
            breadcrumbLinks.setVisible(false);
12✔
82
        }
83
        breadcrumbPath.add(breadcrumbLinks);
30✔
84
        // Tab strip placeholder (right side of the strip); replaced via setTabs().
85
        breadcrumbPath.add(new EmptyPanel("tabs").setVisible(false));
45✔
86
        // The strip shows when there is a breadcrumb to display; setTabs() also
87
        // forces it visible so a tab strip shows even without a breadcrumb.
88
        breadcrumbPath.setVisible(pathRefs.length > 0);
24!
89
        add(breadcrumbPath);
30✔
90
    }
3✔
91

92
    /**
93
     * One breadcrumb segment: the {@link NanodashPageRef} it links to and the
94
     * (possibly split) label text to show for it.
95
     */
96
    public record CrumbPart(NanodashPageRef ref, String label) implements Serializable {
×
97
    }
98

99
    /**
100
     * Flattens a breadcrumb path into the segments to render. Two transforms are
101
     * applied to each ref's label:
102
     * <ul>
103
     *   <li>For each non-root crumb, the part it shares with its parent label
104
     *       is stripped (e.g. parent "Knowledge Pixels", child "Knowledge
105
     *       Pixels Incubator" renders as "Incubator"). The shared part is the
106
     *       longest common character prefix, but only stripped when it covers
107
     *       (almost) all of the parent and ends on a non-letter/digit boundary
108
     *       in the child — this also catches singular/plural variations like
109
     *       parent "Nano Sessions", child "Nano Session #30" → "#30".</li>
110
     *   <li>Only the leading segment of the remaining label is kept — the part
111
     *       before the first list/title separator ({@code ,}, {@code :},
112
     *       {@code ;}, {@code |}, or a spaced {@code -}) — so each path level
113
     *       renders as one concise crumb. E.g. "FIP.38.T.8 | FAIR Implementation
114
     *       Profile Training Session 8" renders as "FIP.38.T.8" and "3PFF: the
115
     *       Three Point FAIRification Framework" as "3PFF".</li>
116
     * </ul>
117
     * The parent-prefix comparison uses the original (un-simplified) labels.
118
     */
119
    static List<CrumbPart> buildCrumbParts(NanodashPageRef[] pathRefs) {
120
        List<CrumbPart> parts = new ArrayList<>();
12✔
121
        for (int i = 0; i < pathRefs.length; i++) {
18!
122
            String label = pathRefs[i].getLabel();
×
123
            if (label == null) {
×
124
                parts.add(new CrumbPart(pathRefs[i], null));
×
125
                continue;
×
126
            }
127
            if (i > 0) {
×
128
                label = stripParentPrefix(pathRefs[i - 1].getLabel(), label);
×
129
            }
130
            // Show only the leading segment (before the first list/title separator)
131
            // so each path level renders as one concise crumb — e.g.
132
            // "FIP.38.T.8 | FAIR Implementation Profile Training Session 8" → "FIP.38.T.8",
133
            // "3PFF: the Three Point FAIRification Framework" → "3PFF".
134
            List<String> segments = splitLabel(label);
×
135
            if (!segments.isEmpty()) {
×
136
                parts.add(new CrumbPart(pathRefs[i], segments.get(0)));
×
137
            }
138
        }
139
        return parts;
6✔
140
    }
141

142
    /**
143
     * Splits a label on list/title separators — comma, colon, semicolon, pipe
144
     * (with or without surrounding spaces), or a space-surrounded hyphen — into
145
     * trimmed, non-empty segments. Returns the trimmed whole label if there is
146
     * no separator (so the result always has at least one element).
147
     */
148
    static List<String> splitLabel(String label) {
149
        List<String> segments = new ArrayList<>();
×
150
        if (label == null) return segments;
×
151
        for (String s : label.split("\\s*[,;:]\\s+|\\s*\\|\\s*|\\s+-\\s+")) {
×
152
            String trimmed = s.trim();
×
153
            if (!trimmed.isEmpty()) segments.add(trimmed);
×
154
        }
155
        if (segments.isEmpty()) {
×
156
            String trimmed = label.trim();
×
157
            if (!trimmed.isEmpty()) segments.add(trimmed);
×
158
        }
159
        return segments;
×
160
    }
161

162
    /**
163
     * If the child label appears to restate the parent's "topic" at the start,
164
     * strips that shared prefix and returns the remainder. Otherwise returns
165
     * the child label unchanged.
166
     */
167
    private static String stripParentPrefix(String parent, String child) {
168
        if (parent == null || parent.isEmpty() || child == null) return child;
×
169
        int lcp = 0;
×
170
        int max = Math.min(parent.length(), child.length());
×
171
        while (lcp < max && parent.charAt(lcp) == child.charAt(lcp)) lcp++;
×
172
        // Require a substantial match: at least 3 chars, and within 2 chars of
173
        // the full parent length (so things like "Sessions" vs "Session" still
174
        // match, but "Nanopublication Sessions" vs "Nano Session #30" doesn't).
175
        if (lcp < 3 || lcp < parent.length() - 2) return child;
×
176
        // The boundary in the child must not fall mid-word, otherwise we'd be
177
        // chopping off a partial word like "Foo Bar" -> "Foo Baz Quux" -> "z Quux".
178
        if (lcp >= child.length() || Character.isLetterOrDigit(child.charAt(lcp))) return child;
×
179
        String remainder = child.substring(lcp).replaceAll("^\\s+", "");
×
180
        if (remainder.isEmpty()) return child;
×
181
        return remainder;
×
182
    }
183

184
    /**
185
     * Places a resource tab strip (Content | About | Raw) on the right side of
186
     * the breadcrumb strip, and forces the strip visible so the tabs show even on
187
     * pages without a breadcrumb (e.g. user pages). Returns {@code this} for
188
     * fluent use at the {@code add(...)} call site.
189
     *
190
     * @param tabs the tab strip (its markup id must be {@code "tabs"})
191
     * @return this TitleBar
192
     */
193
    public TitleBar setTabs(ResourceTabs tabs) {
194
        breadcrumbPath.addOrReplace(tabs);
×
195
        breadcrumbPath.setVisible(true);
×
196
        return this;
×
197
    }
198

199
    private BookmarkablePageLink<Void> createNavLink(String id, Class<? extends WebPage> pageClass) {
200
        BookmarkablePageLink<Void> link = new BookmarkablePageLink<>(id, pageClass);
18✔
201
        if (id.equals(highlight)) {
15!
202
            link.add(new AttributeAppender("class", "selected"));
×
203
        }
204
        add(link);
27✔
205
        return link;
6✔
206
    }
207

208
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc