diff --git a/crates/context_aware_config/src/api/type_templates/handlers.rs b/crates/context_aware_config/src/api/type_templates/handlers.rs index 0e1d3397..70835af8 100644 --- a/crates/context_aware_config/src/api/type_templates/handlers.rs +++ b/crates/context_aware_config/src/api/type_templates/handlers.rs @@ -22,6 +22,7 @@ pub fn endpoints() -> Scope { .service(create_type) .service(update_type) .service(delete_type) + .service(get_type) } #[post("")] @@ -145,3 +146,17 @@ async fn list_types( "data": custom_types }))) } + +#[get("/{type_name}")] +async fn get_type( + db_conn: DbConnection, + path: Path, +) -> superposition::Result { + let DbConnection(mut conn) = db_conn; + let type_name: String = path.into_inner().into(); + + let custom_type = dsl::type_templates + .find(type_name) + .get_result::(&mut conn)?; + Ok(HttpResponse::Ok().json(custom_type)) +} diff --git a/crates/experimentation_platform/src/api/experiments/handlers.rs b/crates/experimentation_platform/src/api/experiments/handlers.rs index 518981c2..9cf567a4 100644 --- a/crates/experimentation_platform/src/api/experiments/handlers.rs +++ b/crates/experimentation_platform/src/api/experiments/handlers.rs @@ -36,7 +36,7 @@ use super::{ types::{ ApplicableVariantsQuery, AuditQueryFilters, ConcludeExperimentRequest, ContextAction, ContextBulkResponse, ContextMoveReq, ContextPutReq, - ExperimentCreateRequest, ExperimentCreateResponse, ExperimentResponse, + ExperimentCreateRequest, ExperimentResponse, ExperimentsResponse, ListFilters, OverrideKeysUpdateRequest, RampRequest, }, }; @@ -285,7 +285,7 @@ async fn create( .get_results(&mut conn)?; let inserted_experiment: Experiment = inserted_experiments.remove(0); - let response = ExperimentCreateResponse::from(inserted_experiment.clone()); + let response = ExperimentResponse::from(inserted_experiment.clone()); if let WebhookConfig::Enabled(experiments_webhook_config) = tenant_config.experiments_webhook_config { diff --git a/crates/experimentation_platform/src/api/experiments/types.rs b/crates/experimentation_platform/src/api/experiments/types.rs index 851dfec2..25f24462 100644 --- a/crates/experimentation_platform/src/api/experiments/types.rs +++ b/crates/experimentation_platform/src/api/experiments/types.rs @@ -17,19 +17,6 @@ pub struct ExperimentCreateRequest { pub variants: Vec, } -#[derive(Serialize)] -pub struct ExperimentCreateResponse { - pub experiment_id: String, -} - -impl From for ExperimentCreateResponse { - fn from(experiment: models::Experiment) -> Self { - ExperimentCreateResponse { - experiment_id: experiment.id.to_string(), - } - } -} - /********** Experiment Response Type **************/ // Same as models::Experiments but `id` field is String // JS have limitation of 53-bit integers, so on diff --git a/crates/frontend/src/api.rs b/crates/frontend/src/api.rs index fd73e15e..cc7e90f0 100644 --- a/crates/frontend/src/api.rs +++ b/crates/frontend/src/api.rs @@ -4,7 +4,7 @@ use superposition_types::Config; use crate::{ types::{ ConfigVersionListResponse, DefaultConfig, Dimension, ExperimentResponse, - ExperimentsResponse, FetchTypeTemplateResponse, FunctionResponse, ListFilters, + ExperimentsResponse, FetchTypeTemplateResponse, FunctionResponse, ListFilters, TypeTemplate, Context, }, utils::{ construct_request_headers, get_host, parse_json_response, request, @@ -13,14 +13,14 @@ use crate::{ }; // #[server(GetDimensions, "/fxn", "GetJson")] -pub async fn fetch_dimensions(tenant: String) -> Result, ServerFnError> { +pub async fn fetch_dimensions(tenant: &str) -> Result, ServerFnError> { let client = reqwest::Client::new(); let host = use_host_server(); let url = format!("{}/dimension", host); let response: Vec = client .get(url) - .header("x-tenant", &tenant) + .header("x-tenant", tenant) .send() .await .map_err(|e| ServerFnError::new(e.to_string()))? @@ -33,7 +33,7 @@ pub async fn fetch_dimensions(tenant: String) -> Result, ServerFn // #[server(GetDefaultConfig, "/fxn", "GetJson")] pub async fn fetch_default_config( - tenant: String, + tenant: &str, ) -> Result, ServerFnError> { let client = reqwest::Client::new(); let host = use_host_server(); @@ -184,7 +184,7 @@ pub async fn fetch_function( // #[server(GetConfig, "/fxn", "GetJson")] pub async fn fetch_config( - tenant: String, + tenant: &str, version: Option, ) -> Result { let client = reqwest::Client::new(); @@ -208,8 +208,8 @@ pub async fn fetch_config( // #[server(GetExperiment, "/fxn", "GetJson")] pub async fn fetch_experiment( - exp_id: String, - tenant: String, + exp_id: &str, + tenant: &str, ) -> Result { let client = reqwest::Client::new(); let host = use_host_server(); @@ -277,3 +277,43 @@ pub async fn fetch_types( .await .map_err(err_handler) } + +pub async fn fetch_type( + tenant: &str, + name: &str, +) -> Result { + let host = use_host_server(); + let url = format!("{host}/types/{name}"); + let err_handler = |e: String| ServerFnError::new(e.to_string()); + let response = request::<()>( + url, + reqwest::Method::GET, + None, + construct_request_headers(&[("x-tenant", &tenant)]).map_err(err_handler)?, + ) + .await + .map_err(err_handler)?; + parse_json_response::(response) + .await + .map_err(err_handler) +} + +pub async fn fetch_context( + tenant: &str, + id: &str, +) -> Result { + let host = use_host_server(); + let url = format!("{host}/context/{id}"); + let err_handler = |e: String| ServerFnError::new(e.to_string()); + let response = request::<()>( + url, + reqwest::Method::GET, + None, + construct_request_headers(&[("x-tenant", &tenant)]).map_err(err_handler)?, + ) + .await + .map_err(err_handler)?; + parse_json_response::(response) + .await + .map_err(err_handler) +} diff --git a/crates/frontend/src/app.rs b/crates/frontend/src/app.rs index aeb26a1c..719f81df 100755 --- a/crates/frontend/src/app.rs +++ b/crates/frontend/src/app.rs @@ -3,19 +3,8 @@ use leptos_meta::*; use leptos_router::*; use serde_json::json; -use crate::hoc::layout::Layout; -use crate::pages::config_version::ConfigVersion; -use crate::pages::config_version_list::ConfigVersionList; -use crate::pages::dimensions::Dimensions; -use crate::pages::experiment_list::ExperimentList; -use crate::pages::function::{ - function_create::CreateFunctionView, function_list::FunctionList, FunctionPage, -}; -use crate::pages::{ - context_override::ContextOverride, custom_types::TypesPage, - default_config::DefaultConfig, experiment::ExperimentPage, home::Home, -}; use crate::providers::alert_provider::AlertProvider; +use crate::routes::AppRoutes; use crate::types::Envs; #[component] @@ -37,8 +26,8 @@ pub fn app(app_envs: Envs) -> impl IntoView { let js_href = base.to_owned() + "/pkg/frontend.js"; let import_callback = "() => mod.hydrate()"; view! { - - + + impl IntoView { type_="application/wasm" crossorigin="" /> - + - - - - } - } - /> - - - - - } - } - /> - - - - - } - } - /> - - - - - } - } - /> - - - - - } - } - /> - - - - - } - } - /> - - - - - } - } - /> - - - - - } - } - /> - - - - - } - } - /> - - - - - } - } - /> - - - - - } - } - /> - - - - - } - } - /> - - // - // - // - // } - // } - // /> - + diff --git a/crates/frontend/src/components.rs b/crates/frontend/src/components.rs index 0be4071d..d9f43b8f 100644 --- a/crates/frontend/src/components.rs +++ b/crates/frontend/src/components.rs @@ -27,3 +27,4 @@ pub mod table; pub mod toast; pub mod type_template_form; pub mod variant_form; +pub mod contextual_override_form; diff --git a/crates/frontend/src/components/button.rs b/crates/frontend/src/components/button.rs index dee46a3c..ccdd7e49 100644 --- a/crates/frontend/src/components/button.rs +++ b/crates/frontend/src/components/button.rs @@ -3,13 +3,13 @@ use web_sys::MouseEvent; #[component] pub fn button( - text: String, + #[prop(into)] text: String, on_click: F, #[prop(default = String::new())] class: String, #[prop(default = String::new())] id: String, #[prop(default = false)] loading: bool, ) -> impl IntoView { - let mut button_class = format!("btn-purple font-medium rounded-lg text-sm px-5 py-2.5 text-center me-2 mb-2 {class}"); + let mut button_class = format!("btn-purple font-medium rounded-lg text-sm px-5 py-2.5 text-center {class}"); if loading { button_class = button_class + "hover:cursor-not-allowed"; } diff --git a/crates/frontend/src/components/context_card.rs b/crates/frontend/src/components/context_card.rs index e6104442..f04dc653 100644 --- a/crates/frontend/src/components/context_card.rs +++ b/crates/frontend/src/components/context_card.rs @@ -1,4 +1,5 @@ use leptos::*; +use leptos_router::A; use serde_json::{Map, Value}; use superposition_types::Context; @@ -68,21 +69,16 @@ pub fn context_card(
- - + + + - + > @@ -96,8 +92,7 @@ pub fn context_card( let context_id = context_id.get_value(); handle_delete.call(context_id); } - > - + >
diff --git a/crates/frontend/src/components/context_form.rs b/crates/frontend/src/components/context_form.rs index 844fa6ab..8015cdab 100644 --- a/crates/frontend/src/components/context_form.rs +++ b/crates/frontend/src/components/context_form.rs @@ -1,6 +1,7 @@ pub mod utils; use std::collections::{HashMap, HashSet}; +use crate::components::dropdown::DropdownBtnType; use crate::components::input::{Input, InputType}; use crate::logic::{Condition, Conditions, Operand, Operands, Operator}; use crate::schema::EnumVariants; @@ -31,17 +32,11 @@ pub fn condition_input( } = condition.get_value(); view! { -
-
-