Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/app/state/sync.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
use super::{App, Panel};

/// Collect autocomplete candidates: sorted, de-duplicated, blanks dropped.
fn distinct(values: impl Iterator<Item = String>) -> Vec<String> {
let mut values: Vec<String> = values.filter(|v| !v.is_empty()).collect();
values.sort_unstable();
values.dedup();
values
}

impl App {
/// Sync a specific panel's data from `environment_state`.
pub fn sync_panel(&mut self, panel: &Panel) {
Expand All @@ -15,6 +23,23 @@ impl App {
.map(|d| d.dag_id.to_string())
.collect();
self.dags.table.filter.set_primary_values("dag_id", dag_ids);
// Free-text fields autocomplete from the values actually present.
let owners = distinct(
self.dags
.table
.all
.iter()
.flat_map(|d| d.owners.iter().cloned()),
);
self.dags.table.filter.set_field_values("owners", owners);
let tags = distinct(
self.dags
.table
.all
.iter()
.flat_map(|d| d.tags.iter().map(|t| t.name.clone())),
);
self.dags.table.filter.set_field_values("tags", tags);
self.dags.table.apply_filter();
}
Panel::DAGRun => {
Expand Down Expand Up @@ -57,6 +82,17 @@ impl App {
.table
.filter
.set_primary_values("task_id", task_ids);
let operators = distinct(
self.task_instances
.table
.all
.iter()
.filter_map(|ti| ti.operator.clone()),
);
self.task_instances
.table
.filter
.set_field_values("operator", operators);
self.task_instances.table.apply_filter();
} else {
self.task_instances.table.all.clear();
Expand Down Expand Up @@ -88,7 +124,27 @@ impl App {
.table
.filter
.set_primary_values("name", config_names);
let endpoints = distinct(self.configs.table.all.iter().map(|c| c.endpoint.clone()));
self.configs
.table
.filter
.set_field_values("endpoint", endpoints);
}
}
}
}

#[cfg(test)]
mod tests {
use super::distinct;

#[test]
fn distinct_sorts_dedups_and_drops_blanks() {
let got = distinct(
["bob", "alice", "bob", "", "alice"]
.into_iter()
.map(str::to_string),
);
assert_eq!(got, vec!["alice", "bob"]);
}
}
Loading