Search moves into the drive, new-folder becomes a disclosure
Browse files at this commit4283bb6451a3306c01c97f9ddb28e24fa635a87fParent: 71c4130- feat
- search moves into the drive, new-folder becomes a disclosure
6 changed files +261 -141
- crates/in-web/src/drive.rs +114 -16
- crates/in-web/src/i18n.rs +4 -0
- crates/in-web/src/layout.rs +1 -4
- crates/in-web/src/lib.rs +0 -1
- crates/in-web/src/search.rs +0 -111
- crates/in-web/tests/http.rs +142 -9
crates/in-web/src/drive.rsmodified+114 -16
| @@ -7,6 +7,11 @@ | |||
| 7 | //! is trashed is unreachable, and a move that would nest a folder inside | 7 | //! is trashed is unreachable, and a move that would nest a folder inside |
| 8 | //! itself is refused. Anything naming another owner's tree answers 404, | 8 | //! itself is refused. Anything naming another owner's tree answers 404, |
| 9 | //! never 403. | 9 | //! never 403. |
| 10 | +//! | ||
| 11 | +//! `GET /drive?q=<text>` keeps the same page and swaps the folder panels | ||
| 12 | +//! for library-wide name hits — the filterbar's search box, submitted as a | ||
| 13 | +//! plain GET form. The old `GET /search?q=` address 303s here, so old links | ||
| 14 | +//! keep working. | ||
| 10 | 15 | ||
| 11 | use in_core::store::{Folder, Store, StoreError, ThumbState}; | 16 | use in_core::store::{Folder, Store, StoreError, ThumbState}; |
| 12 | use topcoat::router::request::uri; | 17 | use topcoat::router::request::uri; |
| @@ -48,9 +53,13 @@ fn redirect(cx: &Cx, refusal: Option<Refusal>) -> Redirect { | |||
| 48 | )) | 53 | )) |
| 49 | } | 54 | } |
| 50 | 55 | ||
| 56 | +/// How many hits each search list carries at most. | ||
| 57 | +const LIMIT: u32 = 50; | ||
| 58 | + | ||
| 51 | #[query_params] | 59 | #[query_params] |
| 52 | struct DriveQuery { | 60 | struct DriveQuery { |
| 53 | folder: Option<String>, | 61 | folder: Option<String>, |
| 62 | + q: Option<String>, | ||
| 54 | } | 63 | } |
| 55 | 64 | ||
| 56 | /// The folder the query names, if it names one this account may open: owned, | 65 | /// The folder the query names, if it names one this account may open: owned, |
| @@ -169,9 +178,21 @@ async fn drive(cx: &Cx) -> Result { | |||
| 169 | let language = lang(cx).await; | 178 | let language = lang(cx).await; |
| 170 | let store = app(cx).store.clone(); | 179 | let store = app(cx).store.clone(); |
| 171 | 180 | ||
| 172 | - let wanted = query_params::<DriveQuery>(cx) | 181 | + let params = query_params::<DriveQuery>(cx).ok(); |
| 173 | - .ok() | 182 | + let wanted = params.as_ref().and_then(|query| query.folder.clone()); |
| 174 | - .and_then(|query| query.folder.clone()); | 183 | + // The filterbar's search box, trimmed: anything else on the query is |
| 184 | + // ignored, and an empty box is the plain folder view, never the whole | ||
| 185 | + // library. | ||
| 186 | + let asked = params | ||
| 187 | + .as_ref() | ||
| 188 | + .and_then(|query| query.q.clone()) | ||
| 189 | + .map(|query| query.trim().to_string()) | ||
| 190 | + .filter(|query| !query.is_empty()); | ||
| 191 | + let hits = match asked.as_deref() { | ||
| 192 | + Some(query) => Some(store.search(&user.id, query, LIMIT).await?), | ||
| 193 | + None => None, | ||
| 194 | + }; | ||
| 195 | + let box_text = asked.clone().unwrap_or_default(); | ||
| 175 | let current = current_folder(store.as_ref(), &user.id, wanted.as_deref()).await?; | 196 | let current = current_folder(store.as_ref(), &user.id, wanted.as_deref()).await?; |
| 176 | let crumbs = breadcrumbs(store.as_ref(), current.as_ref()).await; | 197 | let crumbs = breadcrumbs(store.as_ref(), current.as_ref()).await; |
| 177 | let listing = match store | 198 | let listing = match store |
| @@ -202,22 +223,39 @@ async fn drive(cx: &Cx) -> Result { | |||
| 202 | (topbar(cx, NavPage::Drive, &user, language).await?) | 223 | (topbar(cx, NavPage::Drive, &user, language).await?) |
| 203 | <main class="settings-stage"> | 224 | <main class="settings-stage"> |
| 204 | <div class="filterbar"> | 225 | <div class="filterbar"> |
| 205 | - if current.is_some() { | 226 | + if let Some(query) = asked.as_deref() { |
| 206 | - <nav class="detail-crumbs" aria-label=(current_name.clone())> | 227 | + <p class="detail-quiet">(t(language, Key::SearchResults)) (format!(" “{query}”"))</p> |
| 207 | - <a class="detail-crumb" href="/drive">(t(language, Key::Drive))</a> | 228 | + } else { |
| 208 | - for crumb in crumbs.iter() { | 229 | + if current.is_some() { |
| 209 | - <span class="detail-crumb-sep">"/"</span> | 230 | + <nav class="detail-crumbs" aria-label=(current_name.clone())> |
| 210 | - <a class="detail-crumb" href=(format!("/drive?folder={}", crumb.id))>(crumb.name.clone())</a> | 231 | + <a class="detail-crumb" href="/drive">(t(language, Key::Drive))</a> |
| 211 | - } | 232 | + for crumb in crumbs.iter() { |
| 212 | - </nav> | 233 | + <span class="detail-crumb-sep">"/"</span> |
| 234 | + <a class="detail-crumb" href=(format!("/drive?folder={}", crumb.id))>(crumb.name.clone())</a> | ||
| 235 | + } | ||
| 236 | + </nav> | ||
| 237 | + } | ||
| 213 | } | 238 | } |
| 214 | <div class="spacer"></div> | 239 | <div class="spacer"></div> |
| 215 | - <form class="tag-form" method="post" action="/api/folder/create"> | 240 | + <form class="field-box-search" method="get" action="/drive"> |
| 216 | - <input type="hidden" name="parent_id" value=(current_id.clone())> | 241 | + <input |
| 217 | - <input class="field-input" type="text" name="name" maxlength="255" | 242 | + class="field-input" |
| 218 | - placeholder=(t(language, Key::FolderName)) required="" aria-label=(t(language, Key::FolderName))> | 243 | + type="search" |
| 219 | - <button class="primary" type="submit">(t(language, Key::CreateFolder))</button> | 244 | + name="q" |
| 245 | + value=(box_text) | ||
| 246 | + placeholder=(t(language, Key::SearchPlaceholder)) | ||
| 247 | + aria-label=(t(language, Key::SearchPlaceholder)) | ||
| 248 | + > | ||
| 220 | </form> | 249 | </form> |
| 250 | + <details class="tag-new"> | ||
| 251 | + <summary class="tag-new-open">(t(language, Key::NewFolder))</summary> | ||
| 252 | + <form class="tag-form" method="post" action="/api/folder/create"> | ||
| 253 | + <input type="hidden" name="parent_id" value=(current_id.clone())> | ||
| 254 | + <input class="field-input" type="text" name="name" maxlength="255" | ||
| 255 | + placeholder=(t(language, Key::FolderName)) required="" aria-label=(t(language, Key::FolderName))> | ||
| 256 | + <button class="primary" type="submit">(t(language, Key::CreateFolder))</button> | ||
| 257 | + </form> | ||
| 258 | + </details> | ||
| 221 | </div> | 259 | </div> |
| 222 | if let Some(refusal) = refusal { | 260 | if let Some(refusal) = refusal { |
| 223 | <p class="field-error">(refusal.message_in(language))</p> | 261 | <p class="field-error">(refusal.message_in(language))</p> |
| @@ -231,6 +269,37 @@ async fn drive(cx: &Cx) -> Result { | |||
| 231 | </div> | 269 | </div> |
| 232 | </section> | 270 | </section> |
| 233 | } | 271 | } |
| 272 | + if let Some(hits) = hits { | ||
| 273 | + if hits.folders.is_empty() && hits.files.is_empty() { | ||
| 274 | + <p class="detail-quiet">(t(language, Key::NoResults))</p> | ||
| 275 | + } | ||
| 276 | + if !hits.folders.is_empty() { | ||
| 277 | + <section class="panel"> | ||
| 278 | + <div class="panel-head"> | ||
| 279 | + <h2 class="panel-title">(t(language, Key::FoldersHeading))</h2> | ||
| 280 | + <span class="chip">(format!("{}", hits.folders.len()))</span> | ||
| 281 | + </div> | ||
| 282 | + <div class="panel-body"> | ||
| 283 | + for folder in &hits.folders { | ||
| 284 | + <p><a href=(format!("/drive?folder={}", folder.id))>(folder.name.clone())</a></p> | ||
| 285 | + } | ||
| 286 | + </div> | ||
| 287 | + </section> | ||
| 288 | + } | ||
| 289 | + if !hits.files.is_empty() { | ||
| 290 | + <section class="panel"> | ||
| 291 | + <div class="panel-head"> | ||
| 292 | + <h2 class="panel-title">(t(language, Key::FilesHeading))</h2> | ||
| 293 | + <span class="chip">(format!("{}", hits.files.len()))</span> | ||
| 294 | + </div> | ||
| 295 | + <div class="panel-body"> | ||
| 296 | + for file in &hits.files { | ||
| 297 | + <p><a href=(format!("/file/{}", file.id))>(file.name.clone())</a></p> | ||
| 298 | + } | ||
| 299 | + </div> | ||
| 300 | + </section> | ||
| 301 | + } | ||
| 302 | + } else { | ||
| 234 | <section class="panel"> | 303 | <section class="panel"> |
| 235 | <div class="panel-head"> | 304 | <div class="panel-head"> |
| 236 | <h2 class="panel-title">(t(language, Key::FoldersHeading))</h2> | 305 | <h2 class="panel-title">(t(language, Key::FoldersHeading))</h2> |
| @@ -321,12 +390,41 @@ async fn drive(cx: &Cx) -> Result { | |||
| 321 | </div> | 390 | </div> |
| 322 | </div> | 391 | </div> |
| 323 | </section> | 392 | </section> |
| 393 | + } | ||
| 324 | </main> | 394 | </main> |
| 325 | (crate::dropdown::dropdown_script(cx).await?) | 395 | (crate::dropdown::dropdown_script(cx).await?) |
| 326 | (upload_script(cx).await?) | 396 | (upload_script(cx).await?) |
| 327 | } | 397 | } |
| 328 | } | 398 | } |
| 329 | 399 | ||
| 400 | +/// `GET /search`: the old address — a 303 to the drive's search box, keeping | ||
| 401 | +/// the query so old links land on their results. Nothing renders here. | ||
| 402 | +#[page("/search")] | ||
| 403 | +async fn search_redirect(cx: &Cx) -> Result { | ||
| 404 | + let target = match query_value(uri(cx).query().unwrap_or(""), "q") { | ||
| 405 | + Some(raw) if !raw.trim().is_empty() => format!("/drive?q={raw}"), | ||
| 406 | + _ => "/drive".to_string(), | ||
| 407 | + }; | ||
| 408 | + let location = ( | ||
| 409 | + header::LOCATION, | ||
| 410 | + HeaderValue::from_str(&target).unwrap_or(HeaderValue::from_static("/drive")), | ||
| 411 | + ); | ||
| 412 | + view! { | ||
| 413 | + cx => | ||
| 414 | + (StatusCode::SEE_OTHER) | ||
| 415 | + (location) | ||
| 416 | + } | ||
| 417 | +} | ||
| 418 | + | ||
| 419 | +/// The value of one query pair, if present. A hand-edited query names | ||
| 420 | +/// nothing rather than failing the redirect. | ||
| 421 | +fn query_value(query: &str, key: &str) -> Option<String> { | ||
| 422 | + query.split('&').find_map(|pair| { | ||
| 423 | + let (name, value) = pair.split_once('=')?; | ||
| 424 | + (name == key).then(|| value.to_string()) | ||
| 425 | + }) | ||
| 426 | +} | ||
| 427 | + | ||
| 330 | /// The upload control's client half: files under 8 MiB ride the form's own | 428 | /// The upload control's client half: files under 8 MiB ride the form's own |
| 331 | /// multipart post; files at or over it are split into the chunked protocol's | 429 | /// multipart post; files at or over it are split into the chunked protocol's |
| 332 | /// calls with a progress bar. | 430 | /// calls with a progress bar. |
crates/in-web/src/i18n.rsmodified+4 -0
| @@ -210,7 +210,9 @@ pub fn t(lang: Lang, key: Key) -> &'static str { | |||
| 210 | UserMenuLabel => "Account", | 210 | UserMenuLabel => "Account", |
| 211 | Drive => "Drive", | 211 | Drive => "Drive", |
| 212 | NewFolder => "New folder", | 212 | NewFolder => "New folder", |
| 213 | + NewFolder => "New folder", | ||
| 213 | FolderName => "Folder name", | 214 | FolderName => "Folder name", |
| 215 | + NewFolder => "New folder", | ||
| 214 | CreateFolder => "Create folder", | 216 | CreateFolder => "Create folder", |
| 215 | RenameFolder => "Rename folder", | 217 | RenameFolder => "Rename folder", |
| 216 | MoveFolder => "Move folder", | 218 | MoveFolder => "Move folder", |
| @@ -310,7 +312,9 @@ pub fn t(lang: Lang, key: Key) -> &'static str { | |||
| 310 | UserMenuLabel => "Hesap", | 312 | UserMenuLabel => "Hesap", |
| 311 | Drive => "Sürücü", | 313 | Drive => "Sürücü", |
| 312 | NewFolder => "Yeni klasör", | 314 | NewFolder => "Yeni klasör", |
| 315 | + NewFolder => "Yeni klasör", | ||
| 313 | FolderName => "Klasör adı", | 316 | FolderName => "Klasör adı", |
| 317 | + NewFolder => "Yeni klasör", | ||
| 314 | CreateFolder => "Klasörü oluştur", | 318 | CreateFolder => "Klasörü oluştur", |
| 315 | RenameFolder => "Klasörü yeniden adlandır", | 319 | RenameFolder => "Klasörü yeniden adlandır", |
| 316 | MoveFolder => "Klasörü taşı", | 320 | MoveFolder => "Klasörü taşı", |
crates/in-web/src/layout.rsmodified+1 -4
| @@ -138,7 +138,6 @@ pub enum NavPage { | |||
| 138 | Drive, | 138 | Drive, |
| 139 | Shared, | 139 | Shared, |
| 140 | Trash, | 140 | Trash, |
| 141 | - Search, | ||
| 142 | Settings, | 141 | Settings, |
| 143 | } | 142 | } |
| 144 | 143 | ||
| @@ -146,14 +145,13 @@ impl NavPage { | |||
| 146 | /// Settings is deliberately absent: it lives in the user menu, not the | 145 | /// Settings is deliberately absent: it lives in the user menu, not the |
| 147 | /// page nav — the variant stays so the settings page can still name | 146 | /// page nav — the variant stays so the settings page can still name |
| 148 | /// itself active without a link to mark. | 147 | /// itself active without a link to mark. |
| 149 | - const ALL: [Self; 4] = [Self::Drive, Self::Shared, Self::Trash, Self::Search]; | 148 | + const ALL: [Self; 3] = [Self::Drive, Self::Shared, Self::Trash]; |
| 150 | 149 | ||
| 151 | fn href(self) -> &'static str { | 150 | fn href(self) -> &'static str { |
| 152 | match self { | 151 | match self { |
| 153 | Self::Drive => "/drive", | 152 | Self::Drive => "/drive", |
| 154 | Self::Shared => "/shared", | 153 | Self::Shared => "/shared", |
| 155 | Self::Trash => "/trash", | 154 | Self::Trash => "/trash", |
| 156 | - Self::Search => "/search", | ||
| 157 | Self::Settings => "/settings", | 155 | Self::Settings => "/settings", |
| 158 | } | 156 | } |
| 159 | } | 157 | } |
| @@ -163,7 +161,6 @@ impl NavPage { | |||
| 163 | Self::Drive => Key::NavDrive, | 161 | Self::Drive => Key::NavDrive, |
| 164 | Self::Shared => Key::NavShared, | 162 | Self::Shared => Key::NavShared, |
| 165 | Self::Trash => Key::NavTrash, | 163 | Self::Trash => Key::NavTrash, |
| 166 | - Self::Search => Key::NavSearch, | ||
| 167 | Self::Settings => Key::NavSettings, | 164 | Self::Settings => Key::NavSettings, |
| 168 | } | 165 | } |
| 169 | } | 166 | } |
crates/in-web/src/lib.rsmodified+0 -1
| @@ -10,7 +10,6 @@ pub mod i18n; | |||
| 10 | pub mod layout; | 10 | pub mod layout; |
| 11 | pub mod live; | 11 | pub mod live; |
| 12 | pub mod pages; | 12 | pub mod pages; |
| 13 | -pub mod search; | ||
| 14 | pub mod server; | 13 | pub mod server; |
| 15 | pub mod settings; | 14 | pub mod settings; |
| 16 | pub mod share; | 15 | pub mod share; |
crates/in-web/src/search.rsdeleted+0 -111
| @@ -1,111 +0,0 @@ | |||
| 1 | -//! Name search over the reader's own drive. | ||
| 2 | -//! | ||
| 3 | -//! `GET /search?q=` matches the query against file and folder names with an | ||
| 4 | -//! owner-scoped `LIKE`, non-trashed rows only. Results link straight to the | ||
| 5 | -//! file view or the containing folder. An empty query renders the empty | ||
| 6 | -//! prompt, not the whole drive. | ||
| 7 | - | ||
| 8 | -use topcoat::Result; | ||
| 9 | -use topcoat::context::Cx; | ||
| 10 | -use topcoat::router::page; | ||
| 11 | -use topcoat::router::request::uri; | ||
| 12 | -use topcoat::view::view; | ||
| 13 | - | ||
| 14 | -use crate::i18n::{Key, lang, t}; | ||
| 15 | -use crate::layout::{NavPage, topbar}; | ||
| 16 | -use crate::server::{app, require_user}; | ||
| 17 | - | ||
| 18 | -/// How many hits each list carries at most. | ||
| 19 | -const LIMIT: u32 = 50; | ||
| 20 | - | ||
| 21 | -/// The search box's text, trimmed. Anything else on the query is ignored. | ||
| 22 | -fn searched(raw: Option<&str>) -> Option<String> { | ||
| 23 | - raw.map(str::trim) | ||
| 24 | - .filter(|query| !query.is_empty()) | ||
| 25 | - .map(str::to_string) | ||
| 26 | -} | ||
| 27 | - | ||
| 28 | -/// The reader's own live files and folders wearing the query in their name. | ||
| 29 | -/// Never another owner's, never trashed, never everything on an empty box. | ||
| 30 | -#[page("/search")] | ||
| 31 | -async fn search(cx: &Cx) -> Result { | ||
| 32 | - let user = match require_user(cx).await { | ||
| 33 | - Ok(user) => user, | ||
| 34 | - Err(refusal) => { | ||
| 35 | - let language = lang(cx).await; | ||
| 36 | - return view! { | ||
| 37 | - cx => | ||
| 38 | - <main class="scaffold-note"> | ||
| 39 | - <p>(refusal.message_in(language))</p> | ||
| 40 | - <p><a href="/">(t(language, Key::BackToDrive))</a></p> | ||
| 41 | - </main> | ||
| 42 | - }; | ||
| 43 | - } | ||
| 44 | - }; | ||
| 45 | - let language = lang(cx).await; | ||
| 46 | - let asked = searched(query_value(uri(cx).query().unwrap_or(""), "q").as_deref()); | ||
| 47 | - let hits = match asked.as_deref() { | ||
| 48 | - Some(query) => Some(app(cx).store.search(&user.id, query, LIMIT).await?), | ||
| 49 | - None => None, | ||
| 50 | - }; | ||
| 51 | - let box_text = asked.clone().unwrap_or_default(); | ||
| 52 | - view! { | ||
| 53 | - cx => | ||
| 54 | - (topbar(cx, NavPage::Search, &user, language).await?) | ||
| 55 | - <main class="settings-stage"> | ||
| 56 | - <h1 class="settings-title">(t(language, Key::SearchResults))</h1> | ||
| 57 | - <form class="field-box-search" method="get" action="/search"> | ||
| 58 | - <input | ||
| 59 | - class="field-input" | ||
| 60 | - type="search" | ||
| 61 | - name="q" | ||
| 62 | - value=(box_text) | ||
| 63 | - placeholder=(t(language, Key::SearchPlaceholder)) | ||
| 64 | - aria-label=(t(language, Key::SearchPlaceholder)) | ||
| 65 | - > | ||
| 66 | - </form> | ||
| 67 | - if let Some(hits) = hits { | ||
| 68 | - if hits.folders.is_empty() && hits.files.is_empty() { | ||
| 69 | - <p class="field-note">(t(language, Key::NoResults))</p> | ||
| 70 | - } | ||
| 71 | - if !hits.folders.is_empty() { | ||
| 72 | - <section class="panel"> | ||
| 73 | - <div class="panel-head"> | ||
| 74 | - <h2 class="panel-title">(t(language, Key::FoldersHeading))</h2> | ||
| 75 | - <span class="chip">(format!("{}", hits.folders.len()))</span> | ||
| 76 | - </div> | ||
| 77 | - <div class="panel-body"> | ||
| 78 | - for folder in &hits.folders { | ||
| 79 | - <p><a href=(format!("/drive?folder={}", folder.id))>(folder.name.clone())</a></p> | ||
| 80 | - } | ||
| 81 | - </div> | ||
| 82 | - </section> | ||
| 83 | - } | ||
| 84 | - if !hits.files.is_empty() { | ||
| 85 | - <section class="panel"> | ||
| 86 | - <div class="panel-head"> | ||
| 87 | - <h2 class="panel-title">(t(language, Key::FilesHeading))</h2> | ||
| 88 | - <span class="chip">(format!("{}", hits.files.len()))</span> | ||
| 89 | - </div> | ||
| 90 | - <div class="panel-body"> | ||
| 91 | - for file in &hits.files { | ||
| 92 | - <p><a href=(format!("/file/{}", file.id))>(file.name.clone())</a></p> | ||
| 93 | - } | ||
| 94 | - </div> | ||
| 95 | - </section> | ||
| 96 | - } | ||
| 97 | - } else { | ||
| 98 | - <p class="field-note">(t(language, Key::TypeToSearch))</p> | ||
| 99 | - } | ||
| 100 | - </main> | ||
| 101 | - } | ||
| 102 | -} | ||
| 103 | - | ||
| 104 | -/// The value of one query pair, if present. A hand-edited query names | ||
| 105 | -/// nothing rather than failing the page. | ||
| 106 | -fn query_value(query: &str, key: &str) -> Option<String> { | ||
| 107 | - query.split('&').find_map(|pair| { | ||
| 108 | - let (name, value) = pair.split_once('=')?; | ||
| 109 | - (name == key).then(|| value.to_string()) | ||
| 110 | - }) | ||
| 111 | -} | ||
crates/in-web/tests/http.rsmodified+142 -9
| @@ -1458,23 +1458,155 @@ async fn search_scopes_to_owner_and_hides_trashed() { | |||
| 1458 | let buried = file_id(&app, &ada, "quarterly draft.txt", b"c").await; | 1458 | let buried = file_id(&app, &ada, "quarterly draft.txt", b"c").await; |
| 1459 | app.store.delete_file(&buried).await.unwrap(); | 1459 | app.store.delete_file(&buried).await.unwrap(); |
| 1460 | 1460 | ||
| 1461 | - // Empty query is the prompt, not the whole drive. | 1461 | + // Empty query is the folder view, not the whole library under a new |
| 1462 | - let page = app.get("/search", Some(&admin)).await; | 1462 | + // name: the upload control renders, no results caption does. |
| 1463 | + let page = app.get("/drive", Some(&admin)).await; | ||
| 1463 | assert_eq!(page.status, StatusCode::OK, "{}", page.text()); | 1464 | assert_eq!(page.status, StatusCode::OK, "{}", page.text()); |
| 1464 | - assert!(!page.text().contains("quarterly report.txt"), "{}", page.text()); | 1465 | + assert!(page.text().contains("id=\"upload-form\""), "{}", page.text()); |
| 1466 | + assert!(!page.text().contains("Search results"), "{}", page.text()); | ||
| 1465 | 1467 | ||
| 1466 | - let page = app.get("/search?q=quarterly", Some(&admin)).await; | 1468 | + let page = app.get("/drive?q=quarterly", Some(&admin)).await; |
| 1467 | assert_eq!(page.status, StatusCode::OK, "{}", page.text()); | 1469 | assert_eq!(page.status, StatusCode::OK, "{}", page.text()); |
| 1468 | assert!(page.text().contains("quarterly report.txt"), "{}", page.text()); | 1470 | assert!(page.text().contains("quarterly report.txt"), "{}", page.text()); |
| 1469 | assert!(!page.text().contains("quarterly notes.txt"), "{}", page.text()); | 1471 | assert!(!page.text().contains("quarterly notes.txt"), "{}", page.text()); |
| 1470 | assert!(!page.text().contains("quarterly draft.txt"), "{}", page.text()); | 1472 | assert!(!page.text().contains("quarterly draft.txt"), "{}", page.text()); |
| 1471 | assert!(app.store.file(&mine).await.unwrap().is_some()); | 1473 | assert!(app.store.file(&mine).await.unwrap().is_some()); |
| 1472 | 1474 | ||
| 1473 | - let page = app.get("/search?q=quarterly", Some(&bob)).await; | 1475 | + let page = app.get("/drive?q=quarterly", Some(&bob)).await; |
| 1474 | assert!(page.text().contains("quarterly notes.txt"), "{}", page.text()); | 1476 | assert!(page.text().contains("quarterly notes.txt"), "{}", page.text()); |
| 1475 | assert!(!page.text().contains("quarterly report.txt"), "{}", page.text()); | 1477 | assert!(!page.text().contains("quarterly report.txt"), "{}", page.text()); |
| 1476 | } | 1478 | } |
| 1477 | 1479 | ||
| 1480 | +#[tokio::test] | ||
| 1481 | +async fn drive_search_results_replace_the_folder_panels() { | ||
| 1482 | + let app = TestApp::build().await; | ||
| 1483 | + let cookie = app.sign_in("sub-search-in-place", "inplace@in.test", "InPlace").await; | ||
| 1484 | + let owner = owner_of(&app, "sub-search-in-place").await; | ||
| 1485 | + let answer = app | ||
| 1486 | + .post( | ||
| 1487 | + "/api/folder/create", | ||
| 1488 | + Some(&cookie), | ||
| 1489 | + &[("parent_id", ""), ("name", "holiday photos")], | ||
| 1490 | + ) | ||
| 1491 | + .await; | ||
| 1492 | + assert!(answer.accepted(), "create refused: {:?}", answer.location); | ||
| 1493 | + let folder = folder_id(&app, &owner, None, "holiday photos").await; | ||
| 1494 | + let file = file_id(&app, &owner, "holiday report.txt", b"sun").await; | ||
| 1495 | + | ||
| 1496 | + let page = app.get("/drive?q=holiday", Some(&cookie)).await; | ||
| 1497 | + assert_eq!(page.status, StatusCode::OK, "{}", page.text()); | ||
| 1498 | + let body = page.text(); | ||
| 1499 | + // Both hits render in place on the drive, wired to their surfaces. | ||
| 1500 | + assert!(body.contains("holiday photos"), "{body}"); | ||
| 1501 | + assert!(body.contains("holiday report.txt"), "{body}"); | ||
| 1502 | + assert!(body.contains(&format!("/drive?folder={folder}")), "{body}"); | ||
| 1503 | + assert!(body.contains(&format!("/file/{file}")), "{body}"); | ||
| 1504 | + // One chip per list, like the folder panels they replace. | ||
| 1505 | + assert_eq!(body.matches("<span class=\"chip\">1</span>").count(), 2, "{body}"); | ||
| 1506 | + // The caption names the query and the box keeps it. | ||
| 1507 | + assert!(body.contains("Search results"), "{body}"); | ||
| 1508 | + assert!(body.contains("holiday"), "{body}"); | ||
| 1509 | + assert!(body.contains("value=\"holiday\""), "{body}"); | ||
| 1510 | + assert!(body.contains("name=\"q\""), "{body}"); | ||
| 1511 | + // The folder view is gone: no crumbs, no upload, no row mutations. | ||
| 1512 | + assert!(!body.contains("detail-crumbs"), "{body}"); | ||
| 1513 | + assert!(!body.contains("id=\"upload-form\""), "{body}"); | ||
| 1514 | + assert!(!body.contains("action=\"/api/folder/rename\""), "{body}"); | ||
| 1515 | +} | ||
| 1516 | + | ||
| 1517 | +#[tokio::test] | ||
| 1518 | +async fn drive_search_never_shows_other_owners_hits() { | ||
| 1519 | + let app = TestApp::build().await; | ||
| 1520 | + let ada = app.sign_in("sub-search-ada", "ada2@in.test", "Ada").await; | ||
| 1521 | + let bob = app.sign_in("sub-search-bob", "bob2@in.test", "Bob").await; | ||
| 1522 | + let bob_id = owner_of(&app, "sub-search-bob").await; | ||
| 1523 | + let _ = file_id(&app, &bob_id, "secret ledger.txt", b"b").await; | ||
| 1524 | + let answer = app | ||
| 1525 | + .post( | ||
| 1526 | + "/api/folder/create", | ||
| 1527 | + Some(&bob), | ||
| 1528 | + &[("parent_id", ""), ("name", "secret drawer")], | ||
| 1529 | + ) | ||
| 1530 | + .await; | ||
| 1531 | + assert!(answer.accepted(), "create refused: {:?}", answer.location); | ||
| 1532 | + | ||
| 1533 | + // Ada's library-wide search stays hers: Bob's file and folder hits never | ||
| 1534 | + // appear, and the quiet note says so. | ||
| 1535 | + let page = app.get("/drive?q=secret", Some(&ada)).await; | ||
| 1536 | + assert_eq!(page.status, StatusCode::OK, "{}", page.text()); | ||
| 1537 | + let body = page.text(); | ||
| 1538 | + assert!(!body.contains("secret ledger.txt"), "{body}"); | ||
| 1539 | + assert!(!body.contains("secret drawer"), "{body}"); | ||
| 1540 | + assert!(body.contains("Nothing found."), "{body}"); | ||
| 1541 | + | ||
| 1542 | + // Sanity: the same query finds them for their owner. | ||
| 1543 | + let page = app.get("/drive?q=secret", Some(&bob)).await; | ||
| 1544 | + assert_eq!(page.status, StatusCode::OK, "{}", page.text()); | ||
| 1545 | + assert!(page.text().contains("secret ledger.txt"), "{}", page.text()); | ||
| 1546 | + assert!(page.text().contains("secret drawer"), "{}", page.text()); | ||
| 1547 | +} | ||
| 1548 | + | ||
| 1549 | +#[tokio::test] | ||
| 1550 | +async fn drive_search_empty_query_is_the_folder_view() { | ||
| 1551 | + let app = TestApp::build().await; | ||
| 1552 | + let cookie = app.sign_in("sub-search-empty", "empty@in.test", "Empty").await; | ||
| 1553 | + let owner = owner_of(&app, "sub-search-empty").await; | ||
| 1554 | + let _ = file_id(&app, &owner, "plain.txt", b"p").await; | ||
| 1555 | + | ||
| 1556 | + for path in ["/drive?q=", "/drive?q=%20%20"] { | ||
| 1557 | + let page = app.get(path, Some(&cookie)).await; | ||
| 1558 | + assert_eq!(page.status, StatusCode::OK, "{}: {}", path, page.text()); | ||
| 1559 | + let body = page.text(); | ||
| 1560 | + // The folder listing renders as usual — the file is there through | ||
| 1561 | + // its directory, not through a result — with the box held empty. | ||
| 1562 | + assert!(body.contains("plain.txt"), "{path}: {body}"); | ||
| 1563 | + assert!(body.contains("id=\"upload-form\""), "{path}: {body}"); | ||
| 1564 | + assert!(body.contains("name=\"q\""), "{path}: {body}"); | ||
| 1565 | + assert!(!body.contains("Search results"), "{path}: {body}"); | ||
| 1566 | + } | ||
| 1567 | +} | ||
| 1568 | + | ||
| 1569 | +#[tokio::test] | ||
| 1570 | +async fn old_search_address_redirects_to_drive() { | ||
| 1571 | + let app = TestApp::build().await; | ||
| 1572 | + let cookie = app.sign_in("sub-search-old", "old@in.test", "Old").await; | ||
| 1573 | + | ||
| 1574 | + let page = app.get("/search?q=quarterly", Some(&cookie)).await; | ||
| 1575 | + assert_eq!(page.status, StatusCode::SEE_OTHER, "{}", page.text()); | ||
| 1576 | + assert_eq!(page.location.as_deref(), Some("/drive?q=quarterly")); | ||
| 1577 | + | ||
| 1578 | + // The raw pair rides through untouched, so encoded queries survive. | ||
| 1579 | + let page = app.get("/search?q=holiday+report", Some(&cookie)).await; | ||
| 1580 | + assert_eq!(page.status, StatusCode::SEE_OTHER, "{}", page.text()); | ||
| 1581 | + assert_eq!(page.location.as_deref(), Some("/drive?q=holiday+report")); | ||
| 1582 | + | ||
| 1583 | + // No query is the plain drive; no session still redirects, never 401s. | ||
| 1584 | + let page = app.get("/search", Some(&cookie)).await; | ||
| 1585 | + assert_eq!(page.status, StatusCode::SEE_OTHER, "{}", page.text()); | ||
| 1586 | + assert_eq!(page.location.as_deref(), Some("/drive")); | ||
| 1587 | + let page = app.get("/search?q=quarterly", None).await; | ||
| 1588 | + assert_eq!(page.status, StatusCode::SEE_OTHER, "{}", page.text()); | ||
| 1589 | + assert_eq!(page.location.as_deref(), Some("/drive?q=quarterly")); | ||
| 1590 | +} | ||
| 1591 | + | ||
| 1592 | +#[tokio::test] | ||
| 1593 | +async fn topbar_nav_has_no_search_link() { | ||
| 1594 | + let app = TestApp::build().await; | ||
| 1595 | + let cookie = app.sign_in("sub-search-nav", "nav@in.test", "Nav").await; | ||
| 1596 | + let page = app.get("/drive", Some(&cookie)).await; | ||
| 1597 | + assert_eq!(page.status, StatusCode::OK, "{}", page.text()); | ||
| 1598 | + let body = page.text(); | ||
| 1599 | + let nav_start = body.find("topbar-nav-links").expect("no nav"); | ||
| 1600 | + let nav_end = body[nav_start..].find("</nav>").expect("nav never closes"); | ||
| 1601 | + let nav = &body[nav_start..nav_start + nav_end]; | ||
| 1602 | + // Drive, Shared, Trash — and nothing else. | ||
| 1603 | + assert!(nav.contains("href=\"/drive\""), "{nav}"); | ||
| 1604 | + assert!(nav.contains("href=\"/shared\""), "{nav}"); | ||
| 1605 | + assert!(nav.contains("href=\"/trash\""), "{nav}"); | ||
| 1606 | + assert!(!nav.contains("/search"), "search leaked into the nav: {nav}"); | ||
| 1607 | + assert!(!nav.contains("Search"), "search leaked into the nav: {nav}"); | ||
| 1608 | +} | ||
| 1609 | + | ||
| 1478 | // -- settings --------------------------------------------------------------- | 1610 | // -- settings --------------------------------------------------------------- |
| 1479 | 1611 | ||
| 1480 | #[tokio::test] | 1612 | #[tokio::test] |
| @@ -2119,7 +2251,7 @@ async fn settings_panels_nest_inside_the_stage() { | |||
| 2119 | assert!(body.contains("<th class=\"member-col-name\""), "{body}"); | 2251 | assert!(body.contains("<th class=\"member-col-name\""), "{body}"); |
| 2120 | } | 2252 | } |
| 2121 | 2253 | ||
| 2122 | -// The /shared, /trash and /search strip fix: content belongs in the stage, | 2254 | +// The /shared and /trash strip fix: content belongs in the stage, |
| 2123 | // never directly in the flex-row shell. Mirrors | 2255 | // never directly in the flex-row shell. Mirrors |
| 2124 | // settings_panels_nest_inside_the_stage. | 2256 | // settings_panels_nest_inside_the_stage. |
| 2125 | fn assert_stage_nests(body: &str, markers: &[&str]) { | 2257 | fn assert_stage_nests(body: &str, markers: &[&str]) { |
| @@ -2187,12 +2319,12 @@ async fn trash_panels_nest_inside_the_stage() { | |||
| 2187 | } | 2319 | } |
| 2188 | 2320 | ||
| 2189 | #[tokio::test] | 2321 | #[tokio::test] |
| 2190 | -async fn search_panels_nest_inside_the_stage() { | 2322 | +async fn drive_search_panels_nest_inside_the_stage() { |
| 2191 | let app = TestApp::build().await; | 2323 | let app = TestApp::build().await; |
| 2192 | let admin = app.sign_in("sub-stage-search", "stagesearch@in.test", "StageSearch").await; | 2324 | let admin = app.sign_in("sub-stage-search", "stagesearch@in.test", "StageSearch").await; |
| 2193 | let owner = owner_of(&app, "sub-stage-search").await; | 2325 | let owner = owner_of(&app, "sub-stage-search").await; |
| 2194 | file_id(&app, &owner, "staged-report.txt", b"staged").await; | 2326 | file_id(&app, &owner, "staged-report.txt", b"staged").await; |
| 2195 | - let page = app.get("/search?q=staged-report", Some(&admin)).await; | 2327 | + let page = app.get("/drive?q=staged-report", Some(&admin)).await; |
| 2196 | assert_eq!(page.status, StatusCode::OK, "{}", page.text()); | 2328 | assert_eq!(page.status, StatusCode::OK, "{}", page.text()); |
| 2197 | assert_stage_nests( | 2329 | assert_stage_nests( |
| 2198 | &page.text(), | 2330 | &page.text(), |
| @@ -2224,8 +2356,9 @@ async fn drive_root_hides_crumbs_while_a_subfolder_shows_them() { | |||
| 2224 | let page = app.get("/drive", Some(&cookie)).await; | 2356 | let page = app.get("/drive", Some(&cookie)).await; |
| 2225 | assert_eq!(page.status, StatusCode::OK, "{}", page.text()); | 2357 | assert_eq!(page.status, StatusCode::OK, "{}", page.text()); |
| 2226 | assert!(!page.text().contains("detail-crumbs"), "{}", page.text()); | 2358 | assert!(!page.text().contains("detail-crumbs"), "{}", page.text()); |
| 2227 | - // The filterbar itself stays, holding just the create form. | 2359 | + // The filterbar itself stays, holding the search box and the create form. |
| 2228 | assert!(page.text().contains("class=\"filterbar\""), "{}", page.text()); | 2360 | assert!(page.text().contains("class=\"filterbar\""), "{}", page.text()); |
| 2361 | + assert!(page.text().contains("name=\"q\""), "{}", page.text()); | ||
| 2229 | assert!( | 2362 | assert!( |
| 2230 | page.text().contains("action=\"/api/folder/create\""), | 2363 | page.text().contains("action=\"/api/folder/create\""), |
| 2231 | "{}", | 2364 | "{}", |