Skip to content

Commit

Permalink
refactor: workspace ui & form (#373)
Browse files Browse the repository at this point in the history
* refactor: workspace ui & form

* refactor: moved api types behind  feature flag
  • Loading branch information
ShubhranshuSanjeev authored and Datron committed Jan 23, 2025
1 parent abdab61 commit 2c0eaa1
Show file tree
Hide file tree
Showing 16 changed files with 44 additions and 143 deletions.
1 change: 1 addition & 0 deletions crates/context_aware_config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ service_utils = { path = "../service_utils" }
strum_macros = { workspace = true }
superposition_macros = { path = "../superposition_macros" }
superposition_types = { path = "../superposition_types", features = [
"api",
"result",
"diesel_derives",
] }
Expand Down
1 change: 1 addition & 0 deletions crates/experimentation_platform/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ serde_json = { workspace = true }
service_utils = { path = "../service_utils" }
superposition_macros = { path = "../superposition_macros" }
superposition_types = { path = "../superposition_types", features = [
"api",
"experimentation",
"result",
"diesel_derives",
Expand Down
1 change: 1 addition & 0 deletions crates/frontend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ strum = { workspace = true }
strum_macros = { workspace = true }
superposition_types = { path = "../superposition_types", features = [
"experimentation",
"api"
], default-features = false }
url = { workspace = true }
wasm-bindgen = "=0.2.89"
Expand Down
1 change: 0 additions & 1 deletion crates/frontend/src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ pub mod experiment_form;
pub mod experiment_ramp_form;
pub mod function_form;
pub mod input;
pub mod input_components;
pub mod modal;
pub mod monaco_editor;
pub mod nav_item;
Expand Down
90 changes: 0 additions & 90 deletions crates/frontend/src/components/input_components.rs

This file was deleted.

28 changes: 12 additions & 16 deletions crates/frontend/src/components/workspace_form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,31 @@ pub mod utils;

use leptos::*;
use serde_json::to_string;
use superposition_types::api::workspace::{
CreateWorkspaceRequest, UpdateWorkspaceRequest,
};
use superposition_types::database::models::WorkspaceStatus;
use web_sys::MouseEvent;

use crate::components::input_components::BooleanToggle;
use crate::components::input::Toggle;
use crate::components::workspace_form::utils::string_to_vec;
use crate::components::{alert::AlertType, button::Button};
use crate::types::OrganisationId;
use crate::{
components::workspace_form::{
types::{CreateWorkspaceRequest, UpdateWorkspaceRequest},
utils::{create_workspace, update_workspace},
},
components::workspace_form::utils::{create_workspace, update_workspace},
providers::{alert_provider::enqueue_alert, editor_provider::EditorProvider},
};

#[component]
pub fn workspace_form<NF>(
pub fn workspace_form(
org_id: RwSignal<OrganisationId>,
#[prop(default = false)] edit: bool,
#[prop(default = String::new())] workspace_admin_email: String,
#[prop(default = String::new())] workspace_name: String,
#[prop(default = WorkspaceStatus::ENABLED)] workspace_status: WorkspaceStatus,
#[prop(default = vec![])] mandatory_dimensions: Vec<String>,
handle_submit: NF,
) -> impl IntoView
where
NF: Fn() + 'static + Clone,
{
#[prop(into)] handle_submit: Callback<(), ()>,
) -> impl IntoView {
let (workspace_name_rs, workspace_name_ws) = create_signal(workspace_name);
let (workspace_admin_email_rs, workspace_admin_email_ws) =
create_signal(workspace_admin_email);
Expand All @@ -54,10 +51,8 @@ where
mandatory_dimensions: Some(mandatory_dimensions_rs.get()),
};

let handle_submit_clone = handle_submit.clone();
let is_edit = edit;
spawn_local({
let handle_submit = handle_submit_clone;
async move {
let result = if is_edit {
update_workspace(
Expand All @@ -72,7 +67,7 @@ where

match result {
Ok(_) => {
handle_submit();
handle_submit.call(());
let success_message = if is_edit {
"Workspace updated successfully!"
} else {
Expand Down Expand Up @@ -164,14 +159,15 @@ where
<label class="label">
<span class="label-text">Workspace Status</span>
</label>
<BooleanToggle
<Toggle
name="workspace-status"
value=if workspace_status_rs.get_untracked() == WorkspaceStatus::ENABLED {
true
} else {
false
}
on_change=Callback::new(move |flag: bool| {
on_change=Callback::new(move |flag: serde_json::Value| {
let flag = flag.as_bool().unwrap();
if flag {
workspace_status_ws.set(WorkspaceStatus::ENABLED)
} else {
Expand Down
14 changes: 0 additions & 14 deletions crates/frontend/src/components/workspace_form/types.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
use serde::{Deserialize, Serialize};
use superposition_types::database::models::WorkspaceStatus;

#[derive(Debug, Serialize, Deserialize)]
pub struct CreateWorkspaceRequest {
pub workspace_admin_email: String,
pub workspace_name: String,
pub workspace_status: Option<WorkspaceStatus>,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct UpdateWorkspaceRequest {
pub workspace_admin_email: String,
pub workspace_status: Option<WorkspaceStatus>,
pub mandatory_dimensions: Option<Vec<String>>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct RowData {
pub workspace_name: String,
Expand Down
4 changes: 3 additions & 1 deletion crates/frontend/src/components/workspace_form/utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use super::types::{CreateWorkspaceRequest, UpdateWorkspaceRequest};
use crate::utils::{construct_request_headers, get_host, parse_json_response, request};
use serde_json::Value;
use superposition_types::api::workspace::{
CreateWorkspaceRequest, UpdateWorkspaceRequest,
};

pub async fn create_workspace(
org_id: String,
Expand Down
4 changes: 2 additions & 2 deletions crates/frontend/src/pages/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ pub fn workspace() -> impl IntoView {
mandatory_dimensions=selected_workspace_data
.mandatory_dimensions
.unwrap_or_default()
handle_submit=move || {
handle_submit=move |_| {
workspace_resource.refetch();
selected_workspace.set(None);
close_drawer("workspace_drawer");
Expand All @@ -182,7 +182,7 @@ pub fn workspace() -> impl IntoView {
>
<WorkspaceForm
org_id=org_id
handle_submit=move || {
handle_submit=move |_| {
workspace_resource.refetch();
selected_workspace.set(None);
close_drawer("workspace_drawer");
Expand Down
2 changes: 1 addition & 1 deletion crates/superposition/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ serde = { workspace = true }
serde_json = { workspace = true }
service_utils = { path = "../service_utils" }
superposition_macros = { path = "../superposition_macros" }
superposition_types = { path = "../superposition_types", features = ["diesel_derives"]}
superposition_types = { path = "../superposition_types", features = ["api", "diesel_derives"]}
url = { workspace = true }

[features]
Expand Down
5 changes: 2 additions & 3 deletions crates/superposition/src/workspace/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use regex::Regex;
use service_utils::service::types::{DbConnection, OrganisationId};
use superposition_macros::{db_error, unexpected_error, validation_error};
use superposition_types::{
api::workspace::{CreateWorkspaceRequest, UpdateWorkspaceRequest},
custom_query::PaginationParams,
database::{
models::{Organisation, Workspace, WorkspaceStatus},
Expand All @@ -24,9 +25,7 @@ use superposition_types::{
result as superposition, PaginatedResponse, User,
};

use crate::workspace::types::{
CreateWorkspaceRequest, UpdateWorkspaceRequest, WorkspaceListFilters,
};
use crate::workspace::types::WorkspaceListFilters;

const WORKSPACE_TEMPLATE_PATH: &str = "workspace_template.sql";

Expand Down
15 changes: 0 additions & 15 deletions crates/superposition/src/workspace/types.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
use serde::Deserialize;
use superposition_types::database::models::WorkspaceStatus;

#[derive(Debug, Deserialize)]
pub struct CreateWorkspaceRequest {
pub workspace_admin_email: String,
pub workspace_name: String,
pub workspace_status: Option<WorkspaceStatus>,
}

#[derive(Debug, Deserialize)]
pub struct UpdateWorkspaceRequest {
pub workspace_admin_email: String,
pub workspace_status: Option<WorkspaceStatus>,
pub mandatory_dimensions: Option<Vec<String>>,
}

#[derive(Deserialize, Debug)]
pub struct WorkspaceListFilters {
Expand Down
1 change: 1 addition & 0 deletions crates/superposition_types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ disable_db_data_validation = []
result = ["dep:diesel", "dep:anyhow", "dep:thiserror", "dep:actix-web"]
server = ["dep:actix-web"]
experimentation = []
api = []

[lints]
workspace = true
1 change: 1 addition & 0 deletions crates/superposition_types/src/api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod workspace;
17 changes: 17 additions & 0 deletions crates/superposition_types/src/api/workspace.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use serde::{Deserialize, Serialize};

use crate::database::models::WorkspaceStatus;

#[derive(Debug, Deserialize, Serialize)]
pub struct CreateWorkspaceRequest {
pub workspace_admin_email: String,
pub workspace_name: String,
pub workspace_status: Option<WorkspaceStatus>,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct UpdateWorkspaceRequest {
pub workspace_admin_email: String,
pub workspace_status: Option<WorkspaceStatus>,
pub mandatory_dimensions: Option<Vec<String>>,
}
2 changes: 2 additions & 0 deletions crates/superposition_types/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#![deny(unused_crate_dependencies)]
#[cfg(feature = "api")]
pub mod api;
mod config;
mod contextual;
pub mod custom_query;
Expand Down

0 comments on commit 2c0eaa1

Please sign in to comment.