Skip to content

Commit

Permalink
fix: using ExperimentResponse type for single experiment get response
Browse files Browse the repository at this point in the history
  • Loading branch information
ShubhranshuSanjeev authored and Datron committed Sep 7, 2024
1 parent cdd59b2 commit 2906966
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
6 changes: 3 additions & 3 deletions crates/frontend/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use leptos::ServerFnError;

use crate::{
types::{
Config, DefaultConfig, Dimension, Experiment, ExperimentsResponse,
FetchTypeTemplateResponse, FunctionResponse, ListFilters,
Config, DefaultConfig, Dimension, Experiment, ExperimentResponse,
ExperimentsResponse, FetchTypeTemplateResponse, FunctionResponse, ListFilters,
},
utils::{
construct_request_headers, get_host, parse_json_response, request,
Expand Down Expand Up @@ -181,7 +181,7 @@ pub async fn fetch_config(tenant: String) -> Result<Config, ServerFnError> {
pub async fn fetch_experiment(
exp_id: String,
tenant: String,
) -> Result<Experiment, ServerFnError> {
) -> Result<ExperimentResponse, ServerFnError> {
let client = reqwest::Client::new();
let host = use_host_server();
let url = format!("{}/experiments/{}", host, exp_id);
Expand Down
2 changes: 1 addition & 1 deletion crates/frontend/src/pages/experiment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub fn experiment_page() -> impl IntoView {

// Construct the combined result, handling errors as needed
CombinedResource {
experiment: experiments_result.ok(),
experiment: experiments_result.ok().map(|v| v.into()),
dimensions: dimensions_result
.unwrap_or(vec![])
.into_iter()
Expand Down
23 changes: 21 additions & 2 deletions crates/frontend/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ use std::{str::FromStr, vec::Vec};

use chrono::{DateTime, NaiveDateTime, Utc};
use derive_more::{Deref, DerefMut};
use serde_json::{Map, Value};
use serde_json::{json, Map, Value};

use crate::components::{
condition_pills::types::Condition, dropdown::utils::DropdownOption,
condition_pills::{types::Condition, utils::extract_conditions},
dropdown::utils::DropdownOption,
};

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -193,6 +194,24 @@ pub struct Experiment {
pub(crate) chosen_variant: Option<String>,
}

impl From<ExperimentResponse> for Experiment {
fn from(value: ExperimentResponse) -> Self {
Experiment {
name: value.name,
id: value.id,
traffic_percentage: value.traffic_percentage as u8,
status: value.status,
override_keys: json!(value.override_keys),
created_by: value.created_by,
created_at: value.created_at,
last_modified: value.last_modified,
chosen_variant: value.chosen_variant,
variants: serde_json::from_value(value.variants).unwrap_or_default(),
context: extract_conditions(&value.context),
}
}
}

/*************************** Context-Override types ********************************/

#[derive(Serialize, Deserialize, Clone, Debug)]
Expand Down

0 comments on commit 2906966

Please sign in to comment.