Skip to content

Commit

Permalink
refactor: formatted code
Browse files Browse the repository at this point in the history
  • Loading branch information
ShubhranshuSanjeev committed Jan 15, 2025
1 parent 616a73b commit c4e2d75
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 94 deletions.
4 changes: 3 additions & 1 deletion crates/frontend/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use leptos::ServerFnError;
use superposition_types::{
custom_query::PaginationParams,
database::{
models::cac::{ConfigVersion, Context, DefaultConfig, Dimension, Function, TypeTemplate},
models::cac::{
ConfigVersion, Context, DefaultConfig, Dimension, Function, TypeTemplate,
},
types::DimensionWithMandatory,
},
Config, PaginatedResponse,
Expand Down
138 changes: 69 additions & 69 deletions crates/frontend/src/pages/context_override.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,81 +179,81 @@ pub fn context_override() -> impl IntoView {
});

view! {
<div class="flex justify-between">
<h2 class="card-title">Overrides</h2>
<div class="flex justify-between">
<h2 class="card-title">Overrides</h2>

<A href="new">
<Button text="Create Override" on_click=move |_| {} />
</A>
</div>
<A href="new">
<Button text="Create Override" on_click=move |_| {} />
</A>
</div>

<Suspense fallback=move || {
view! { <Skeleton variant=SkeletonVariant::Block /> }
}>
<div class="space-y-6">
{move || {
let config = page_resource.get().map(|v| v.config).unwrap_or_default();
let ctx_n_overrides = config
.contexts
.into_iter()
.map(|context| {
let overrides = context
.override_with_keys
.iter()
.flat_map(|id| {
config
.overrides
.get(id)
.cloned()
.map_or(Map::new(), |overrides| overrides.into())
.into_iter()
.collect::<Vec<(String, Value)>>()
})
.collect::<Map<String, Value>>();
(context.clone(), overrides)
})
.collect::<Vec<(Context, Map<String, Value>)>>();
let is_empty = ctx_n_overrides.is_empty();
view! {
<Show when=move || is_empty>
<div class="flex-row" style="margin-top:20rem;">
<div class="flex justify-center text-gray-400">
<i class="ri-file-add-line ri-xl"></i>
</div>
<div class="flex mt-4 font-semibold items-center text-gray-400 text-xl justify-center">
"Start with creating an override"
</div>
<Suspense fallback=move || {
view! { <Skeleton variant=SkeletonVariant::Block /> }
}>
<div class="space-y-6">
{move || {
let config = page_resource.get().map(|v| v.config).unwrap_or_default();
let ctx_n_overrides = config
.contexts
.into_iter()
.map(|context| {
let overrides = context
.override_with_keys
.iter()
.flat_map(|id| {
config
.overrides
.get(id)
.cloned()
.map_or(Map::new(), |overrides| overrides.into())
.into_iter()
.collect::<Vec<(String, Value)>>()
})
.collect::<Map<String, Value>>();
(context.clone(), overrides)
})
.collect::<Vec<(Context, Map<String, Value>)>>();
let is_empty = ctx_n_overrides.is_empty();
view! {
<Show when=move || is_empty>
<div class="flex-row" style="margin-top:20rem;">
<div class="flex justify-center text-gray-400">
<i class="ri-file-add-line ri-xl"></i>
</div>
</Show>
<ConditionCollapseProvider>
<div class="flex mt-4 font-semibold items-center text-gray-400 text-xl justify-center">
"Start with creating an override"
</div>
</div>
</Show>
<ConditionCollapseProvider>

{ctx_n_overrides
.into_iter()
.map(|(context, overrides)| {
view! {
<ContextCard
context=context
overrides=overrides
handle_delete=on_context_delete
/>
}
})
.collect_view()}
{ctx_n_overrides
.into_iter()
.map(|(context, overrides)| {
view! {
<ContextCard
context=context
overrides=overrides
handle_delete=on_context_delete
/>
}
})
.collect_view()}

</ConditionCollapseProvider>
}
}}
</ConditionCollapseProvider>
}
}}

</div>
</div>

<DeleteModal
modal_visible=modal_visible
confirm_delete=on_delete_confirm
set_modal_visible=set_modal_visible
header_text="Are you sure you want to delete this context? Action is irreversible."
.to_string()
/>
<DeleteModal
modal_visible=modal_visible
confirm_delete=on_delete_confirm
set_modal_visible=set_modal_visible
header_text="Are you sure you want to delete this context? Action is irreversible."
.to_string()
/>

</Suspense>
}
</Suspense>
}
}
4 changes: 1 addition & 3 deletions crates/frontend/src/pages/default_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,7 @@ pub fn default_config() -> impl IntoView {

{move || {
let prefix = query_params.get().get("prefix").cloned().unwrap_or_default();
let default_config = default_config_resource
.get()
.unwrap_or_default();
let default_config = default_config_resource.get().unwrap_or_default();
let table_rows = default_config
.data
.into_iter()
Expand Down
9 changes: 3 additions & 6 deletions crates/frontend/src/pages/experiment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,10 @@ pub fn experiment_page() -> impl IntoView {
let combined_resource: Resource<(String, String), CombinedResource> =
create_blocking_resource(source, |(exp_id, tenant)| async move {
// Perform all fetch operations concurrently
let experiments_future =
fetch_experiment(&exp_id, &tenant);
let experiments_future = fetch_experiment(&exp_id, &tenant);
let empty_list_filters = PaginationParams::all_entries();
let dimensions_future =
fetch_dimensions(&empty_list_filters, &tenant);
let config_future =
fetch_default_config(&empty_list_filters, &tenant);
let dimensions_future = fetch_dimensions(&empty_list_filters, &tenant);
let config_future = fetch_default_config(&empty_list_filters, &tenant);

let (experiments_result, dimensions_result, config_result) =
join!(experiments_future, dimensions_future, config_future);
Expand Down
5 changes: 4 additions & 1 deletion crates/frontend/src/pages/experiment_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ use superposition_types::{
};
use utils::experiment_table_columns;

use crate::{api::{fetch_default_config, fetch_dimensions, fetch_experiments}, components::button::Button};
use crate::components::skeleton::Skeleton;
use crate::components::table::types::TablePaginationProps;
use crate::components::{stat::Stat, table::Table};
use crate::{
api::{fetch_default_config, fetch_dimensions, fetch_experiments},
components::button::Button,
};

use crate::providers::condition_collapse_provider::ConditionCollapseProvider;
use crate::types::{ExperimentListFilters, ExperimentResponse};
Expand Down
2 changes: 1 addition & 1 deletion crates/frontend/src/pages/function/function_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct CombinedResource {

#[component]
pub fn function_list() -> impl IntoView {
let tenant_rs = use_context::<ReadSignal<String>>().unwrap();
let tenant_rs = use_context::<Signal<String>>().unwrap();
let (filters, set_filters) = create_signal(PaginationParams::default_request());
let table_columns = create_memo(move |_| function_table_columns());

Expand Down
5 changes: 1 addition & 4 deletions crates/frontend/src/pages/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,7 @@ pub fn home() -> impl IntoView {
<h2 class="card-title">Resolve Configs</h2>

<ContextForm
dimensions=dimension
.to_owned()
.unwrap_or_default()
.data
dimensions=dimension.to_owned().unwrap_or_default().data
context=Conditions::default()
heading_sub_text="Query your configs".to_string()
dropdown_direction=DropdownDirection::Right
Expand Down
7 changes: 4 additions & 3 deletions crates/frontend/src/pages/new_contextual_override.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ use leptos::*;
use leptos_router::{use_navigate, use_query_map, ParamsMap};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use superposition_types::{custom_query::PaginationParams, database::{
models::cac::DefaultConfig, types::DimensionWithMandatory,
}};
use superposition_types::{
custom_query::PaginationParams,
database::{models::cac::DefaultConfig, types::DimensionWithMandatory},
};

use crate::{
api::{fetch_context, fetch_default_config, fetch_dimensions},
Expand Down
20 changes: 17 additions & 3 deletions crates/frontend/src/pages/organisations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,30 @@ pub fn organisations() -> impl IntoView {
let organisation = event_target_value(&event);
organisation_ws
.set(
if organisation.as_str() != "" { Some(organisation) } else { None },
if organisation.as_str() != "" {
Some(organisation)
} else {
None
},
);
}
>
<option value=String::from("")>Select Organisation</option>
<For
each=move || organisation_resource.get().clone().unwrap_or_default()
each=move || {
organisation_resource.get().clone().unwrap_or_default()
}
key=|organisation| organisation.clone()
children=move |organisation| {
view! { <option value=organisation.clone() selected={organisation == organisation_rs.get().unwrap_or_default()}>{organisation}</option> }
view! {
<option
value=organisation.clone()
selected=organisation
== organisation_rs.get().unwrap_or_default()
>
{organisation}
</option>
}
}
/>
</select>
Expand Down
2 changes: 1 addition & 1 deletion crates/frontend/src/pages/template_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{api::fetch_types, components::table::types::Column};

#[component]
pub fn types_page() -> impl IntoView {
let tenant_rs = use_context::<ReadSignal<String>>().unwrap();
let tenant_rs = use_context::<Signal<String>>().unwrap();
let types_resource = create_blocking_resource(
move || tenant_rs.get(),
|t| async move {
Expand Down
1 change: 0 additions & 1 deletion crates/service_utils/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use superposition_types::{
},
Condition,
};
use urlencoding::encode;

const CONFIG_TAG_REGEX: &str = "^[a-zA-Z0-9_-]{1,64}$";

Expand Down
2 changes: 1 addition & 1 deletion crates/superposition_types/src/database/models/cac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub struct Context {
pub override_id: String,
pub created_at: DateTime<Utc>,
pub created_by: String,
#[serde(rename(serialize = "override"))]
#[serde(rename(serialize = "override", deserialize = "override"))]
pub override_: Overrides,
pub last_modified_at: NaiveDateTime,
pub last_modified_by: String,
Expand Down

0 comments on commit c4e2d75

Please sign in to comment.