Skip to content

Commit

Permalink
fix: allow positive i32 number for dimension priority in dimension cr…
Browse files Browse the repository at this point in the history
…eate (#135)
  • Loading branch information
ayushjain17 authored Jun 27, 2024
1 parent 3a40973 commit 5e79ad8
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
4 changes: 2 additions & 2 deletions crates/context_aware_config/src/api/dimension/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async fn create(
) -> superposition::Result<HttpResponse> {
let DbConnection(mut conn) = db_conn;

if req.priority == 0 {
if req.priority <= 0 {
return Err(bad_argument!("Priority should be greater than 0"));
}

Expand Down Expand Up @@ -66,7 +66,7 @@ async fn create(

let new_dimension = Dimension {
dimension: create_req.dimension,
priority: i32::from(create_req.priority),
priority: create_req.priority,
schema: schema_value,
created_by: user.get_email(),
created_at: Utc::now(),
Expand Down
2 changes: 1 addition & 1 deletion crates/context_aware_config/src/api/dimension/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use serde_json::Value;
#[derive(Debug, Deserialize)]
pub struct CreateReq {
pub dimension: String,
pub priority: u16,
pub priority: i32,
pub schema: Value,
#[serde(default, deserialize_with = "deserialize_option")]
pub function_name: Option<Value>,
Expand Down
20 changes: 16 additions & 4 deletions crates/frontend/src/components/dimension_form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use web_sys::MouseEvent;
#[component]
pub fn dimension_form<NF>(
#[prop(default = false)] edit: bool,
#[prop(default = 0)] priority: u16,
#[prop(default = 0)] priority: u32,
#[prop(default = String::new())] dimension_name: String,
#[prop(default = String::new())] dimension_type: String,
#[prop(default = Value::Null)] dimension_schema: Value,
Expand Down Expand Up @@ -191,14 +191,26 @@ where
</label>
<input
type="Number"
min=0
placeholder="Priority"
class="input input-bordered w-full max-w-md"
value=priority.get()
on:keypress=move |ev| {
let char_code = ev.char_code();
if char_code != 0 && char_code != 8 && char_code != 13
&& !(char_code >= 48 && char_code <= 57)
{
ev.prevent_default();
}
}
on:change=move |ev| {
logging::log!("{:?}", event_target_value(& ev).parse::< u16 > ());
match event_target_value(&ev).parse::<u16>() {
logging::log!("{:?}", event_target_value(&ev).parse::<u32>());
match event_target_value(&ev).parse::<u32>() {
Ok(i_prio) => set_priority.set(i_prio),
Err(e) => logging::log!("{e}"),
Err(e) => {
set_priority.set(0);
logging::log!("{e}");
}
};
}
/>
Expand Down
2 changes: 1 addition & 1 deletion crates/frontend/src/components/dimension_form/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use serde_json::Value;
#[derive(Serialize, Clone)]
pub struct DimensionCreateReq {
pub dimension: String,
pub priority: u16,
pub priority: u32,
pub schema: Value,
pub function_name: Option<Value>,
}
4 changes: 2 additions & 2 deletions crates/frontend/src/pages/dimensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::api::fetch_dimensions;
#[derive(Clone, Debug, Default)]
pub struct RowData {
pub dimension: String,
pub priority: u16,
pub priority: u32,
pub schema: Value,
pub function_name: Option<Value>,
}
Expand All @@ -38,7 +38,7 @@ pub fn Dimensions() -> impl IntoView {
logging::log!("Dimension row: {:?}", row);
let row_dimension = row["dimension"].to_string().replace('"', "");
let row_priority_str = row["priority"].to_string().replace('"', "");
let row_priority = row_priority_str.parse::<u16>().unwrap_or(0_u16);
let row_priority = row_priority_str.parse::<u32>().unwrap_or(0_u32);

let schema = row["schema"].clone().to_string();
let schema = serde_json::from_str::<Value>(&schema).unwrap_or(Value::Null);
Expand Down

0 comments on commit 5e79ad8

Please sign in to comment.