pipedash_plugin_api/
schema.rs

1use serde::{
2    Deserialize,
3    Serialize,
4};
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub enum ConfigFieldType {
8    Text,
9    Password,
10    TextArea,
11    Boolean,
12    Select,
13    MultiSelect,
14    Number,
15}
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
18pub struct ConfigField {
19    pub key: String,
20    pub label: String,
21    pub description: Option<String>,
22    pub field_type: ConfigFieldType,
23    pub required: bool,
24    pub default_value: Option<serde_json::Value>,
25    pub options: Option<Vec<String>>,
26    pub validation_regex: Option<String>,
27    pub validation_message: Option<String>,
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize)]
31pub struct ConfigSchema {
32    pub fields: Vec<ConfigField>,
33}
34
35impl ConfigSchema {
36    pub fn new() -> Self {
37        Self { fields: Vec::new() }
38    }
39
40    pub fn add_field(mut self, field: ConfigField) -> Self {
41        self.fields.push(field);
42        self
43    }
44}
45
46impl Default for ConfigSchema {
47    fn default() -> Self {
48        Self::new()
49    }
50}
51
52#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
53pub enum ColumnDataType {
54    String,
55    Number,
56    DateTime,
57    Duration,
58    Status,
59    Badge,
60    Url,
61    Json,
62    Boolean,
63    Custom(String),
64}
65
66#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
67pub enum CellRenderer {
68    Text,
69    Badge,
70    DateTime,
71    Duration,
72    StatusBadge,
73    Commit,
74    Avatar,
75    TruncatedText,
76    Link,
77    JsonViewer,
78    Custom(String),
79}
80
81#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
82pub enum ColumnVisibility {
83    Always,
84    WhenPresent,
85    WhenCapability(String),
86    Conditional {
87        field: String,
88        equals: serde_json::Value,
89    },
90}
91
92#[derive(Debug, Clone, Serialize, Deserialize)]
93pub struct ColumnDefinition {
94    pub id: String,
95    pub label: String,
96    pub description: Option<String>,
97    pub field_path: String,
98    pub data_type: ColumnDataType,
99    pub renderer: CellRenderer,
100    pub visibility: ColumnVisibility,
101    #[serde(default = "default_visible_true")]
102    pub default_visible: bool,
103    pub width: Option<u32>,
104    pub sortable: bool,
105    pub filterable: bool,
106    pub align: Option<String>,
107}
108
109fn default_visible_true() -> bool {
110    true
111}
112
113#[derive(Debug, Clone, Serialize, Deserialize)]
114pub struct TableDefinition {
115    pub id: String,
116    pub name: String,
117    pub description: Option<String>,
118    pub columns: Vec<ColumnDefinition>,
119    pub default_sort_column: Option<String>,
120    pub default_sort_direction: Option<String>,
121}
122
123#[derive(Debug, Clone, Serialize, Deserialize)]
124pub struct TableSchema {
125    pub tables: Vec<TableDefinition>,
126}
127
128impl TableSchema {
129    pub fn new() -> Self {
130        Self { tables: Vec::new() }
131    }
132
133    pub fn add_table(mut self, table: TableDefinition) -> Self {
134        self.tables.push(table);
135        self
136    }
137
138    pub fn get_table(&self, table_id: &str) -> Option<&TableDefinition> {
139        self.tables.iter().find(|t| t.id == table_id)
140    }
141}
142
143impl Default for TableSchema {
144    fn default() -> Self {
145        Self::new()
146    }
147}