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

knowledgepixels / nanodash / 26622127697

29 May 2026 06:33AM UTC coverage: 20.725% (-0.007%) from 20.732%
26622127697

push

github

tkuhn
feat: apply view filters live as the user types

Filter text fields used AjaxFormComponentUpdatingBehavior("change"),
which only fires on blur/Enter, so the filter required pressing Enter.

Add a reusable FilterUpdatingBehavior that listens on the "input" event
(fires per keystroke) with a 300ms debounce so rapid typing coalesces
into a single request. Swap it into all filter fields.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

1003 of 6148 branches covered (16.31%)

Branch coverage included in aggregate %.

2584 of 11160 relevant lines covered (23.15%)

3.31 hits per line

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

0.0
src/main/java/com/knowledgepixels/nanodash/component/QueryResultTable.java
1
package com.knowledgepixels.nanodash.component;
2

3
import com.knowledgepixels.nanodash.*;
4
import com.knowledgepixels.nanodash.domain.MaintainedResource;
5
import com.knowledgepixels.nanodash.page.NanodashPage;
6
import com.knowledgepixels.nanodash.page.PublishPage;
7
import com.knowledgepixels.nanodash.repository.MaintainedResourceRepository;
8
import com.knowledgepixels.nanodash.template.Template;
9
import org.apache.wicket.Component;
10
import org.apache.wicket.ajax.AjaxRequestTarget;
11
import org.apache.wicket.behavior.AttributeAppender;
12
import org.apache.wicket.extensions.ajax.markup.html.repeater.data.table.AjaxFallbackHeadersToolbar;
13
import org.apache.wicket.extensions.ajax.markup.html.repeater.data.table.AjaxNavigationToolbar;
14
import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
15
import org.apache.wicket.extensions.markup.html.repeater.data.table.*;
16
import org.apache.wicket.markup.html.basic.Label;
17
import org.apache.wicket.markup.html.form.TextField;
18
import org.apache.wicket.markup.html.link.AbstractLink;
19
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
20
import org.apache.wicket.util.string.Strings;
21
import org.apache.wicket.markup.repeater.Item;
22
import org.apache.wicket.model.IModel;
23
import org.apache.wicket.model.Model;
24
import org.apache.wicket.request.mapper.parameter.PageParameters;
25
import org.eclipse.rdf4j.model.IRI;
26
import org.nanopub.extra.services.ApiResponse;
27
import org.nanopub.extra.services.ApiResponseEntry;
28
import org.nanopub.extra.services.QueryRef;
29
import org.slf4j.Logger;
30
import org.slf4j.LoggerFactory;
31

32
import java.util.ArrayList;
33
import java.util.List;
34

35
/**
36
 * Component for displaying query results in a table format.
37
 */
38
public class QueryResultTable extends QueryResult {
39

40
    private static final Logger logger = LoggerFactory.getLogger(QueryResultTable.class);
×
41

42
    private Model<String> errorMessages = Model.of("");
×
43
    private DataTable<ApiResponseEntry, String> table;
44
    private Label errorLabel;
45
    private FilteredQueryResultDataProvider filteredDataProvider;
46
    private Model<String> filterModel = Model.of("");
×
47

48
    QueryResultTable(String id, QueryRef queryRef, ApiResponse response, ViewDisplay viewDisplay, boolean plain) {
49
        super(id, queryRef, response, viewDisplay);
×
50

51
        if (plain) {
×
52
            add(new Label("label").setVisible(false));
×
53
            add(new Label("np").setVisible(false));
×
54
            showViewDisplayMenu = false;
×
55
        } else {
56
            String label = grlcQuery.getLabel();
×
57
            if (viewDisplay.getTitle() != null) {
×
58
                label = viewDisplay.getTitle();
×
59
            }
60
            add(new Label("label", label));
×
61
        }
62

63
        errorLabel = new Label("error-messages", errorMessages);
×
64
        errorLabel.setVisible(false);
×
65
        add(errorLabel);
×
66

67
        TextField<String> filterField = new TextField<>("filter", filterModel);
×
68
        filterField.setOutputMarkupId(true);
×
69
        filterField.add(new FilterUpdatingBehavior() {
×
70
            @Override
71
            protected void onUpdate(AjaxRequestTarget target) {
72
                if (filteredDataProvider != null && table != null) {
×
73
                    filteredDataProvider.setFilterText(filterModel.getObject());
×
74
                    target.add(table);
×
75
                }
76
            }
×
77
        });
78
        add(filterField);
×
79

80
        populateComponent();
×
81
    }
×
82

83
    private void addErrorMessage(String errorMessage) {
84
        String s = errorMessages.getObject();
×
85
        if (s.isEmpty()) {
×
86
            s = "Error: " + errorMessage;
×
87
        } else {
88
            s += ", " + errorMessage;
×
89
        }
90
        errorMessages.setObject(s);
×
91
        errorLabel.setVisible(true);
×
92
        if (table != null) table.setVisible(false);
×
93
    }
×
94

95
    @Override
96
    protected void populateComponent() {
97
        List<IColumn<ApiResponseEntry, String>> columns = new ArrayList<>();
×
98
        QueryResultDataProvider dataProvider;
99
        try {
100
            for (String h : response.getHeader()) {
×
101
                if (h.endsWith("_label") || h.endsWith("_label_multi")) {
×
102
                    continue;
×
103
                }
104
                String displayLabel = h;
×
105
                if (displayLabel.endsWith("_multi_iri")) {
×
106
                    displayLabel = displayLabel.substring(0, displayLabel.length() - "_multi_iri".length());
×
107
                } else if (displayLabel.endsWith("_multi_val")) {
×
108
                    displayLabel = displayLabel.substring(0, displayLabel.length() - "_multi_val".length());
×
109
                } else if (displayLabel.endsWith("_multi")) {
×
110
                    displayLabel = displayLabel.substring(0, displayLabel.length() - "_multi".length());
×
111
                } else if (displayLabel.endsWith("_iri")) {
×
112
                    displayLabel = displayLabel.substring(0, displayLabel.length() - "_iri".length());
×
113
                }
114
                columns.add(new Column(displayLabel.replaceAll("_", " "), h));
×
115
            }
116
            if (viewDisplay.getView() != null && !viewDisplay.getView().getViewEntryActionList().isEmpty()) {
×
117
                columns.add(new Column("", Column.ACTIONS));
×
118
            }
119
            dataProvider = new QueryResultDataProvider(response.getData());
×
120
            filteredDataProvider = new FilteredQueryResultDataProvider(dataProvider, response);
×
121
            table = new DataTable<>("table", columns, filteredDataProvider, viewDisplay.getPageSize() < 1 ? Integer.MAX_VALUE : viewDisplay.getPageSize());
×
122
            table.setOutputMarkupId(true);
×
123
            table.addBottomToolbar(new AjaxNavigationToolbar(table));
×
124
            table.addBottomToolbar(new NoRecordsToolbar(table));
×
125
            table.addTopToolbar(new AjaxFallbackHeadersToolbar<String>(table, dataProvider));
×
126
            add(table);
×
127
        } catch (Exception ex) {
×
128
            logger.error("Error creating table for query {}", grlcQuery.getQueryId(), ex);
×
129
            add(new Label("table", "").setVisible(false));
×
130
            addErrorMessage(ex.getMessage());
×
131
        }
×
132
    }
×
133

134
    private class Column extends AbstractColumn<ApiResponseEntry, String> {
135

136
        private String key;
137
        public static final String ACTIONS = "*actions*";
138

139
        public Column(String title, String key) {
×
140
            super(new Model<String>(title), key);
×
141
            this.key = key;
×
142
        }
×
143

144
        @Override
145
        public void populateItem(Item<ICellPopulator<ApiResponseEntry>> cellItem, String componentId, IModel<ApiResponseEntry> rowModel) {
146
            try {
147
                View view = viewDisplay.getView();
×
148
                if (key.equals(ACTIONS) && view != null) {
×
149
                    List<AbstractLink> links = new ArrayList<>();
×
150
                    for (IRI actionIri : view.getViewEntryActionList()) {
×
151
                        // TODO Copied code and adjusted from QueryResultTableBuilder:
152
                        Template t = view.getTemplateForAction(actionIri);
×
153
                        if (t == null) continue;
×
154
                        String targetField = view.getTemplateTargetFieldForAction(actionIri);
×
155
                        if (targetField == null) targetField = "resource";
×
156
                        String label = view.getLabelForAction(actionIri);
×
157
                        if (label == null) label = "action...";
×
158
                        if (!label.endsWith("...")) label += "...";
×
159
                        PageParameters params = new PageParameters().set("template", t.getId())
×
160
                                .set("param_" + targetField, contextId)
×
161
                                .set("context", contextId)
×
162
                                .set("template-version", "latest");
×
163
                        if (partId != null && contextId != null && !partId.equals(contextId)) {
×
164
                            params.set("part", partId);
×
165
                        }
166
                        String partField = view.getTemplatePartFieldForAction(actionIri);
×
167
                        if (partField != null) {
×
168
                            // TODO Find a better way to pass the MaintainedResource object to this method:
169
                            MaintainedResource r = MaintainedResourceRepository.get().findById(contextId);
×
170
                            if (r != null && r.getNamespace() != null) {
×
171
                                params.set("param_" + partField, r.getNamespace() + "<SET-SUFFIX>");
×
172
                            }
173
                        }
174
                        String queryMapping = view.getTemplateQueryMapping(actionIri);
×
175
                        if (queryMapping != null && queryMapping.contains(":")) {
×
176
                            // This part is different from the code in QueryResultTableBuilder:
177
                            String queryParam = queryMapping.split(":")[0];
×
178
                            String templateParam = queryMapping.split(":")[1];
×
179
                            params.set("param_" + templateParam, rowModel.getObject().get(queryParam));
×
180
                        }
181
                        params.set("refresh-upon-publish", queryRef.getAsUrlString());
×
182
                        AbstractLink button = new BookmarkablePageLink<NanodashPage>("button", PublishPage.class, params);
×
183
                        button.setBody(Model.of(label));
×
184
                        links.add(button);
×
185
                    }
×
186
                    cellItem.add(new ButtonList(componentId, resourceWithProfile, links, null, null));
×
187
                } else {
×
188
                    String value = rowModel.getObject().get(key);
×
189
                    if (key.endsWith("_multi_iri")) {
×
190
                        String labelKey = key.substring(0, key.length() - "_multi_iri".length()) + "_label_multi";
×
191
                        String labelValue = rowModel.getObject().get(labelKey);
×
192
                        String[] uris = (value == null || value.isBlank()) ? new String[0] : value.split("\\s+");
×
193
                        String[] labels = labelValue != null ? labelValue.split("\n", -1) : null;
×
194
                        List<Component> links = new ArrayList<>();
×
195
                        for (int i = 0; i < uris.length; i++) {
×
196
                            String uri = uris[i];
×
197
                            if (uri.isBlank()) continue;
×
198
                            String rawLabel = (labels != null && i < labels.length && !labels[i].isBlank()) ? Utils.unescapeMultiValue(labels[i]) : null;
×
199
                            // SPARQL coalesce often falls back to the URI string itself; treat that as no label
200
                            // so NanodashLink can derive a short name from the URI.
201
                            if (rawLabel != null && rawLabel.equals(uri)) rawLabel = null;
×
202
                            String label = truncateLabel(rawLabel);
×
203
                            links.add(new NanodashLink("component", uri, null, null, label, contextId));
×
204
                        }
205
                        cellItem.add(new ComponentSequence(componentId, ", ", links));
×
206
                    } else if (key.endsWith("_multi_val")) {
×
207
                        String labelKey = key.substring(0, key.length() - "_multi_val".length()) + "_label_multi";
×
208
                        String labelValue = rowModel.getObject().get(labelKey);
×
209
                        String[] parts = (value == null) ? new String[0] : value.split("\n", -1);
×
210
                        String[] labels = labelValue != null ? labelValue.split("\n", -1) : null;
×
211
                        List<Component> components = new ArrayList<>();
×
212
                        for (int i = 0; i < parts.length; i++) {
×
213
                            String part = parts[i];
×
214
                            String rawLabel = (labels != null && i < labels.length && !labels[i].isBlank()) ? Utils.unescapeMultiValue(labels[i]) : null;
×
215
                            if (part.matches("https?://.+")) {
×
216
                                if (rawLabel != null && rawLabel.equals(part)) rawLabel = null;
×
217
                                String label = truncateLabel(rawLabel);
×
218
                                components.add(new NanodashLink("component", part, null, null, label, contextId));
×
219
                            } else {
×
220
                                String label = truncateLabel(rawLabel);
×
221
                                String display = label != null ? label : Utils.unescapeMultiValue(part);
×
222
                                if (Utils.looksLikeHtml(display)) {
×
223
                                    components.add(new Label("component", Utils.sanitizeHtml(display))
×
224
                                            .setEscapeModelStrings(false)
×
225
                                            .add(new AttributeAppender("class", "cell-data-html")));
×
226
                                } else {
227
                                    components.add(new Label("component", display));
×
228
                                }
229
                            }
230
                        }
231
                        cellItem.add(new ComponentSequence(componentId, ", ", components));
×
232
                    } else if (key.endsWith("_multi")) {
×
233
                        String labelKey = key.substring(0, key.length() - "_multi".length()) + "_label_multi";
×
234
                        String labelValue = rowModel.getObject().get(labelKey);
×
235
                        String[] parts = (value == null) ? new String[0] : value.split("\n", -1);
×
236
                        String[] labels = labelValue != null ? labelValue.split("\n", -1) : null;
×
237
                        List<Component> components = new ArrayList<>();
×
238
                        for (int i = 0; i < parts.length; i++) {
×
239
                            String display;
240
                            if (labels != null && i < labels.length && !labels[i].isBlank()) {
×
241
                                display = Utils.unescapeMultiValue(labels[i]);
×
242
                            } else {
243
                                display = Utils.unescapeMultiValue(parts[i]);
×
244
                            }
245
                            if (Utils.looksLikeHtml(display)) {
×
246
                                components.add(new Label("component", Utils.sanitizeHtml(display))
×
247
                                        .setEscapeModelStrings(false)
×
248
                                        .add(new AttributeAppender("class", "cell-data-html")));
×
249
                            } else {
250
                                components.add(new Label("component", display));
×
251
                            }
252
                        }
253
                        cellItem.add(new ComponentSequence(componentId, ", ", components));
×
254
                    } else if (key.endsWith("template_iri")) {
×
255
                        String label = truncateLabel(rowModel.getObject().get(key + "_label"));
×
256
                        if (label == null || label.isBlank()) label = truncateLabel(value);
×
257
                        String templateUrl = PublishPage.MOUNT_PATH + "?template=" + Utils.urlEncode(value) + "&template-version=latest";
×
258
                        String html = "<a href=\"" + Strings.escapeMarkup(templateUrl) + "\">" + Strings.escapeMarkup(label) + "</a>";
×
259
                        cellItem.add(new Label(componentId, html).setEscapeModelStrings(false));
×
260
                    } else if (value.matches("https?://.+")) {
×
261
                        String label = truncateLabel(rowModel.getObject().get(key + "_label"));
×
262
                        cellItem.add(new NanodashLink(componentId, value, null, null, label, contextId));
×
263
                    } else {
×
264
                        if (key.startsWith("pubkey")) {
×
265
                            cellItem.add(new Label(componentId, value).add(new AttributeAppender("style", "overflow-wrap: anywhere;")));
×
266
                        } else {
267
                            Label cellLabel;
268
                            if (Utils.looksLikeHtml(value)) {
×
269
                                cellLabel = (Label) new Label(componentId, Utils.sanitizeHtml(value))
×
270
                                        .setEscapeModelStrings(false)
×
271
                                        .add(new AttributeAppender("class", "cell-data-html"));
×
272
                            } else {
273
                                cellLabel = new Label(componentId, value);
×
274
                            }
275
                            cellItem.add(cellLabel);
×
276
                        }
277
                    }
278
                }
279
            } catch (Exception ex) {
×
280
                logger.error("Failed to populate table column: ", ex);
×
281
                cellItem.add(new Label(componentId).setVisible(false));
×
282
                addErrorMessage(ex.getMessage());
×
283
            }
×
284
        }
×
285

286
    }
287

288
    private static String truncateLabel(String label) {
289
        return Utils.truncateLabel(label);
×
290
    }
291

292
}
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