Skip to content

Commit

Permalink
query: re-run opened queries on filter param change
Browse files Browse the repository at this point in the history
  • Loading branch information
nbdd0121 authored and yagebu committed Dec 28, 2024
1 parent 3452e7a commit 4da3342
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion frontend/src/reports/query/Query.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
let query_string = "";
/** The currently loaded results. */
const results: Record<string, Result<QueryResult, string>> = {};
let results: Record<string, Result<QueryResult, string>> = {};
const is_open: Record<string, boolean> = {};
onMount(() =>
Expand All @@ -29,6 +29,12 @@
}),
);
onMount(() =>
filter_params.subscribe(() => {
rerun_all_open();
}),
);
/** Submit the current query and load the result for it. */
function submit() {
const query = query_string;
Expand Down Expand Up @@ -57,6 +63,26 @@
.catch(log_error);
}
/* Re-run all open queries on global filter change */
function rerun_all_open() {
const to_rerun = [...Object.entries(is_open)]
.filter(([, is_open]) => is_open)
.map(([query]) => query);
results = {};
for (const query of to_rerun) {
get("query", { query_string: query, ...$filter_params })
.then(
(res) => ok(res),
(error: unknown) =>
err(error instanceof Error ? error.message : "INTERNAL ERROR"),
)
.then((res) => {
results[query] = res;
})
.catch(log_error);
}
}
/** Delete the given query from the history and potentially clear it from the form. */
function delete_item(query: string) {
query_shell_history.remove(query);
Expand Down

0 comments on commit 4da3342

Please sign in to comment.