Skip to content

Commit 4e4b760

Browse files
remove layout from dashboard, make fields optional
1 parent 8c4c415 commit 4e4b760

File tree

3 files changed

+10
-18
lines changed

3 files changed

+10
-18
lines changed

src/handlers/http/users/dashboards.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub async fn list() -> Result<impl Responder, DashboardError> {
4848
);
4949
map.insert(
5050
"author".to_string(),
51-
serde_json::Value::String(dashboard.author.clone()),
51+
serde_json::Value::String(dashboard.author.as_ref().unwrap().clone()),
5252
);
5353
map.insert(
5454
"modified".to_string(),
@@ -81,10 +81,10 @@ pub async fn post(
8181
let mut user_id = get_user_from_request(&req)?;
8282
user_id = get_hash(&user_id);
8383
let dashboard_id = Ulid::new();
84-
dashboard.dashboard_id = dashboard_id;
84+
dashboard.dashboard_id = Some(dashboard_id);
8585
dashboard.version = Some(CURRENT_DASHBOARD_VERSION.to_string());
8686
dashboard.modified = Some(Utc::now());
87-
dashboard.author = user_id.clone();
87+
dashboard.author = Some(user_id.clone());
8888
for tile in dashboard.tiles.iter_mut() {
8989
tile.tile_id = Ulid::new();
9090
}
@@ -117,8 +117,8 @@ pub async fn update(
117117
if DASHBOARDS.get_dashboard(dashboard_id).await.is_none() {
118118
return Err(DashboardError::Metadata("Dashboard does not exist"));
119119
}
120-
dashboard.dashboard_id = dashboard_id;
121-
dashboard.author = user_id.clone();
120+
dashboard.dashboard_id = Some(dashboard_id);
121+
dashboard.author = Some(user_id.clone());
122122
dashboard.modified = Some(Utc::now());
123123
dashboard.version = Some(CURRENT_DASHBOARD_VERSION.to_string());
124124
for tile in dashboard.tiles.iter_mut() {

src/prism/home/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ async fn get_dashboard_titles() -> Result<Vec<TitleAndId>, PrismHomeError> {
246246
.iter()
247247
.map(|dashboard| TitleAndId {
248248
title: dashboard.title.clone(),
249-
id: dashboard.dashboard_id.to_string(),
249+
id: dashboard.dashboard_id.as_ref().unwrap().to_string(),
250250
})
251251
.collect_vec();
252252

src/users/dashboards.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,14 @@ pub struct Tile {
3434
#[serde(flatten)]
3535
pub other_fields: Option<serde_json::Map<String, Value>>,
3636
}
37-
38-
#[derive(Debug, Serialize, Deserialize, Default, Clone)]
39-
pub struct Layout {
40-
pub tile_id: Option<String>,
41-
#[serde(flatten)]
42-
pub other_fields: Option<serde_json::Map<String, Value>>,
43-
}
4437
#[derive(Debug, Serialize, Deserialize, Default, Clone)]
4538
pub struct Dashboard {
4639
pub version: Option<String>,
4740
pub title: String,
48-
pub author: String,
49-
pub dashboard_id: Ulid,
41+
pub author: Option<String>,
42+
pub dashboard_id: Option<Ulid>,
5043
pub modified: Option<DateTime<Utc>>,
5144
pub tiles: Vec<Tile>,
52-
pub layout: Vec<Layout>,
5345
}
5446

5547
#[derive(Default, Debug)]
@@ -87,15 +79,15 @@ impl Dashboards {
8779

8880
pub async fn delete_dashboard(&self, dashboard_id: Ulid) {
8981
let mut s = self.0.write().await;
90-
s.retain(|d| d.dashboard_id != dashboard_id);
82+
s.retain(|d| *d.dashboard_id.as_ref().unwrap() != dashboard_id);
9183
}
9284

9385
pub async fn get_dashboard(&self, dashboard_id: Ulid) -> Option<Dashboard> {
9486
self.0
9587
.read()
9688
.await
9789
.iter()
98-
.find(|d| d.dashboard_id == dashboard_id)
90+
.find(|d| *d.dashboard_id.as_ref().unwrap() == dashboard_id)
9991
.cloned()
10092
}
10193

0 commit comments

Comments
 (0)