Skip to main content

systemprompt_models/artifacts/dashboard/
section.rs

1use super::section_types::{SectionLayout, SectionType};
2use schemars::JsonSchema;
3use serde::{Deserialize, Serialize};
4use serde_json::Value as JsonValue;
5
6#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
7pub struct DashboardSection {
8    pub section_id: String,
9    pub title: String,
10    pub section_type: SectionType,
11    pub data: JsonValue,
12    pub layout: SectionLayout,
13}
14
15impl DashboardSection {
16    pub fn new(
17        section_id: impl Into<String>,
18        title: impl Into<String>,
19        section_type: SectionType,
20    ) -> Self {
21        Self {
22            section_id: section_id.into(),
23            title: title.into(),
24            section_type,
25            data: JsonValue::Object(serde_json::Map::new()),
26            layout: SectionLayout::default(),
27        }
28    }
29
30    pub fn with_data<T: Serialize>(mut self, data: T) -> Result<Self, serde_json::Error> {
31        self.data = serde_json::to_value(data)?;
32        Ok(self)
33    }
34
35    pub const fn with_layout(mut self, layout: SectionLayout) -> Self {
36        self.layout = layout;
37        self
38    }
39
40    pub const fn with_order(mut self, order: u32) -> Self {
41        self.layout.order = order;
42        self
43    }
44}