Skip to content

Commit

Permalink
fix: moved forms to pages and added breadcrumbs for navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
ShubhranshuSanjeev committed Jan 15, 2025
1 parent a1db40d commit 616a73b
Show file tree
Hide file tree
Showing 63 changed files with 2,552 additions and 1,749 deletions.
12 changes: 12 additions & 0 deletions crates/context_aware_config/src/api/default_config/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub fn endpoints() -> Scope {
.service(update_default_config)
.service(get)
.service(delete)
.service(get_by_name)
}

#[post("")]
Expand Down Expand Up @@ -283,6 +284,17 @@ fn fetch_default_key(
Ok(res)
}

#[get("/{key}")]
async fn get_by_name(
db_conn: DbConnection,
path: Path<DefaultConfigKey>,
) -> superposition::Result<Json<models::DefaultConfig>> {
let DbConnection(mut conn) = db_conn;
let key: String = path.into_inner().into();
let data = fetch_default_key(&key, &mut conn)?;
Ok(Json(data))
}

#[get("")]
async fn get(
db_conn: DbConnection,
Expand Down
22 changes: 22 additions & 0 deletions crates/context_aware_config/src/api/dimension/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub fn endpoints() -> Scope {
.service(create)
.service(update)
.service(get)
.service(get_by_name)
.service(delete_dimension)
}

Expand Down Expand Up @@ -269,6 +270,27 @@ async fn get(
}))
}

#[get("/{name}")]
async fn get_by_name(
db_conn: DbConnection,
path: Path<String>,
tenant_config: TenantConfig,
) -> superposition::Result<HttpResponse> {
use superposition_types::database::{
models::cac::Dimension,
schema::dimensions::{self, dsl},
};
let DbConnection(mut conn) = db_conn;
let name: String = path.into_inner().into();
let res = dsl::dimensions
.filter(dimensions::dimension.eq(name))
.select(Dimension::as_select())
.get_result(&mut conn)?;
let is_mandatory = tenant_config.mandatory_dimensions.contains(&res.dimension);

Ok(HttpResponse::Ok().json(DimensionWithMandatory::new(res, is_mandatory)))
}

#[delete("/{name}")]
async fn delete_dimension(
path: Path<DeleteReq>,
Expand Down
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 @@ -23,6 +23,7 @@ pub fn endpoints() -> Scope {
.service(create_type)
.service(update_type)
.service(delete_type)
.service(get_type)
}

#[post("")]
Expand Down Expand Up @@ -154,3 +155,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::<TypeTemplate>(&mut conn)?;
Ok(HttpResponse::Ok().json(custom_type))
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ use super::{
types::{
ApplicableVariantsQuery, AuditQueryFilters, ConcludeExperimentRequest,
ContextAction, ContextBulkResponse, ContextMoveReq, ContextPutReq,
ExperimentCreateRequest, ExperimentCreateResponse, ExperimentListFilters,
ExperimentResponse, OverrideKeysUpdateRequest, RampRequest,
ExperimentCreateRequest, ExperimentListFilters, ExperimentResponse,
OverrideKeysUpdateRequest, RampRequest,
},
};
use crate::api::experiments::{helpers::construct_header_map, types::ExperimentSortOn};
Expand Down Expand Up @@ -287,7 +287,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 @@ -16,19 +16,6 @@ pub struct ExperimentCreateRequest {
pub variants: Vec<Variant>,
}

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

impl From<Experiment> for ExperimentCreateResponse {
fn from(experiment: Experiment) -> Self {
Self {
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
88 changes: 81 additions & 7 deletions crates/frontend/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use leptos::ServerFnError;
use superposition_types::{
custom_query::PaginationParams,
database::{
models::cac::{ConfigVersion, DefaultConfig, Function, TypeTemplate},
models::cac::{ConfigVersion, Context, DefaultConfig, Dimension, Function, TypeTemplate},
types::DimensionWithMandatory,
},
Config, PaginatedResponse,
Expand All @@ -19,15 +19,15 @@ use crate::{
// #[server(GetDimensions, "/fxn", "GetJson")]
pub async fn fetch_dimensions(
filters: &PaginationParams,
tenant: String,
tenant: &str,
) -> Result<PaginatedResponse<DimensionWithMandatory>, ServerFnError> {
let client = reqwest::Client::new();
let host = use_host_server();

let url = format!("{}/dimension?{}", host, filters.to_string());
let response: PaginatedResponse<DimensionWithMandatory> = client
.get(url)
.header("x-tenant", &tenant)
.header("x-tenant", tenant)
.send()
.await
.map_err(|e| ServerFnError::new(e.to_string()))?
Expand All @@ -41,7 +41,7 @@ pub async fn fetch_dimensions(
// #[server(GetDefaultConfig, "/fxn", "GetJson")]
pub async fn fetch_default_config(
filters: &PaginationParams,
tenant: String,
tenant: &str,
) -> Result<PaginatedResponse<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 @@ -293,3 +293,77 @@ 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)
}

pub async fn fetch_default_config_key(
tenant: &str,
key: &str,
) -> Result<DefaultConfig, ServerFnError> {
let host = use_host_server();
let url = format!("{host}/default-config/{key}");
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::<DefaultConfig>(response)
.await
.map_err(err_handler)
}

pub async fn fetch_dimension(
tenant: &str,
name: &str,
) -> Result<Dimension, ServerFnError> {
let host = use_host_server();
let url = format!("{host}/dimension/{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::<Dimension>(response)
.await
.map_err(err_handler)
}
Loading

0 comments on commit 616a73b

Please sign in to comment.