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