Skip to content

Commit

Permalink
[JENKINS-37241] Support for query parameters in autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
timja committed Nov 11, 2024
1 parent e6ec065 commit d017d30
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
6 changes: 6 additions & 0 deletions core/src/main/java/hudson/model/Descriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,12 @@ public void calcAutoCompleteSettings(String field, Map<String, Object> attribute
if (method == null)
return; // no auto-completion

// build query parameter line by figuring out what should be submitted
List<String> depends = buildFillDependencies(method, new ArrayList<>());
if (!depends.isEmpty()) {

Check warning on line 479 in core/src/main/java/hudson/model/Descriptor.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 479 is only partially covered, one branch is missing
attributes.put("fillDependsOn", String.join(" ", depends));
}

attributes.put("autoCompleteUrl", String.format("%s/%s/autoComplete%s", getCurrentDescriptorByNameUrl(), getDescriptorUrl(), capitalizedFieldName));
}

Expand Down
2 changes: 2 additions & 0 deletions eslint.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ module.exports = [
object: "readonly",
objectToUrlFormEncoded: "readonly",
onSetupWizardInitialized: "readonly",
qs: "readonly",
refillOnChange: "readonly",
refreshPart: "readonly",
registerSortableDragDrop: "readonly",
Expand All @@ -72,6 +73,7 @@ module.exports = [
shortenName: "readonly",
Sortable: "readonly",
toQueryString: "readonly",
TryEach: "readonly",
ts_refresh: "readonly",
updateOptionalBlock: "readonly",
Utilities: "readonly",
Expand Down
27 changes: 24 additions & 3 deletions src/main/js/components/dropdowns/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,30 @@ function init() {
}
return;
}
const url =
e.getAttribute("autoCompleteUrl") + "?value=" + encodeURIComponent(word);
fetch(url)

const url = e.getAttribute("autoCompleteUrl");

const depends = e.getAttribute("fillDependsOn");
const q = qs(e).addThis();
if (depends && depends.length > 0) {
depends.split(" ").forEach(
TryEach(function (n) {
q.nearBy(n);
}),
);
}

const queryString = q.toString();
const idx = queryString.indexOf("?");
const parameters = queryString.substring(idx + 1);

fetch(url, {
method: "post",
headers: crumb.wrap({
"Content-Type": "application/x-www-form-urlencoded",
}),
body: parameters,
})
.then((rsp) => (rsp.ok ? rsp.json() : {}))
.then((response) => createAndShowDropdown(e, response.suggestions || []));
}
Expand Down

0 comments on commit d017d30

Please sign in to comment.