Merge pull request #9959 from timja/JENKINS-37241/autocomplete-improvements

[JENKINS-37241] Support for query parameters in autocomplete
This commit is contained in:
Kris Stern 2024-12-06 23:08:38 +08:00 committed by GitHub
commit 3beaec617b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 32 additions and 3 deletions

View File

@ -474,6 +474,12 @@ public abstract class Descriptor<T extends Describable<T>> implements Loadable,
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()) {
attributes.put("fillDependsOn", String.join(" ", depends));
}
attributes.put("autoCompleteUrl", String.format("%s/%s/autoComplete%s", getCurrentDescriptorByNameUrl(), getDescriptorUrl(), capitalizedFieldName));
}

View File

@ -61,6 +61,7 @@ module.exports = [
object: "readonly",
objectToUrlFormEncoded: "readonly",
onSetupWizardInitialized: "readonly",
qs: "readonly",
refillOnChange: "readonly",
refreshPart: "readonly",
registerSortableDragDrop: "readonly",
@ -72,6 +73,7 @@ module.exports = [
shortenName: "readonly",
Sortable: "readonly",
toQueryString: "readonly",
TryEach: "readonly",
ts_refresh: "readonly",
updateOptionalBlock: "readonly",
Utilities: "readonly",

View File

@ -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 || []));
}