diff --git a/crates/context_aware_config/Cargo.toml b/crates/context_aware_config/Cargo.toml index 30cf0e3a8..83ffa2dcc 100644 --- a/crates/context_aware_config/Cargo.toml +++ b/crates/context_aware_config/Cargo.toml @@ -31,6 +31,7 @@ service_utils = { path = "../service_utils" } strum_macros = { workspace = true } superposition_macros = { path = "../superposition_macros" } superposition_types = { path = "../superposition_types", features = [ + "api", "result", "diesel_derives", ] } diff --git a/crates/experimentation_platform/Cargo.toml b/crates/experimentation_platform/Cargo.toml index f952a9b3f..fe154d42c 100644 --- a/crates/experimentation_platform/Cargo.toml +++ b/crates/experimentation_platform/Cargo.toml @@ -19,6 +19,7 @@ serde_json = { workspace = true } service_utils = { path = "../service_utils" } superposition_macros = { path = "../superposition_macros" } superposition_types = { path = "../superposition_types", features = [ + "api", "experimentation", "result", "diesel_derives", diff --git a/crates/frontend/Cargo.toml b/crates/frontend/Cargo.toml index 2feff3ed0..182c797f0 100644 --- a/crates/frontend/Cargo.toml +++ b/crates/frontend/Cargo.toml @@ -26,6 +26,7 @@ strum = { workspace = true } strum_macros = { workspace = true } superposition_types = { path = "../superposition_types", features = [ "experimentation", + "api" ], default-features = false } url = { workspace = true } wasm-bindgen = "=0.2.89" diff --git a/crates/frontend/src/components.rs b/crates/frontend/src/components.rs index f2b38c5e8..b3c1e0b18 100644 --- a/crates/frontend/src/components.rs +++ b/crates/frontend/src/components.rs @@ -14,7 +14,6 @@ pub mod experiment_form; pub mod experiment_ramp_form; pub mod function_form; pub mod input; -pub mod input_components; pub mod modal; pub mod monaco_editor; pub mod nav_item; diff --git a/crates/frontend/src/components/input_components.rs b/crates/frontend/src/components/input_components.rs deleted file mode 100644 index 6cfdd70f6..000000000 --- a/crates/frontend/src/components/input_components.rs +++ /dev/null @@ -1,90 +0,0 @@ -use leptos::*; -use serde_json::{Map, Value}; - -use crate::components::dropdown::{Dropdown, DropdownBtnType, DropdownDirection}; - -#[component] -pub fn enum_dropdown( - schema: Map, - config_value: String, - handle_change: Callback, - #[prop(default = String::new())] class: String, - #[prop(default = false)] disabled: bool, - #[prop(default = "")] name: &'static str, -) -> impl IntoView { - let (value, set_value) = create_signal(config_value.replace("\\", "")); - let (selected_enum, set_selected_enum) = create_signal(String::from("Choose Enum")); - - let enum_array: Vec = schema - .get("enum") - .and_then(|v| v.as_array()) - .map(|arr| { - arr.iter() - .filter_map(|v| v.as_str().map(|s| s.to_string())) - .collect() - }) - .unwrap_or_default(); - - create_effect({ - let value = value.clone(); - let enum_array = enum_array.clone(); - move |_| { - if !value.get().is_empty() && enum_array.contains(&value.get()) { - set_selected_enum.set(value.get()); - } - } - }); - - view! { -
- {move || { - view! { - - } - }} - -
- } -} - -#[component] -pub fn boolean_toggle( - value: bool, - on_change: Callback, - #[prop(default = String::new())] class: String, - #[prop(default = false)] disabled: bool, - #[prop(default = "")] name: &'static str, -) -> impl IntoView { - let (flag, set_flag) = create_signal(value); - view! { - - } -} diff --git a/crates/frontend/src/components/workspace_form.rs b/crates/frontend/src/components/workspace_form.rs index f2b7d0105..4db1974ff 100644 --- a/crates/frontend/src/components/workspace_form.rs +++ b/crates/frontend/src/components/workspace_form.rs @@ -3,34 +3,31 @@ pub mod utils; use leptos::*; use serde_json::to_string; +use superposition_types::api::workspace::{ + CreateWorkspaceRequest, UpdateWorkspaceRequest, +}; use superposition_types::database::models::WorkspaceStatus; use web_sys::MouseEvent; -use crate::components::input_components::BooleanToggle; +use crate::components::input::Toggle; use crate::components::workspace_form::utils::string_to_vec; use crate::components::{alert::AlertType, button::Button}; use crate::types::OrganisationId; use crate::{ - components::workspace_form::{ - types::{CreateWorkspaceRequest, UpdateWorkspaceRequest}, - utils::{create_workspace, update_workspace}, - }, + components::workspace_form::utils::{create_workspace, update_workspace}, providers::{alert_provider::enqueue_alert, editor_provider::EditorProvider}, }; #[component] -pub fn workspace_form( +pub fn workspace_form( org_id: RwSignal, #[prop(default = false)] edit: bool, #[prop(default = String::new())] workspace_admin_email: String, #[prop(default = String::new())] workspace_name: String, #[prop(default = WorkspaceStatus::ENABLED)] workspace_status: WorkspaceStatus, #[prop(default = vec![])] mandatory_dimensions: Vec, - handle_submit: NF, -) -> impl IntoView -where - NF: Fn() + 'static + Clone, -{ + #[prop(into)] handle_submit: Callback<(), ()>, +) -> impl IntoView { let (workspace_name_rs, workspace_name_ws) = create_signal(workspace_name); let (workspace_admin_email_rs, workspace_admin_email_ws) = create_signal(workspace_admin_email); @@ -54,10 +51,8 @@ where mandatory_dimensions: Some(mandatory_dimensions_rs.get()), }; - let handle_submit_clone = handle_submit.clone(); let is_edit = edit; spawn_local({ - let handle_submit = handle_submit_clone; async move { let result = if is_edit { update_workspace( @@ -72,7 +67,7 @@ where match result { Ok(_) => { - handle_submit(); + handle_submit.call(()); let success_message = if is_edit { "Workspace updated successfully!" } else { @@ -164,14 +159,15 @@ where - , -} - -#[derive(Debug, Serialize, Deserialize)] -pub struct UpdateWorkspaceRequest { - pub workspace_admin_email: String, - pub workspace_status: Option, - pub mandatory_dimensions: Option>, -} - #[derive(Clone, Debug, Serialize, Deserialize)] pub struct RowData { pub workspace_name: String, diff --git a/crates/frontend/src/components/workspace_form/utils.rs b/crates/frontend/src/components/workspace_form/utils.rs index efa3c0b26..2eb3ed91e 100644 --- a/crates/frontend/src/components/workspace_form/utils.rs +++ b/crates/frontend/src/components/workspace_form/utils.rs @@ -1,6 +1,8 @@ -use super::types::{CreateWorkspaceRequest, UpdateWorkspaceRequest}; use crate::utils::{construct_request_headers, get_host, parse_json_response, request}; use serde_json::Value; +use superposition_types::api::workspace::{ + CreateWorkspaceRequest, UpdateWorkspaceRequest, +}; pub async fn create_workspace( org_id: String, diff --git a/crates/frontend/src/pages/workspace.rs b/crates/frontend/src/pages/workspace.rs index 919e1c8d3..37c617a96 100644 --- a/crates/frontend/src/pages/workspace.rs +++ b/crates/frontend/src/pages/workspace.rs @@ -164,7 +164,7 @@ pub fn workspace() -> impl IntoView { mandatory_dimensions=selected_workspace_data .mandatory_dimensions .unwrap_or_default() - handle_submit=move || { + handle_submit=move |_| { workspace_resource.refetch(); selected_workspace.set(None); close_drawer("workspace_drawer"); @@ -182,7 +182,7 @@ pub fn workspace() -> impl IntoView { > , -} - -#[derive(Debug, Deserialize)] -pub struct UpdateWorkspaceRequest { - pub workspace_admin_email: String, - pub workspace_status: Option, - pub mandatory_dimensions: Option>, -} #[derive(Deserialize, Debug)] pub struct WorkspaceListFilters { diff --git a/crates/superposition_types/Cargo.toml b/crates/superposition_types/Cargo.toml index 65a6ffe18..e71acdb38 100644 --- a/crates/superposition_types/Cargo.toml +++ b/crates/superposition_types/Cargo.toml @@ -37,6 +37,7 @@ disable_db_data_validation = [] result = ["dep:diesel", "dep:anyhow", "dep:thiserror", "dep:actix-web"] server = ["dep:actix-web"] experimentation = [] +api = [] [lints] workspace = true diff --git a/crates/superposition_types/src/api.rs b/crates/superposition_types/src/api.rs new file mode 100644 index 000000000..b91220bb3 --- /dev/null +++ b/crates/superposition_types/src/api.rs @@ -0,0 +1 @@ +pub mod workspace; diff --git a/crates/superposition_types/src/api/workspace.rs b/crates/superposition_types/src/api/workspace.rs new file mode 100644 index 000000000..178355507 --- /dev/null +++ b/crates/superposition_types/src/api/workspace.rs @@ -0,0 +1,17 @@ +use serde::{Deserialize, Serialize}; + +use crate::database::models::WorkspaceStatus; + +#[derive(Debug, Deserialize, Serialize)] +pub struct CreateWorkspaceRequest { + pub workspace_admin_email: String, + pub workspace_name: String, + pub workspace_status: Option, +} + +#[derive(Debug, Deserialize, Serialize)] +pub struct UpdateWorkspaceRequest { + pub workspace_admin_email: String, + pub workspace_status: Option, + pub mandatory_dimensions: Option>, +} diff --git a/crates/superposition_types/src/lib.rs b/crates/superposition_types/src/lib.rs index 95b5c6958..076884b84 100644 --- a/crates/superposition_types/src/lib.rs +++ b/crates/superposition_types/src/lib.rs @@ -1,4 +1,6 @@ #![deny(unused_crate_dependencies)] +#[cfg(feature = "api")] +pub mod api; mod config; mod contextual; pub mod custom_query;