Skip to content

Commit f9e18a7

Browse files
fix: allow multiple tags in dashboards list_by_tag API
1 parent c4533be commit f9e18a7

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

src/handlers/http/modal/server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,9 @@ impl Server {
308308
),
309309
)
310310
.service(
311-
web::resource("/list_by_tag/{tag}").route(
311+
web::resource("/list_by_tag/{tags}").route(
312312
web::get()
313-
.to(dashboards::list_dashboards_by_tag)
313+
.to(dashboards::list_dashboards_by_tags)
314314
.authorize(Action::ListDashboard),
315315
),
316316
)

src/handlers/http/users/dashboards.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,21 @@ pub async fn list_tags() -> Result<impl Responder, DashboardError> {
203203
Ok((web::Json(tags), StatusCode::OK))
204204
}
205205

206-
pub async fn list_dashboards_by_tag(tag: Path<String>) -> Result<impl Responder, DashboardError> {
207-
let tag = tag.into_inner();
208-
if tag.is_empty() {
209-
return Err(DashboardError::Metadata("Tag cannot be empty"));
206+
pub async fn list_dashboards_by_tags(tags: Path<String>) -> Result<impl Responder, DashboardError> {
207+
let tags = tags.into_inner();
208+
if tags.is_empty() {
209+
return Err(DashboardError::Metadata("Tags cannot be empty"));
210210
}
211-
212-
let dashboards = DASHBOARDS.list_dashboards_by_tag(&tag).await;
211+
// tags can be comma separated list of tags
212+
let tags = tags
213+
.split(',')
214+
.map(|s| s.trim().to_string())
215+
.filter(|s| !s.is_empty())
216+
.collect::<Vec<_>>();
217+
if tags.is_empty() {
218+
return Err(DashboardError::Metadata("Tags cannot be empty"));
219+
}
220+
let dashboards = DASHBOARDS.list_dashboards_by_tags(tags).await;
213221
let dashboard_summaries = dashboards
214222
.iter()
215223
.map(|dashboard| dashboard.to_summary())

src/users/dashboards.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,14 +364,16 @@ impl Dashboards {
364364

365365
/// List dashboards by tag
366366
/// This function returns a list of dashboards that have the specified tag
367-
pub async fn list_dashboards_by_tag(&self, tag: &str) -> Vec<Dashboard> {
367+
pub async fn list_dashboards_by_tags(&self, tags: Vec<String>) -> Vec<Dashboard> {
368368
let dashboards = self.0.read().await;
369369
dashboards
370370
.iter()
371371
.filter(|d| {
372-
d.tags
373-
.as_ref()
374-
.is_some_and(|tags| tags.contains(&tag.to_string()))
372+
if let Some(dashboard_tags) = &d.tags {
373+
!tags.is_empty() && dashboard_tags.iter().any(|tag| tags.contains(tag))
374+
} else {
375+
false
376+
}
375377
})
376378
.cloned()
377379
.collect()

0 commit comments

Comments
 (0)