Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/easy navigation #281

Draft
wants to merge 5 commits into
base: fix/context-form
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions crates/context_aware_config/src/api/type_templates/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub fn endpoints() -> Scope {
.service(create_type)
.service(update_type)
.service(delete_type)
.service(get_type)
}

#[post("")]
Expand Down Expand Up @@ -145,3 +146,17 @@ async fn list_types(
"data": custom_types
})))
}

#[get("/{type_name}")]
async fn get_type(
db_conn: DbConnection,
path: Path<TypeTemplateName>,
) -> superposition::Result<HttpResponse> {
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::<TypeTemplates>(&mut conn)?;
Ok(HttpResponse::Ok().json(custom_type))
}
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
54 changes: 47 additions & 7 deletions crates/frontend/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 Expand Up @@ -277,3 +277,43 @@ pub async fn fetch_types(
.await
.map_err(err_handler)
}

pub async fn fetch_type(
tenant: &str,
name: &str,
) -> Result<TypeTemplate, ServerFnError> {
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::<TypeTemplate>(response)
.await
.map_err(err_handler)
}

pub async fn fetch_context(
tenant: &str,
id: &str,
) -> Result<Context, ServerFnError> {
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::<Context>(response)
.await
.map_err(err_handler)
}
180 changes: 7 additions & 173 deletions crates/frontend/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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! {
<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 +48,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,169 +74,14 @@ 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">
<AlertProvider>
<Routes base=service_prefix.to_string()>
<Route
ssr=SsrMode::Async
path="/admin/:tenant/dimensions"
view=move || {
view! {
<Layout>
<Dimensions/>
</Layout>
}
}
/>

<Route
ssr=SsrMode::Async
path="/admin/:tenant/function"
view=move || {
view! {
<Layout>
<FunctionList/>
</Layout>
}
}
/>

<Route
ssr=SsrMode::Async
path="/admin/:tenant/function/create"
view=move || {
view! {
<Layout>
<CreateFunctionView/>
</Layout>
}
}
/>

<Route
ssr=SsrMode::Async
path="/admin/:tenant/function/:function_name"
view=move || {
view! {
<Layout>
<FunctionPage/>
</Layout>
}
}
/>

<Route
ssr=SsrMode::Async
path="/admin/:tenant/experiments"
view=move || {
view! {
<Layout>
<ExperimentList/>
</Layout>
}
}
/>

<Route
ssr=SsrMode::Async
path="/admin/:tenant/experiments/:id"
view=move || {
view! {
<Layout>
<ExperimentPage/>
</Layout>
}
}
/>

<Route
ssr=SsrMode::Async
path="/admin/:tenant/default-config"
view=move || {
view! {
<Layout>
<DefaultConfig/>
</Layout>
}
}
/>

<Route
ssr=SsrMode::Async
path="/admin/:tenant/overrides"
view=move || {
view! {
<Layout>
<ContextOverride/>
</Layout>
}
}
/>

<Route
ssr=SsrMode::Async
path="/admin/:tenant/resolve"
view=move || {
view! {
<Layout>
<Home/>
</Layout>
}
}
/>

<Route
ssr=SsrMode::Async
path="/admin/:tenant/types"
view=move || {
view! {
<Layout>
<TypesPage/>
</Layout>
}
}
/>

<Route
ssr=SsrMode::Async
path="/admin/:tenant/config/versions"
view=move || {
view! {
<Layout>
<ConfigVersionList/>
</Layout>
}
}
/>

<Route
ssr=SsrMode::Async
path="/admin/:tenant/config/versions/:version"
view=move || {
view! {
<Layout>
<ConfigVersion/>
</Layout>
}
}
/>

// <Route
// path="/*any"
// view=move || {
// view! {
// <Layout>
// <NotFound/>
// </Layout>
// }
// }
// />

<AppRoutes/>
</Routes>
</AlertProvider>
</body>
Expand Down
1 change: 1 addition & 0 deletions crates/frontend/src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ pub mod table;
pub mod toast;
pub mod type_template_form;
pub mod variant_form;
pub mod contextual_override_form;
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
Loading
Loading