systemprompt_models/artifacts/dashboard/section_data/
table.rs1use schemars::JsonSchema;
7use serde::{Deserialize, Serialize};
8
9#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
10pub struct TableSectionData {
11 pub columns: Vec<String>,
12 pub rows: Vec<serde_json::Value>,
14 #[serde(skip_serializing_if = "Option::is_none")]
15 pub sortable: Option<bool>,
16 #[serde(skip_serializing_if = "Option::is_none")]
17 pub default_sort: Option<SortConfig>,
18}
19
20#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
21pub struct SortConfig {
22 pub column: String,
23 pub order: String,
24}
25
26impl TableSectionData {
27 pub const fn new(columns: Vec<String>, rows: Vec<serde_json::Value>) -> Self {
29 Self {
30 columns,
31 rows,
32 sortable: None,
33 default_sort: None,
34 }
35 }
36
37 pub const fn with_sortable(mut self, sortable: bool) -> Self {
38 self.sortable = Some(sortable);
39 self
40 }
41
42 pub fn with_default_sort(
43 mut self,
44 column: impl Into<String>,
45 order: impl Into<String>,
46 ) -> Self {
47 self.default_sort = Some(SortConfig {
48 column: column.into(),
49 order: order.into(),
50 });
51 self
52 }
53}