Skip to content

Commit 8e0e4da

Browse files
fix: allow multiple tags in dashboards list_by_tag API
1 parent 2bd8f2f commit 8e0e4da

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
@@ -215,13 +215,21 @@ pub async fn list_tags() -> Result<impl Responder, DashboardError> {
215215
Ok((web::Json(tags), StatusCode::OK))
216216
}
217217

218-
pub async fn list_dashboards_by_tag(tag: Path<String>) -> Result<impl Responder, DashboardError> {
219-
let tag = tag.into_inner();
220-
if tag.is_empty() {
221-
return Err(DashboardError::Metadata("Tag cannot be empty"));
218+
pub async fn list_dashboards_by_tags(tags: Path<String>) -> Result<impl Responder, DashboardError> {
219+
let tags = tags.into_inner();
220+
if tags.is_empty() {
221+
return Err(DashboardError::Metadata("Tags cannot be empty"));
222222
}
223-
224-
let dashboards = DASHBOARDS.list_dashboards_by_tag(&tag).await;
223+
// tags can be comma separated list of tags
224+
let tags = tags
225+
.split(',')
226+
.map(|s| s.trim().to_string())
227+
.filter(|s| !s.is_empty())
228+
.collect::<Vec<_>>();
229+
if tags.is_empty() {
230+
return Err(DashboardError::Metadata("Tags cannot be empty"));
231+
}
232+
let dashboards = DASHBOARDS.list_dashboards_by_tags(tags).await;
225233
let dashboard_summaries = dashboards
226234
.iter()
227235
.map(|dashboard| dashboard.to_summary())

src/users/dashboards.rs

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

377377
/// List dashboards by tag
378378
/// This function returns a list of dashboards that have the specified tag
379-
pub async fn list_dashboards_by_tag(&self, tag: &str) -> Vec<Dashboard> {
379+
pub async fn list_dashboards_by_tags(&self, tags: Vec<String>) -> Vec<Dashboard> {
380380
let dashboards = self.0.read().await;
381381
dashboards
382382
.iter()
383383
.filter(|d| {
384-
d.tags
385-
.as_ref()
386-
.is_some_and(|tags| tags.contains(&tag.to_string()))
384+
if let Some(dashboard_tags) = &d.tags {
385+
!tags.is_empty() && dashboard_tags.iter().any(|tag| tags.contains(tag))
386+
} else {
387+
false
388+
}
387389
})
388390
.cloned()
389391
.collect()

0 commit comments

Comments
 (0)