diff --git a/crates/engine/src/notes/view.rs b/crates/engine/src/notes/view.rs index 85ef8740..d6884662 100644 --- a/crates/engine/src/notes/view.rs +++ b/crates/engine/src/notes/view.rs @@ -461,6 +461,14 @@ impl NotesView { pub fn cards(&self) -> impl Iterator { self.sections.iter().flat_map(|section| §ion.cards) } + + /// A section keeps the card a note is created from: empty, the view is a place to create in, + /// not a search that found nothing. + pub fn offers_creation(&self) -> bool { + self.sections + .iter() + .any(|section| section.show_create_ghost) + } } /// What a card carries beside its note, read from other tables, and so apart from [`build`], @@ -1155,6 +1163,38 @@ mod tests { assert_eq!(view.matched, 2); } + #[test] + fn an_empty_folder_still_offers_the_slot_a_note_is_created_from() { + let view = build( + Vec::new(), + Facets::default(), + &NotesQuery { + folder_id: Some("f-1".to_string()), + ..request() + }, + ); + + assert_eq!(view.matched, 0); + assert_eq!(keys(&view), [NoteSectionKey::Results]); + assert!(view.sections[0].cards.is_empty()); + assert!(view.offers_creation()); + } + + #[test] + fn a_search_that_finds_nothing_offers_nothing_to_create() { + let view = build( + vec![note("a", "Un")], + Facets::default(), + &NotesQuery { + search: "absent".to_string(), + ..request() + }, + ); + + assert_eq!(view.matched, 0); + assert!(!view.offers_creation()); + } + #[test] fn an_opened_folder_keeps_the_slot_a_note_is_created_from() { let view = build( diff --git a/crates/ui/src/app/captures.rs b/crates/ui/src/app/captures.rs index 3ebd03f0..3c03933b 100644 --- a/crates/ui/src/app/captures.rs +++ b/crates/ui/src/app/captures.rs @@ -2002,3 +2002,35 @@ fn reports_in_the_corner() { settle(&mut harness); capture(&mut harness, "error-toast"); } + +#[test] +fn an_empty_folder_opened() { + use engine::folders::model::FolderDraft; + let profile = tempfile::tempdir().unwrap(); + let mut harness = launch(profile.path()); + type_into(&mut harness, "vault-passphrase", PASSPHRASE); + type_into(&mut harness, "vault-confirmation", PASSPHRASE); + click(&mut harness, "vault-submit"); + settle(&mut harness); + let backend = &harness.state().backend; + engine::db::run_here(backend.engine(), |engine| { + let space = engine::spaces::list_spaces(engine)?.remove(0); + let draft = FolderDraft { + space_id: space.id, + name: "Brouillons".to_owned(), + parent_id: None, + }; + engine::folders::create_folder(engine, &draft) + }) + .unwrap(); + harness.state_mut().state.revision.bump(); + settle(&mut harness); + harness + .get_by(|node| { + node.author_id() == Some("folder-option") + && node.label().as_deref() == Some("Brouillons") + }) + .click(); + settle(&mut harness); + capture(&mut harness, "folder-empty"); +} diff --git a/crates/ui/src/notes/canvas/mod.rs b/crates/ui/src/notes/canvas/mod.rs index fb238726..26353ead 100644 --- a/crates/ui/src/notes/canvas/mod.rs +++ b/crates/ui/src/notes/canvas/mod.rs @@ -76,7 +76,7 @@ pub fn show(ui: &mut Ui, state: &AppState, canvas_view: &mut CanvasView, actions }); return; }; - if view.matched == 0 { + if view.matched == 0 && !view.offers_creation() { let filtered = query.has_user_filters(); // The page that explains this screen, not the top of the documentation. let (label, author_id) = if !filtered { diff --git a/crates/ui/src/notes/canvas/tests.rs b/crates/ui/src/notes/canvas/tests.rs index 2ece732e..8b8946f2 100644 --- a/crates/ui/src/notes/canvas/tests.rs +++ b/crates/ui/src/notes/canvas/tests.rs @@ -103,13 +103,18 @@ fn of_thirty_thousand_notes_only_the_rows_in_view_are_drawn() { } #[test] -fn a_library_without_notes_says_nothing_matches() { +fn a_library_without_notes_offers_the_card_to_create_one() { let (backend, profile) = testing::unlocked(); let harness = canvas(backend, profile); assert_eq!(cards(&harness), 0); - harness.get_by(|node| node.author_id() == Some("canvas-no-results")); + harness.get_by(|node| node.author_id() == Some("create-ghost")); + assert!( + harness + .query_by(|node| node.author_id() == Some("canvas-no-results")) + .is_none() + ); } #[test] @@ -126,3 +131,28 @@ fn a_view_that_failed_offers_to_retry() { assert_ne!(harness.state().state.revision, before); } + +#[test] +fn an_empty_folder_offers_the_card_a_note_is_created_from() { + let (backend, profile) = testing::unlocked(); + testing::note(&backend, "loose"); + let spaces = crate::notes::bench::spaces_of_backend(&backend); + let runbooks = crate::notes::bench::folder(&backend, &spaces[0], None, "Runbooks"); + let mut harness = crate::notes::bench::area(backend, profile); + + crate::notes::bench::click(&mut harness, "folder-option", "Runbooks"); + + let present = |author_id: &str| { + harness + .query_by(|node| node.author_id() == Some(author_id)) + .is_some() + }; + assert!(!present("canvas-no-results"), "nothing was searched"); + assert!(present("create-ghost")); + crate::notes::bench::click_id(&mut harness, "create-ghost"); + let opened = harness.state().state.editor.opened(); + let draft = opened + .and_then(|opened| opened.note()) + .expect("a draft opens"); + assert_eq!(draft.folder_id.as_deref(), Some(runbooks.id.as_str())); +} diff --git a/docs/architecture.md b/docs/architecture.md index 5b0d966e..19d7b9c3 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -4389,8 +4389,9 @@ worked out once a frame and only the rows that cross the viewport are drawn (`ScrollArea::show_viewport`): of 30 000 notes, a screenful. Sections are the core's, in its order, empty ones included (they are exhaustive); the cell after a section's last card is its « paste or create » ghost when the core says so. The region (`canvas`) says loading, nothing -found (`matched == 0`, `canvas-no-results`) or a failure with its retry (`canvas-retry`, which -bumps the revision) instead of the sections. +found (`matched == 0` with no section keeping the ghost, `NotesView::offers_creation`, +`canvas-no-results`) or a failure with its retry (`canvas-retry`, which bumps the revision) +instead of the sections: an empty folder or space is a place to create in, not a search. A card (`canvas::card`) draws the core's `DisplayNote` and decides nothing about it, in three bands (→ "A card is two layers"): the title bar (the card's box; the kind's icon, diff --git a/e2e/tests/20_folder_descent.rs b/e2e/tests/20_folder_descent.rs index 70652c1b..d256c785 100644 --- a/e2e/tests/20_folder_descent.rs +++ b/e2e/tests/20_folder_descent.rs @@ -1,4 +1,5 @@ -//! Opening a folder: from a zone's title on the board, a flat grid of its notes named after it, +//! Opening a folder: empty, it offers the card a note is made from, not « nothing matches »; from +//! a zone's title on the board, a flat grid of its notes named after it, //! the switchers put away for its breadcrumb, a note made inside it filed there, renamed from //! beside the breadcrumb, and left again — Escape giving the search back first, then the folder //! — down to the board it was opened from, or through the breadcrumb, or by deleting it. @@ -33,8 +34,9 @@ fn heading(tree: &Tree) -> String { tree.texts("note-section").join(" ") } -fn write(app: &mut App, title: &str) { - app.click("new-note"); +/// A note made from `from`: « + New note », or the card that offers it. +fn write(app: &mut App, from: &str, title: &str) { + app.click(from); app.fill("editor-title", title); app.fill("editor-body", "SELECT 1;"); app.click("editor-close"); @@ -69,11 +71,18 @@ fn seed(app: &mut App) { app.press(Key::Enter, Modifiers::NONE); app.eventually("the folder is listed", |tree| tree.has("folder-option")); app.click_where("folder-option", named("Perf")); - app.wait_for("folder-breadcrumb-name"); - write(app, INSIDE); + app.eventually( + "empty, it offers the card to create from, not a search", + |tree| { + tree.has("create-ghost") + && !tree.has("canvas-no-results") + && heading(tree).to_uppercase().starts_with("PERF") + }, + ); + write(app, "create-ghost", INSIDE); app.click_where("space-option", named(SPACE)); app.eventually("the space is shown", |tree| crumb(tree).is_none()); - write(app, LOOSE); + write(app, "new-note", LOOSE); app.click("view-board"); app.wait_for("board-zone"); }, @@ -124,7 +133,7 @@ fn inside(app: &mut App) { ); step("a note made here arrives filed", || { - write(app, MADE); + write(app, "new-note", MADE); app.eventually("both notes are in it", |tree| titles(tree).len() == 2); });