diff --git a/CHANGELOG.md b/CHANGELOG.md index a6c41ad5e8..2b457783be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,23 @@ # Changelog +## [1.381.0](https://github.com/windmill-labs/windmill/compare/v1.380.0...v1.381.0) (2024-08-16) + + +### Features + +* add env to refresh cgroup readings ([#4250](https://github.com/windmill-labs/windmill/issues/4250)) ([e23c3fa](https://github.com/windmill-labs/windmill/commit/e23c3fad628cc718314472f3cb53c0f257c4c9e5)) +* cache common hub scripts in image ([#4249](https://github.com/windmill-labs/windmill/issues/4249)) ([99f7828](https://github.com/windmill-labs/windmill/commit/99f7828ebb5fddf799afb52af7214ba4119e57b9)) + + +### Bug Fixes + +* **cli:** add inject and define options ([dffd5f7](https://github.com/windmill-labs/windmill/commit/dffd5f7f7d5c84624953bf8c778b14586a14e2d4)) +* **frontend:** improve UI for email triggers ([#4243](https://github.com/windmill-labs/windmill/issues/4243)) ([6c9e32a](https://github.com/windmill-labs/windmill/commit/6c9e32af104a897e5c2a5b41867d2ffbbacc8acb)) +* improve password field lifetime incorrectly recycled too early ([5a8fa1d](https://github.com/windmill-labs/windmill/commit/5a8fa1d72487ac2a29dca8833b8c92b8cac3726e)) +* improve row update of aggrid table actions II ([3cf4f00](https://github.com/windmill-labs/windmill/commit/3cf4f00dca677fc592d5dde8a7b8fdcac5f08e0a)) +* **typescript-client:** add runFlow and runFlowAsync ([c9ef2c8](https://github.com/windmill-labs/windmill/commit/c9ef2c8e97bdecb16b9a54805f1c90523e3b406f)) +* workspace specific default tags do not override step level custom tags ([49835ca](https://github.com/windmill-labs/windmill/commit/49835ca6ca65e569ea2915b2ef4f7ce1c4988cae)) + ## [1.380.0](https://github.com/windmill-labs/windmill/compare/v1.379.4...v1.380.0) (2024-08-14) diff --git a/Dockerfile b/Dockerfile index 7fd89ba6fa..c0f15162de 100644 --- a/Dockerfile +++ b/Dockerfile @@ -175,7 +175,11 @@ WORKDIR ${APP} RUN ln -s ${APP}/windmill /usr/local/bin/windmill -RUN windmill cache +COPY ./frontend/src/lib/hubPaths.json ${APP}/hubPaths.json + +RUN windmill cache ${APP}/hubPaths.json + +RUN rm ${APP}/hubPaths.json EXPOSE 8000 diff --git a/backend/.sqlx/query-bac12eff366f6b76f97d1a44041e0c1b5fdcb2c4205c1c1c0026b71ce404f089.json b/backend/.sqlx/query-b0c2f470f7d2df567eca550db1ae638fcb554622b61a5f4fb6b6696f6283516a.json similarity index 73% rename from backend/.sqlx/query-bac12eff366f6b76f97d1a44041e0c1b5fdcb2c4205c1c1c0026b71ce404f089.json rename to backend/.sqlx/query-b0c2f470f7d2df567eca550db1ae638fcb554622b61a5f4fb6b6696f6283516a.json index a84b6b5ff0..86a8abb432 100644 --- a/backend/.sqlx/query-bac12eff366f6b76f97d1a44041e0c1b5fdcb2c4205c1c1c0026b71ce404f089.json +++ b/backend/.sqlx/query-b0c2f470f7d2df567eca550db1ae638fcb554622b61a5f4fb6b6696f6283516a.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "DELETE FROM variable WHERE expires_at IS NOT NULL AND expires_at > now() RETURNING path", + "query": "DELETE FROM variable WHERE expires_at IS NOT NULL AND expires_at < now() RETURNING path", "describe": { "columns": [ { @@ -16,5 +16,5 @@ false ] }, - "hash": "bac12eff366f6b76f97d1a44041e0c1b5fdcb2c4205c1c1c0026b71ce404f089" + "hash": "b0c2f470f7d2df567eca550db1ae638fcb554622b61a5f4fb6b6696f6283516a" } diff --git a/backend/Cargo.lock b/backend/Cargo.lock index a5f863c6ce..a553da04f0 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -845,9 +845,9 @@ dependencies = [ [[package]] name = "aws-sdk-sso" -version = "1.37.0" +version = "1.38.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1074e818fbe4f9169242d78448b15be8916a79daa38ea1231f2e2e10d993fcd2" +checksum = "fca5e0b9fb285638f1007e9d961d963b9e504ab968fe5a3807cce94070bd0ce3" dependencies = [ "aws-credential-types", "aws-runtime", @@ -867,9 +867,9 @@ dependencies = [ [[package]] name = "aws-sdk-ssooidc" -version = "1.38.0" +version = "1.39.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29755c51e33fa3f678598f64324a169cf4b7d3c4865d2709d4308f53366a92a4" +checksum = "bc3e48ec239bb734db029ceef83599f4c9b3ce5d25c961b5bcd3f031c15bed54" dependencies = [ "aws-credential-types", "aws-runtime", @@ -889,9 +889,9 @@ dependencies = [ [[package]] name = "aws-sdk-sts" -version = "1.37.0" +version = "1.38.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e52dc3fd7dfa6c01a69cf3903e00aa467261639138a05b06cd92314d2c8fb07" +checksum = "ede095dfcc5c92b224813c24a82b65005a475c98d737e2726a898cf583e2e8bd" dependencies = [ "aws-credential-types", "aws-runtime", @@ -985,9 +985,9 @@ dependencies = [ [[package]] name = "aws-smithy-runtime" -version = "1.6.2" +version = "1.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce87155eba55e11768b8c1afa607f3e864ae82f03caf63258b37455b0ad02537" +checksum = "0abbf454960d0db2ad12684a1640120e7557294b0ff8e2f11236290a1b293225" dependencies = [ "aws-smithy-async", "aws-smithy-http", @@ -1029,9 +1029,9 @@ dependencies = [ [[package]] name = "aws-smithy-types" -version = "1.2.0" +version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfe321a6b21f5d8eabd0ade9c55d3d0335f3c3157fc2b3e87f05f34b539e4df5" +checksum = "6cee7cadb433c781d3299b916fbf620fea813bf38f49db282fb6858141a05cc8" dependencies = [ "base64-simd 0.8.0", "bytes", @@ -1483,18 +1483,18 @@ dependencies = [ [[package]] name = "bytemuck" -version = "1.16.3" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "102087e286b4677862ea56cf8fc58bb2cdfa8725c40ffb80fe3a008eb7f2fc83" +checksum = "6fd4c6dcc3b0aea2f5c0b4b82c2b15fe39ddbc76041a310848f4706edf76bb31" dependencies = [ "bytemuck_derive", ] [[package]] name = "bytemuck_derive" -version = "1.7.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ee891b04274a59bd38b412188e24b849617b2e45a0fd8d057deb63e7403761b" +checksum = "0cc8b54b395f2fcfbb3d90c47b01c7f444d94d05bdeb775811dec868ac3bbc26" dependencies = [ "proc-macro2", "quote", @@ -1613,9 +1613,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.1.11" +version = "1.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fb8dd288a69fc53a1996d7ecfbf4a20d59065bff137ce7e56bbd620de191189" +checksum = "72db2f7947ecee9b03b510377e8bb9077afa27176fdbff55c51027e976fdcc48" dependencies = [ "jobserver", "libc", @@ -1718,9 +1718,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.15" +version = "4.5.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11d8838454fda655dafd3accb2b6e2bea645b9e4078abe84a22ceb947235c5cc" +checksum = "ed6719fffa43d0d87e5fd8caeab59be1554fb028cd30edc88fc4369b17971019" dependencies = [ "clap_builder", "clap_derive", @@ -1758,9 +1758,9 @@ checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" [[package]] name = "cmake" -version = "0.1.50" +version = "0.1.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a31c789563b815f77f4250caee12365734369f942439b7defd71e18a48197130" +checksum = "fb1e43aa7fd152b1f968787f7dbcdeb306d1867ff373c69955211876c053f91a" dependencies = [ "cc", ] @@ -4660,9 +4660,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.155" +version = "0.2.156" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "a5f43f184355eefb8d17fc948dbecf6c13be3c141f20d834ae842193a448c72a" [[package]] name = "libgit2-sys" @@ -7466,9 +7466,9 @@ checksum = "a3f0bf26fd526d2a95683cd0f87bf103b8539e2ca1ef48ce002d67aad59aa0b4" [[package]] name = "serde" -version = "1.0.207" +version = "1.0.208" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5665e14a49a4ea1b91029ba7d3bca9f299e1f7cfa194388ccc20f14743e784f2" +checksum = "cff085d2cb684faa248efb494c39b68e522822ac0de72ccf08109abde717cfb2" dependencies = [ "serde_derive", ] @@ -7507,9 +7507,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.207" +version = "1.0.208" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6aea2634c86b0e8ef2cfdc0c340baede54ec27b1e46febd7f80dffb2aa44a00e" +checksum = "24008e81ff7613ed8e5ba0cfaf24e2c2f1e5b8a0495711e44fcd4882fca62bcf" dependencies = [ "proc-macro2", "quote", @@ -7529,9 +7529,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.124" +version = "1.0.125" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66ad62847a56b3dba58cc891acd13884b9c61138d330c0d7b6181713d4fce38d" +checksum = "83c8e735a073ccf5be70aa8066aa984eaf2fa000db6c8d0100ae605b366d31ed" dependencies = [ "indexmap 2.4.0", "itoa", @@ -7592,9 +7592,9 @@ dependencies = [ [[package]] name = "serde_tokenstream" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8790a7c3fe883e443eaa2af6f705952bc5d6e8671a220b9335c8cae92c037e74" +checksum = "64060d864397305347a78851c51588fd283767e7e7589829e8121d65512340f1" dependencies = [ "proc-macro2", "quote", @@ -10409,7 +10409,7 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windmill" -version = "1.380.0" +version = "1.381.0" dependencies = [ "anyhow", "axum", @@ -10449,7 +10449,7 @@ dependencies = [ [[package]] name = "windmill-api" -version = "1.380.0" +version = "1.381.0" dependencies = [ "anyhow", "argon2", @@ -10533,7 +10533,7 @@ dependencies = [ [[package]] name = "windmill-api-client" -version = "1.380.0" +version = "1.381.0" dependencies = [ "base64 0.21.7", "chrono", @@ -10551,7 +10551,7 @@ dependencies = [ [[package]] name = "windmill-audit" -version = "1.380.0" +version = "1.381.0" dependencies = [ "chrono", "serde", @@ -10564,7 +10564,7 @@ dependencies = [ [[package]] name = "windmill-common" -version = "1.380.0" +version = "1.381.0" dependencies = [ "anyhow", "async-stream", @@ -10605,7 +10605,7 @@ dependencies = [ [[package]] name = "windmill-git-sync" -version = "1.380.0" +version = "1.381.0" dependencies = [ "regex", "rsmq_async", @@ -10620,7 +10620,7 @@ dependencies = [ [[package]] name = "windmill-indexer" -version = "1.380.0" +version = "1.381.0" dependencies = [ "anyhow", "bytes", @@ -10641,7 +10641,7 @@ dependencies = [ [[package]] name = "windmill-parser" -version = "1.380.0" +version = "1.381.0" dependencies = [ "serde", "serde_json", @@ -10649,7 +10649,7 @@ dependencies = [ [[package]] name = "windmill-parser-bash" -version = "1.380.0" +version = "1.381.0" dependencies = [ "anyhow", "lazy_static", @@ -10660,7 +10660,7 @@ dependencies = [ [[package]] name = "windmill-parser-go" -version = "1.380.0" +version = "1.381.0" dependencies = [ "anyhow", "gosyn", @@ -10672,7 +10672,7 @@ dependencies = [ [[package]] name = "windmill-parser-graphql" -version = "1.380.0" +version = "1.381.0" dependencies = [ "anyhow", "lazy_static", @@ -10683,7 +10683,7 @@ dependencies = [ [[package]] name = "windmill-parser-php" -version = "1.380.0" +version = "1.381.0" dependencies = [ "anyhow", "convert_case 0.6.0", @@ -10697,7 +10697,7 @@ dependencies = [ [[package]] name = "windmill-parser-py" -version = "1.380.0" +version = "1.381.0" dependencies = [ "anyhow", "itertools 0.13.0", @@ -10708,7 +10708,7 @@ dependencies = [ [[package]] name = "windmill-parser-py-imports" -version = "1.380.0" +version = "1.381.0" dependencies = [ "anyhow", "async-recursion", @@ -10725,7 +10725,7 @@ dependencies = [ [[package]] name = "windmill-parser-sql" -version = "1.380.0" +version = "1.381.0" dependencies = [ "anyhow", "lazy_static", @@ -10736,7 +10736,7 @@ dependencies = [ [[package]] name = "windmill-parser-ts" -version = "1.380.0" +version = "1.381.0" dependencies = [ "anyhow", "convert_case 0.6.0", @@ -10755,7 +10755,7 @@ dependencies = [ [[package]] name = "windmill-parser-wasm" -version = "1.380.0" +version = "1.381.0" dependencies = [ "anyhow", "getrandom 0.2.15", @@ -10774,7 +10774,7 @@ dependencies = [ [[package]] name = "windmill-queue" -version = "1.380.0" +version = "1.381.0" dependencies = [ "anyhow", "async-recursion", @@ -10807,7 +10807,7 @@ dependencies = [ [[package]] name = "windmill-sql-datatype-parser-wasm" -version = "1.380.0" +version = "1.381.0" dependencies = [ "wasm-bindgen", "wasm-bindgen-test", @@ -10817,7 +10817,7 @@ dependencies = [ [[package]] name = "windmill-worker" -version = "1.380.0" +version = "1.381.0" dependencies = [ "anyhow", "async-recursion", diff --git a/backend/Cargo.toml b/backend/Cargo.toml index e033e5396d..906d9f08b9 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "windmill" -version = "1.380.0" +version = "1.381.0" authors.workspace = true edition.workspace = true @@ -25,7 +25,7 @@ members = [ ] [workspace.package] -version = "1.380.0" +version = "1.381.0" authors = ["Ruben Fiszel "] edition = "2021" diff --git a/backend/src/main.rs b/backend/src/main.rs index c26695d7c5..ebc7f6dc3b 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -6,15 +6,20 @@ * LICENSE-AGPL for a copy of the license. */ +use anyhow::Context; use gethostname::gethostname; use git_version::git_version; use rand::Rng; use sqlx::{postgres::PgListener, Pool, Postgres}; use std::{ + collections::HashMap, net::{IpAddr, Ipv4Addr, SocketAddr}, time::Duration, }; -use tokio::fs::DirBuilder; +use tokio::{ + fs::{create_dir_all, DirBuilder, File}, + io::AsyncReadExt, +}; use windmill_api::HTTP_CLIENT; #[cfg(feature = "enterprise")] @@ -54,9 +59,10 @@ use windmill_common::METRICS_ADDR; use windmill_common::global_settings::OBJECT_STORE_CACHE_CONFIG_SETTING; use windmill_worker::{ - BUN_BUNDLE_CACHE_DIR, BUN_CACHE_DIR, BUN_DEPSTAR_CACHE_DIR, DENO_CACHE_DIR, - DENO_CACHE_DIR_DEPS, DENO_CACHE_DIR_NPM, GO_BIN_CACHE_DIR, GO_CACHE_DIR, HUB_CACHE_DIR, - LOCK_CACHE_DIR, PIP_CACHE_DIR, POWERSHELL_CACHE_DIR, TAR_PIP_CACHE_DIR, TMP_LOGS_DIR, + get_hub_script_content_and_requirements, BUN_BUNDLE_CACHE_DIR, BUN_CACHE_DIR, + BUN_DEPSTAR_CACHE_DIR, DENO_CACHE_DIR, DENO_CACHE_DIR_DEPS, DENO_CACHE_DIR_NPM, + GO_BIN_CACHE_DIR, GO_CACHE_DIR, HUB_CACHE_DIR, LOCK_CACHE_DIR, PIP_CACHE_DIR, + POWERSHELL_CACHE_DIR, TAR_PIP_CACHE_DIR, TMP_LOGS_DIR, }; use crate::monitor::{ @@ -111,6 +117,28 @@ pub fn main() -> anyhow::Result<()> { create_and_run_current_thread_inner(windmill_main()) } +async fn cache_hub_scripts(file_path: Option) -> anyhow::Result<()> { + let file_path = file_path.unwrap_or("./hubPaths.json".to_string()); + let mut file = File::open(&file_path) + .await + .with_context(|| format!("Could not open {}, make sure it exists", &file_path))?; + let mut contents = String::new(); + file.read_to_string(&mut contents).await?; + let paths = serde_json::from_str::>(&contents).with_context(|| { + format!( + "Could not parse {}, make sure it is a valid JSON object with string keys and values", + &file_path + ) + })?; + + create_dir_all(HUB_CACHE_DIR).await?; + + for path in paths.values() { + get_hub_script_content_and_requirements(Some(path.to_string()), None).await?; + } + Ok(()) +} + async fn windmill_main() -> anyhow::Result<()> { dotenv::dotenv().ok(); @@ -141,6 +169,9 @@ async fn windmill_main() -> anyhow::Result<()> { { tracing::warn!("Embeddings are not enabled, ignoring..."); } + + cache_hub_scripts(std::env::args().nth(2)).await?; + return Ok(()); } "-v" | "--version" | "version" => { diff --git a/backend/src/monitor.rs b/backend/src/monitor.rs index 1f8eae150a..ad835c713b 100644 --- a/backend/src/monitor.rs +++ b/backend/src/monitor.rs @@ -407,7 +407,7 @@ pub async fn delete_expired_items(db: &DB) -> () { } let deleted_expired_variables = sqlx::query_scalar!( - "DELETE FROM variable WHERE expires_at IS NOT NULL AND expires_at > now() RETURNING path", + "DELETE FROM variable WHERE expires_at IS NOT NULL AND expires_at < now() RETURNING path", ) .fetch_all(db) .await; diff --git a/backend/windmill-api/openapi.yaml b/backend/windmill-api/openapi.yaml index 722f431336..0a44378b6d 100644 --- a/backend/windmill-api/openapi.yaml +++ b/backend/windmill-api/openapi.yaml @@ -1,7 +1,7 @@ openapi: "3.0.3" info: - version: 1.380.0 + version: 1.381.0 title: Windmill API contact: diff --git a/backend/windmill-api/src/apps.rs b/backend/windmill-api/src/apps.rs index 97409f5b81..9bfb84e34f 100644 --- a/backend/windmill-api/src/apps.rs +++ b/backend/windmill-api/src/apps.rs @@ -705,7 +705,7 @@ pub async fn get_hub_app_by_id( &format!("{}/apps/{}/json", *HUB_BASE_URL.read().await, id), false, None, - &db, + Some(&db), ) .await? .json() diff --git a/backend/windmill-api/src/embeddings.rs b/backend/windmill-api/src/embeddings.rs index 6848ceb3d3..5cc7226753 100644 --- a/backend/windmill-api/src/embeddings.rs +++ b/backend/windmill-api/src/embeddings.rs @@ -313,7 +313,7 @@ impl EmbeddingsDb { &format!("{}/scripts/embeddings", hub_base_url), false, None, - pg_db, + Some(pg_db), ) .await? } else { @@ -326,7 +326,7 @@ impl EmbeddingsDb { &format!("{}/scripts/embeddings", hub_base_url), false, None, - pg_db, + Some(pg_db), ) .await? } @@ -375,7 +375,7 @@ impl EmbeddingsDb { &format!("{}/resource_types/embeddings", hub_base_url), false, None, - pg_db, + Some(pg_db), ) .await? } else { @@ -388,7 +388,7 @@ impl EmbeddingsDb { &format!("{}/resource_types/embeddings", hub_base_url), false, None, - pg_db, + Some(pg_db), ) .await? } diff --git a/backend/windmill-api/src/flows.rs b/backend/windmill-api/src/flows.rs index c1f8ec70a4..ccec53c4dc 100644 --- a/backend/windmill-api/src/flows.rs +++ b/backend/windmill-api/src/flows.rs @@ -230,7 +230,7 @@ pub async fn get_hub_flow_by_id( &format!("{}/flows/{}/json", *HUB_BASE_URL.read().await, id), false, None, - &db, + Some(&db), ) .await? .json() diff --git a/backend/windmill-api/src/scripts.rs b/backend/windmill-api/src/scripts.rs index 0ed84404a8..41214dfcbb 100644 --- a/backend/windmill-api/src/scripts.rs +++ b/backend/windmill-api/src/scripts.rs @@ -817,7 +817,8 @@ pub async fn get_full_hub_script_by_path( Extension(db): Extension, ) -> JsonResult { Ok(Json( - windmill_common::scripts::get_full_hub_script_by_path(path, &HTTP_CLIENT, &db).await?, + windmill_common::scripts::get_full_hub_script_by_path(path, &HTTP_CLIENT, Some(&db)) + .await?, )) } diff --git a/backend/windmill-common/src/scripts.rs b/backend/windmill-common/src/scripts.rs index 86c506f467..b10558e40f 100644 --- a/backend/windmill-common/src/scripts.rs +++ b/backend/windmill-common/src/scripts.rs @@ -384,7 +384,7 @@ pub async fn get_hub_script_by_path( &format!("{}/raw/{}.ts", hub_base_url, path), true, None, - db, + Some(db), ) .await? .text() @@ -409,7 +409,7 @@ pub async fn get_hub_script_by_path( &format!("{}/raw/{}.ts", DEFAULT_HUB_BASE_URL, path), true, None, - db, + Some(db), ) .await? .text() @@ -427,7 +427,7 @@ pub async fn get_hub_script_by_path( pub async fn get_full_hub_script_by_path( path: StripPath, http_client: &reqwest::Client, - db: &DB, + db: Option<&DB>, ) -> crate::error::Result { let path = path .to_path() diff --git a/backend/windmill-common/src/utils.rs b/backend/windmill-common/src/utils.rs index 81031a7359..63cece0fe2 100644 --- a/backend/windmill-common/src/utils.rs +++ b/backend/windmill-common/src/utils.rs @@ -96,7 +96,7 @@ pub async fn query_elems_from_hub( reqwest::header::HeaderMap, axum::body::Body, )> { - let response = http_get_from_hub(http_client, url, false, query_params, db).await?; + let response = http_get_from_hub(http_client, url, false, query_params, Some(db)).await?; let status = response.status(); @@ -112,9 +112,18 @@ pub async fn http_get_from_hub( url: &str, plain: bool, query_params: Option>, - db: &Pool, + db: Option<&Pool>, ) -> Result { - let uid = get_uid(db).await; + let uid = match db { + Some(db) => match get_uid(db).await { + Ok(uid) => Some(uid), + Err(err) => { + tracing::info!("No valid uid found: {}", err); + None + } + }, + None => None, + }; let mut request = http_client.get(url).header( "Accept", @@ -125,10 +134,8 @@ pub async fn http_get_from_hub( }, ); - if let Ok(uid) = uid { + if let Some(uid) = uid { request = request.header("X-uid", uid); - } else { - tracing::info!("No valid uid found: {}", uid.err().unwrap()) } if let Some(query_params) = query_params { diff --git a/backend/windmill-queue/src/jobs.rs b/backend/windmill-queue/src/jobs.rs index 4214398752..7e1bf9b192 100644 --- a/backend/windmill-queue/src/jobs.rs +++ b/backend/windmill-queue/src/jobs.rs @@ -53,7 +53,6 @@ use windmill_common::{ jobs::{ get_payload_tag_from_prefixed_path, CompletedJob, JobKind, JobPayload, QueuedJob, RawCode, }, - oauth2::WORKSPACE_SLACK_BOT_TOKEN_PATH, schedule::Schedule, scripts::{get_full_hub_script_by_path, ScriptHash, ScriptLang}, users::{SUPERADMIN_NOTIFICATION_EMAIL, SUPERADMIN_SECRET_EMAIL}, @@ -1479,16 +1478,6 @@ pub async fn push_error_handler< } } - // TODO(gbouv): REMOVE THIS after December 1st 2023 and ping users to re-save their error handlers - if on_failure_path - .to_string() - .eq("script/hub/5792/workspace-or-schedule-error-handler-slack") - { - // default slack error handler being used -> we need to inject the slack token - let slack_resource = format!("$res:{WORKSPACE_SLACK_BOT_TOKEN_PATH}"); - extra.insert("slack".to_string(), to_raw_value(&slack_resource)); - } - let result = sanitize_result(result); let tx = PushIsolationLevel::IsolatedRoot(db.clone(), rsmq); @@ -1602,15 +1591,6 @@ async fn handle_recovered_schedule< )); } } - // TODO(gbouv): REMOVE THIS after December 1st 2023 and ping users to re-save their error handlers - if on_recovery_path - .to_string() - .eq("script/hub/2430/slack/schedule-recovery-handler-slack") - { - // default slack error handler being used -> we need to inject the slack token - let slack_resource = format!("$res:{WORKSPACE_SLACK_BOT_TOKEN_PATH}"); - extra.insert("slack".to_string(), to_raw_value(&slack_resource)); - } let args = error_job .result @@ -3137,7 +3117,8 @@ pub async fn push<'c, 'd, R: rsmq_async::RsmqConnection + Send + 'c>( } let hub_script = - get_full_hub_script_by_path(StripPath(path.clone()), &HTTP_CLIENT, _db).await?; + get_full_hub_script_by_path(StripPath(path.clone()), &HTTP_CLIENT, Some(_db)) + .await?; ( None, diff --git a/backend/windmill-worker/src/worker.rs b/backend/windmill-worker/src/worker.rs index b34fede376..6a6ccc7daf 100644 --- a/backend/windmill-worker/src/worker.rs +++ b/backend/windmill-worker/src/worker.rs @@ -2736,9 +2736,9 @@ pub struct ContentReqLangEnvs { pub codebase: Option, } -async fn get_hub_script_content_and_requirements( +pub async fn get_hub_script_content_and_requirements( script_path: Option, - db: &DB, + db: Option<&DB>, ) -> error::Result { let script_path = script_path .clone() @@ -2783,7 +2783,7 @@ async fn get_script_content_by_path( .clone() .ok_or_else(|| Error::InternalErr(format!("expected script path")))?; return if script_path.starts_with("hub/") { - get_hub_script_content_and_requirements(Some(script_path), db).await + get_hub_script_content_and_requirements(Some(script_path), Some(db)).await } else { let (script_hash, ..) = get_latest_deployed_hash_for_path(db, w_id, script_path.as_str()).await?; @@ -2870,7 +2870,7 @@ async fn handle_code_execution_job( codebase }}, JobKind::Script_Hub => { - get_hub_script_content_and_requirements(job.script_path.clone(), db).await? + get_hub_script_content_and_requirements(job.script_path.clone(), Some(db)).await? } JobKind::Script => { get_script_content_by_hash( diff --git a/backend/windmill-worker/src/worker_flow.rs b/backend/windmill-worker/src/worker_flow.rs index a4b65a589c..c27400c485 100644 --- a/backend/windmill-worker/src/worker_flow.rs +++ b/backend/windmill-worker/src/worker_flow.rs @@ -2379,7 +2379,7 @@ async fn push_next_flow_job continue_on_same_worker, err, flow_job.visible_to_owner, - if flow_job.tag == "flow" { + if flow_job.tag == "flow" || flow_job.tag == format!("flow-{}", flow_job.workspace_id) { payload_tag.tag } else { Some(flow_job.tag.clone()) diff --git a/benchmarks/lib.ts b/benchmarks/lib.ts index 018eb7a7d2..94d6034205 100644 --- a/benchmarks/lib.ts +++ b/benchmarks/lib.ts @@ -2,7 +2,7 @@ import { sleep } from "https://deno.land/x/sleep@v1.2.1/mod.ts"; import * as windmill from "https://deno.land/x/windmill@v1.174.0/mod.ts"; import * as api from "https://deno.land/x/windmill@v1.174.0/windmill-api/index.ts"; -export const VERSION = "v1.380.0"; +export const VERSION = "v1.381.0"; export async function login(email: string, password: string): Promise { return await windmill.UserService.login({ diff --git a/cli/main.ts b/cli/main.ts index dd9ee93d42..f2e1fd094b 100644 --- a/cli/main.ts +++ b/cli/main.ts @@ -34,7 +34,7 @@ addEventListener("error", (event) => { } }); -export const VERSION = "v1.380.0"; +export const VERSION = "v1.381.0"; let command: any = new Command() .name("wmill") diff --git a/docker/DockerfileSlim b/docker/DockerfileSlim index af27740cd6..47d26b0470 100644 --- a/docker/DockerfileSlim +++ b/docker/DockerfileSlim @@ -27,7 +27,11 @@ COPY --from=denoland/deno:1.44.4 --chmod=755 /usr/bin/deno /usr/bin/deno RUN ln -s ${APP}/windmill /usr/local/bin/windmill -RUN windmill cache +COPY ./frontend/src/lib/hubPaths.json ${APP}/hubPaths.json + +RUN windmill cache ${APP}/hubPaths.json + +RUN rm ${APP}/hubPaths.json EXPOSE 8000 diff --git a/frontend/package-lock.json b/frontend/package-lock.json index b975e2858d..2362fcdcf4 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -1,12 +1,12 @@ { "name": "windmill-components", - "version": "1.380.0", + "version": "1.381.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "windmill-components", - "version": "1.380.0", + "version": "1.381.0", "license": "AGPL-3.0", "dependencies": { "@aws-crypto/sha256-js": "^4.0.0", diff --git a/frontend/package.json b/frontend/package.json index 8e8cf2d08f..26140e7f23 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,6 +1,6 @@ { "name": "windmill-components", - "version": "1.380.0", + "version": "1.381.0", "scripts": { "dev": "vite dev", "build": "vite build", diff --git a/frontend/src/lib/components/ErrorOrRecoveryHandler.svelte b/frontend/src/lib/components/ErrorOrRecoveryHandler.svelte index 465805fb61..c54965d8be 100644 --- a/frontend/src/lib/components/ErrorOrRecoveryHandler.svelte +++ b/frontend/src/lib/components/ErrorOrRecoveryHandler.svelte @@ -19,9 +19,10 @@ import { hubBaseUrlStore } from '$lib/stores' import { CheckCircle2, Loader2, RotateCw, XCircle } from 'lucide-svelte' + import { hubPaths } from '$lib/hub' - const slackRecoveryHandler = 'hub/2430/slack/schedule-recovery-handler-slack' - const slackHandlerScriptPath = 'hub/6512/workspace-or-schedule-error-handler-slack' + const slackRecoveryHandler = hubPaths.slackRecoveryHandler + const slackHandlerScriptPath = hubPaths.slackErrorHandler export let errorOrRecovery: 'error' | 'recovery' export let isEditable: boolean diff --git a/frontend/src/lib/components/FlowGraphViewer.svelte b/frontend/src/lib/components/FlowGraphViewer.svelte index 423dc2abaf..b81b1184c2 100644 --- a/frontend/src/lib/components/FlowGraphViewer.svelte +++ b/frontend/src/lib/components/FlowGraphViewer.svelte @@ -38,7 +38,6 @@ stepDetail = e.detail dispatch('select', stepDetail) }} - rebuildOnChange={flow} /> {/if} diff --git a/frontend/src/lib/components/FlowJobResult.svelte b/frontend/src/lib/components/FlowJobResult.svelte index 41209fad98..9cb8eb382a 100644 --- a/frontend/src/lib/components/FlowJobResult.svelte +++ b/frontend/src/lib/components/FlowJobResult.svelte @@ -10,6 +10,7 @@ import type { DurationStatus } from './graph' import type { Writable } from 'svelte/store' + export let waitingForExecutor: boolean = false export let result: any export let logs: string | undefined export let col: boolean = false @@ -17,6 +18,7 @@ export let loading: boolean export let filename: string | undefined = undefined export let jobId: string | undefined = undefined + export let tag: string | undefined = undefined export let workspaceId: string | undefined = undefined export let refreshLog: boolean = false export let durationStates: Writable> | undefined @@ -79,9 +81,9 @@ {/if}
-
- +
diff --git a/frontend/src/lib/components/FlowStatusViewerInner.svelte b/frontend/src/lib/components/FlowStatusViewerInner.svelte index fcbbb82f2c..8951433312 100644 --- a/frontend/src/lib/components/FlowStatusViewerInner.svelte +++ b/frontend/src/lib/components/FlowStatusViewerInner.svelte @@ -167,7 +167,7 @@ mod.type === 'WaitingForEvents' && $localModuleStates?.[innerModules?.[i - 1]?.id ?? '']?.type == 'Success' ) { - setModuleState(mod.id ?? '', { type: mod.type, args: job?.args }) + setModuleState(mod.id ?? '', { type: mod.type, args: job?.args, tag: job?.tag }) } else if ( mod.type === 'WaitingForExecutor' && $localModuleStates[mod.id ?? '']?.scheduled_for == undefined @@ -183,7 +183,8 @@ scheduled_for: job?.['scheduled_for'], job_id: job?.id, parent_module: mod['parent_module'], - args: job?.args + args: job?.args, + tag: job?.tag } setModuleState(mod.id ?? '', newState) }) @@ -395,6 +396,7 @@ job_id: job.id, logs: job.logs, args: job.args, + tag: job.tag, started_at, parent_module: mod['parent_module'] }, @@ -413,6 +415,7 @@ logs: job.logs, result: job['result'], job_id: job.id, + tag: job.tag, parent_module: mod['parent_module'], duration_ms: job['duration_ms'], started_at: started_at, @@ -645,6 +648,7 @@ {/if} + diff --git a/frontend/src/lib/components/apps/editor/AppReportsDrawer.svelte b/frontend/src/lib/components/apps/editor/AppReportsDrawer.svelte index c2c160722e..5df6e41fb2 100644 --- a/frontend/src/lib/components/apps/editor/AppReportsDrawer.svelte +++ b/frontend/src/lib/components/apps/editor/AppReportsDrawer.svelte @@ -24,6 +24,7 @@ import { RotateCw, Save } from 'lucide-svelte' import { CUSTOM_TAGS_SETTING, WORKSPACE_SLACK_BOT_TOKEN_PATH } from '$lib/consts' import { loadSchemaFromPath } from '$lib/infer' + import { hubPaths } from '$lib/hub' export let appPath: string export let open = false @@ -187,7 +188,7 @@ export async function main(app_path: string, startup_duration = 5, kind: 'pdf' | const notificationScripts = { discord: { - path: 'hub/7838/discord', + path: hubPaths.discordReport, schema: { type: 'object', properties: { @@ -203,7 +204,7 @@ export async function main(app_path: string, startup_duration = 5, kind: 'pdf' | } }, slack: { - path: 'hub/7836/slack', // if to be updated, also update it in in backend/windmill-queue/src/jobs.rs + path: hubPaths.slackReport, // if to be updated, also update it in in backend/windmill-queue/src/jobs.rs schema: { type: 'object', properties: { @@ -216,7 +217,7 @@ export async function main(app_path: string, startup_duration = 5, kind: 'pdf' | } }, email: { - path: 'hub/7837/smtp', + path: hubPaths.smtpReport, schema: { type: 'object', properties: { diff --git a/frontend/src/lib/components/apps/editor/settingsPanel/DecisionTreeGraphEditor.svelte b/frontend/src/lib/components/apps/editor/settingsPanel/DecisionTreeGraphEditor.svelte index c159990519..70d4ad3bac 100644 --- a/frontend/src/lib/components/apps/editor/settingsPanel/DecisionTreeGraphEditor.svelte +++ b/frontend/src/lib/components/apps/editor/settingsPanel/DecisionTreeGraphEditor.svelte @@ -46,7 +46,6 @@ { diff --git a/frontend/src/lib/components/apps/editor/settingsPanel/DecisionTreeGraphHeader.svelte b/frontend/src/lib/components/apps/editor/settingsPanel/DecisionTreeGraphHeader.svelte index 21bad417bd..0a3302814f 100644 --- a/frontend/src/lib/components/apps/editor/settingsPanel/DecisionTreeGraphHeader.svelte +++ b/frontend/src/lib/components/apps/editor/settingsPanel/DecisionTreeGraphHeader.svelte @@ -1,65 +1,81 @@ -
-
-
{label}
-
- - {#if canDelete} -
- -
- {/if} - - {#if node.id !== 'end' && editable} + +
- dispatch('nodeInsert')} - on:addBranch={() => dispatch('addBranch')} - canAddBranch={false} - /> +
{data.node.label}
- {/if} -
+ + {#if data.canDelete} +
+ +
+ {/if} + + {#if data.node.id !== 'end'} +
+ { + data.nodeCallbackHandler( + 'nodeInsert', + data.node.id, + data.node, + data.parentIds ?? [], + data.branchHeader + ) + }} + on:addBranch={() => { + data.nodeCallbackHandler('addBranch', data.node.id, data.node, data.parentIds, true) + }} + canAddBranch={false} + /> +
+ {/if} +
+ diff --git a/frontend/src/lib/components/apps/editor/settingsPanel/DecisionTreeGraphNode.svelte b/frontend/src/lib/components/apps/editor/settingsPanel/DecisionTreeGraphNode.svelte index 4ab3578b41..53d23e7a88 100644 --- a/frontend/src/lib/components/apps/editor/settingsPanel/DecisionTreeGraphNode.svelte +++ b/frontend/src/lib/components/apps/editor/settingsPanel/DecisionTreeGraphNode.svelte @@ -1,5 +1,5 @@ -
- - - {#if canDelete} - - {/if} +
+ {data.node.label === '' ? `Tab: ${data.node.id}` : data.node.label} +
+ + Tab index: {data.index} + + You can manually select a node using the setTab function with this index in a frontend + runnable. + + + - {#if node.id !== 'end'} -
- dispatch('nodeInsert')} - on:addBranch={() => dispatch('addBranch')} - canAddBranch={canAddBranch || node.next.length > 1} - canAddNode={node.next.length <= 1} - /> -
- {/if} -
+ {#if data.canDelete} + + {/if} + + {#if data.node.id !== 'end'} +
+ { + data.nodeCallbackHandler('nodeInsert', data.node.id, data.node, data.parentIds, false) + }} + on:addBranch={() => { + data.nodeCallbackHandler('addBranch', data.node.id, data.node, data.parentIds, true) + }} + canAddBranch={data.canAddBranch || data.node.next.length > 1} + canAddNode={data.node.next.length <= 1} + /> +
+ {/if} + + diff --git a/frontend/src/lib/components/apps/editor/settingsPanel/decisionTree/DecisionTreePreview.svelte b/frontend/src/lib/components/apps/editor/settingsPanel/decisionTree/DecisionTreePreview.svelte index 9408962449..ab83790a41 100644 --- a/frontend/src/lib/components/apps/editor/settingsPanel/decisionTree/DecisionTreePreview.svelte +++ b/frontend/src/lib/components/apps/editor/settingsPanel/decisionTree/DecisionTreePreview.svelte @@ -1,16 +1,15 @@ - + +
-{#if mounted} - -{/if} + + diff --git a/frontend/src/lib/components/apps/editor/settingsPanel/decisionTree/nodeHelpers.ts b/frontend/src/lib/components/apps/editor/settingsPanel/decisionTree/nodeHelpers.ts index cdb285c5bf..4b6949daa4 100644 --- a/frontend/src/lib/components/apps/editor/settingsPanel/decisionTree/nodeHelpers.ts +++ b/frontend/src/lib/components/apps/editor/settingsPanel/decisionTree/nodeHelpers.ts @@ -1,4 +1,5 @@ -import { NODE, type Node } from '$lib/components/graph' +import { NODE } from '$lib/components/graph' +import { type Node } from '@xyflow/svelte' interface NodeConfig { id: string @@ -35,12 +36,7 @@ export function createNode(nodeConfig: NodeConfig): Node { position: nodeConfig.position || { x: -1, y: -1 }, data: nodeConfig.data, width: nodeConfig.width || NODE.width, - height: nodeConfig.height || NODE.height, - borderColor: nodeConfig.borderColor || '#999', - sourcePosition: 'bottom', - targetPosition: 'top', - parentIds: nodeConfig.parentIds || [], - loopDepth: nodeConfig.loopDepth || 0 + height: nodeConfig.height || NODE.height } } diff --git a/frontend/src/lib/components/flows/map/FlowModuleSchemaMap.svelte b/frontend/src/lib/components/flows/map/FlowModuleSchemaMap.svelte index 118b672270..3941e310ce 100644 --- a/frontend/src/lib/components/flows/map/FlowModuleSchemaMap.svelte +++ b/frontend/src/lib/components/flows/map/FlowModuleSchemaMap.svelte @@ -258,7 +258,6 @@ scroll {minHeight} moving={$moving?.module.id} - rebuildOnChange={$flowStore} maxHeight={minHeight} modules={$flowStore.value?.modules} {selectedId} @@ -269,8 +268,6 @@ const cb = () => { push(history, $flowStore) - console.log('deleting node', e.id) - selectNextId(e.id) removeAtId($flowStore.value.modules, e.id) diff --git a/frontend/src/lib/components/flows/map/VirtualItem.svelte b/frontend/src/lib/components/flows/map/VirtualItem.svelte index 6258dfe0bf..52e9d2bb22 100644 --- a/frontend/src/lib/components/flows/map/VirtualItem.svelte +++ b/frontend/src/lib/components/flows/map/VirtualItem.svelte @@ -1,25 +1,16 @@ -{#if insertable && deleteBranch} -
- -
-{/if}
{ - if (selectable) { - if (id) { +======= + style="width: 275px; max-height: 34px; background-color: {bgColor} !important;" +>>>>>>> main dispatch('select', id) - } else { dispatch('select', label) } } @@ -97,70 +69,3 @@
- -{#if insertable && modules && label == 'Input'} - {#if !disableAi} -
- - - {#if !$copilotInfo.exists_openai_resource_path} -
-

- Enable Windmill AI in the - { - close() - }} - > - workspace settings - - -

-
- {/if} -
-
- {/if} -
- { - if (modules) { - dispatch('insert', { - modules, - index: 0, - detail: e.detail - }) - } - }} - index={0} - modules={modules ?? []} - /> -
-{/if} diff --git a/frontend/src/lib/components/graph/FlowGraph.svelte b/frontend/src/lib/components/graph/FlowGraph.svelte deleted file mode 100644 index 9fa4146d66..0000000000 --- a/frontend/src/lib/components/graph/FlowGraph.svelte +++ /dev/null @@ -1,893 +0,0 @@ - - - - - -
- {#if !error} - {#if width && height} - {#key renderCount} - { - try { - localStorage.setItem('svelvet', encodeState({ modules, failureModule })) - } catch (e) { - console.error('error interacting with local storage', e) - } - window.open('/view_graph', '_blank') - }} - {download} - highlightEdges={false} - locked - bind:dataflow - {nodes} - width={fullSize ? fullWidth : width} - {edges} - {height} - {scroll} - nodeSelected={showDataflow} - background={false} - /> - {/key} - {/if} - {:else} -
- Error computing the graph: {error} -
- {/if} -
diff --git a/frontend/src/lib/components/graph/FlowGraphV2.svelte b/frontend/src/lib/components/graph/FlowGraphV2.svelte index 0f57d5041d..46d0a0c11d 100644 --- a/frontend/src/lib/components/graph/FlowGraphV2.svelte +++ b/frontend/src/lib/components/graph/FlowGraphV2.svelte @@ -40,7 +40,6 @@ export let maxHeight: number | undefined = undefined export let notSelectable = false export let flowModuleStates: Record | undefined = undefined - export let rebuildOnChange: any = undefined export let selectedId: Writable = writable(undefined) @@ -177,7 +176,7 @@ $nodes = layoutNodes(graph?.nodes) $edges = graph.edges - height = Math.max(...$nodes.map((n) => n.position.y + NODE.height), minHeight) + height = Math.max(...$nodes.map((n) => n.position.y + NODE.height + 40), minHeight) } $: graph && updateStores() @@ -205,17 +204,6 @@ const proOptions = { hideAttribution: true } - function handleNodeClick(e: CustomEvent) { - const mod = e.detail.node.data.module as FlowModule - - if (!notSelectable && mod) { - if ($selectedId != mod.id) { - $selectedId = mod.id - } - dispatch('select', mod) - } - } - $: showDataflow = $selectedId != undefined && !$selectedId.startsWith('constants') && @@ -225,7 +213,7 @@ const viewport = writable({ x: 0, - y: 100, + y: 5, zoom: 1 }) @@ -240,7 +228,7 @@ $: width && centerViewport(width) -
+
handleNodeClick(e)} >
diff --git a/frontend/src/lib/components/graph/index.ts b/frontend/src/lib/components/graph/index.ts index a1802f6a3c..7c0d23e403 100644 --- a/frontend/src/lib/components/graph/index.ts +++ b/frontend/src/lib/components/graph/index.ts @@ -1,4 +1,2 @@ -export { default as FlowGraph } from './FlowGraph.svelte' - export * from './model' export * from './util' diff --git a/frontend/src/lib/components/graph/model.ts b/frontend/src/lib/components/graph/model.ts index fb268a5acc..e6b61d29db 100644 --- a/frontend/src/lib/components/graph/model.ts +++ b/frontend/src/lib/components/graph/model.ts @@ -1,18 +1,9 @@ import type { FlowStatusModule, Job } from '$lib/gen' import type { Writable } from 'svelte/store' -import type { UserNodeType } from './svelvet/types' import type { FlowState } from '../flows/flowState' export type ModuleHost = 'workspace' | 'inline' | 'hub' -export type Node = UserNodeType & { - parentIds: string[] - edgeLabel?: string - host?: ModuleHost - type: 'node' - loopDepth: number -} - export type Loop = { type: 'loop' items: NestedNodes @@ -50,6 +41,7 @@ export type GraphModuleState = { flow_jobs_results?: any branchChosen?: number result?: any + tag?: string scheduled_for?: Date job_id?: string parent_module?: string diff --git a/frontend/src/lib/components/graph/renderers/edges/BaseEdge.svelte b/frontend/src/lib/components/graph/renderers/edges/BaseEdge.svelte index c39b498ac0..39bac15583 100644 --- a/frontend/src/lib/components/graph/renderers/edges/BaseEdge.svelte +++ b/frontend/src/lib/components/graph/renderers/edges/BaseEdge.svelte @@ -29,7 +29,7 @@ disableMoveIds: string[] } - $: [edgePath, labelX, labelY] = getBezierPath({ + $: [edgePath] = getBezierPath({ sourceX, sourceY: targetY - sourceY > 100 ? targetY - 100 : sourceY, sourcePosition, @@ -47,13 +47,15 @@ const { useDataflow } = getContext<{ useDataflow: Writable }>('FlowGraphContext') + + let menuOpen = false {#if data?.insertable && !$useDataflow && !data?.moving}
{ data?.eventHandlers.insert({ modules: data.modules, index: data.index, detail: e.detail }) }} + bind:open={menuOpen} />
{#if data.enableTrigger}
{#if data.moving && !data.disableMoveIds?.includes(data.moving)} - - - {#if download} - - {/if} -
- - diff --git a/frontend/src/lib/components/graph/svelvet/container/views/Svelvet.svelte b/frontend/src/lib/components/graph/svelvet/container/views/Svelvet.svelte deleted file mode 100644 index 955226b9b2..0000000000 --- a/frontend/src/lib/components/graph/svelvet/container/views/Svelvet.svelte +++ /dev/null @@ -1,131 +0,0 @@ - - - -
- {#if error != ''} -
{error}
- {:else} - - {/if} -
- - diff --git a/frontend/src/lib/components/graph/svelvet/customCss/controllers/getCss.ts b/frontend/src/lib/components/graph/svelvet/customCss/controllers/getCss.ts deleted file mode 100644 index 16e68814cf..0000000000 --- a/frontend/src/lib/components/graph/svelvet/customCss/controllers/getCss.ts +++ /dev/null @@ -1,50 +0,0 @@ -// Required for "custom css" feature - -import type { NodeType, StoreType } from '../../store/types/types' - -// WHAT: For a given node with a user-defined classname, see if there are any css properties for height and width -// Get that height and width and set properties in node store. This is necessary for -export const forceCssHeightAndWidth = (store: StoreType, node: NodeType) => { - let width, height, innerText - // Look through each CSS rule to find the one the user defined - for (let i = 0; i < document.styleSheets.length; i++) { - const styleSheet = document.styleSheets[i] - const styleRules = styleSheet.cssRules - for (let j = 0; j < styleRules.length; j++) { - const rule = styleRules[j] - - // this is necessary to get rid of typescript warning for rule.selectorText - if (!(rule instanceof CSSStyleRule)) continue - - if (rule.selectorText === `.${node.className}`) { - const initialText = rule.cssText // getting the full text of the CSS rule - const i = initialText.indexOf('{') // finding index of first bracket - innerText = initialText.substring(i + 1, initialText.length - 1) // extracting the CSS to insert into inline style - // Adjusting the width and height if they are set via the custom class - const arr = innerText.split(' ') - arr.forEach((str, i) => { - if (str === 'width:') { - width = str.concat(arr[i + 1]) // go through the array and join width and the number - const w = parseInt(arr[i + 1]) // getting the number for the width - width = w - } - if (str === 'height:') { - height = str.concat(arr[i + 1]) // same as with the width - const h = parseInt(arr[i + 1]) - height = h - } - }) - } - } - } - - // update the width/height of the node - store.nodesStore.update((nodes) => { - if (width !== undefined) nodes[node.id].width = width - if (height !== undefined) nodes[node.id].height = height - return { ...nodes } - }) - - // move the node a bit to force update to anchors, potential anchors - node.setPositionFromMovement(0, 0) -} diff --git a/frontend/src/lib/components/graph/svelvet/d3/controllers/d3.ts b/frontend/src/lib/components/graph/svelvet/d3/controllers/d3.ts deleted file mode 100644 index 8eec38fccd..0000000000 --- a/frontend/src/lib/components/graph/svelvet/d3/controllers/d3.ts +++ /dev/null @@ -1,91 +0,0 @@ -// import { zoom, zoomTransform } from 'd3-zoom'; -// import { select, selectAll } from 'd3-selection'; -import type { ZoomBehavior } from 'd3-zoom'; -import { get } from 'svelte/store'; - -export function zoomInit( - d3, - canvasId, - d3Zoom, - d3Translate, - initialLocation, - initialZoom, - d3Scale -) { - //set default zoom logic - d3.select(`.Edges-${canvasId}`) - //makes sure translation is default at center coordinates - .transition() - .duration(0) - .call(d3Zoom.translateTo, 0, 0) - //moves camera to coordinates - .transition() - .duration(0) - .call( - d3Zoom.translateTo, - initialLocation.x / initialZoom, - initialLocation.y / initialZoom - ) - // zooms in on selected point - .transition() - .duration(0) - .call(d3Zoom.scaleTo, initialZoom.toFixed(2)); - // updates d3Translate with d3 object with x, y, and k values to be sent down to the minimap to be further calculated further - d3Translate = d3.zoomIdentity - .translate(initialLocation.x, initialLocation.y) - .scale(initialZoom.toFixed(2)); - d3.select(`.Nodes-${canvasId}`) - .transition() - .duration(0) - .call(d3Zoom.translateTo, 0, 0) - .transition() - .duration(0) - .call( - d3Zoom.translateTo, - initialLocation.x / initialZoom, - initialLocation.y / initialZoom - ) - .transition() - .duration(0) - .call(d3Zoom.scaleTo, initialZoom.toFixed(2)); - // sets D3 scale to current k of object - d3Scale.set(d3.zoomTransform(d3.select(`.Nodes-${canvasId}`)).k); - return d3Translate; -} -// create d3 instance conditionally based on boundary prop -export function determineD3Instance( - boundary, - d3: { zoom: () => ZoomBehavior }, - nodeSelected, - width, - height, - movementStore, - backgroundStore, - gridSize, - dotSize, - canvasId, - d3Scale, - handleZoom -): ZoomBehavior { - if (boundary) { - return d3 - .zoom() - .filter(() => !get(nodeSelected)) - .scaleExtent([0.4, 4]) // limits for zooming in/out - .translateExtent([ - [0, 0], - [boundary.x, boundary.y], - ]) // world extent - .extent([ - [0, 0], - [width, height], - ]) - .on('zoom', handleZoom); - } else { - return d3 - .zoom() - .filter(() => !get(nodeSelected)) - .scaleExtent([0.4, 2]) - .on('zoom', handleZoom); - } -} diff --git a/frontend/src/lib/components/graph/svelvet/edges/controllers/anchorCbDev.ts b/frontend/src/lib/components/graph/svelvet/edges/controllers/anchorCbDev.ts deleted file mode 100644 index 342698f25f..0000000000 --- a/frontend/src/lib/components/graph/svelvet/edges/controllers/anchorCbDev.ts +++ /dev/null @@ -1,119 +0,0 @@ -import { rightCb, leftCb, topCb, bottomCb } from './anchorCbUser' // these are callbacks used to calculate anchor position relative to node -import type { AnchorCbType } from '../../edges/types/types' -import type { StoreType } from '../../store/types/types' - -import { getAnchors } from './util' -import { getNodeById } from '../../nodes/controllers/util' -export function fixedCbCreator( - store: StoreType, - edgeId: string, - anchorId: string, - userNodeId: string, - positionCb: Function // positionCb should be a function that takes 4 arguments (x,y,width,height) and returns a 3-array [x,y,angle] that represents the x,y position of the anchor as well as it's angle with respect to it's node. -) { - const rn = fixedCb - rn.type = 'fixed' - return rn - - function fixedCb() { - // get the two anchors - const anchors = getAnchors(store, { edgeId: edgeId }) - if (anchors.length !== 2) throw `there should be two anchors per edge, have: ${anchors.length}` - let [anchorSelf, anchorOther] = anchors - if (anchorSelf.id !== anchorId) [anchorSelf, anchorOther] = [anchorOther, anchorSelf] - - const node = getNodeById(store, userNodeId) - const { positionX, positionY, width, height } = node - const [x, y, angle] = positionCb(positionX, positionY, width, height) - anchorSelf.positionX = x - anchorSelf.positionY = y - anchorSelf.angle = angle - // update the other anchor if it is a dynamic anchor - // Note dyanamic anchor callbacks have a check that prevents an infinite loop - if (anchorOther.callback.type === 'dynamic') anchorOther.callback() - } -} - -export function dynamicCbCreator(store: StoreType, edgeId: string, anchorId: string) { - const rn = dynamicCb - rn.type = 'dynamic' - return rn - - function dynamicCb() { - // get the two anchors - const anchors = getAnchors(store, { edgeId: edgeId }) - if (anchors.length !== 2) throw `there should be two anchors per edge, have: ${anchors.length}` - - let [anchorSelf, anchorOther] = anchors - if (anchorSelf.id !== anchorId) [anchorSelf, anchorOther] = [anchorOther, anchorSelf] - // get the two nodes - const nodeSelf = getNodeById(store, anchorSelf.nodeId) - const nodeOther = getNodeById(store, anchorOther.nodeId) - // get the midpoints - const [xSelf, ySelf, xOther, yOther] = [ - nodeSelf.positionX + nodeSelf.width / 2, - nodeSelf.positionY + nodeSelf.height / 2, - nodeOther.positionX + nodeOther.width / 2, - nodeOther.positionY + nodeOther.height / 2 - ] - - // record angle for later. We use this so we don't have an infinite loop - let prevAngle = anchorSelf.angle - - // calculate the slope - const slope = (ySelf - yOther) / (xSelf - xOther) - // slope<1 means -45 to 45 degrees so left/right anchors - if (Math.abs(slope) < 1) { - // self node is on the left, other node is on the right - if (nodeSelf.positionX < nodeOther.positionX) { - const [selfX, selfY] = rightCb( - nodeSelf.positionX, - nodeSelf.positionY, - nodeSelf.width, - nodeSelf.height - ) - leftCb(nodeOther.positionX, nodeOther.positionY, nodeOther.width, nodeOther.height) - anchorSelf.setPosition(selfX, selfY) - anchorSelf.angle = 0 // if the self node is on the left, the anchor should have orientation of 0 degrees on the unit circle - } else { - // in this case, the self node is on the right and the other node is on the left - const [selfX, selfY] = leftCb( - nodeSelf.positionX, - nodeSelf.positionY, - nodeSelf.width, - nodeSelf.height - ) - rightCb(nodeOther.positionX, nodeOther.positionY, nodeOther.width, nodeOther.height) - anchorSelf.setPosition(selfX, selfY) - anchorSelf.angle = 180 - } - } else { - if (nodeSelf.positionY < nodeOther.positionY) { - // here the self node is above the other node - const [selfX, selfY] = bottomCb( - nodeSelf.positionX, - nodeSelf.positionY, - nodeSelf.width, - nodeSelf.height - ) - topCb(nodeOther.positionX, nodeOther.positionY, nodeOther.width, nodeOther.height) - anchorSelf.setPosition(selfX, selfY) - anchorSelf.angle = 270 - } else { - const [selfX, selfY] = topCb( - nodeSelf.positionX, - nodeSelf.positionY, - nodeSelf.width, - nodeSelf.height - ) - bottomCb(nodeOther.positionX, nodeOther.positionY, nodeOther.width, nodeOther.height) - anchorSelf.setPosition(selfX, selfY) - anchorSelf.angle = 90 - } - } - - // if the anchor changed position, then do operation for other anchor - // otherwise, don't do anything. This check is so we don't have an infinite loop - if (prevAngle !== anchorSelf.angle) anchorOther.callback() - } -} diff --git a/frontend/src/lib/components/graph/svelvet/edges/controllers/anchorCbUser.ts b/frontend/src/lib/components/graph/svelvet/edges/controllers/anchorCbUser.ts deleted file mode 100644 index 69e4d86bcd..0000000000 --- a/frontend/src/lib/components/graph/svelvet/edges/controllers/anchorCbUser.ts +++ /dev/null @@ -1,98 +0,0 @@ -/** - * These are callbacks used to define anchor positions relative to the node they are attached to. - * These may be provided to developers as examples of how to write their own custom callbacks for adjustable anchors - * It calculates the position of an anchor (x,y) coordinates given a node parameterized by (x,y,width, height) - */ - -/** - * @function rightCb - This is a callback function to define the anchor position on the node to be on the right side of the node. - * @param xNode - positionX of the attached node - * @param yNode - positionY of the attached node - * @param widthNode - width of the attached node - * @param heightNode - height of the attached node - * @returns [xAnchor, yAnchor, 0] - * xAnchor - positionX for the anchor - * yAnchor - positionY for the anchor - * 0 - this is angle of the anchor with respect to the node. The right anchor should fall at 0 degrees on the unit circle. - * @export rightCb - */ -export const rightCb = ( - xNode: number, - yNode: number, - widthNode: number, - heightNode: number -) => { - const xAnchor = xNode + widthNode; - const yAnchor = yNode + heightNode / 2; - return [xAnchor, yAnchor, 0]; -}; - -/** - * @function leftCb - This is a callback function to define the anchor position on the node to be on the left side of the node. - * @param xNode - positionX of the attached node - * @param yNode - positionY of the attached node - * @param widthNode - width of the attached node - * @param heightNode - height of the attached node - * @returns [xAnchor, yAnchor, 180] - * xAnchor - positionX for the anchor - * yAnchor - positionY for the anchor - * 180 - this is angle of the anchor with respect to the node. The left anchor should fall at 180 degrees on the unit circle. - * @export leftCb - */ -export const leftCb = ( - xNode: number, - yNode: number, - widthNode: number, - heightNode: number -) => { - const xAnchor = xNode; - const yAnchor = yNode + heightNode / 2; - return [xAnchor, yAnchor, 180]; -}; - -/** - * @function topCb - This is a callback function to define the anchor position on the node to be on the top of the node. - * @param xNode - positionX of the attached node - * @param yNode - positionY of the attached node - * @param widthNode - width of the attached node - * @param heightNode - height of the attached node - * @returns [xAnchor, yAnchor, 90] - * xAnchor - positionX for the anchor - * yAnchor - positionY for the anchor - * 90 - this is angle of the anchor with respect to the node. The top anchor should fall at 90 degrees on the unit circle. - * @export topCb - */ - -export const topCb = ( - xNode: number, - yNode: number, - widthNode: number, - heightNode: number -) => { - const xAnchor = xNode + widthNode / 2; - const yAnchor = yNode; - return [xAnchor, yAnchor, 90]; -}; - -/** - * @function bottomCb - This is a callback function to define the anchor position on the node to be on the bottom of the node. - * @param xNode - positionX of the attached node - * @param yNode - positionY of the attached node - * @param widthNode - width of the attached node - * @param heightNode - height of the attached node - * @returns - [xAnchor, yAnchor, 90] - * xAnchor - positionX for the anchor - * yAnchor - positionY for the anchor - * 270 - this is angle of the anchor with respect to the node. The bottom anchor should fall at 270 degrees on the unit circle. - * @export bottomCb - */ -export const bottomCb = ( - xNode: number, - yNode: number, - widthNode: number, - heightNode: number -) => { - const xAnchor = xNode + widthNode / 2; - const yAnchor = yNode + heightNode; - return [xAnchor, yAnchor, 270]; -}; diff --git a/frontend/src/lib/components/graph/svelvet/edges/controllers/util.ts b/frontend/src/lib/components/graph/svelvet/edges/controllers/util.ts deleted file mode 100644 index 7fdb1281da..0000000000 --- a/frontend/src/lib/components/graph/svelvet/edges/controllers/util.ts +++ /dev/null @@ -1,78 +0,0 @@ -import type { StoreType } from '../../store/types/types' -import { get } from 'svelte/store' -import type { AnchorType } from '../types/types' - -/** - * Finds all Anchors that matches the conditions specified in the filter parameter from a Svelvet store and returns these Anchors in an array. - * - * @param store The Svelvet store containing the state of a Svelvet component - * @param filter An object to specify conditions. Example: if filter = \{ sourceOrTarget: 'source', positionX: 35 \} then we will return all anchors with sourceOrTarget = source AND poxitionX = 35 - * @returns An array of Anchors that matches the conditions specified in the filter parameter - */ -export function getAnchors(store: StoreType, filter?: { [key: string]: any }) { - let anchors = Object.values(get(store.anchorsStore)) - // filter the array of anchors for elements that match filter - // Example: if filter = {sourceOrTarget: 'source', positionX: 35} then we will - //return all anchors with sourceOrTarget = source AND poxitionX = 35 - if (filter !== undefined) { - anchors = anchors.filter((anchor) => { - for (let filterKey in filter) { - const filterValue = filter[filterKey] - if (anchor[filterKey as keyof AnchorType] !== filterValue) return false - } - return true - }) - } - // return list of anchors - return anchors -} - -/** - * Gets one anchor (source anchor or target anchor) from a given edge - * - * @param store The Svelvet store containing the state of the Svelvet component - * @param edgeId The id of a given edge - * @param sourceOrTarget A string of 'source' or 'target' to specify which anchor the function should return - * @returns The source or target Anchor object of a given edge - */ -export function getAnchorFromEdge( - store: StoreType, - edgeId: string, - sourceOrTarget: 'source' | 'target' -): AnchorType { - getEdgeById(store, edgeId) - const anchors = getAnchors(store, { edgeId: edgeId }) - if (anchors.length !== 2) - throw `there should be two anchors for a given edge, there are ${anchors.length}` - // there should be one source anchor and one target anchor. Return the source anchor - const anchor = anchors.filter((anchor) => anchor.sourceOrTarget === sourceOrTarget) - if (anchor.length !== 1) throw `there should only be one source/target anchor` - return anchor[0] -} - -/** - * getEdgeById will look for the targeted Edge that has the same id provided in the Svelvet component store. - * - * @param store The Svelvet store containing the state of a Svelvet component - * @param id The id of the targeted Node - * @returns The targeted Edge object in store.edgesStore - */ -export function getEdgeById(store: StoreType, id: string) { - const edgesStore = get(store.edgesStore) - const edge = edgesStore[id] - if (edge === undefined) throw 'edge not found' - return edge -} - -/** - * getAnchorById will look for the targeted Anchor that has the same id in the Svelvet component store. - * - * @param store The Svelvet store containing the state of a Svelvet component - * @param id The id of the targeted Anchor - * @returns The target Anchor object in store.anchorsStore - */ -export function getAnchorById(store: StoreType, id: string) { - const anchorsStore = get(store.anchorsStore) - const anchor = anchorsStore[id] - return anchor -} diff --git a/frontend/src/lib/components/graph/svelvet/edges/models/Anchor.ts b/frontend/src/lib/components/graph/svelvet/edges/models/Anchor.ts deleted file mode 100644 index daa9b25b51..0000000000 --- a/frontend/src/lib/components/graph/svelvet/edges/models/Anchor.ts +++ /dev/null @@ -1,119 +0,0 @@ -/** - * This is where we create, update the Anchor store. - */ - -import type { AnchorCbType, AnchorType } from '../../edges/types/types'; -import { stores } from '../../store/models/store'; -import { getAnchors } from '../controllers/util'; - -/** Class representing an Anchor that implements Anchortype. - * @param {string} id The id of the Anchor - * @param {string} nodeId The id of the Node which the instantiated Anchor will be attached to - * @param {string} edgeId The id of the Edge which connects to the instantiated Anchor - * @param {'source' | 'target'} sourceOrTarget Specify the Anchor is a source or target - * @param {number} positionX The 'X' coordinate of the Anchor - * @param {number} positionY The 'Y' coordinate of the Anchor - * @param {function} callback The callback function that will determine the position of this Anchor - * @param {string} canvasId The canvasId of the Svelvet component that will hold this Anchor - * @param { number } angle This is the orientation of the anchor and is used to make sure bezier/step curves are rendered perpendicular to the node. Angles are defined along the unit circle. EX: 0 = right side of node, 180 = left side of node. - */ -export class Anchor implements AnchorType { - constructor( - public id: string, - public nodeId: string, - public edgeId: string, - public sourceOrTarget: 'source' | 'target', - public positionX: number, - public positionY: number, - public callback: AnchorCbType, - public canvasId: string, - public angle: 0 | 90 | 180 | 270 - ) {} - - getOtherAnchorId() { - const store = stores[this.canvasId]; - const anchors = getAnchors(store, { edgeId: this.edgeId }); - if (anchors.length !== 2) - throw 'something is wrong, every anchor should have exactly one other associated anchor'; - const anchor = anchors.filter((anchor) => anchor.id !== this.id)[0]; - return anchor.id; - } - - /** - * setPositionFromNode will invoke the user-defined callback to calculate the position of the Anchor, set the position of the Anchor in the anchorsStore, and also update the Edge position accordingly. - */ - setPositionFromNode() { - // calculate the new position of the anchor using user-defined callback - this.callback(); - const { edgesStore } = stores[this.canvasId]; - // update edges - edgesStore.update((edges) => { - const edge = edges[this.edgeId]; - if (this.sourceOrTarget === 'source') { - edge.sourceX = this.positionX; - edge.sourceY = this.positionY; - } else { - edge.targetX = this.positionX; - edge.targetY = this.positionY; - } - return { ...edges }; - }); - } - /** - * updateEdges will update the edgesStore based on Anchor's change. - */ - updateEdges() { - const { edgesStore } = stores[this.canvasId]; - /** update edges by deconstructing edges store and setting its new vlue to stores[this.canvasID] */ - - edgesStore.update((edges) => { - const edge = edges[this.edgeId]; - // this means that no edge was found, just return without doing anything - - if (edge === undefined) { - return { ...edges }; - } - if (this.sourceOrTarget === 'source') { - edge.sourceX = this.positionX; - edge.sourceY = this.positionY; - } else { - edge.targetX = this.positionX; - edge.targetY = this.positionY; - } - return { ...edges }; - }); - } - - /** - * setPosition will update the positionX and positionY of the Anchor and also cascade changes to related Edge. - * @param x The X coordinate of the new position for the Anchor - * @param y The Y coordinate of the new position for the Anchor - */ - setPosition(x: number, y: number) { - this.positionX = x; - this.positionY = y; - this.updateEdges(); - } - - /** - * Anchor.setPositionFromMovement works similarly to Anchor.setPosition. But setPosition is more powerful and we recommend using setPosition whenever possible and in the future, setPositionFromMovement can be removed. - * @param movementX The mouse movement value on the X-axis - * @param movementY The mouse movement value on the Y-axis - */ - setPositionFromMovement(movementX: number, movementY: number) { - this.positionX += movementX; - this.positionY += movementY; - const { edgesStore } = stores[this.canvasId]; - edgesStore.update((edges) => { - const edge = edges[this.edgeId]; - if (this.sourceOrTarget === 'source') { - edge.sourceX += movementX; - edge.sourceY += movementY; - } else { - edge.targetX += movementX; - edge.targetY += movementY; - } - return { ...edges }; - }); - } -} diff --git a/frontend/src/lib/components/graph/svelvet/edges/models/Edge.ts b/frontend/src/lib/components/graph/svelvet/edges/models/Edge.ts deleted file mode 100644 index f6f6ca8339..0000000000 --- a/frontend/src/lib/components/graph/svelvet/edges/models/Edge.ts +++ /dev/null @@ -1,95 +0,0 @@ -import { findStore } from '../../store/models/store' -import type { UserEdgeType } from '../../types/types' -import type { EdgeType } from '../../store/types/types' - -import { stores } from '../../store/models/store' -import { getAnchors, getAnchorFromEdge } from '../../edges/controllers/util' -/** - * Class Edge that implements EdgeType. - * @param id The id of the Edge - * @param sourceX The X coordinate of the source Anchor - * @param sourceY The Y coordinate of the source Anchor - * @param targetX The X coordinate of the target Anchor - * @param targetY The Y coordinate of the target Anchor - * @param canvasId The canvasId of the Svelvet component that holds the instantiated Edge - * @param label The label of the Edge - * @param type The type of the Edge (options: 'straight', 'smoothstep', 'step', or 'bezier'). If user doesn't specify, the type will default to 'bezier'. - * @param labelBgColor The background color of the Edge label - * @param labelTextColor The text color of the Edge label - * @param edgeColor The color of the Edge - * @param animate Boolean value to specify whether the Edge should be animated - * @param noHandle Boolean value but looks like it is already depracated and can be removed without damage - * @param arraw Boolean value to specify whether the Edge displays an arrow near its target Anchor - */ -export class Edge implements EdgeType { - constructor( - public id: string, - public sourceX: number, - public sourceY: number, - public targetX: number, - public targetY: number, - public canvasId: string, - public label: string, - public type: 'straight' | 'smoothstep' | 'step' | 'bezier', - public labelBgColor: string, - public labelTextColor: string, - public edgeColor: string, - public animate: boolean, - public noHandle: boolean, - public arrow: boolean, - public clickCallback: Function, - public className: string, - public offset?: number - ) {} - - /** - * delete is going to delete the Edge and also delete associated Anchors - */ - delete() { - const store = stores[this.canvasId] - const { anchorsStore, edgesStore } = store - const sourceAnchor = getAnchorFromEdge(store, this.id, 'source') // this is a bit wasteful - const targetAnchor = getAnchorFromEdge(store, this.id, 'target') - anchorsStore.update((anchors) => { - for (const anchorId in anchors) { - if (anchorId === sourceAnchor.id || anchorId == targetAnchor.id) delete anchors[anchorId] - } - return { ...anchors } - }) - edgesStore.update((edges) => { - delete edges[this.id] - return { ...edges } - }) - } - - /** - * setExportableData will construct an object that holds all the edge data that can be exported. This is needed for the Exporting Diagram feature. - * @returns The object of exportable edge data. The format of the object should be as close as what user initially passes in to Svelvet. - */ - setExportableData() { - const exportableData: UserEdgeType = { - id: this.id, - label: this.label, - type: this.type, - labelBgColor: this.labelBgColor, - labelTextColor: this.labelTextColor, - edgeColor: this.edgeColor, - animate: this.animate, - noHandle: this.noHandle, - arrow: this.arrow, - source: 'dummy', // these will be set later - target: 'dummy' // these will be set later - } - - // set source, target on exportableData - const store = findStore(this.canvasId) - const anchors = getAnchors(store, { edgeId: this.id }) - if (anchors.length !== 2) throw 'there should be two anchors per edge' - for (const anchor of anchors) { - if (anchor.sourceOrTarget === 'target') exportableData.target = anchor.nodeId - if (anchor.sourceOrTarget === 'source') exportableData.source = anchor.nodeId - } - - return exportableData - } -} diff --git a/frontend/src/lib/components/graph/svelvet/edges/types/types.ts b/frontend/src/lib/components/graph/svelvet/edges/types/types.ts deleted file mode 100644 index 57917fc098..0000000000 --- a/frontend/src/lib/components/graph/svelvet/edges/types/types.ts +++ /dev/null @@ -1,19 +0,0 @@ -export type AnchorCbType = { - (): void; - type: 'dynamic' | 'fixed'; -}; - -export interface AnchorType { - id: string; // note that the user never specifies an anchor and they are generated dynamically. id will be a random string. - nodeId: string; - edgeId: string; - sourceOrTarget: 'source' | 'target'; - positionX: number; - positionY: number; - callback: AnchorCbType; // callback is used to calculate positionX, positionY based on parent node's data, and set the anchor position // TODO: rename to something better - angle: number; - setPositionFromNode: Function; - setPosition: Function; - updateEdges: Function; - getOtherAnchorId: Function; -} diff --git a/frontend/src/lib/components/graph/svelvet/edges/views/Edges/BaseEdge.svelte b/frontend/src/lib/components/graph/svelvet/edges/views/Edges/BaseEdge.svelte deleted file mode 100644 index 59b09bf80f..0000000000 --- a/frontend/src/lib/components/graph/svelvet/edges/views/Edges/BaseEdge.svelte +++ /dev/null @@ -1,108 +0,0 @@ - - - - - - - - - -{#if highlightEdgesOption} - {}} - /> -{/if} - -{#if arrow} - -{:else} - -{/if} - -{#if edgeTextProps.label} - -{/if} - - diff --git a/frontend/src/lib/components/graph/svelvet/edges/views/Edges/EdgeText.svelte b/frontend/src/lib/components/graph/svelvet/edges/views/Edges/EdgeText.svelte deleted file mode 100644 index 8e2021f6df..0000000000 --- a/frontend/src/lib/components/graph/svelvet/edges/views/Edges/EdgeText.svelte +++ /dev/null @@ -1,48 +0,0 @@ - - -{#if typeof label === 'undefined' || !label} - {null} -{:else} - - - - {label} - - -{/if} diff --git a/frontend/src/lib/components/graph/svelvet/edges/views/Edges/SimpleBezierEdge.svelte b/frontend/src/lib/components/graph/svelvet/edges/views/Edges/SimpleBezierEdge.svelte deleted file mode 100644 index e3c606ef8c..0000000000 --- a/frontend/src/lib/components/graph/svelvet/edges/views/Edges/SimpleBezierEdge.svelte +++ /dev/null @@ -1,175 +0,0 @@ - - - diff --git a/frontend/src/lib/components/graph/svelvet/edges/views/Edges/SmoothStepEdge.svelte b/frontend/src/lib/components/graph/svelvet/edges/views/Edges/SmoothStepEdge.svelte deleted file mode 100644 index 88ee91a754..0000000000 --- a/frontend/src/lib/components/graph/svelvet/edges/views/Edges/SmoothStepEdge.svelte +++ /dev/null @@ -1,157 +0,0 @@ - - - diff --git a/frontend/src/lib/components/graph/svelvet/edges/views/Edges/StepEdge.svelte b/frontend/src/lib/components/graph/svelvet/edges/views/Edges/StepEdge.svelte deleted file mode 100644 index 0e192fcd5f..0000000000 --- a/frontend/src/lib/components/graph/svelvet/edges/views/Edges/StepEdge.svelte +++ /dev/null @@ -1,8 +0,0 @@ - - - - diff --git a/frontend/src/lib/components/graph/svelvet/edges/views/Edges/types.ts b/frontend/src/lib/components/graph/svelvet/edges/views/Edges/types.ts deleted file mode 100644 index 48a97a8582..0000000000 --- a/frontend/src/lib/components/graph/svelvet/edges/views/Edges/types.ts +++ /dev/null @@ -1,58 +0,0 @@ -import type { XYPosition, Position } from './utils'; - -export interface Node { - id: number; - position: XYPosition; - data: T; - width: number; - height: number; - bgColor?: string; - fontSize?: number; - borderColor?: string; - borderRadius?: number; - textColor?: string; - clickCallback?: Function; - image?: boolean; - src?: string; - sourcePosition?: 'left' | 'right' | 'top' | 'bottom'; - targetPosition?: 'left' | 'right' | 'top' | 'bottom'; -} - -export interface Edge { - id: string; - source: number; - target: number; - label?: string; - labelBgColor?: string; - labelTextColor?: string; - edgeColor?: string; - type?: string; - animate?: boolean; - noHandle?: boolean; - arrow?: boolean; -} - -export interface DerivedEdge extends Edge { - sourceX: number; - sourceY: number; - sourcePosition: Position; - targetX: number; - targetY: number; - targetPosition: Position; -} - -export interface EdgeProps extends DerivedEdge { - path: string; - centerX: number; - centerY: number; -} - -export interface EdgeTextProps { - label?: any; - labelBgColor?: string; - labelTextColor?: string; - centerX: number; - centerY: number; -} - -export type HandleType = 'source' | 'target'; diff --git a/frontend/src/lib/components/graph/svelvet/edges/views/Edges/utils.ts b/frontend/src/lib/components/graph/svelvet/edges/views/Edges/utils.ts deleted file mode 100644 index 8685e6e3e8..0000000000 --- a/frontend/src/lib/components/graph/svelvet/edges/views/Edges/utils.ts +++ /dev/null @@ -1,84 +0,0 @@ -// enumerable values (static) set for Position -export enum Position { - Left = 'left', - Right = 'right', - Top = 'top', - Bottom = 'bottom', -} - -// interface for XYPosition to use in nodes and edges -export interface XYPosition { - x: number; - y: number; -} - -// type for z axis positioning with D3 -export type XYZPosition = XYPosition & { z: number }; - -// interface for changing dimensions of Viewport -export interface Dimensions { - width: number; - height: number; -} - -// interface of Rect divs in zoompane -export interface Rect extends Dimensions, XYPosition {} - -// interface of Box using XYPosition of nodes -export interface Box extends XYPosition { - x2: number; - y2: number; -} - -// D3 type array for Transform -export type Transform = [number, number, number]; - -// -// export type CoordinateExtent = [[number, number], [number, number]]; - -export interface GetCenterParams { - sourceX: number; - sourceY: number; - targetX: number; - targetY: number; - sourcePosition?: Position; - targetPosition?: Position; -} -//needed for getCenter funciotn -const LeftOrRight = [Position.Left, Position.Right]; -//used to determine the position for edge text on a Smooth or Step Edge -export const getCenter = ({ - sourceX, - sourceY, - targetX, - targetY, - sourcePosition = Position.Bottom, - targetPosition = Position.Top, -}: GetCenterParams): [number, number, number, number] => { - const sourceIsLeftOrRight = LeftOrRight.includes(sourcePosition); - const targetIsLeftOrRight = LeftOrRight.includes(targetPosition); - - // we expect flows to be horizontal or vertical (all handles left or right respectively top or bottom) - // a mixed edge is when one the source is on the left and the target is on the top for example. - const mixedEdge = - (sourceIsLeftOrRight && !targetIsLeftOrRight) || - (targetIsLeftOrRight && !sourceIsLeftOrRight); - - if (mixedEdge) { - const xOffset = sourceIsLeftOrRight ? Math.abs(targetX - sourceX) : 0; - const centerX = sourceX > targetX ? sourceX - xOffset : sourceX + xOffset; - - const yOffset = sourceIsLeftOrRight ? 0 : Math.abs(targetY - sourceY); - const centerY = sourceY < targetY ? sourceY + yOffset : sourceY - yOffset; - - return [centerX, centerY, xOffset, yOffset]; - } - - const xOffset = Math.abs(targetX - sourceX) / 2; - const centerX = targetX < sourceX ? targetX + xOffset : targetX - xOffset; - - const yOffset = Math.abs(targetY - sourceY) / 2; - const centerY = targetY < sourceY ? targetY + yOffset : targetY - yOffset; - - return [centerX, centerY, xOffset, yOffset]; -}; diff --git a/frontend/src/lib/components/graph/svelvet/nodes/controllers/util.ts b/frontend/src/lib/components/graph/svelvet/nodes/controllers/util.ts deleted file mode 100644 index f3aff1d3b3..0000000000 --- a/frontend/src/lib/components/graph/svelvet/nodes/controllers/util.ts +++ /dev/null @@ -1,16 +0,0 @@ -import type { StoreType } from '../../store/types/types'; -import { get } from 'svelte/store'; - -/** - * getNodeById will look for the targeted Node that has the same id provided in the Svelvet component store. - * - * @param store The Svelvet store containing the state of a Svelvet component - * @param id The id of the targeted Node - * @returns The targeted Node object in store.nodesStore - */ - -export function getNodeById(store: StoreType, id: string) { - const nodesStore = get(store.nodesStore); - const node = nodesStore[id]; - return node; -} diff --git a/frontend/src/lib/components/graph/svelvet/nodes/models/Node.ts b/frontend/src/lib/components/graph/svelvet/nodes/models/Node.ts deleted file mode 100644 index cbadfde187..0000000000 --- a/frontend/src/lib/components/graph/svelvet/nodes/models/Node.ts +++ /dev/null @@ -1,156 +0,0 @@ -/** this is where we create our node store */ -import type { NodeType } from '../../store/types/types' -import { get } from 'svelte/store' -import { stores } from '../../store/models/store' -/** A Node class that implements NodeType interface - * @param {string} id The id of the Node - * @param {number} positionX The X-axis position of the Node (left top corner of the Node) - * @param {number} positionY The Y-axis position of the Node (left top corner of the Node) - * @param {number} width The width of the Node - * @param {number} height The height of the Node - * @param {string} bgColor The background color of the node - * @param {object} data A data object that user can specify; possible keys are 'label' and 'custom'; - * @param {string} canvasId The canvasId of the Svelvet component that the instantiated Node will be on. - * @param {string} borderColor The border color of the Node - * @param {boolean} image A boolean set to true if the Node needs to display an image - * @param {string} src The src link for the image; image and src are closely tied and a src link is only needed when image sets to true - * @param {string} textColor The color of the text in the Node - * @param {string} borderRadius The border radius of the Node - * @param {string} childNodes An array of node ids that will be grouped as child nodes of this Node. This is for the GroupNodes feature. The current implementation of this feature works one way but not the other (when you drag the parent node, the child nodes will move as a group but when you drag the child node, the parent node would not move along) - * @param {string} className The custom class name if user specifies. This is for the custom className feature for Node. - */ -export class Node implements NodeType { - constructor( - public id: string, - public positionX: number, - public positionY: number, - public width: number, - public height: number, - public bgColor: string, - public data: object, - public canvasId: string, - public borderColor: string, - public image: boolean, - public src: string, - public textColor: string, - public borderRadius: number, - public childNodes: string[], - public className: string, - public clickCallback: Function - ) {} - - /** - * setPositionFromMovement will update the positionX and positionY of the Node when user drags a Node around on the canvas, reflect the changes in real time in the nodesStore, and also cascade the changes to all relative elements like Anchors and Edges. - * @param {number} movementX The mouse movement value on the X-axis - * @param {number} movementY The mouse movement value on the Y-axis - */ - setPositionFromMovement(movementX: number, movementY: number) { - const { nodesStore, anchorsStore, potentialAnchorsStore, boundary, lockedOption } = - stores[this.canvasId] - - if (get(lockedOption)) return // don't do anything if locked is enabled - - // boundary sets the boundary of the canvas, or else it is false if their is no boundary - // check if out of bounds, and if so return without doing anything - const boundaryObj = get(boundary) - if ( - typeof boundaryObj === 'object' && - (this.positionX + this.width + movementX >= boundaryObj.x || - this.positionY + this.height + movementY >= boundaryObj.y || - this.positionY + movementY <= 0 || - this.positionX + movementX <= 0) - ) - return - //update all necessary data - this.positionX += movementX - this.positionY += movementY - - // update children - nodesStore.update((nodes) => { - if (this.childNodes) - for (const childNodeId of this.childNodes) - nodes[childNodeId].setPositionFromMovement(movementX, movementY) - return { ...nodes } - }) - - //update all the anchors on the node in the anchorsStore - anchorsStore.update((anchors) => { - for (const anchorId in anchors) { - if (anchors[anchorId].nodeId === this.id) { - anchors[anchorId].setPositionFromNode() - } - } - return { ...anchors } - }) - - //update all the anchors on the node in the anchorsStore - potentialAnchorsStore.update((anchors) => { - for (const anchorId in anchors) { - if (anchors[anchorId].nodeId === this.id) { - anchors[anchorId].callback() // we don't have to worry about setting partner anchors/etc; - } - } - return { ...anchors } - }) - } - - /** - * setSizeFromMovement will update the width and height of the Node when user resizes the Node by dragging at the right bottom corner (where the ResizedNode attached), reflect the changes in real time in the nodesStore, and also cascade the changes to all relative elements like Anchors and potential Anchors. - * - * @param movementX The mouse movement value on the X-axis - * @param movementY The mouse movement value on the Y-axis - */ - setSizeFromMovement(movementX: number, movementY: number) { - this.width += movementX - this.height += movementY - - const { anchorsStore, potentialAnchorsStore } = stores[this.canvasId] - - //Updates the anchor so it follows the node's position as the dimensions change - anchorsStore.update((anchors) => { - for (const anchorId in anchors) { - if (anchors[anchorId].nodeId === this.id) { - anchors[anchorId].setPositionFromNode() - //anchors[anchorId].setPosition(movementX, movementY); - } - } - return { ...anchors } - }) - - //update all the anchors on the node in the anchorsStore - potentialAnchorsStore.update((anchors) => { - for (const anchorId in anchors) { - if (anchors[anchorId].nodeId === this.id) { - anchors[anchorId].callback() // we don't have to worry about setting partner anchors/etc; - } - } - return { ...anchors } - }) - } - - /** - * setExportableData is going to construct an object that holds all the node data that can be exported. This method is used for Exporting Diagrams feature. - * - * @returns An object with all the exportable data of the Node. The format of this object should align with the original format of node data user provided. - */ - setExportableData() { - const exportableData = { - id: this.id, - // canvasId: this.canvasId, - width: this.width, - height: this.height, - position: { x: this.positionX, y: this.positionY }, - data: this.data, - bgColor: this.bgColor, - borderColor: this.borderColor, - textColor: this.textColor, - borderRadius: this.borderRadius, - image: this.image, - src: this.src, - childNodes: this.childNodes, - customClassName: this.className - } - - return exportableData - } -} diff --git a/frontend/src/lib/components/graph/svelvet/nodes/views/Node.svelte b/frontend/src/lib/components/graph/svelvet/nodes/views/Node.svelte deleted file mode 100644 index f409fe9d26..0000000000 --- a/frontend/src/lib/components/graph/svelvet/nodes/views/Node.svelte +++ /dev/null @@ -1,91 +0,0 @@ - - - -
- - {#if node.image} - - {/if} - -
- - diff --git a/frontend/src/lib/components/graph/svelvet/store/controllers/storeApi.ts b/frontend/src/lib/components/graph/svelvet/store/controllers/storeApi.ts deleted file mode 100644 index 3cbb7ffe93..0000000000 --- a/frontend/src/lib/components/graph/svelvet/store/controllers/storeApi.ts +++ /dev/null @@ -1,103 +0,0 @@ -/* - - -Important functions (in order of how likely I think you are to use them): - -findStore(canvasId: string) -- Input: canvasId. There can be multiple Svelvet canvases on the same page, and each has their own store -- Returns: store -- Notes: You will need to call this function on every component you make - -getNodes(store, filter) -- Description: this function returns of list of Node objects -- Input: store: the store where you get the list of Node objects from -- filter: an object where you can filter the array. For example, if you want to find nodes with an id of 'sdf-2d3fs' and positionX=35, then you - would set filter = {id: 'sdf-2d3fs, positionX: 35}. - Right now, you can only test for equality. -- Notes: This is a very mongoose way of retrieving information. Given the relational nature of our stores, maybe it would be better to use an SQL-like syntax - This array is non-reactive (ie, you cannot use information from this array to force a re-render of a Svelte component) - -createStoreEmpty(canvasId: string) -- Input: canvasId. -- Returns: store -- Notes. This should be called once every time you initialize a new Svelvet canvas, (ie, only in the Svelvet.svelte file) - -populateSvelvetStoreFromUserInput(canvasId, nodes, edges) -- canvasId: this the the canvasId of the Svelvet component you are creating a store for -- nodes: this is an array of objects containing node info that is defined by the user. NOTE THAT THE STRUCTURE DIFFERS FROM THE NODES CLASS - The whole point of populateSvelvetStoreFromUserInput is to convert nodes into proper Svelvet Node objects. An example of nodes is in - $routes/testingplayground/index.svelte -- edges: same as nodes, this is an array of objects containing edge info THAT IS DIFFERENT FROM THE EDGE CLASS. -- Returns: store -*/ -import { findStore, stores } from '../models/store' -import { writable } from 'svelte/store' - -import type { StoreType } from '../types/types' -import type { UserNodeType, UserEdgeType } from '../../types/types' -import { populateAnchorsStore, populateNodesStore, populateEdgesStore } from './util' - - -/** - * createStoreEmpty will initialize a new Svelvet store with a unique canvasId. - * If you have multiple Svelvet components on the page, the stores object will look like the following example: - * const stores = \{ - * canvasId-1: store of Svelvet component 1, - * canvasId-2: store of Svelvet component 2, - * canvasId-3: store of Svelvet component 3, - * \} - * Notes: This should be called once every time you initialize a new Svelvet canvas, (ie, only in the Svelvet.svelte file). - * This function will initialize an empty store for the Svelvet component and should be followed by invoking populateSvelvetStoreFromUserInput to populate all the initial state from the user input. - * - * @param canvasId The canvasId of the newly created Svelvet component - * @returns An empty store for the newly created Svelvet component. - */ -export function createStoreEmpty(canvasId: string): StoreType { - stores[canvasId] = { - nodesStore: writable({}), - edgesStore: writable({}), - anchorsStore: writable({}), - potentialAnchorsStore: writable({}), - widthStore: writable(600), - heightStore: writable(600), - backgroundStore: writable(false), - movementStore: writable(true), - nodeSelected: writable(false), - nodeIdSelected: writable(-1), - d3Scale: writable(1), - options: writable({}), - temporaryEdgeStore: writable([]), - nodeCreate: writable(false), // this option sets whether the "nodeEdit" feature is enabled - boundary: writable(false), - edgeEditModal: writable(null), // this is used for edgeEditModal feature. When an edge is right clicked, store.edgeEditModal is set to the edgeId string. This causes a modal to be rendered - lockedOption: writable(false), - editableOption: writable(false), // true if you want nodes/edges to be editable. See feature editEdges - d3ZoomParameters: writable({}), // this stores d3 parameters x, y, and zoom. This isn't used for anything other than giving users a way to access d3 zoom parameters if they want to build on top of Svelvet - highlightEdgesOption: writable(true) // option to turn on/off highlightable edges - } - return stores[canvasId] -} - -/** - * populateSvelvetStoreFromUserInput will populate all the states and set these states into the Svelvet store initialized by invoking createStoreEmpty - * - * @param canvasId The canvasId of the Svelvet component you are creating a store for - * @param nodes This is an array of objects containing node info that is defined by the user. NOTE THAT THE STRUCTURE DIFFERS FROM THE NODES CLASS. The whole point of populateSvelvetStoreFromUserInput is to convert nodes into proper Svelvet Node objects. An example of nodes is in $routes/testingplayground/index.svelte - * @param edges Same as nodes, this is an array of objects containing edge info THAT IS DIFFERENT FROM THE EDGE CLASS. - */ -export function populateSvelvetStoreFromUserInput( - canvasId: string, - nodes: UserNodeType[], - edges: UserEdgeType[] -): void { - // find the store - const store = findStore(canvasId) - - // populate store.nodesStore with user nodes - populateNodesStore(store, nodes, canvasId) - // populate store.anchorsStore with anchors. Note the userdoes not explictly define anchors; anchors are calculated from the edges - populateAnchorsStore(store, nodes, edges, canvasId) - // populate edges - populateEdgesStore(store, edges, canvasId) - -} diff --git a/frontend/src/lib/components/graph/svelvet/store/controllers/userApi.ts b/frontend/src/lib/components/graph/svelvet/store/controllers/userApi.ts deleted file mode 100644 index edeec17454..0000000000 --- a/frontend/src/lib/components/graph/svelvet/store/controllers/userApi.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { findStore } from '../models/store'; -import { get } from 'svelte/store'; -export function getD3PositionX(canvasId) { - const store = findStore(canvasId); - const width = get(store.widthStore); - const x = width / 2 - get(store.d3ZoomParameters).x; // user input is shifted so that x=0, y=0 occurs in the center - return x; -} -export function getD3PositionY(canvasId) { - const store = findStore(canvasId); - const height = get(store.heightStore); - const y = height / 2 - get(store.d3ZoomParameters).y; // user input is shifted so that x=0, y=0 occurs in the center - return y; -} -export function getD3Zoom(canvasId) { - const store = findStore(canvasId); - return get(store.d3ZoomParameters).k; -} diff --git a/frontend/src/lib/components/graph/svelvet/store/controllers/util.ts b/frontend/src/lib/components/graph/svelvet/store/controllers/util.ts deleted file mode 100644 index bcd42fe9a1..0000000000 --- a/frontend/src/lib/components/graph/svelvet/store/controllers/util.ts +++ /dev/null @@ -1,215 +0,0 @@ -const pkStringGenerator = () => (Math.random() + 1).toString(36).substring(7) // these are callbacks used to calculate anchor position relative to node -import { dynamicCbCreator, fixedCbCreator } from '../../edges/controllers/anchorCbDev' - -import type { AnchorCbType, AnchorType } from '../../edges/types/types' - -import type { UserEdgeType, UserNodeType } from '../../types/types' -import type { EdgeType, NodeType, StoreType } from '../types/types' - -import { getAnchors } from '../../edges/controllers/util' -import { Anchor } from '../../edges/models/Anchor' -import { Edge } from '../../edges/models/Edge' -import { Node } from '../../nodes/models/Node' - -/** - * Creates an Anchor on the targeted Node with infomation the userNode holds - * @param store An object containing the state of the Svelvet component. You can access the following through `store`: nodesStore, edgesStore, anchorsStore, etc. - * @param userNode A node that the user specifies. This is NOT the same as a Node object. - * @param sourceOrTarget User specified information of source or target - * @param canvasId The id of the canvas that holds the Anchor and its attached Node - * @param edge An edge that the user specifies. It should target the userNode as source or target. This is NOT the same as an Edge object - * @returns An Anchor object - */ - -function createAnchor( - store: StoreType, - userNode: UserNodeType | null, - sourceOrTarget: 'source' | 'target', - canvasId: string, - edge: UserEdgeType -) { - // edge case - if (userNode === null) throw `you cannot create an anchor without a user node (for now)` - - const edgeId = edge.id - const anchorId = pkStringGenerator() - - // userCb is the appropriate source or taret callback from userEdge object. It is - // possible the user to NOT set userCb in which case userCb will be undefined - let userCb: Function | undefined - if (sourceOrTarget === 'target') userCb = edge.targetAnchorCb - else userCb = edge.sourceAnchorCb - - // create anchor callbacks - - let cb: AnchorCbType - if (userCb === undefined) cb = dynamicCbCreator(store, edgeId, anchorId) - else cb = fixedCbCreator(store, edgeId, anchorId, userNode.id, userCb) - - // Create a new anchor. - const anchor = new Anchor( - anchorId, - userNode.id, - edgeId, - sourceOrTarget, - -1, // dummy variables for x,y,angle for now - -1, // dummy variables for x,y,angle for now - cb, - canvasId, - 0 // dummy variables for x,y,angle for now - ) - // return - return anchor -} - -/** - * Populates edgesStore of Edges. This function does not return the edgesStore. Instead it sets the nodesStore of Svelvet store. - * @param store An object containing the state of the Svelvet component. You can access the following through `store`: nodesStore, edgesStore, anchorsStore, etc. - * @param edges An edge that the user specifies. This is NOT the same as a Edge object. - * @param canvasId The canvasId of the Svelvet component that holds the Edges - */ -export function populateEdgesStore(store: StoreType, edges: UserEdgeType[], canvasId: string) { - const edgesStore: { [key: string]: EdgeType } = {} - for (let i = 0; i < edges.length; i++) { - const userEdge = edges[i] - // { id: 'e1-2', source: 1, type: 'straight', target: 2, label: 'e1-2' }, - // source is node.id for the source node - // target is node.id for the target node - // We need to get the anchors - const { id: edgeId } = userEdge - - const anchors = getAnchors(store, { edgeId: edgeId }) - // check that we have two anchors for every edge - if (anchors.length !== 2) throw 'We should have two anchors for every node' - // check that we have 1 source anchor and 1 target anchor. Since sourceOrTarget is typed to be either 'source' - // or 'target', it suffices to check whether there are two unique elements - if (new Set(anchors.map((e) => e.sourceOrTarget)).size !== 2) - throw 'we should have one source and one target anchor' - // get source and target anchor - let sourceAnchor, targetAnchor - if (anchors[0].sourceOrTarget === 'source') { - sourceAnchor = anchors[0] - targetAnchor = anchors[1] - } else { - sourceAnchor = anchors[1] - targetAnchor = anchors[0] - } - - edgesStore[edgeId] = new Edge( - edgeId, - sourceAnchor.positionX, - sourceAnchor.positionY, - targetAnchor.positionX, - targetAnchor.positionY, - canvasId, - userEdge.label === undefined ? '' : userEdge.label, - userEdge.type === undefined ? 'bezier' : userEdge.type, - userEdge.labelBgColor === undefined ? 'white' : userEdge.labelBgColor, - userEdge.labelTextColor === undefined ? 'black' : userEdge.labelTextColor, - userEdge.edgeColor === undefined ? 'black' : userEdge.edgeColor, - userEdge.animate === undefined ? false : userEdge.animate, - userEdge.noHandle === undefined ? false : userEdge.noHandle, - userEdge.arrow === undefined ? false : userEdge.arrow, - userEdge.clickCallback === undefined ? () => {} : userEdge.clickCallback, - userEdge.className === undefined ? '' : userEdge.className, - userEdge.offset - ) - } - store.edgesStore.set(edgesStore) -} - -/** - * Finds userNode (with UserNodeType; Not the same as the Node) by the node id from nodesStore - * @param id The id of the Node in its nodesStore - * @param userNodes The array of userNodes (NOT the same as Node object) - * @returns The node that user specified or null if not found - */ -function findUserNodeById(id: string, userNodes: UserNodeType[]): UserNodeType | null { - for (let i = 0; i < userNodes.length; i++) { - const userNode = userNodes[i] - if (userNode.id === id) return userNode - } - return null -} - -/** - * Populates the anchorsStore. This will overwrite any data in the AnchorsStore. - * @param store The Svelvet store containing the state of the Svelvet component - * @param nodes An array of user specified nodes - * @param edges An array of user specified edges - * @param canvasId The canvasId of the Svelvet component that holds the nodes and edges - */ -export function populateAnchorsStore( - store: StoreType, - nodes: UserNodeType[], - edges: UserEdgeType[], - canvasId: string -) { - // anchorsStore will populated and eventaully synchronized to store.anchorsStore - const anchorsStore: { [key: string]: AnchorType } = {} - // iterate through user edges. Note the user never explicitly defines anchors; we calculate anchors - // from the user edge/node information - for (let i = 0; i < edges.length; i++) { - const userEdge = edges[i] - // find the source and target userNodes. These will be used to create the nodeId foreign key and - // determine placement of the anchor based on userNode.targetPosition, useNode.sourcePosition - const { source: sourceNodeId, target: targetNodeId } = userEdge - const sourceUserNode = findUserNodeById(sourceNodeId, nodes) - const targetUserNode = findUserNodeById(targetNodeId, nodes) - // create source anchor - const sourceAnchor = createAnchor(store, sourceUserNode, 'source', canvasId, userEdge) - // create target anchor - const targetAnchor = createAnchor(store, targetUserNode, 'target', canvasId, userEdge) - // store source and target anchors - anchorsStore[sourceAnchor.id] = sourceAnchor - anchorsStore[targetAnchor.id] = targetAnchor - } - - //populates the anchorsStore - store.anchorsStore.set(anchorsStore) - - // set anchor positions. We can only set anchor positions after anchorsStore and nodesStore - // has been populated. TODO: maybe add a check to see that anchorsStore and NodesStore populated? - const anchors = getAnchors(store) - for (const anchor of anchors) anchor.callback() -} - -/** - * Populates the nodesStore. This will overwrite any data in the nodesStore. - * @param store The Svelvet store containing the state of the Svelvet component - * @param nodes An array of user specifed nodes - * @param canvasId The canvasId of the Svelvet component that holds the nodes - */ -export function populateNodesStore(store: StoreType, nodes: UserNodeType[], canvasId: string) { - // this is the nodesStore object. THIS IS NOT THE SAME AS A NODESTORE - const nodesStore: { [key: string]: NodeType } = {} - // iterate through user nodes and create node objects - for (let i = 0; i < nodes.length; i++) { - const userNode: UserNodeType = nodes[i] - const nodeId = userNode.id - - // TODO: move sanitizing default values to middleware - const node = new Node( - nodeId.toString(), - userNode.position.x, - userNode.position.y, - userNode.width, - userNode.height, - userNode.bgColor ?? 'white', - userNode.data, - canvasId, - userNode.borderColor === undefined ? 'black' : userNode.borderColor, - userNode.image === undefined ? false : userNode.image, - userNode.src === undefined ? '' : userNode.src, - userNode.textColor === undefined ? '' : userNode.textColor, - userNode.borderRadius === undefined ? 0 : userNode.borderRadius, - userNode.childNodes === undefined ? [] : userNode.childNodes, - userNode.className === undefined ? '' : userNode.className, - userNode.clickCallback === undefined ? () => {} : userNode.clickCallback - ) - - nodesStore[nodeId] = node - } - // This is actually what sets the store - store.nodesStore.set(nodesStore) -} diff --git a/frontend/src/lib/components/graph/svelvet/store/models/store.ts b/frontend/src/lib/components/graph/svelvet/store/models/store.ts deleted file mode 100644 index 0765623a9a..0000000000 --- a/frontend/src/lib/components/graph/svelvet/store/models/store.ts +++ /dev/null @@ -1,15 +0,0 @@ -import type { StoreType } from '../types/types'; - - -export function findStore(canvasId: string): StoreType { - return stores[canvasId] -} -/** - `store` is a dictionary of Svelvet stores. - * The reason why we have multiple Svelvet stores is to handle multiple canvases on the same page. - * A Svelvet store is the single source of truth for a canvas state. - * We discourage developers from interacting with stores directly; instead use the api methods in - `src/lib/controllers/storeApi.ts`. However, if need to direct access you can do so by importing: - `import { store } from 'src/lib/models/store';` -*/ -export const stores: { [key: string]: StoreType } = {}; diff --git a/frontend/src/lib/components/graph/svelvet/store/types/types.ts b/frontend/src/lib/components/graph/svelvet/store/types/types.ts deleted file mode 100644 index 8cd17b95a6..0000000000 --- a/frontend/src/lib/components/graph/svelvet/store/types/types.ts +++ /dev/null @@ -1,122 +0,0 @@ -import type { Writable } from 'svelte/store' -import type { AnchorType } from '../../edges/types/types' - -export interface ResizeNodeType { - id: string - nodeId: string - edgeId?: string - canvasId: string - anchorId?: string - positionX: number - positionY: number - setPositionAndCascade: Function - setPosition: Function - delete: Function -} - -/* -Type for a single svelvet store -*/ -export interface StoreType { - nodesStore: Writable<{ [key: string]: NodeType }> - edgesStore: Writable<{ [key: string]: EdgeType }> - anchorsStore: Writable<{ [key: string]: AnchorType }> - potentialAnchorsStore: Writable<{ [key: string]: PotentialAnchorType }> - widthStore: Writable - heightStore: Writable - backgroundStore: Writable - movementStore: Writable - nodeIdSelected: Writable - nodeSelected: Writable // this is used to stop d3 panning when node is being dragged - d3Scale: Writable // for zoom and pan - options: Writable<{ [key: string]: any }> - temporaryEdgeStore: Writable - nodeCreate: Writable // this option sets whether the "nodeEdit" feature is enabled - boundary: Writable - edgeEditModal: Writable // this options is used to place the edgeEdit modal when an edge is right-clicked. null is no modal, positionType if modal should be placed at position defined by postionType.x, positionType.y - lockedOption: Writable - editableOption: Writable - d3ZoomParameters: Writable<{ - [key: string]: number - }> - highlightEdgesOption: Writable -} - -export interface PositionType { - x: number - y: number -} - -export interface NodeType { - id: string - width: number - height: number - positionX: number - positionY: number - bgColor: string - data: { - html?: any - custom?: { component: any; props?: any; cb?: (e: string, detail: any) => void } - img?: any - label?: string - } - canvasId: string - setPositionFromMovement: Function - setSizeFromMovement: Function - setExportableData: Function - borderColor: string - image: boolean - src: string - textColor: string - borderRadius: number - childNodes: string[] - className: string //This is for custom className for node - clickCallback: Function // user-supplied callback that executes when the node is clicked -} - -export interface EdgeType { - id: string - sourceX: number - sourceY: number - targetX: number - targetY: number - canvasId: string - label: string - type: 'straight' | 'smoothstep' | 'step' | 'bezier' - labelBgColor: string - labelTextColor: string - edgeColor: string - animate: boolean - noHandle: boolean - arrow: boolean - clickCallback: Function - className: string - delete: Function - setExportableData: Function -} - -export interface PotentialAnchorType { - id: string - nodeId: string - callback: Function // callback is used to calculate positionX, positionY based on parent node's data, and set the anchor position // TODO: rename to something better - positionX: number - positionY: number - angle: number - canvasId: string - delete: Function -} - -export interface TemporaryEdgeType { - id: string - sourcePotentialAnchorId: string // this will always be set - sourceX: number - sourceY: number - targetPotentialAnchorId: string | null // this will be null until the temporary edge reaches another temporary anchor - targetX: number - targetY: number - canvasId: string - type: string - edgeColor: string - createEdge: Function - createNode: Function -} diff --git a/frontend/src/lib/components/graph/svelvet/types/README.md b/frontend/src/lib/components/graph/svelvet/types/README.md deleted file mode 100644 index 85773d6efc..0000000000 --- a/frontend/src/lib/components/graph/svelvet/types/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Types - -This folder contains types exported to the user, as decribed in feature: `https://www.svelvet.io/docs/typescript/` diff --git a/frontend/src/lib/components/graph/svelvet/types/index.ts b/frontend/src/lib/components/graph/svelvet/types/index.ts deleted file mode 100644 index 22937de732..0000000000 --- a/frontend/src/lib/components/graph/svelvet/types/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -// this file exports user types -import type { UserEdgeType, UserNodeType } from './types' -export type { UserEdgeType, UserNodeType } diff --git a/frontend/src/lib/components/graph/svelvet/types/types.ts b/frontend/src/lib/components/graph/svelvet/types/types.ts deleted file mode 100644 index b24b3672ed..0000000000 --- a/frontend/src/lib/components/graph/svelvet/types/types.ts +++ /dev/null @@ -1,60 +0,0 @@ -export interface UserNodeType { - id: string - width: number - height: number - bgColor?: string - data: { - html?: any - custom?: { component: any; props?: any; cb?: (e: string, detail: any) => void } - img?: any - } - position: { x: number; y: number } - borderColor?: string | undefined - image?: boolean - src?: string - textColor?: string - targetPosition?: 'left' | 'right' | 'top' | 'bottom' - sourcePosition?: 'left' | 'right' | 'top' | 'bottom' - borderRadius?: number - childNodes?: string[] - className?: string - clickCallback?: Function -} - -export interface UserEdgeType { - id: string - source: string - target: string - sourceAnchorCb?: Function - targetAnchorCb?: Function - label?: string - labelBgColor?: string - labelTextColor?: string - edgeColor?: string - type?: 'straight' | 'smoothstep' | 'step' | 'bezier' | undefined - animate?: boolean - noHandle?: boolean - arrow?: boolean - clickCallback?: Function - className?: string - offset?: number -} - -import { findStore } from '../store/models/store' -import { get } from 'svelte/store' -export function getD3PositionX(canvasId: string) { - const store = findStore(canvasId) - const width = get(store.widthStore) - const x = width / 2 - get(store.d3ZoomParameters).x // user input is shifted so that x=0, y=0 occurs in the center - return x -} -export function getD3PositionY(canvasId: string) { - const store = findStore(canvasId) - const height = get(store.heightStore) - const y = height / 2 - get(store.d3ZoomParameters).y // user input is shifted so that x=0, y=0 occurs in the center - return y -} -export function getD3Zoom(canvasId: string) { - const store = findStore(canvasId) - return get(store.d3ZoomParameters).k -} diff --git a/frontend/src/lib/components/graph/util.ts b/frontend/src/lib/components/graph/util.ts index 91b1f2dfa4..f3c3d1bbb3 100644 --- a/frontend/src/lib/components/graph/util.ts +++ b/frontend/src/lib/components/graph/util.ts @@ -9,13 +9,6 @@ export const NODE = { } } -export function* createIdGenerator(): Generator { - let id = 0 - while (true) { - yield id++ - } -} - export function getStateColor( state: FlowStatusModule['type'] | undefined, isDark: boolean, diff --git a/frontend/src/lib/hub.ts b/frontend/src/lib/hub.ts index cb4fba3f2a..f5ff47ff1a 100644 --- a/frontend/src/lib/hub.ts +++ b/frontend/src/lib/hub.ts @@ -1,6 +1,7 @@ import type { Schema } from './common' import { AppService, FlowService, type Flow, type Script } from './gen' import { encodeState } from './utils' +import rawHubPaths from './hubPaths.json?raw' export function scriptToHubUrl( content: string, @@ -55,3 +56,15 @@ export function appToHubUrl(staticApp: any, hubBaseUrl: string): URL { url.searchParams.append('app', encodeState(staticApp)) return url } + +type HubPaths = { + gitSync: string + gitSyncTest: string + slackErrorHandler: string + slackRecoveryHandler: string + slackReport: string + discordReport: string + smtpReport: string +} + +export const hubPaths = JSON.parse(rawHubPaths) as HubPaths diff --git a/frontend/src/lib/hubPaths.json b/frontend/src/lib/hubPaths.json new file mode 100644 index 0000000000..5d274614a0 --- /dev/null +++ b/frontend/src/lib/hubPaths.json @@ -0,0 +1,9 @@ +{ + "gitSync": "hub/8931/sync-script-to-git-repo-windmill", + "gitSyncTest": "hub/8944/git-repo-test-read-write-windmill", + "slackErrorHandler": "hub/6512/workspace-or-schedule-error-handler-slack", + "slackRecoveryHandler": "hub/2430/slack/schedule-recovery-handler-slack", + "slackReport": "hub/7836/slack", + "discordReport": "hub/7838/discord", + "smtpReport": "hub/7837/smtp" +} \ No newline at end of file diff --git a/frontend/src/routes/(root)/(logged)/workspace_settings/+page.svelte b/frontend/src/routes/(root)/(logged)/workspace_settings/+page.svelte index 723336e2a3..a06bed1d34 100644 --- a/frontend/src/routes/(root)/(logged)/workspace_settings/+page.svelte +++ b/frontend/src/routes/(root)/(logged)/workspace_settings/+page.svelte @@ -55,6 +55,7 @@ type S3ResourceSettings } from '$lib/workspace_settings' import { base } from '$lib/base' + import { hubPaths } from '$lib/hub' type GitSyncTypeMap = { scripts: boolean @@ -138,7 +139,7 @@ | 'error_handler') ?? 'users' let usingOpenaiClientCredentialsOauth = false - const latestGitSyncHubScript = `hub/8931/sync-script-to-git-repo-windmill` + const latestGitSyncHubScript = hubPaths.gitSync // function getDropDownItems(username: string): DropdownItem[] { // return [ // { @@ -566,7 +567,7 @@ } let jobId = await JobService.runScriptByPath({ workspace: $workspaceStore!, - path: 'hub/8944/git-repo-test-read-write-windmill', + path: hubPaths.gitSyncTest, requestBody: { repo_url_resource_path: gitSyncRepository.git_repo_resource_path.replace('$res:', '') } diff --git a/lsp/Pipfile b/lsp/Pipfile index 8a22af0897..fe8041a2cc 100644 --- a/lsp/Pipfile +++ b/lsp/Pipfile @@ -4,8 +4,8 @@ verify_ssl = true name = "pypi" [packages] -wmill = ">=1.380.0" -wmill_pg = ">=1.380.0" +wmill = ">=1.381.0" +wmill_pg = ">=1.381.0" sendgrid = "*" mysql-connector-python = "*" pymongo = "*" diff --git a/openflow.openapi.yaml b/openflow.openapi.yaml index d615b413b4..935672229f 100644 --- a/openflow.openapi.yaml +++ b/openflow.openapi.yaml @@ -1,7 +1,7 @@ openapi: "3.0.3" info: - version: 1.380.0 + version: 1.381.0 title: OpenFlow Spec contact: name: Ruben Fiszel diff --git a/powershell-client/WindmillClient/WindmillClient.psd1 b/powershell-client/WindmillClient/WindmillClient.psd1 index 0bcfd5576c..638344529e 100644 --- a/powershell-client/WindmillClient/WindmillClient.psd1 +++ b/powershell-client/WindmillClient/WindmillClient.psd1 @@ -12,7 +12,7 @@ RootModule = 'WindmillClient.psm1' # Version number of this module. -ModuleVersion = '1.380.0' +ModuleVersion = '1.381.0' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/python-client/wmill/pyproject.toml b/python-client/wmill/pyproject.toml index c0c4d05e87..07d2c21fe9 100644 --- a/python-client/wmill/pyproject.toml +++ b/python-client/wmill/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "wmill" -version = "1.380.0" +version = "1.381.0" description = "A client library for accessing Windmill server wrapping the Windmill client API" license = "Apache-2.0" homepage = "https://windmill.dev" diff --git a/python-client/wmill_pg/pyproject.toml b/python-client/wmill_pg/pyproject.toml index e3a85960d1..6f51fab915 100644 --- a/python-client/wmill_pg/pyproject.toml +++ b/python-client/wmill_pg/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "wmill-pg" -version = "1.380.0" +version = "1.381.0" description = "An extension client for the wmill client library focused on pg" license = "Apache-2.0" homepage = "https://windmill.dev" diff --git a/typescript-client/jsr.json b/typescript-client/jsr.json index 311f7343cd..8f9d365208 100644 --- a/typescript-client/jsr.json +++ b/typescript-client/jsr.json @@ -1,6 +1,6 @@ { "name": "@windmill/windmill", - "version": "1.380.0", + "version": "1.381.0", "exports": "./src/index.ts", "publish": { "exclude": ["!src", "./s3Types.ts", "./client.ts"] diff --git a/typescript-client/package.json b/typescript-client/package.json index 80f3aedfa1..11c14fa58a 100644 --- a/typescript-client/package.json +++ b/typescript-client/package.json @@ -1,7 +1,7 @@ { "name": "windmill-client", "description": "Windmill SDK client for browsers and Node.js", - "version": "1.380.0", + "version": "1.381.0", "author": "Ruben Fiszel", "license": "Apache 2.0", "devDependencies": { diff --git a/version.txt b/version.txt index 7c2b74d6ee..74c015aee9 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.380.0 +1.381.0