Skip to content
This repository was archived by the owner on Aug 13, 2024. It is now read-only.

Commit cf82ceb

Browse files
committed
wip(backend): improve config parser to use enum type instead of string for field type
1 parent d33b8ac commit cf82ceb

File tree

2 files changed

+8
-28
lines changed

2 files changed

+8
-28
lines changed

backend/examples/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ catalogs:
149149
title: field 8
150150
description: field 8
151151
placeholder: field 8
152-
type: string
152+
type: text
153153
default: field 8
154154
required: true
155155
- slug: field-9

backend/src/yaml_config.rs

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -87,41 +87,21 @@ pub struct CatalogFieldYamlConfig {
8787
pub description: Option<String>,
8888
pub placeholder: Option<String>,
8989
#[serde(rename = "type")]
90-
pub type_: String,
90+
pub type_: CatalogFieldType,
9191
pub default: Option<String>,
9292
pub required: Option<bool>,
9393
pub autocomplete_fetcher: Option<String>,
9494
}
9595

96+
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
97+
#[serde(rename_all = "snake_case")]
9698
pub enum CatalogFieldType {
97-
String,
99+
Text,
100+
Textarea,
98101
Number,
99102
Boolean,
100103
Date,
101-
DateTime,
104+
Datetime,
102105
Time,
103-
Enum,
104-
Array,
105-
Object,
106-
}
107-
108-
impl CatalogFieldYamlConfig {
109-
pub fn get_type(&self) -> CatalogFieldType {
110-
match self.type_.as_str() {
111-
"string" => CatalogFieldType::String,
112-
"number" => CatalogFieldType::Number,
113-
"boolean" => CatalogFieldType::Boolean,
114-
"date" => CatalogFieldType::Date,
115-
"datetime" => CatalogFieldType::DateTime,
116-
"time" => CatalogFieldType::Time,
117-
"enum" => CatalogFieldType::Enum,
118-
"array" => CatalogFieldType::Array,
119-
"object" => CatalogFieldType::Object,
120-
_ => panic!("Unknown field type: {}", self.type_),
121-
}
122-
}
123-
124-
pub fn is_required(&self) -> bool {
125-
self.required.unwrap_or(false)
126-
}
106+
List,
127107
}

0 commit comments

Comments
 (0)