Skip to content

fix: allow multiple tags in dashboards list_by_tag API #1374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 15, 2025
Merged
Show file tree
Hide file tree
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
7 changes: 0 additions & 7 deletions src/handlers/http/modal/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,6 @@ impl Server {
.authorize(Action::ListDashboard),
),
)
.service(
web::resource("/list_by_tag/{tag}").route(
web::get()
.to(dashboards::list_dashboards_by_tag)
.authorize(Action::ListDashboard),
),
)
.service(
web::scope("/{dashboard_id}")
.service(
Expand Down
32 changes: 17 additions & 15 deletions src/handlers/http/users/dashboards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,23 @@ pub async fn list_dashboards(req: HttpRequest) -> Result<impl Responder, Dashboa
return Err(DashboardError::Metadata("Invalid limit value"));
}
}

if let Some(tags) = query_map.get("tags") {
let tags: Vec<String> = tags
.split(',')
.map(|s| s.trim().to_string())
.filter(|s| !s.is_empty())
.collect();
if tags.is_empty() {
return Err(DashboardError::Metadata("Tags cannot be empty"));
}
let dashboards = DASHBOARDS.list_dashboards_by_tags(tags).await;
let dashboard_summaries = dashboards
.iter()
.map(|dashboard| dashboard.to_summary())
.collect::<Vec<_>>();
return Ok((web::Json(dashboard_summaries), StatusCode::OK));
}
}
let dashboards = DASHBOARDS.list_dashboards(dashboard_limit).await;
let dashboard_summaries = dashboards
Expand Down Expand Up @@ -215,21 +232,6 @@ pub async fn list_tags() -> Result<impl Responder, DashboardError> {
Ok((web::Json(tags), StatusCode::OK))
}

pub async fn list_dashboards_by_tag(tag: Path<String>) -> Result<impl Responder, DashboardError> {
let tag = tag.into_inner();
if tag.is_empty() {
return Err(DashboardError::Metadata("Tag cannot be empty"));
}

let dashboards = DASHBOARDS.list_dashboards_by_tag(&tag).await;
let dashboard_summaries = dashboards
.iter()
.map(|dashboard| dashboard.to_summary())
.collect::<Vec<_>>();

Ok((web::Json(dashboard_summaries), StatusCode::OK))
}

#[derive(Debug, thiserror::Error)]
pub enum DashboardError {
#[error("Failed to connect to storage: {0}")]
Expand Down
15 changes: 10 additions & 5 deletions src/users/dashboards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,15 +375,20 @@ impl Dashboards {
}

/// List dashboards by tag
/// This function returns a list of dashboards that have the specified tag
pub async fn list_dashboards_by_tag(&self, tag: &str) -> Vec<Dashboard> {
/// This function returns a list of dashboards that match any of the provided tags
/// If no tags are provided, it returns an empty list
pub async fn list_dashboards_by_tags(&self, tags: Vec<String>) -> Vec<Dashboard> {
let dashboards = self.0.read().await;
dashboards
.iter()
.filter(|d| {
d.tags
.as_ref()
.is_some_and(|tags| tags.contains(&tag.to_string()))
if let Some(dashboard_tags) = &d.tags {
dashboard_tags
.iter()
.any(|dashboard_tag| tags.contains(dashboard_tag))
} else {
false
}
})
.cloned()
.collect()
Expand Down
Loading