Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions crates/engine/src/notes/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,14 @@ impl NotesView {
pub fn cards(&self) -> impl Iterator<Item = &Card> {
self.sections.iter().flat_map(|section| &section.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`],
Expand Down Expand Up @@ -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(
Expand Down
32 changes: 32 additions & 0 deletions crates/ui/src/app/captures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
2 changes: 1 addition & 1 deletion crates/ui/src/notes/canvas/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
34 changes: 32 additions & 2 deletions crates/ui/src/notes/canvas/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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()));
}
5 changes: 3 additions & 2 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 16 additions & 7 deletions e2e/tests/20_folder_descent.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
},
Expand Down Expand Up @@ -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);
});

Expand Down
Loading