Skip to content

Commit

Permalink
fix: easy navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
ShubhranshuSanjeev committed Nov 8, 2024
1 parent 90f420a commit 574d6e7
Show file tree
Hide file tree
Showing 35 changed files with 912 additions and 908 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use super::{
types::{
ApplicableVariantsQuery, AuditQueryFilters, ConcludeExperimentRequest,
ContextAction, ContextBulkResponse, ContextMoveReq, ContextPutReq,
ExperimentCreateRequest, ExperimentCreateResponse, ExperimentResponse,
ExperimentCreateRequest, ExperimentResponse,
ExperimentsResponse, ListFilters, OverrideKeysUpdateRequest, RampRequest,
},
};
Expand Down Expand Up @@ -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
{
Expand Down
13 changes: 0 additions & 13 deletions crates/experimentation_platform/src/api/experiments/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,6 @@ pub struct ExperimentCreateRequest {
pub variants: Vec<Variant>,
}

#[derive(Serialize)]
pub struct ExperimentCreateResponse {
pub experiment_id: String,
}

impl From<models::Experiment> 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
Expand Down
12 changes: 6 additions & 6 deletions crates/frontend/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ use crate::{
};

// #[server(GetDimensions, "/fxn", "GetJson")]
pub async fn fetch_dimensions(tenant: String) -> Result<Vec<Dimension>, ServerFnError> {
pub async fn fetch_dimensions(tenant: &str) -> Result<Vec<Dimension>, ServerFnError> {
let client = reqwest::Client::new();
let host = use_host_server();

let url = format!("{}/dimension", host);
let response: Vec<Dimension> = client
.get(url)
.header("x-tenant", &tenant)
.header("x-tenant", tenant)
.send()
.await
.map_err(|e| ServerFnError::new(e.to_string()))?
Expand All @@ -33,7 +33,7 @@ pub async fn fetch_dimensions(tenant: String) -> Result<Vec<Dimension>, ServerFn

// #[server(GetDefaultConfig, "/fxn", "GetJson")]
pub async fn fetch_default_config(
tenant: String,
tenant: &str,
) -> Result<Vec<DefaultConfig>, ServerFnError> {
let client = reqwest::Client::new();
let host = use_host_server();
Expand Down Expand Up @@ -184,7 +184,7 @@ pub async fn fetch_function(

// #[server(GetConfig, "/fxn", "GetJson")]
pub async fn fetch_config(
tenant: String,
tenant: &str,
version: Option<String>,
) -> Result<Config, ServerFnError> {
let client = reqwest::Client::new();
Expand All @@ -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<ExperimentResponse, ServerFnError> {
let client = reqwest::Client::new();
let host = use_host_server();
Expand Down
49 changes: 30 additions & 19 deletions crates/frontend/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ 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::create_experiment::CreateExperiment;
use crate::pages::dimensions::Dimensions;
use crate::pages::experiment_list::ExperimentList;
use crate::pages::function::{
Expand Down Expand Up @@ -37,8 +38,8 @@ pub fn app(app_envs: Envs) -> impl IntoView {
let js_href = base.to_owned() + "/pkg/frontend.js";
let import_callback = "() => mod.hydrate()";
view! {
<Stylesheet id="leptos" href=styles_href/>
<Link rel="shortcut icon" type_="image/ico" href=favicon_href/>
<Stylesheet id="leptos" href=styles_href />
<Link rel="shortcut icon" type_="image/ico" href=favicon_href />
<Link
href="https://cdn.jsdelivr.net/npm/remixicon/fonts/remixicon.css"
rel="stylesheet"
Expand All @@ -59,7 +60,7 @@ pub fn app(app_envs: Envs) -> impl IntoView {
type_="application/wasm"
crossorigin=""
/>
<link as_="script" rel="modulepreload" href=js_href.clone()/>
<link as_="script" rel="modulepreload" href=js_href.clone() />
<script type_="module">
{format!(
r#"
Expand All @@ -85,9 +86,8 @@ pub fn app(app_envs: Envs) -> impl IntoView {
}
}}
}
}}
// sets the document title
<Title text="Welcome to Superposition"/>
}} // sets the document title
<Title text="Welcome to Superposition" />
<script type_="text/javascript">"__APP_ENVS=" {json!(app_envs).to_string()}</script>
<Router base=service_prefix>
<body class="m-0 min-h-screen bg-gray-50 font-mono">
Expand All @@ -99,7 +99,7 @@ pub fn app(app_envs: Envs) -> impl IntoView {
view=move || {
view! {
<Layout>
<Dimensions/>
<Dimensions />
</Layout>
}
}
Expand All @@ -111,7 +111,7 @@ pub fn app(app_envs: Envs) -> impl IntoView {
view=move || {
view! {
<Layout>
<FunctionList/>
<FunctionList />
</Layout>
}
}
Expand All @@ -123,7 +123,7 @@ pub fn app(app_envs: Envs) -> impl IntoView {
view=move || {
view! {
<Layout>
<CreateFunctionView/>
<CreateFunctionView />
</Layout>
}
}
Expand All @@ -135,7 +135,7 @@ pub fn app(app_envs: Envs) -> impl IntoView {
view=move || {
view! {
<Layout>
<FunctionPage/>
<FunctionPage />
</Layout>
}
}
Expand All @@ -147,7 +147,19 @@ pub fn app(app_envs: Envs) -> impl IntoView {
view=move || {
view! {
<Layout>
<ExperimentList/>
<ExperimentList />
</Layout>
}
}
/>

<Route
ssr=SsrMode::Async
path="/admin/:tenant/experiments/new"
view=move || {
view! {
<Layout>
<CreateExperiment />
</Layout>
}
}
Expand All @@ -159,7 +171,7 @@ pub fn app(app_envs: Envs) -> impl IntoView {
view=move || {
view! {
<Layout>
<ExperimentPage/>
<ExperimentPage />
</Layout>
}
}
Expand All @@ -171,7 +183,7 @@ pub fn app(app_envs: Envs) -> impl IntoView {
view=move || {
view! {
<Layout>
<DefaultConfig/>
<DefaultConfig />
</Layout>
}
}
Expand All @@ -183,7 +195,7 @@ pub fn app(app_envs: Envs) -> impl IntoView {
view=move || {
view! {
<Layout>
<ContextOverride/>
<ContextOverride />
</Layout>
}
}
Expand All @@ -195,7 +207,7 @@ pub fn app(app_envs: Envs) -> impl IntoView {
view=move || {
view! {
<Layout>
<Home/>
<Home />
</Layout>
}
}
Expand All @@ -207,7 +219,7 @@ pub fn app(app_envs: Envs) -> impl IntoView {
view=move || {
view! {
<Layout>
<TypesPage/>
<TypesPage />
</Layout>
}
}
Expand All @@ -219,7 +231,7 @@ pub fn app(app_envs: Envs) -> impl IntoView {
view=move || {
view! {
<Layout>
<ConfigVersionList/>
<ConfigVersionList />
</Layout>
}
}
Expand All @@ -231,7 +243,7 @@ pub fn app(app_envs: Envs) -> impl IntoView {
view=move || {
view! {
<Layout>
<ConfigVersion/>
<ConfigVersion />
</Layout>
}
}
Expand All @@ -247,7 +259,6 @@ pub fn app(app_envs: Envs) -> impl IntoView {
// }
// }
// />

</Routes>
</AlertProvider>
</body>
Expand Down
4 changes: 2 additions & 2 deletions crates/frontend/src/components/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use web_sys::MouseEvent;

#[component]
pub fn button<F: Fn(MouseEvent) + 'static>(
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";
}
Expand Down
69 changes: 36 additions & 33 deletions crates/frontend/src/components/context_form.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -245,6 +246,30 @@ where
<span class="label-text font-semibold text-base">Context</span>
<span class="label-text text-slate-400">{heading_sub_text}</span>
</label>
<Show when=move || {
!context_rs.get().is_empty() && !disabled
}>
{move || {
let dimensions = dimensions
.get_value()
.into_iter()
.filter(|dimension| {
!used_dimensions_rs.get().contains(&dimension.dimension)
})
.collect::<Vec<Dimension>>();
view! {
<Dropdown
dropdown_icon="ri-add-line".to_string()
dropdown_text="Add Context".to_string()
dropdown_btn_type=DropdownBtnType::Link
dropdown_options=dimensions
disabled=disabled
dropdown_direction
on_select=on_select_dimension
/>
}
}}
</Show>
</div>
<div class="card w-full bg-slate-50">
<div class="card-body">
Expand Down Expand Up @@ -278,7 +303,6 @@ where
children=move |(idx, condition)| {
let (schema_type, enum_variants) = dimension_map
.with_value(|v| {
// if this panics then something is wrong
let d = v.get(&condition.dimension).unwrap();
(
SchemaType::try_from(d.schema.clone()),
Expand All @@ -287,10 +311,11 @@ where
});
if schema_type.is_err() || enum_variants.is_err() {
return view! {
<span class="text-sm red"> An error occured </span>
}.into_view()
// if this panics then something is wrong
<span class="text-sm red">An error occured</span>
}
.into_view();
}

let schema_type = store_value(schema_type.unwrap());
let allow_remove = !disabled
&& !mandatory_dimensions.get_value().contains(&condition.dimension);
Expand All @@ -301,7 +326,9 @@ where
condition.operator.clone(),
)),
);
logging::log!("here {:?} {:?}", input_type.get_value(), condition.operator);
logging::log!(
"here {:?} {:?}", input_type.get_value(), condition.operator
);
let condition = store_value(condition);
let on_remove = move |d_name| on_remove.call((idx, d_name));
let on_value_change = move |(operand_idx, value)| {
Expand All @@ -317,6 +344,8 @@ where
))
};
view! {
// if this panics then something is wrong

// TODO: get rid of unwraps here

<ConditionInput
Expand All @@ -342,36 +371,10 @@ where
view! {}.into_view()
}
}}
}.into_view()
}
.into_view()
}
/>

<Show when=move || { !context_rs.get().is_empty() && !disabled }>
<div class="mt-4">

{move || {
let dimensions = dimensions
.get_value()
.into_iter()
.filter(|dimension| {
!used_dimensions_rs.get().contains(&dimension.dimension)
})
.collect::<Vec<Dimension>>();
view! {
<Dropdown
dropdown_icon="ri-add-line".to_string()
dropdown_text="Add Context".to_string()
dropdown_options=dimensions
disabled=disabled
dropdown_direction
on_select=on_select_dimension
/>
}
}}

</div>
</Show>

</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion crates/frontend/src/components/default_config_form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn default_config_form<NF>(
where
NF: Fn() + 'static + Clone,
{
let tenant_rs = use_context::<ReadSignal<String>>().unwrap();
let tenant_rs = use_context::<Signal<String>>().unwrap();

let (config_key_rs, config_key_ws) = create_signal(config_key);
let (config_type_rs, config_type_ws) = create_signal(config_type);
Expand Down
Loading

0 comments on commit 574d6e7

Please sign in to comment.