diff --git a/crates/frontend/src/api.rs b/crates/frontend/src/api.rs index 421d3fc0..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, TypeTemplate, + ExperimentsResponse, FetchTypeTemplateResponse, FunctionResponse, ListFilters, TypeTemplate, Context, }, utils::{ construct_request_headers, get_host, parse_json_response, request, @@ -297,3 +297,23 @@ pub async fn fetch_type( .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/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/context_card.rs b/crates/frontend/src/components/context_card.rs index e6104442..df3c15a0 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; @@ -15,14 +16,6 @@ pub fn context_card( context: Context, overrides: Map, #[prop(default = true)] show_actions: bool, - #[prop(default=Callback::new(|_| {}))] handle_edit: Callback< - (Context, Map), - (), - >, - #[prop(default=Callback::new(|_| {}))] handle_clone: Callback< - (Context, Map), - (), - >, #[prop(default=Callback::new(|_| {}))] handle_delete: Callback, ) -> impl IntoView { let conditions: Conditions = (&context).try_into().unwrap_or_default(); @@ -38,10 +31,7 @@ pub fn context_card( }) .collect::>>(); - // Clone context and overrides for use in event handlers let context_id = store_value(context.id.clone()); - let context = store_value(context); - let overrides = store_value(overrides); let table_columns = vec![ Column::default("KEY".to_string()), @@ -68,21 +58,15 @@ pub fn context_card(
- - + + + + - + > + @@ -96,8 +80,7 @@ pub fn context_card( let context_id = context_id.get_value(); handle_delete.call(context_id); } - > - + >
@@ -110,7 +93,6 @@ pub fn context_card(
( #[prop(default = false)] disabled: bool, #[prop(default = false)] resolve_mode: bool, #[prop(default = String::new())] heading_sub_text: String, - #[prop(default = DropdownDirection::Right)] dropdown_direction: DropdownDirection, + #[prop(default = DropdownDirection::Left)] dropdown_direction: DropdownDirection, ) -> impl IntoView where NF: Fn(Conditions) + 'static, @@ -255,6 +255,7 @@ where
, + dimensions: Vec, + default_config: Vec, + on_submit: Callback<(), ()>, +) -> impl IntoView { + let tenant_rs = use_context::>().unwrap(); + let (context, set_context) = create_signal(context); + let (overrides, set_overrides) = create_signal(overrides); + let dimensions = StoredValue::new(dimensions); + let (req_inprogess_rs, req_inprogress_ws) = create_signal(false); + + let on_submit = move |_| { + req_inprogress_ws.set(true); + spawn_local(async move { + let f_context = context.get(); + let f_overrides = overrides.get(); + let result = if edit { + update_context( + tenant_rs.get().clone(), + Map::from_iter(f_overrides), + f_context, + ) + .await + } else { + create_context( + tenant_rs.get().clone(), + Map::from_iter(f_overrides), + f_context, + ) + .await + }; + + match result { + Ok(_) => { + logging::log!("Context and overrides submitted successfully"); + on_submit.call(()); + } + Err(e) => { + logging::log!("Error submitting context and overrides: {:?}", e); + } + } + req_inprogress_ws.set(false); + }); + }; + view! { +
+
+ + +
+
+ {move || { + let loading = req_inprogess_rs.get(); + view! { +
+
+ } +} diff --git a/crates/frontend/src/components/dropdown.rs b/crates/frontend/src/components/dropdown.rs index a5efd2a2..abd5ae22 100644 --- a/crates/frontend/src/components/dropdown.rs +++ b/crates/frontend/src/components/dropdown.rs @@ -61,7 +61,7 @@ where view! {
    {if searchable { diff --git a/crates/frontend/src/components/experiment_form.rs b/crates/frontend/src/components/experiment_form.rs index 292a424c..d8aa58e4 100644 --- a/crates/frontend/src/components/experiment_form.rs +++ b/crates/frontend/src/components/experiment_form.rs @@ -4,6 +4,7 @@ pub mod utils; use self::utils::{create_experiment, update_experiment}; use crate::components::button::Button; use crate::components::context_form::ContextForm; +use crate::components::dropdown::DropdownDirection; use crate::components::variant_form::VariantForm; use crate::types::{DefaultConfig, Dimension, VariantFormT, VariantType}; use leptos::*; @@ -149,6 +150,7 @@ pub fn experiment_form( context=context handle_change=handle_context_form_change disabled=edit + dropdown_direction=DropdownDirection::Down heading_sub_text=String::from( "Define rules under which this experiment would run", ) diff --git a/crates/frontend/src/components/override_form.rs b/crates/frontend/src/components/override_form.rs index fe9e995e..5d0a1a8f 100644 --- a/crates/frontend/src/components/override_form.rs +++ b/crates/frontend/src/components/override_form.rs @@ -2,7 +2,7 @@ use std::collections::{HashMap, HashSet}; use crate::{ components::{ - dropdown::{Dropdown, DropdownDirection}, + dropdown::{Dropdown, DropdownDirection, DropdownBtnType}, input::{Input, InputType}, }, schema::{EnumVariants, SchemaType}, @@ -58,8 +58,8 @@ fn override_input( view! {
    -