Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: workspace ui & form #373

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this change needed because the type is being changed from NF to Callback ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we remove BooleanToggle altogether if its no longer meant to be used in any place ?

<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>>,
}
Comment on lines +1 to +17
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this has been created, can we reuse it in context-aware-config crate in this PR itself and remove the type repetition from that crate as well

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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets put this file behind a cfg

mod config;
mod contextual;
pub mod custom_query;
Expand Down
Loading