Skip to main content

systemprompt_models/artifacts/dashboard/section_data/
table.rs

1//! Table section payload.
2//!
3//! Copyright (c) systemprompt.io — Business Source License 1.1.
4//! See <https://systemprompt.io> for licensing details.
5
6use 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>,
13    #[serde(skip_serializing_if = "Option::is_none")]
14    pub sortable: Option<bool>,
15    #[serde(skip_serializing_if = "Option::is_none")]
16    pub default_sort: Option<SortConfig>,
17}
18
19#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
20pub struct SortConfig {
21    pub column: String,
22    pub order: String,
23}
24
25impl TableSectionData {
26    pub const fn new(columns: Vec<String>, rows: Vec<serde_json::Value>) -> Self {
27        Self {
28            columns,
29            rows,
30            sortable: None,
31            default_sort: None,
32        }
33    }
34
35    pub const fn with_sortable(mut self, sortable: bool) -> Self {
36        self.sortable = Some(sortable);
37        self
38    }
39
40    pub fn with_default_sort(
41        mut self,
42        column: impl Into<String>,
43        order: impl Into<String>,
44    ) -> Self {
45        self.default_sort = Some(SortConfig {
46            column: column.into(),
47            order: order.into(),
48        });
49        self
50    }
51}