Skip to content

Commit

Permalink
feat: added config-versions UI
Browse files Browse the repository at this point in the history
feat: added snapshot_list and single view UI

Revert "feat: get config-versions api"

This reverts commit 6594ee1.
  • Loading branch information
Ankit Mahato authored and sauraww committed Sep 29, 2024
1 parent 25eb4c6 commit 8759b15
Show file tree
Hide file tree
Showing 25 changed files with 1,382 additions and 705 deletions.
41 changes: 40 additions & 1 deletion crates/frontend/src/api.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use leptos::ServerFnError;
use serde_json::Value;

use crate::{
types::{
Config, DefaultConfig, Dimension, ExperimentResponse, ExperimentsResponse,
FetchTypeTemplateResponse, FunctionResponse, ListFilters,
FetchTypeTemplateResponse, FunctionResponse, ListFilters,SnapshotResponse,
},
utils::{
construct_request_headers, get_host, parse_json_response, request,
Expand Down Expand Up @@ -48,6 +49,26 @@ pub async fn fetch_default_config(
.await
.map_err(|e| ServerFnError::new(e.to_string()))?;

Ok(response)
}

pub async fn get_snapshots(
tenant: String,
) -> Result<SnapshotResponse, ServerFnError> {
let client = reqwest::Client::new();
let host = use_host_server();

let url = format!("{host}/config-versions");
let response: SnapshotResponse = client
.get(url)
.header("x-tenant", tenant)
.send()
.await
.map_err(|e| ServerFnError::new(e.to_string()))?
.json()
.await
.map_err(|e| ServerFnError::new(e.to_string()))?;

Ok(response)
}

Expand Down Expand Up @@ -248,3 +269,21 @@ pub async fn fetch_types(
.await
.map_err(err_handler)
}

pub async fn get_config_by_version(tenant: String, version: String) -> Result<Value, ServerFnError> {
let client = reqwest::Client::new();
let host = use_host_server();

let url = format!("{host}/config?version={}", version);
let response: Value = client
.get(url)
.header("x-tenant", tenant)
.send()
.await
.map_err(|e| ServerFnError::new(e.to_string()))?
.json()
.await
.map_err(|e| ServerFnError::new(e.to_string()))?;

Ok(response)
}
26 changes: 26 additions & 0 deletions crates/frontend/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use serde_json::json;

use crate::hoc::layout::Layout;
use crate::pages::dimensions::Dimensions;
use crate::pages::snapshot_list::SnapshotList;
use crate::pages::snapshotconfig::SnapshotConfig;
use crate::pages::experiment_list::ExperimentList;
use crate::pages::function::{
function_create::CreateFunctionView, function_list::FunctionList, FunctionPage,
Expand Down Expand Up @@ -211,6 +213,30 @@ pub fn app(app_envs: Envs) -> impl IntoView {
}
/>

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

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

// <Route
// path="/*any"
// view=move || {
Expand Down
15 changes: 5 additions & 10 deletions crates/frontend/src/components/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,17 @@ pub fn button<F: Fn(MouseEvent) + 'static>(
button_class = button_class + "hover:cursor-not-allowed";
}
view! {
<button
class=button_class
id=id
on:click=on_click
disabled=loading
>
<button class=button_class id=id on:click=on_click disabled=loading>
{if loading {
view! { <><span class="loading loading-dots loading-sm"></span></> }
} else {
view! {
<>
{text}
<i class="ri-edit-2-line ml-2"></i>
<span class="loading loading-dots loading-sm"></span>
</>
}
} else {
view! { <>{text} <i class="ri-edit-2-line ml-2"></i></> }
}}

</button>
}
}
108 changes: 58 additions & 50 deletions crates/frontend/src/components/condition_pills.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,32 +59,39 @@ pub fn condition_expression(
} else {
("condition-item-collapsed", "condition-value-collapsed")
};

// Destructure the condition
let Condition { left_operand: dimension, operator, right_operand: value } = condition.get_value();

// Filter and convert values to strings for rendering
let filtered_vals: Vec<String> = value.into_iter().filter_map(|v|
if v.is_object() && v.get("var").is_some() {
None
} else {
match v {
Value::String(s) => Some(s.to_string()),
Value::Number(n) => Some(n.to_string()),
Value::Bool(b) => Some(b.to_string()),
Value::Array(arr) => {
Some(arr.iter().map(|v| v.to_string()).collect::<Vec<String>>().join(","))
}
Value::Object(o) => {
serde_json::to_string_pretty(&o).ok()
let Condition { left_operand: dimension, operator, right_operand: value } = condition
.get_value();
let filtered_vals: Vec<String> = value
.into_iter()
.filter_map(|v| {
if v.is_object() && v.get("var").is_some() {
None
} else {
match v {
Value::String(s) => Some(s.to_string()),
Value::Number(n) => Some(n.to_string()),
Value::Bool(b) => Some(b.to_string()),
Value::Array(arr) => {
Some(
arr
.iter()
.map(|v| v.to_string())
.collect::<Vec<String>>()
.join(","),
)
}
Value::Object(o) => serde_json::to_string_pretty(&o).ok(),
_ => None,
}
}
_ => None,
}
}
).collect();

// Render based on the operator type
})
.collect();
view! {
// Destructure the condition

// Filter and convert values to strings for rendering

// Render based on the operator type
<li
id=id.get_value()
class=list_item_class
Expand All @@ -102,37 +109,38 @@ pub fn condition_expression(
{operator.to_string()}
</span>

{
match operator {
ConditionOperator::Between => {
if filtered_vals.len() == 2 {
view! {
<>
<span class="font-mono font-semibold context_condition">
{&filtered_vals[0]}
</span>
<span class="font-mono font-medium text-gray-650 context_condition">
{"and"}
</span>
<span class="font-mono font-semibold context_condition">
{&filtered_vals[1]}
</span>
</>
}.into_view()
} else {
view! { <span class="font-mono text-red-500">"Invalid between values"</span> }.into_view()
{match operator {
ConditionOperator::Between => {
if filtered_vals.len() == 2 {
view! {
<>
<span class="font-mono font-semibold context_condition">
{&filtered_vals[0]}
</span>
<span class="font-mono font-medium text-gray-650 context_condition">
{"and"}
</span>
<span class="font-mono font-semibold context_condition">
{&filtered_vals[1]}
</span>
</>
}
},
_ => {
let rendered_value = filtered_vals.join(", ");
.into_view()
} else {
view! {
<span class=value_class>
{rendered_value}
<span class="font-mono text-red-500">
"Invalid between values"
</span>
}.into_view()
}
.into_view()
}
}
}
_ => {
let rendered_value = filtered_vals.join(", ");
view! { <span class=value_class>{rendered_value}</span> }.into_view()
}
}}

</li>
}
}}
Expand Down
9 changes: 6 additions & 3 deletions crates/frontend/src/components/context_card.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,16 @@ pub fn context_card(
on:click=move |_| {
handle_edit.call((context.get_value(), overrides.get_value()));
}
></i>
>
</i>

<i
class="ri-file-copy-line ri-lg text-blue-500 cursor-pointer"
on:click=move |_| {
handle_clone.call((context.get_value(), overrides.get_value()));
}
></i>
>
</i>

</Show>
<Show when=move || edit_unsupported>
Expand All @@ -91,7 +93,8 @@ pub fn context_card(
let context_id = context_id.get_value();
handle_delete.call(context_id);
}
></i>
>
</i>

</div>
</Show>
Expand Down
Loading

0 comments on commit 8759b15

Please sign in to comment.