Skip to content

Commit ea9a9c4

Browse files
Flix6xclaude
andcommitted
Bound the source search, and open the automation form on a clean slate
The search now asks for one source more than the list shows, which is what tells the list that there are more to narrow down to, and which keeps an instance with many sources from sending all of them to the browser on every pause in typing. The list therefore says that it leaves sources out rather than how many, which is no longer a number it has. A source picked and then left behind by closing the form used to still disable the data generator fields when the form was opened again, with nothing on screen to say why, so closing the form now clears the picked source. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0129WrXeJ5gia2pctFH93BqC Signed-off-by: F.N. Claessen <claessen@seita.nl>
1 parent 0d7cb82 commit ea9a9c4

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

‎flexmeasures/ui/templates/assets/asset_automations.html‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,9 @@ <h5 class="modal-title">Edit automation</h5>
412412
if (searchTerm) {
413413
parameters.append("filter", searchTerm);
414414
}
415+
// One more source than the list shows, which is what tells the list that there are more to narrow down to,
416+
// and which keeps a search on an instance with many sources from sending all of them to the browser.
417+
parameters.append("limit", String(MAX_SOURCE_RESULTS + 1));
415418
return `/api/v3_0/sources?${parameters.toString()}`;
416419
}
417420

@@ -429,8 +432,9 @@ <h5 class="modal-title">Edit automation</h5>
429432
</button>`
430433
);
431434
if (sources.length > MAX_SOURCE_RESULTS) {
435+
// The search asks for one source more than it shows, so this says that there are more, not how many.
432436
items.push(
433-
`<div class="list-group-item text-muted">${sources.length - MAX_SOURCE_RESULTS} more match; narrow the search to see them.</div>`
437+
'<div class="list-group-item text-muted">More data sources match; narrow the search to see them.</div>'
434438
);
435439
}
436440
return items.join("");
@@ -1026,6 +1030,10 @@ <h6>Recently created jobs
10261030

10271031
$("#automationSourceClear").on("click", () => clearSelectedSource());
10281032

1033+
// A source picked and then left behind by closing the form would still disable the generator fields when the form is opened again,
1034+
// with nothing on screen to say why, so the form opens on a clean slate.
1035+
$("#newAutomationModal").on("hidden.bs.modal", () => clearSelectedSource());
1036+
10291037
// Read a JSON textarea, reporting where it is malformed rather than failing silently.
10301038
function readJsonField(selector, label) {
10311039
const text = $(selector).val().trim();

‎flexmeasures/ui/tests/js/test_automation_source_picker.py‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@ def test_source_search_asks_for_the_sources_of_the_automations_own_type(assert_j
4040
""")
4141

4242

43+
def test_source_search_asks_for_no_more_sources_than_it_shows(assert_js):
44+
"""A search on an instance with many sources is bounded by the server, rather than sent to the browser in full."""
45+
assert_js(f"""
46+
window.$ = () => ({{ready: () => {{}}}});
47+
const page = new Function({json.dumps(picker_script())}
48+
+ "\\nreturn {{ sourceSearchUrl, MAX_SOURCE_RESULTS }};")();
49+
50+
const url = new URL(page.sourceSearchUrl("forecasting", "pipeline"), "http://x");
51+
eq("the search asks for one source more than the list shows",
52+
url.searchParams.get("limit"), String(page.MAX_SOURCE_RESULTS + 1));
53+
""")
54+
55+
4356
def test_search_results_name_each_source_and_cap_a_broad_search(assert_js):
4457
"""Each result carries the id the picker reads the source by, and a long list says how much it leaves out."""
4558
assert_js(f"""
@@ -64,7 +77,8 @@ def test_search_results_name_each_source_and_cap_a_broad_search(assert_js):
6477
const capped = page.sourceResultsHtml(many);
6578
eq("a broad search shows at most the cap",
6679
(capped.match(/automation-source-option/g) || []).length, page.MAX_SOURCE_RESULTS);
67-
check("and says how many it leaves out", capped.includes("3 more match"), capped);
80+
check("and says that it leaves some out, which the count behind the limit cannot say",
81+
capped.includes("More data sources match"), capped);
6882
6983
const hostile = page.sourceResultsHtml([{{id: 1, name: "<img src=x onerror=alert(1)>"}}]);
7084
check("a source name is escaped rather than rendered", !hostile.includes("<img"), hostile);

0 commit comments

Comments
 (0)