diff --git a/backend/ee-repo-ref.txt b/backend/ee-repo-ref.txt index b40437560a..1dcbbbf6c3 100644 --- a/backend/ee-repo-ref.txt +++ b/backend/ee-repo-ref.txt @@ -1 +1 @@ -664708fff04d4f9e0660bcae3edb307fb2c9481b +0b6bcd1a1537e255ec69131f27a92074ab3ce532 diff --git a/backend/tests/runnables_list_pagination.rs b/backend/tests/runnables_list_pagination.rs index 663bd6c080..b3e0ef0734 100644 --- a/backend/tests/runnables_list_pagination.rs +++ b/backend/tests/runnables_list_pagination.rs @@ -536,3 +536,109 @@ async fn test_runnables_starred_pinned_first(db: Pool) -> anyhow::Resu ); Ok(()) } + +async fn star(db: &Pool, path: &str, kind: &str) -> anyhow::Result<()> { + sqlx::query( + "INSERT INTO favorite (usr, workspace_id, path, favorite_kind) VALUES ('test-user','test-workspace',$1,$2::favorite_kind)", + ) + .bind(path) + .bind(kind) + .execute(db) + .await?; + Ok(()) +} + +/// The total `/runnables/counts` reports, which a home tab shows as its badge. +async fn count_total(port: u16, query: &str) -> i64 { + let url = format!("http://localhost:{port}/api/w/test-workspace/runnables/counts?{query}"); + let resp = authed(client().get(&url), "SECRET_TOKEN") + .send() + .await + .unwrap(); + assert_eq!(resp.status(), 200, "counts should succeed for {query}"); + let body: serde_json::Value = resp.json().await.unwrap(); + body["counts"] + .as_object() + .unwrap() + .values() + .map(|v| v.as_i64().unwrap()) + .sum() +} + +#[sqlx::test(fixtures("base"))] +async fn test_runnables_starred_first_false_pages_starred_in_order( + db: Pool, +) -> anyhow::Result<()> { + initialize_tracing().await; + let server = ApiServer::start(db.clone()).await?; + let port = server.addr.port(); + let base = format!("http://localhost:{port}/api/w/test-workspace"); + seed_mixed(&base, &db).await?; + star(&db, "u/test-user/solo", "script").await?; + + let items = list_once(port, "order_by=name&order_desc=false&starred_first=false").await; + assert_eq!( + items.last().map(String::as_str), + Some("script:u/test-user/solo"), + "without pinning, the starred row keeps its place in the name order, got {items:?}" + ); + assert_eq!(items.len(), 6, "every row listed once, got {items:?}"); + Ok(()) +} + +#[sqlx::test(fixtures("base"))] +async fn test_runnables_only_starred_pages_past_first(db: Pool) -> anyhow::Result<()> { + initialize_tracing().await; + let server = ApiServer::start(db.clone()).await?; + let port = server.addr.port(); + let base = format!("http://localhost:{port}/api/w/test-workspace"); + seed_mixed(&base, &db).await?; + star(&db, "u/test-user/solo", "script").await?; + star(&db, "f/alpha/two", "script").await?; + star(&db, "f/beta/appy", "app").await?; + + // One row per page, so the starred rows can only all arrive through the cursor. + let items = paginate_all(port, "order_by=name&order_desc=false&only_starred=true").await; + assert_eq!( + items, + vec![ + "app:f/beta/appy", + "script:f/alpha/two", + "script:u/test-user/solo" + ], + "only the starred rows, in order, across pages" + ); + assert_eq!(count_total(port, "only_starred=true").await, 3); + Ok(()) +} + +#[sqlx::test(fixtures("base"))] +async fn test_runnables_only_drafts_lists_both_draft_kinds( + db: Pool, +) -> anyhow::Result<()> { + initialize_tracing().await; + let server = ApiServer::start(db.clone()).await?; + let port = server.addr.port(); + let base = format!("http://localhost:{port}/api/w/test-workspace"); + seed_mixed(&base, &db).await?; + // A pending draft over a deployed script, a never-deployed flow, and another + // user's draft, which is not the caller's. + sqlx::query( + r#"INSERT INTO draft (workspace_id, path, typ, value, email) VALUES + ('test-workspace', 'f/alpha/one', 'script', '{"path": "f/alpha/one", "summary": "Deploy tool"}', 'test@windmill.dev'), + ('test-workspace', 'u/test-user/draft_new', 'flow', '{"summary": "New flow", "value": {"modules": []}}', 'test@windmill.dev'), + ('test-workspace', 'f/alpha/two', 'script', '{"path": "f/alpha/two", "summary": "Cleanup job"}', 'test2@windmill.dev')"#, + ) + .execute(&db) + .await?; + + let mut items = paginate_all(port, "include_draft_only=true&only_drafts=true").await; + items.sort(); + assert_eq!( + items, + vec!["flow:u/test-user/draft_new", "script:f/alpha/one"], + "the caller's deployed-with-draft and draft-only rows, and nothing else" + ); + assert_eq!(count_total(port, "only_drafts=true").await, 2); + Ok(()) +} diff --git a/backend/windmill-api/openapi.yaml b/backend/windmill-api/openapi.yaml index 943d05dc11..86aa265e74 100644 --- a/backend/windmill-api/openapi.yaml +++ b/backend/windmill-api/openapi.yaml @@ -12961,6 +12961,28 @@ paths: archived view, and under a label filter (a draft carries no labels). schema: type: boolean + - name: starred_first + in: query + description: >- + pin the caller's starred rows ahead of the first page (default true). + False pages them with every other row, in the requested order. + schema: + type: boolean + - name: only_starred + in: query + description: >- + only the caller's starred rows, paginated normally. Lists no + draft-only row, since those cannot be starred. + schema: + type: boolean + - name: only_drafts + in: query + description: >- + only rows the caller has a draft of: draft-only rows (subject to the + same exclusions as include_draft_only) and deployed rows with the + caller's pending draft. + schema: + type: boolean responses: "200": description: a page of merged, ordered runnables @@ -13002,6 +13024,16 @@ paths: matching the same flag on /runnables/list schema: type: boolean + - name: only_starred + in: query + description: count only the caller's starred rows, matching the same flag on /runnables/list + schema: + type: boolean + - name: only_drafts + in: query + description: count only rows the caller has a draft of, matching the same flag on /runnables/list + schema: + type: boolean responses: "200": description: >- diff --git a/backend/windmill-api/src/runnables.rs b/backend/windmill-api/src/runnables.rs index 754221dac0..75b74d6d67 100644 --- a/backend/windmill-api/src/runnables.rs +++ b/backend/windmill-api/src/runnables.rs @@ -75,6 +75,15 @@ struct ListRunnablesQuery { /// Also list the caller's drafts at paths with no deployed row. Off by /// default so picker callers stay deployed-only. include_draft_only: Option, + /// Pin the caller's starred rows ahead of the first page (default true). + /// False pages them with everything else, in the requested order. + starred_first: Option, + /// Only the caller's starred rows, paged normally. Lists no draft-only row, + /// since those cannot be starred. + only_starred: Option, + /// Only rows the caller has a draft of: draft-only rows and deployed rows + /// with a pending draft (`is_draft`). + only_drafts: Option, } // Absent optional fields are omitted (not serialized as null) to match the @@ -559,7 +568,7 @@ async fn list_runnables( let common_where = common.join(" AND "); let draft_common_where = draft_common.join(" AND "); - // Keyset predicate for pages after the first (non-starred rows only). A + // Keyset predicate for pages after the first (the paged stream only). A // row-value comparison keeps the composite order; the key is cast to the // branch column's type. let keyset_sql: Option = match &q.cursor { @@ -646,6 +655,15 @@ async fn list_runnables( if let Some(s) = &agent_scope { agent_extras.push(s.clone()); } + let only_starred = q.only_starred.unwrap_or(false); + let only_drafts = q.only_drafts.unwrap_or(false); + if only_drafts { + // The branch's own caller-draft join, the one `is_draft` reads. + for extras in [&mut script_extras, &mut flow_extras, &mut agent_extras] { + extras.push("draft.email IS NOT NULL".to_string()); + } + app_extras.push("draft.path IS NOT NULL".to_string()); + } // Draft-only rows are the caller's own work in progress: never archived, so they // have no place in the archived view, and carrying no labels of their own they are @@ -656,7 +674,8 @@ async fn list_runnables( } else { OperatorBuilderRights::default() }; - let include_drafts = q.include_draft_only.unwrap_or(false) + let include_drafts = (q.include_draft_only.unwrap_or(false) || only_drafts) + && !only_starred && (!authed.is_operator || builder.any()) && !show_archived && q.label.as_ref().filter(|s| !s.is_empty()).is_none(); @@ -680,8 +699,7 @@ async fn list_runnables( }; // Favorite filter for a branch: Some(true) = starred only, Some(false) = - // non-starred only, None = no filter. Both views pin starred on the first page - // (each is one row per path), so the paged stream always passes Some(false). + // non-starred only, None = no filter. let build_branch = |base: &str, kind: &str, common: &str, @@ -777,12 +795,13 @@ async fn list_runnables( let mut tx = user_db.begin(&authed).await?; let mut items: Vec = vec![]; let first_page = q.cursor.is_none(); + let pin_starred = q.starred_first.unwrap_or(true) && !only_starred; // Pin starred on the first page. Both views are now one row per path (the // archived view filters to each path's latest row, see archived_pred), so a // favorite is a single row in either — the starred-first contract holds in the // archived view too, and the pinned first page stays bounded. - if first_page { + if first_page && pin_starred { // No draft branch here: a draft-only path has no favorite row (the UI won't let // you star one), so it would scan the caller's whole draft slice per kind to // return nothing. The main stream below takes them unfiltered instead. @@ -803,8 +822,14 @@ async fn list_runnables( } } - // Main paged stream: non-starred rows (starred were pinned on the first page above). - let main_fav = Some(false); + // Main paged stream: non-starred rows when starred were pinned above. + let main_fav = if only_starred { + Some(true) + } else if pin_starred { + Some(false) + } else { + None + }; let ns_branches: Vec = ALL_KINDS .iter() @@ -847,6 +872,10 @@ struct CountRunnablesQuery { /// Also count the caller's drafts at paths with no deployed row, matching /// the same flag on `/list`. include_draft_only: Option, + /// Count what `/list` returns under the same flag. + only_starred: Option, + /// Count what `/list` returns under the same flag. + only_drafts: Option, } #[derive(Serialize)] @@ -913,12 +942,39 @@ async fn count_runnables_by_owner( return Ok(Json(RunnableCountsResponse { counts: HashMap::new() })); } let with_libs = q.include_without_main.unwrap_or(false) && !authed.is_operator; + let only_starred = q.only_starred.unwrap_or(false); + let only_drafts = q.only_drafts.unwrap_or(false); // Per-kind predicates shared by both passes. `alias` is the branch's table // alias; `binds` collects the scope values, numbered from `base + 1`. let kind_filters = |kind: &str, alias: &str, base: usize, binds: &mut Vec| -> Vec { let mut w = vec![format!("{alias}.workspace_id = $1")]; + // The same favorite and caller-draft joins `branch_sqls` reads `starred` + // and `is_draft` from. + if only_starred { + binds.push(authed.username.clone()); + w.push(format!( + "EXISTS (SELECT 1 FROM favorite f WHERE f.favorite_kind = '{kind}' \ + AND f.workspace_id = {alias}.workspace_id AND f.path = {alias}.path \ + AND f.usr = ${})", + base + binds.len() + )); + } + if only_drafts { + let typ = match kind { + "script" => "d.typ = 'script'", + "flow" => "d.typ = 'flow'", + "agent" => "d.typ = 'resource'", + _ => "d.typ IN ('app', 'raw_app')", + }; + binds.push(authed.email.clone()); + w.push(format!( + "EXISTS (SELECT 1 FROM draft d WHERE d.workspace_id = {alias}.workspace_id \ + AND d.path = {alias}.path AND {typ} AND d.email = ${})", + base + binds.len() + )); + } match kind { "script" => { w.push(format!("{alias}.archived = false")); @@ -1110,7 +1166,10 @@ async fn add_draft_counts( q: &CountRunnablesQuery, counts: &mut HashMap, ) -> Result<(), Error> { - if !q.include_draft_only.unwrap_or(false) { + // Draft-only rows can't be starred, so `/list` drops them under `only_starred`. + if !(q.include_draft_only.unwrap_or(false) || q.only_drafts.unwrap_or(false)) + || q.only_starred.unwrap_or(false) + { return Ok(()); } // An operator has no drafts of their own, except of what they may build. diff --git a/frontend/src/lib/components/home/ItemsList.svelte b/frontend/src/lib/components/home/ItemsList.svelte index 8cf9cf0bb4..6fd9bd6000 100644 --- a/frontend/src/lib/components/home/ItemsList.svelte +++ b/frontend/src/lib/components/home/ItemsList.svelte @@ -1,7 +1,7 @@ @@ -16,7 +27,8 @@ {#if narrowed}
-
No items match the current filters
+
No {itemsName} match the current filters
{#if activeFilters && activeFilters.length > 0}
Active: {activeFilters.join(' · ')} @@ -27,6 +39,15 @@ {/if}
+{:else if emptyTitle} +
+
+
{emptyTitle}
+ {#if emptyHint} +
{emptyHint}
+ {/if} +
+
{:else}