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 3f59418 commit d083c0c
Show file tree
Hide file tree
Showing 35 changed files with 1,050 additions and 1,051 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
70 changes: 34 additions & 36 deletions crates/frontend/src/components/context_form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::collections::{HashMap, HashSet};

use crate::components::{
condition_pills::types::ConditionOperator,
dropdown::{Dropdown, DropdownDirection},
dropdown::{Dropdown, DropdownDirection, DropdownBtnType},
input_components::{BooleanToggle, EnumDropdown},
};
use crate::types::Dimension;
Expand Down Expand Up @@ -85,25 +85,49 @@ where
view! {
<div>
<div class="form-control w-full ">
<div class="gap-1">
<div class="flex justify-between gap-1">
<label class="label flex-col justify-center items-start">
<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.get().is_empty() && !disabled }>
{move || {
let dimensions = dimensions
.get_value()
.into_iter()
.filter(|dimension| {
!used_dimensions.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=handle_select_dropdown_option
/>
}
}}
</Show>
</div>
<div class="card w-full bg-slate-50">
<div class="card-body">
<Show when=move || context.get().is_empty()>
<div class="flex justify-center">
<div class="flex flex-col justify-between items-center">
<Dropdown
dropdown_width="w-80"
dropdown_icon="ri-add-line".to_string()
dropdown_text="Add Context".to_string()
dropdown_direction
dropdown_options=dimensions.get_value()
disabled=disabled
on_select=handle_select_dropdown_option
dropdown_icon="ri-add-line".to_string()
dropdown_text="Add Context".to_string()
dropdown_btn_type=DropdownBtnType::Link
dropdown_options=dimensions.get_value()
disabled=disabled
dropdown_direction
on_select=handle_select_dropdown_option
/>
<span class="label-text text-slate-400">"Add conditions using your domain dimensions"</span>
</div>
</Show>
{move || {
Expand Down Expand Up @@ -428,32 +452,6 @@ where
}
}}

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

{move || {
let dimensions = dimensions
.get_value()
.into_iter()
.filter(|dimension| {
!used_dimensions.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=handle_select_dropdown_option
/>
}
}}

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

let (priority, set_priority) = create_signal(priority);
let (dimension_name_rs, dimension_name_ws) = create_signal(dimension_name);
Expand Down
2 changes: 1 addition & 1 deletion crates/frontend/src/components/experiment_conclude_form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn experiment_conclude_form<HS>(
where
HS: Fn() + 'static + Clone,
{
let tenant_rs = use_context::<ReadSignal<String>>().unwrap();
let tenant_rs = use_context::<Signal<String>>().unwrap();
let experiment_rc = Rc::new(experiment);

let experiment_clone = experiment_rc.clone();
Expand Down
Loading

0 comments on commit d083c0c

Please sign in to comment.