| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
use makeover_layout as layout; |
| 80 |
use quasi_declare::declare; |
| 81 |
use quasi_router::screen::{Choice, Consult, Field, Tag}; |
| 82 |
use quasi_router::{Action, Node, RegionKind, Slot}; |
| 83 |
use quasi_webview::Webview; |
| 84 |
|
| 85 |
use crate::templates::DeletedItemRow; |
| 86 |
use crate::types::{BlogPostDashboardRow, ContentItem}; |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
pub const REGION: &str = "project-content"; |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
const SELECTION: &str = "chosen"; |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
const SEARCH_WAIT: std::time::Duration = std::time::Duration::from_millis(200); |
| 107 |
const SEARCH_FLOOR: usize = 2; |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
const STATUSES: [&str; 3] = ["Active", "Draft", "Scheduled"]; |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 121 |
pub enum SortBy { |
| 122 |
Item, |
| 123 |
Kind, |
| 124 |
Price, |
| 125 |
Sales, |
| 126 |
Revenue, |
| 127 |
Status, |
| 128 |
} |
| 129 |
|
| 130 |
impl SortBy { |
| 131 |
|
| 132 |
const fn word(self) -> &'static str { |
| 133 |
match self { |
| 134 |
Self::Item => "item", |
| 135 |
Self::Kind => "type", |
| 136 |
Self::Price => "price", |
| 137 |
Self::Sales => "sales", |
| 138 |
Self::Revenue => "revenue", |
| 139 |
Self::Status => "status", |
| 140 |
} |
| 141 |
} |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
fn of(word: &str) -> Option<Self> { |
| 149 |
[ |
| 150 |
Self::Item, |
| 151 |
Self::Kind, |
| 152 |
Self::Price, |
| 153 |
Self::Sales, |
| 154 |
Self::Revenue, |
| 155 |
Self::Status, |
| 156 |
] |
| 157 |
.into_iter() |
| 158 |
.find(|sort| sort.word() == word) |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
#[derive(Debug, Clone, Default, PartialEq, Eq)] |
| 168 |
pub struct View { |
| 169 |
|
| 170 |
pub query: Option<String>, |
| 171 |
|
| 172 |
pub status: Option<String>, |
| 173 |
|
| 174 |
pub kind: Option<String>, |
| 175 |
|
| 176 |
pub sort: Option<SortBy>, |
| 177 |
|
| 178 |
pub descending: bool, |
| 179 |
|
| 180 |
pub open: Vec<String>, |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
pub ticked: bool, |
| 189 |
} |
| 190 |
|
| 191 |
impl View { |
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
#[must_use] |
| 198 |
pub fn of( |
| 199 |
query: Option<&str>, |
| 200 |
status: Option<&str>, |
| 201 |
kind: Option<&str>, |
| 202 |
sort: Option<&str>, |
| 203 |
direction: Option<&str>, |
| 204 |
open: Option<&str>, |
| 205 |
ticked: Option<&str>, |
| 206 |
) -> Option<Self> { |
| 207 |
let text = |raw: Option<&str>| { |
| 208 |
raw.map(str::trim) |
| 209 |
.filter(|value| !value.is_empty()) |
| 210 |
.map(str::to_owned) |
| 211 |
}; |
| 212 |
|
| 213 |
let sort = match text(sort) { |
| 214 |
None => None, |
| 215 |
Some(word) => Some(SortBy::of(&word)?), |
| 216 |
}; |
| 217 |
|
| 218 |
Some(Self { |
| 219 |
query: text(query), |
| 220 |
status: text(status).filter(|word| STATUSES.contains(&word.as_str())), |
| 221 |
kind: text(kind), |
| 222 |
sort, |
| 223 |
descending: matches!(direction, Some("desc")), |
| 224 |
open: text(open) |
| 225 |
.map(|raw| raw.split(' ').map(str::to_owned).collect()) |
| 226 |
.unwrap_or_default(), |
| 227 |
ticked: matches!(ticked, Some("all")), |
| 228 |
}) |
| 229 |
} |
| 230 |
|
| 231 |
|
| 232 |
fn panel(&self, slug: &str) -> Action { |
| 233 |
self.carry(Action::get(base(slug))).replacing(REGION) |
| 234 |
} |
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
fn write(&self, slug: &str, tail: &str) -> Action { |
| 242 |
self.carry(Action::post(format!("{}/{tail}", base(slug)))) |
| 243 |
.replacing(REGION) |
| 244 |
.awaiting() |
| 245 |
} |
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
fn carry(&self, action: Action) -> Action { |
| 251 |
let mut action = action; |
| 252 |
if let Some(query) = &self.query { |
| 253 |
action = action.carrying("q", query); |
| 254 |
} |
| 255 |
if let Some(status) = &self.status { |
| 256 |
action = action.carrying("status", status); |
| 257 |
} |
| 258 |
if let Some(kind) = &self.kind { |
| 259 |
action = action.carrying("type", kind); |
| 260 |
} |
| 261 |
if let Some(sort) = self.sort { |
| 262 |
action = action.carrying("sort", sort.word()); |
| 263 |
if self.descending { |
| 264 |
action = action.carrying("direction", "desc"); |
| 265 |
} |
| 266 |
} |
| 267 |
if !self.open.is_empty() { |
| 268 |
action = action.carrying("open", self.open.join(" ")); |
| 269 |
} |
| 270 |
if self.ticked { |
| 271 |
action = action.carrying("ticked", "all"); |
| 272 |
} |
| 273 |
action |
| 274 |
} |
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
fn sorted_by(&self, sort: SortBy) -> Self { |
| 279 |
Self { |
| 280 |
sort: Some(sort), |
| 281 |
descending: self.sort == Some(sort) && !self.descending, |
| 282 |
..self.narrowed() |
| 283 |
} |
| 284 |
} |
| 285 |
|
| 286 |
|
| 287 |
fn toggling(&self, bundle: &str) -> Self { |
| 288 |
let mut open = self.open.clone(); |
| 289 |
if let Some(at) = open.iter().position(|id| id == bundle) { |
| 290 |
open.remove(at); |
| 291 |
} else { |
| 292 |
open.push(bundle.to_owned()); |
| 293 |
} |
| 294 |
Self { |
| 295 |
open, |
| 296 |
..self.clone() |
| 297 |
} |
| 298 |
} |
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
fn narrowed(&self) -> Self { |
| 308 |
Self { |
| 309 |
ticked: false, |
| 310 |
..self.clone() |
| 311 |
} |
| 312 |
} |
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
fn without_query(&self) -> Self { |
| 321 |
Self { |
| 322 |
query: None, |
| 323 |
..self.clone() |
| 324 |
} |
| 325 |
} |
| 326 |
|
| 327 |
fn without_status(&self) -> Self { |
| 328 |
Self { |
| 329 |
status: None, |
| 330 |
..self.clone() |
| 331 |
} |
| 332 |
} |
| 333 |
|
| 334 |
fn without_kind(&self) -> Self { |
| 335 |
Self { |
| 336 |
kind: None, |
| 337 |
..self.clone() |
| 338 |
} |
| 339 |
} |
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
fn cleared(&self) -> Self { |
| 347 |
Self { |
| 348 |
sort: self.sort, |
| 349 |
descending: self.descending, |
| 350 |
..Self::default() |
| 351 |
} |
| 352 |
} |
| 353 |
|
| 354 |
|
| 355 |
fn all_ticked(&self) -> Self { |
| 356 |
Self { |
| 357 |
ticked: true, |
| 358 |
..self.clone() |
| 359 |
} |
| 360 |
} |
| 361 |
|
| 362 |
|
| 363 |
fn query_text(&self) -> String { |
| 364 |
self.query.clone().unwrap_or_default() |
| 365 |
} |
| 366 |
|
| 367 |
|
| 368 |
fn status_text(&self) -> String { |
| 369 |
self.status.clone().unwrap_or_default() |
| 370 |
} |
| 371 |
|
| 372 |
|
| 373 |
fn kind_text(&self) -> String { |
| 374 |
self.kind.clone().unwrap_or_default() |
| 375 |
} |
| 376 |
|
| 377 |
|
| 378 |
fn is_open(&self, bundle: &str) -> bool { |
| 379 |
self.open.iter().any(|id| id == bundle) |
| 380 |
} |
| 381 |
|
| 382 |
|
| 383 |
fn direction(&self) -> layout::Sort { |
| 384 |
if self.descending { |
| 385 |
layout::Sort::Descending |
| 386 |
} else { |
| 387 |
layout::Sort::Ascending |
| 388 |
} |
| 389 |
} |
| 390 |
|
| 391 |
|
| 392 |
fn orders_by(&self, sort: SortBy) -> bool { |
| 393 |
self.sort == Some(sort) |
| 394 |
} |
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
fn keeps_order(&self) -> bool { |
| 399 |
self.sort.is_none() |
| 400 |
} |
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
#[must_use] |
| 405 |
pub fn filtered(&self) -> bool { |
| 406 |
self.query.is_some() || self.status.is_some() || self.kind.is_some() |
| 407 |
} |
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
#[must_use] |
| 415 |
pub fn is_default(&self) -> bool { |
| 416 |
*self == Self::default() |
| 417 |
} |
| 418 |
|
| 419 |
|
| 420 |
fn keeps(&self, item: &ContentItem) -> bool { |
| 421 |
let matches_query = self.query.as_ref().is_none_or(|query| { |
| 422 |
item.title |
| 423 |
.to_lowercase() |
| 424 |
.contains(&query.trim().to_lowercase()) |
| 425 |
}); |
| 426 |
let matches_status = self |
| 427 |
.status |
| 428 |
.as_ref() |
| 429 |
.is_none_or(|status| &item.status == status); |
| 430 |
let matches_kind = self |
| 431 |
.kind |
| 432 |
.as_ref() |
| 433 |
.is_none_or(|kind| &item.item_type == kind); |
| 434 |
matches_query && matches_status && matches_kind |
| 435 |
} |
| 436 |
|
| 437 |
|
| 438 |
fn shown<'a>(&self, items: &'a [ContentItem]) -> Vec<&'a ContentItem> { |
| 439 |
let mut shown: Vec<&ContentItem> = items.iter().filter(|item| self.keeps(item)).collect(); |
| 440 |
if let Some(sort) = self.sort { |
| 441 |
|
| 442 |
|
| 443 |
shown.sort_by(|a, b| { |
| 444 |
let ordering = match sort { |
| 445 |
SortBy::Item => a.title.to_lowercase().cmp(&b.title.to_lowercase()), |
| 446 |
SortBy::Kind => a.item_type.to_lowercase().cmp(&b.item_type.to_lowercase()), |
| 447 |
SortBy::Price => a.price_cents.cmp(&b.price_cents), |
| 448 |
SortBy::Sales => a.sales.cmp(&b.sales), |
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
SortBy::Revenue => a.revenue.cmp(&b.revenue), |
| 454 |
SortBy::Status => a.status.cmp(&b.status), |
| 455 |
}; |
| 456 |
if self.descending { |
| 457 |
ordering.reverse() |
| 458 |
} else { |
| 459 |
ordering |
| 460 |
} |
| 461 |
}); |
| 462 |
} |
| 463 |
shown |
| 464 |
} |
| 465 |
} |
| 466 |
|
| 467 |
|
| 468 |
fn base(slug: &str) -> String { |
| 469 |
format!("/dashboard/project/{slug}/tabs/content") |
| 470 |
} |
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
fn tone(word: &str) -> layout::Tone { |
| 478 |
match word { |
| 479 |
"success" => layout::Tone::Success, |
| 480 |
"warning" => layout::Tone::Warning, |
| 481 |
"danger" => layout::Tone::Danger, |
| 482 |
_ => layout::Tone::Neutral, |
| 483 |
} |
| 484 |
} |
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
struct Sortable { |
| 491 |
|
| 492 |
name: &'static str, |
| 493 |
|
| 494 |
sort: SortBy, |
| 495 |
|
| 496 |
width: layout::Width, |
| 497 |
|
| 498 |
priority: layout::Priority, |
| 499 |
} |
| 500 |
|
| 501 |
|
| 502 |
const SORTABLE: &[Sortable] = &[ |
| 503 |
Sortable { |
| 504 |
name: "Item", |
| 505 |
sort: SortBy::Item, |
| 506 |
width: layout::Width::Fill, |
| 507 |
priority: layout::Priority::Essential, |
| 508 |
}, |
| 509 |
Sortable { |
| 510 |
name: "Type", |
| 511 |
sort: SortBy::Kind, |
| 512 |
width: layout::Width::Content, |
| 513 |
priority: layout::Priority::Secondary, |
| 514 |
}, |
| 515 |
Sortable { |
| 516 |
name: "Price", |
| 517 |
sort: SortBy::Price, |
| 518 |
width: layout::Width::Content, |
| 519 |
priority: layout::Priority::Secondary, |
| 520 |
}, |
| 521 |
Sortable { |
| 522 |
name: "Sales", |
| 523 |
sort: SortBy::Sales, |
| 524 |
width: layout::Width::Content, |
| 525 |
priority: layout::Priority::Optional, |
| 526 |
}, |
| 527 |
Sortable { |
| 528 |
name: "Revenue", |
| 529 |
sort: SortBy::Revenue, |
| 530 |
width: layout::Width::Content, |
| 531 |
priority: layout::Priority::Optional, |
| 532 |
}, |
| 533 |
Sortable { |
| 534 |
name: "Status", |
| 535 |
sort: SortBy::Status, |
| 536 |
width: layout::Width::Content, |
| 537 |
priority: layout::Priority::Essential, |
| 538 |
}, |
| 539 |
]; |
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
#[must_use] |
| 547 |
pub fn fill( |
| 548 |
slug: &str, |
| 549 |
items: &[ContentItem], |
| 550 |
deleted: &[DeletedItemRow], |
| 551 |
posts: &[BlogPostDashboardRow], |
| 552 |
view: &View, |
| 553 |
) -> String { |
| 554 |
use quasi_axum::Serves as _; |
| 555 |
|
| 556 |
let mut out = String::new(); |
| 557 |
for node in body(slug, items, deleted, posts, view) { |
| 558 |
out.push_str(&Webview::new().fragment(&node)); |
| 559 |
} |
| 560 |
out |
| 561 |
} |
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
#[must_use] |
| 570 |
pub fn fragment( |
| 571 |
slug: &str, |
| 572 |
items: &[ContentItem], |
| 573 |
deleted: &[DeletedItemRow], |
| 574 |
posts: &[BlogPostDashboardRow], |
| 575 |
view: &View, |
| 576 |
) -> String { |
| 577 |
use quasi_axum::Serves as _; |
| 578 |
|
| 579 |
let mut slot = Slot::new(REGION, RegionKind::Pane); |
| 580 |
for node in body(slug, items, deleted, posts, view) { |
| 581 |
slot = slot.with(node); |
| 582 |
} |
| 583 |
Webview::new().fragment(&Node::Region(slot)) |
| 584 |
} |
| 585 |
|
| 586 |
declare! { |
| 587 |
|
| 588 |
shape body( |
| 589 |
slug: &str, |
| 590 |
items: &[ContentItem], |
| 591 |
deleted: &[DeletedItemRow], |
| 592 |
posts: &[BlogPostDashboardRow], |
| 593 |
view: &View, |
| 594 |
) -> Vec<Node>; |
| 595 |
|
| 596 |
let shown = view.shown(items); |
| 597 |
|
| 598 |
section "Items"; |
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
act "New Item" to external "/dashboard/project/{slug}/new-item"; |
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
empty "No items in this project yet. Add your first item to start publishing." |
| 608 |
when items.is_empty() { |
| 609 |
offering "Add First Item" to external "/dashboard/project/{slug}/new-item"; |
| 610 |
} |
| 611 |
text "After creating an item, set its pricing and publish it to make it available to fans." |
| 612 |
when items.is_empty(); |
| 613 |
|
| 614 |
include filters(slug, items, view) unless items.is_empty(); |
| 615 |
include bulk(slug, view) unless items.is_empty(); |
| 616 |
|
| 617 |
empty "No items match these filters." when shown.is_empty() and not items.is_empty() { |
| 618 |
offering "Clear filters" to doing view.cleared().panel(slug); |
| 619 |
} |
| 620 |
include table(slug, view, &shown) unless shown.is_empty(); |
| 621 |
|
| 622 |
section "Recently Deleted ({deleted.len()})" unless deleted.is_empty(); |
| 623 |
text "Deleted items are permanently removed after 7 days." unless deleted.is_empty(); |
| 624 |
include deleted_table(slug, view, deleted) unless deleted.is_empty(); |
| 625 |
|
| 626 |
section "Blog Posts"; |
| 627 |
act "New Post" to external "/dashboard/project/{slug}/blog/new"; |
| 628 |
empty "No blog posts yet. Share updates, release notes, or stories with your audience." |
| 629 |
when posts.is_empty(); |
| 630 |
include posts_table(slug, view, posts) unless posts.is_empty(); |
| 631 |
} |
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
fn kinds(items: &[ContentItem], view: &View) -> Vec<String> { |
| 642 |
let mut kinds: Vec<String> = items.iter().map(|item| item.item_type.clone()).collect(); |
| 643 |
if let Some(kind) = &view.kind { |
| 644 |
kinds.push(kind.clone()); |
| 645 |
} |
| 646 |
kinds.sort_unstable(); |
| 647 |
kinds.dedup(); |
| 648 |
kinds |
| 649 |
} |
| 650 |
|
| 651 |
declare! { |
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
shape filters(slug: &str, items: &[ContentItem], view: &View) -> Slot; |
| 666 |
|
| 667 |
region "content-filters" as Group { |
| 668 |
field Text "q" "Search items" { |
| 669 |
placeholder "Search items..."; |
| 670 |
value view.query_text(); |
| 671 |
consulting Consult::new(view.narrowed().without_query().panel(slug)) |
| 672 |
.after(SEARCH_WAIT) |
| 673 |
.at_least(SEARCH_FLOOR); |
| 674 |
} |
| 675 |
|
| 676 |
field Select "status" "Status" { |
| 677 |
option Choice::new("", "All statuses"); |
| 678 |
for status in STATUSES { |
| 679 |
option Choice::new(status, status); |
| 680 |
} |
| 681 |
value view.status_text(); |
| 682 |
consulting Consult::at_once(view.narrowed().without_status().panel(slug)); |
| 683 |
} |
| 684 |
|
| 685 |
field Select "type" "Type" { |
| 686 |
option Choice::new("", "All types"); |
| 687 |
for kind in kinds(items, view) { |
| 688 |
option Choice::new(kind.clone(), kind); |
| 689 |
} |
| 690 |
value view.kind_text(); |
| 691 |
consulting Consult::at_once(view.narrowed().without_kind().panel(slug)); |
| 692 |
} |
| 693 |
} |
| 694 |
} |
| 695 |
|
| 696 |
declare! { |
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
shape bulk(slug: &str, view: &View) -> Slot; |
| 707 |
|
| 708 |
region "content-bulk" as Group { |
| 709 |
act "Publish" to doing view.write(slug, "bulk/publish") { |
| 710 |
over SELECTION; |
| 711 |
} |
| 712 |
act "Unpublish" to doing view.write(slug, "bulk/unpublish") { |
| 713 |
over SELECTION; |
| 714 |
} |
| 715 |
act "Set Price" to doing view.write(slug, "bulk/price") { |
| 716 |
over SELECTION; |
| 717 |
asking Field::new(layout::FieldKind::Number, "price_dollars", "New price") |
| 718 |
.unit("USD") |
| 719 |
.hint("Enter 0 to make items free."); |
| 720 |
} |
| 721 |
act "Add Tag" to doing view.write(slug, "bulk/tag") { |
| 722 |
over SELECTION; |
| 723 |
asking Field::new(layout::FieldKind::Text, "tag_slug", "Tag slug") |
| 724 |
.placeholder("e.g. audio.genre.ambient") |
| 725 |
.hint("Use dot-notation: type.category.value"); |
| 726 |
} |
| 727 |
act "Delete" to doing view.write(slug, "bulk/delete") { |
| 728 |
over SELECTION; |
| 729 |
tone Danger; |
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
confirm "Delete every selected item? This cannot be undone."; |
| 734 |
} |
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
act "Select all" to doing view.all_ticked().panel(slug); |
| 739 |
act "Deselect" to doing view.narrowed().panel(slug) when view.ticked; |
| 740 |
} |
| 741 |
} |
| 742 |
|
| 743 |
declare! { |
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
shape table(slug: &str, view: &View, shown: &[&ContentItem]) -> Node; |
| 755 |
|
| 756 |
table { |
| 757 |
column "#" { |
| 758 |
width Content; |
| 759 |
} |
| 760 |
for heading in SORTABLE { |
| 761 |
column heading.name { |
| 762 |
width heading.width; |
| 763 |
priority heading.priority; |
| 764 |
reorder view.sorted_by(heading.sort).panel(slug); |
| 765 |
sorted view.direction() when view.orders_by(heading.sort); |
| 766 |
} |
| 767 |
} |
| 768 |
column "Actions" { |
| 769 |
width Content; |
| 770 |
priority Essential; |
| 771 |
} |
| 772 |
|
| 773 |
for row in numbered(view, shown) { |
| 774 |
include item_row(slug, view, &row); |
| 775 |
for child in row.children() { |
| 776 |
include child_row(view, child); |
| 777 |
} |
| 778 |
} |
| 779 |
} |
| 780 |
} |
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
struct Placed<'a> { |
| 788 |
item: &'a ContentItem, |
| 789 |
|
| 790 |
first: bool, |
| 791 |
|
| 792 |
last: bool, |
| 793 |
|
| 794 |
open: bool, |
| 795 |
} |
| 796 |
|
| 797 |
impl<'a> Placed<'a> { |
| 798 |
|
| 799 |
fn children(&self) -> &'a [ContentItem] { |
| 800 |
if self.open { &self.item.children } else { &[] } |
| 801 |
} |
| 802 |
} |
| 803 |
|
| 804 |
|
| 805 |
fn numbered<'a>(view: &View, shown: &[&'a ContentItem]) -> Vec<Placed<'a>> { |
| 806 |
shown |
| 807 |
.iter() |
| 808 |
.enumerate() |
| 809 |
.map(|(at, item)| Placed { |
| 810 |
item, |
| 811 |
first: at == 0, |
| 812 |
last: at + 1 == shown.len(), |
| 813 |
open: view.is_open(&item.id), |
| 814 |
}) |
| 815 |
.collect() |
| 816 |
} |
| 817 |
|
| 818 |
|
| 819 |
fn kind_label(item: &ContentItem) -> String { |
| 820 |
if item.children.is_empty() { |
| 821 |
item.item_type.clone() |
| 822 |
} else { |
| 823 |
format!("{} ({})", item.item_type, item.children.len()) |
| 824 |
} |
| 825 |
} |
| 826 |
|
| 827 |
|
| 828 |
fn expand_label(row: &Placed<'_>) -> &'static str { |
| 829 |
if row.open { "Collapse" } else { "Expand" } |
| 830 |
} |
| 831 |
|
| 832 |
|
| 833 |
fn is_bundle(row: &Placed<'_>) -> bool { |
| 834 |
!row.item.children.is_empty() |
| 835 |
} |
| 836 |
|
| 837 |
|
| 838 |
fn moves_up(view: &View, row: &Placed<'_>) -> bool { |
| 839 |
view.keeps_order() && !row.first |
| 840 |
} |
| 841 |
|
| 842 |
|
| 843 |
fn moves_down(view: &View, row: &Placed<'_>) -> bool { |
| 844 |
view.keeps_order() && !row.last |
| 845 |
} |
| 846 |
|
| 847 |
|
| 848 |
fn is_draft(item: &ContentItem) -> bool { |
| 849 |
item.status == "Draft" |
| 850 |
} |
| 851 |
|
| 852 |
declare! { |
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
shape item_row(slug: &str, view: &View, row: &Placed<'_>) -> Row; |
| 859 |
|
| 860 |
cells { |
| 861 |
ticking row.item.id.clone() view.ticked; |
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
cell at "#" row.item.position.to_string() { |
| 867 |
act "Move up" to doing view.write(slug, &"move/{row.item.id}").carrying("direction", "up") |
| 868 |
when moves_up(view, row); |
| 869 |
act "Move down" |
| 870 |
to doing view.write(slug, &"move/{row.item.id}").carrying("direction", "down") |
| 871 |
when moves_down(view, row); |
| 872 |
} |
| 873 |
|
| 874 |
cell at "Item" row.item.title.clone() { |
| 875 |
activate to external "/dashboard/item/{row.item.id}"; |
| 876 |
token Tag::badge("Unlisted") when row.item.is_unlisted; |
| 877 |
act expand_label(row) to doing view.toggling(&row.item.id).panel(slug) |
| 878 |
when is_bundle(row); |
| 879 |
} |
| 880 |
|
| 881 |
cell at "Type" kind_label(row.item); |
| 882 |
cell at "Price" row.item.price.clone(); |
| 883 |
cell at "Sales" row.item.sales.to_string(); |
| 884 |
cell at "Revenue" row.item.revenue.clone(); |
| 885 |
cell at "Status" "" { |
| 886 |
token Tag::badge(row.item.status.clone()).tone(tone(row.item.status_tone)); |
| 887 |
} |
| 888 |
|
| 889 |
|
| 890 |
cell at "Actions" "" { |
| 891 |
act "Continue" |
| 892 |
to external "/dashboard/project/{slug}/new-item/{row.item.id}/step/details" |
| 893 |
when is_draft(row.item); |
| 894 |
act "Publish" to doing view.write(slug, &"publish/{row.item.id}") |
| 895 |
when is_draft(row.item); |
| 896 |
act "View" to external "/i/{row.item.id}" unless is_draft(row.item); |
| 897 |
act "Edit" to external "/dashboard/item/{row.item.id}"; |
| 898 |
|
| 899 |
|
| 900 |
act "Rename" to doing view.write(slug, &"rename/{row.item.id}") { |
| 901 |
asking Field::new(layout::FieldKind::Text, "title", "Title") |
| 902 |
.value(row.item.title.clone()); |
| 903 |
} |
| 904 |
} |
| 905 |
} |
| 906 |
} |
| 907 |
|
| 908 |
declare! { |
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
shape child_row(view: &View, child: &ContentItem) -> Row; |
| 923 |
|
| 924 |
cells { |
| 925 |
ticking child.id.clone() view.ticked; |
| 926 |
|
| 927 |
cell at "Item" "\u{21b3} {child.title}" { |
| 928 |
activate to external "/dashboard/item/{child.id}"; |
| 929 |
} |
| 930 |
cell at "Type" child.item_type.clone(); |
| 931 |
cell at "Price" child.price.clone(); |
| 932 |
cell at "Sales" child.sales.to_string(); |
| 933 |
cell at "Revenue" child.revenue.clone(); |
| 934 |
cell at "Status" "" { |
| 935 |
token Tag::badge(child.status.clone()).tone(tone(child.status_tone)); |
| 936 |
} |
| 937 |
cell at "Actions" "" { |
| 938 |
act "Edit" to external "/dashboard/item/{child.id}"; |
| 939 |
} |
| 940 |
} |
| 941 |
} |
| 942 |
|
| 943 |
declare! { |
| 944 |
|
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
shape deleted_table(slug: &str, view: &View, deleted: &[DeletedItemRow]) -> Node; |
| 950 |
|
| 951 |
table { |
| 952 |
column "Title" { |
| 953 |
width Fill; |
| 954 |
priority Essential; |
| 955 |
} |
| 956 |
column "Deleted" { |
| 957 |
width Content; |
| 958 |
} |
| 959 |
column "" { |
| 960 |
width Content; |
| 961 |
priority Essential; |
| 962 |
} |
| 963 |
|
| 964 |
for item in deleted.iter() { |
| 965 |
cells { |
| 966 |
cell item.title.clone(); |
| 967 |
cell item.deleted_at.clone(); |
| 968 |
cell "" { |
| 969 |
act "Restore" to doing view.write(slug, &"restore/{item.id}"); |
| 970 |
} |
| 971 |
} |
| 972 |
} |
| 973 |
} |
| 974 |
} |
| 975 |
|
| 976 |
declare! { |
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
shape posts_table(slug: &str, view: &View, posts: &[BlogPostDashboardRow]) -> Node; |
| 982 |
|
| 983 |
table { |
| 984 |
column "Title" { |
| 985 |
width Fill; |
| 986 |
priority Essential; |
| 987 |
} |
| 988 |
column "Status" { |
| 989 |
width Content; |
| 990 |
} |
| 991 |
column "Published" { |
| 992 |
width Content; |
| 993 |
priority Optional; |
| 994 |
} |
| 995 |
column "Actions" { |
| 996 |
width Content; |
| 997 |
priority Essential; |
| 998 |
} |
| 999 |
|
| 1000 |
for post in posts.iter() { |
| 1001 |
cells { |
| 1002 |
cell post.title.clone() { |
| 1003 |
activate to external "/p/{slug}/blog/{post.slug}"; |
| 1004 |
} |
| 1005 |
cell "" { |
| 1006 |
token Tag::badge(post.status.clone()).tone(tone(post.status_tone)); |
| 1007 |
} |
| 1008 |
cell post.published_at.clone(); |
| 1009 |
cell "" { |
| 1010 |
act "View" to external "/p/{slug}/blog/{post.slug}"; |
| 1011 |
act "Edit" to external "/dashboard/project/{slug}/blog/new?post={post.id}"; |
| 1012 |
act "Delete" to doing view.write(slug, &"blog/{post.id}/delete") { |
| 1013 |
tone Danger; |
| 1014 |
confirm "Delete this blog post?"; |
| 1015 |
} |
| 1016 |
} |
| 1017 |
} |
| 1018 |
} |
| 1019 |
} |
| 1020 |
} |
| 1021 |
|
| 1022 |
#[cfg(test)] |
| 1023 |
mod tests { |
| 1024 |
use super::*; |
| 1025 |
|
| 1026 |
const SLUG: &str = "a-project"; |
| 1027 |
|
| 1028 |
fn item(id: &str, title: &str, kind: &str, status: &str, cents: i32) -> ContentItem { |
| 1029 |
ContentItem { |
| 1030 |
position: 1, |
| 1031 |
title: title.into(), |
| 1032 |
item_type: kind.into(), |
| 1033 |
price: format!("${}", cents / 100), |
| 1034 |
price_cents: cents, |
| 1035 |
price_dollars: format!("{}.00", cents / 100), |
| 1036 |
sales: 0, |
| 1037 |
revenue: "$0".into(), |
| 1038 |
status: status.into(), |
| 1039 |
status_tone: if status == "Active" { |
| 1040 |
"success" |
| 1041 |
} else { |
| 1042 |
"warning" |
| 1043 |
}, |
| 1044 |
id: id.into(), |
| 1045 |
is_unlisted: false, |
| 1046 |
children: Vec::new(), |
| 1047 |
} |
| 1048 |
} |
| 1049 |
|
| 1050 |
fn catalogue() -> Vec<ContentItem> { |
| 1051 |
vec![ |
| 1052 |
item("i-1", "Kick Pack", "audio", "Active", 500), |
| 1053 |
item("i-2", "Snare Pack", "audio", "Draft", 0), |
| 1054 |
item("i-3", "Field Notes", "text", "Active", 1200), |
| 1055 |
] |
| 1056 |
} |
| 1057 |
|
| 1058 |
fn panel(view: &View) -> String { |
| 1059 |
fragment(SLUG, &catalogue(), &[], &[], view) |
| 1060 |
} |
| 1061 |
|
| 1062 |
#[test] |
| 1063 |
fn a_filter_is_a_route_and_not_a_pass_over_rendered_rows() { |
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
let html = panel(&View::default()); |
| 1068 |
|
| 1069 |
assert!(html.contains("name=\"q\""), "{html}"); |
| 1070 |
assert!(html.contains("name=\"status\""), "{html}"); |
| 1071 |
assert!(html.contains("name=\"type\""), "{html}"); |
| 1072 |
assert!(!html.contains("filterContentTable"), "{html}"); |
| 1073 |
assert!( |
| 1074 |
html.contains("/dashboard/project/a-project/tabs/content"), |
| 1075 |
"{html}" |
| 1076 |
); |
| 1077 |
} |
| 1078 |
|
| 1079 |
#[test] |
| 1080 |
fn a_control_does_not_carry_the_value_it_is_asking_for() { |
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
let view = View { |
| 1085 |
query: Some("kick".into()), |
| 1086 |
status: Some("Active".into()), |
| 1087 |
..View::default() |
| 1088 |
}; |
| 1089 |
let filters = filters(SLUG, &catalogue(), &view); |
| 1090 |
let html = { |
| 1091 |
use quasi_axum::Serves as _; |
| 1092 |
Webview::new().fragment(&Node::Region(filters)) |
| 1093 |
}; |
| 1094 |
|
| 1095 |
|
| 1096 |
let controls: Vec<&str> = html.split("<div class=\"field-").skip(1).collect(); |
| 1097 |
assert_eq!(controls.len(), 3, "{html}"); |
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
assert!(controls[0].contains("status=Active"), "{html}"); |
| 1102 |
assert!(!controls[0].contains("q=kick"), "{html}"); |
| 1103 |
|
| 1104 |
|
| 1105 |
assert!(controls[1].contains("q=kick"), "{html}"); |
| 1106 |
assert!(!controls[1].contains("status=Active"), "{html}"); |
| 1107 |
|
| 1108 |
|
| 1109 |
assert!(controls[2].contains("q=kick"), "{html}"); |
| 1110 |
assert!(controls[2].contains("status=Active"), "{html}"); |
| 1111 |
} |
| 1112 |
|
| 1113 |
#[test] |
| 1114 |
fn every_row_joins_the_selection_under_its_own_id() { |
| 1115 |
let html = panel(&View::default()); |
| 1116 |
|
| 1117 |
for id in ["i-1", "i-2", "i-3"] { |
| 1118 |
assert!( |
| 1119 |
html.contains(&format!("name=\"ticked\" value=\"{id}\"")), |
| 1120 |
"{html}" |
| 1121 |
); |
| 1122 |
} |
| 1123 |
|
| 1124 |
assert!(!html.contains("checked"), "{html}"); |
| 1125 |
} |
| 1126 |
|
| 1127 |
#[test] |
| 1128 |
fn select_all_is_an_address() { |
| 1129 |
let html = panel(&View::default()); |
| 1130 |
assert!(html.contains("ticked=all"), "{html}"); |
| 1131 |
|
| 1132 |
let all = panel(&View { |
| 1133 |
ticked: true, |
| 1134 |
..View::default() |
| 1135 |
}); |
| 1136 |
assert_eq!(all.matches("checked").count(), 3, "{all}"); |
| 1137 |
assert!(all.contains(">Deselect<"), "{all}"); |
| 1138 |
} |
| 1139 |
|
| 1140 |
#[test] |
| 1141 |
fn the_bar_holds_five_verbs_over_the_selection() { |
| 1142 |
let html = panel(&View::default()); |
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
assert_eq!(html.matches("data-over=\"chosen\"").count(), 5, "{html}"); |
| 1147 |
for verb in ["Publish", "Unpublish", "Set Price", "Add Tag", "Delete"] { |
| 1148 |
assert!(html.contains(verb), "{verb} missing:\n{html}"); |
| 1149 |
} |
| 1150 |
assert!(html.contains("name=\"price_dollars\""), "{html}"); |
| 1151 |
assert!(html.contains("name=\"tag_slug\""), "{html}"); |
| 1152 |
assert!(html.contains("Enter 0 to make items free."), "{html}"); |
| 1153 |
} |
| 1154 |
|
| 1155 |
#[test] |
| 1156 |
fn a_destructive_verb_asks_before_it_runs() { |
| 1157 |
let html = panel(&View::default()); |
| 1158 |
assert!( |
| 1159 |
html.contains("Delete every selected item? This cannot be undone."), |
| 1160 |
"{html}" |
| 1161 |
); |
| 1162 |
} |
| 1163 |
|
| 1164 |
#[test] |
| 1165 |
fn pressing_a_heading_orders_by_it_and_pressing_it_again_flips() { |
| 1166 |
let first = View::default().sorted_by(SortBy::Price); |
| 1167 |
assert_eq!(first.sort, Some(SortBy::Price)); |
| 1168 |
assert!(!first.descending); |
| 1169 |
|
| 1170 |
let again = first.sorted_by(SortBy::Price); |
| 1171 |
assert!(again.descending); |
| 1172 |
|
| 1173 |
|
| 1174 |
let elsewhere = again.sorted_by(SortBy::Item); |
| 1175 |
assert_eq!(elsewhere.sort, Some(SortBy::Item)); |
| 1176 |
assert!(!elsewhere.descending); |
| 1177 |
} |
| 1178 |
|
| 1179 |
#[test] |
| 1180 |
fn the_sorted_column_says_so_where_a_reader_can_hear_it() { |
| 1181 |
let html = panel(&View { |
| 1182 |
sort: Some(SortBy::Item), |
| 1183 |
descending: true, |
| 1184 |
..View::default() |
| 1185 |
}); |
| 1186 |
|
| 1187 |
assert!(html.contains("aria-sort=\"descending\""), "{html}"); |
| 1188 |
assert_eq!(html.matches("aria-sort=").count(), 1, "{html}"); |
| 1189 |
} |
| 1190 |
|
| 1191 |
#[test] |
| 1192 |
fn ordering_is_the_view_and_not_the_documents_order() { |
| 1193 |
let items = catalogue(); |
| 1194 |
let by_price = View { |
| 1195 |
sort: Some(SortBy::Price), |
| 1196 |
..View::default() |
| 1197 |
}; |
| 1198 |
let titles: Vec<&str> = by_price |
| 1199 |
.shown(&items) |
| 1200 |
.iter() |
| 1201 |
.map(|item| item.title.as_str()) |
| 1202 |
.collect(); |
| 1203 |
assert_eq!(titles, ["Snare Pack", "Kick Pack", "Field Notes"]); |
| 1204 |
|
| 1205 |
let down = View { |
| 1206 |
descending: true, |
| 1207 |
..by_price |
| 1208 |
}; |
| 1209 |
let titles: Vec<&str> = down |
| 1210 |
.shown(&items) |
| 1211 |
.iter() |
| 1212 |
.map(|item| item.title.as_str()) |
| 1213 |
.collect(); |
| 1214 |
assert_eq!(titles, ["Field Notes", "Kick Pack", "Snare Pack"]); |
| 1215 |
} |
| 1216 |
|
| 1217 |
#[test] |
| 1218 |
fn the_reorder_arrows_leave_when_a_sort_is_in_force() { |
| 1219 |
|
| 1220 |
|
| 1221 |
let plain = panel(&View::default()); |
| 1222 |
assert!( |
| 1223 |
plain.contains("Move up") || plain.contains("Move down"), |
| 1224 |
"{plain}" |
| 1225 |
); |
| 1226 |
|
| 1227 |
let sorted = panel(&View { |
| 1228 |
sort: Some(SortBy::Item), |
| 1229 |
..View::default() |
| 1230 |
}); |
| 1231 |
assert!(!sorted.contains("Move up"), "{sorted}"); |
| 1232 |
assert!(!sorted.contains("Move down"), "{sorted}"); |
| 1233 |
} |
| 1234 |
|
| 1235 |
#[test] |
| 1236 |
fn narrowing_drops_the_rows_it_hides_rather_than_hiding_them() { |
| 1237 |
let items = catalogue(); |
| 1238 |
|
| 1239 |
let searched = View { |
| 1240 |
query: Some("pack".into()), |
| 1241 |
..View::default() |
| 1242 |
}; |
| 1243 |
assert_eq!(searched.shown(&items).len(), 2); |
| 1244 |
|
| 1245 |
let drafts = View { |
| 1246 |
status: Some("Draft".into()), |
| 1247 |
..View::default() |
| 1248 |
}; |
| 1249 |
assert_eq!(drafts.shown(&items).len(), 1); |
| 1250 |
|
| 1251 |
let text = View { |
| 1252 |
kind: Some("text".into()), |
| 1253 |
..View::default() |
| 1254 |
}; |
| 1255 |
assert_eq!(text.shown(&items).len(), 1); |
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
let html = panel(&drafts); |
| 1260 |
assert!(html.contains("Snare Pack"), "{html}"); |
| 1261 |
assert!(!html.contains("Kick Pack"), "{html}"); |
| 1262 |
} |
| 1263 |
|
| 1264 |
#[test] |
| 1265 |
fn the_status_filter_can_name_every_status_a_row_wears() { |
| 1266 |
|
| 1267 |
|
| 1268 |
let html = panel(&View::default()); |
| 1269 |
for status in STATUSES { |
| 1270 |
assert!(html.contains(&format!("value=\"{status}\"")), "{html}"); |
| 1271 |
} |
| 1272 |
} |
| 1273 |
|
| 1274 |
#[test] |
| 1275 |
fn a_filter_that_matches_nothing_says_so_and_offers_a_way_out() { |
| 1276 |
let html = panel(&View { |
| 1277 |
query: Some("nothing here".into()), |
| 1278 |
..View::default() |
| 1279 |
}); |
| 1280 |
|
| 1281 |
assert!(html.contains("No items match these filters."), "{html}"); |
| 1282 |
assert!(html.contains("Clear filters"), "{html}"); |
| 1283 |
} |
| 1284 |
|
| 1285 |
#[test] |
| 1286 |
fn an_empty_project_is_a_different_sentence_from_an_empty_filter() { |
| 1287 |
let html = fragment(SLUG, &[], &[], &[], &View::default()); |
| 1288 |
|
| 1289 |
assert!(html.contains("No items in this project yet."), "{html}"); |
| 1290 |
assert!(html.contains("Add First Item"), "{html}"); |
| 1291 |
|
| 1292 |
assert!(!html.contains("data-over"), "{html}"); |
| 1293 |
assert!(!html.contains("name=\"q\""), "{html}"); |
| 1294 |
} |
| 1295 |
|
| 1296 |
#[test] |
| 1297 |
fn a_bundles_children_arrive_when_the_address_says_they_are_open() { |
| 1298 |
let mut items = catalogue(); |
| 1299 |
items[0].children = vec![item("i-1a", "Kick 01", "audio", "Active", 0)]; |
| 1300 |
|
| 1301 |
let shut = fragment(SLUG, &items, &[], &[], &View::default()); |
| 1302 |
assert!(shut.contains("Expand"), "{shut}"); |
| 1303 |
assert!(!shut.contains("Kick 01"), "{shut}"); |
| 1304 |
|
| 1305 |
let open = fragment( |
| 1306 |
SLUG, |
| 1307 |
&items, |
| 1308 |
&[], |
| 1309 |
&[], |
| 1310 |
&View { |
| 1311 |
open: vec!["i-1".into()], |
| 1312 |
..View::default() |
| 1313 |
}, |
| 1314 |
); |
| 1315 |
assert!(open.contains("Kick 01"), "{open}"); |
| 1316 |
assert!(open.contains("Collapse"), "{open}"); |
| 1317 |
|
| 1318 |
assert!(open.contains("name=\"ticked\" value=\"i-1a\""), "{open}"); |
| 1319 |
} |
| 1320 |
|
| 1321 |
#[test] |
| 1322 |
fn a_rename_is_a_control_that_asks_for_the_new_name() { |
| 1323 |
|
| 1324 |
|
| 1325 |
let html = panel(&View::default()); |
| 1326 |
|
| 1327 |
assert!(html.contains("Rename"), "{html}"); |
| 1328 |
assert!(html.contains("value=\"Kick Pack\""), "{html}"); |
| 1329 |
assert!(html.contains("/tabs/content/rename/i-1"), "{html}"); |
| 1330 |
} |
| 1331 |
|
| 1332 |
#[test] |
| 1333 |
fn a_route_answers_with_the_id_its_answer_lands_on() { |
| 1334 |
|
| 1335 |
|
| 1336 |
|
| 1337 |
let answer = panel(&View::default()); |
| 1338 |
assert!(answer.contains("id=\"project-content\""), "{answer}"); |
| 1339 |
assert!( |
| 1340 |
answer.contains("hx-target=\"#project-content\""), |
| 1341 |
"{answer}" |
| 1342 |
); |
| 1343 |
|
| 1344 |
|
| 1345 |
|
| 1346 |
let inline = fill(SLUG, &catalogue(), &[], &[], &View::default()); |
| 1347 |
assert!(!inline.contains("id=\"project-content\""), "{inline}"); |
| 1348 |
} |
| 1349 |
|
| 1350 |
#[test] |
| 1351 |
fn a_write_comes_back_under_the_view_it_was_pressed_on() { |
| 1352 |
let view = View { |
| 1353 |
query: Some("pack".into()), |
| 1354 |
status: Some("Active".into()), |
| 1355 |
..View::default() |
| 1356 |
}; |
| 1357 |
let html = panel(&view); |
| 1358 |
|
| 1359 |
|
| 1360 |
|
| 1361 |
assert!(html.contains("bulk/publish?"), "{html}"); |
| 1362 |
assert!(html.contains("q=pack"), "{html}"); |
| 1363 |
} |
| 1364 |
|
| 1365 |
#[test] |
| 1366 |
fn an_address_naming_a_column_no_heading_carries_is_refused() { |
| 1367 |
|
| 1368 |
assert!(View::of(None, None, None, Some("urgency"), None, None, None).is_none()); |
| 1369 |
assert!(View::of(None, None, None, Some("price"), None, None, None).is_some()); |
| 1370 |
} |
| 1371 |
|
| 1372 |
#[test] |
| 1373 |
fn a_blank_param_is_an_absent_one() { |
| 1374 |
|
| 1375 |
let view = View::of(Some(" "), Some(""), Some(""), None, None, None, None) |
| 1376 |
.expect("a blank view parses"); |
| 1377 |
assert!(view.is_default()); |
| 1378 |
assert!(!view.filtered()); |
| 1379 |
} |
| 1380 |
|
| 1381 |
#[test] |
| 1382 |
fn a_status_the_table_cannot_show_narrows_nothing() { |
| 1383 |
|
| 1384 |
|
| 1385 |
let view = |
| 1386 |
View::of(None, Some("Retired"), None, None, None, None, None).expect("the view parses"); |
| 1387 |
assert_eq!(view.status, None); |
| 1388 |
} |
| 1389 |
|
| 1390 |
#[test] |
| 1391 |
fn a_narrowing_does_not_carry_everything_forward() { |
| 1392 |
|
| 1393 |
|
| 1394 |
let view = View { |
| 1395 |
ticked: true, |
| 1396 |
query: Some("pack".into()), |
| 1397 |
..View::default() |
| 1398 |
}; |
| 1399 |
assert!(!view.sorted_by(SortBy::Item).ticked); |
| 1400 |
assert!(!view.narrowed().ticked); |
| 1401 |
|
| 1402 |
assert!(view.toggling("i-1").ticked); |
| 1403 |
} |
| 1404 |
|
| 1405 |
#[test] |
| 1406 |
fn the_deleted_and_blog_tables_are_the_panels_own() { |
| 1407 |
let deleted = [DeletedItemRow { |
| 1408 |
id: "i-9".into(), |
| 1409 |
title: "Old Pack".into(), |
| 1410 |
deleted_at: "Aug 10, 2026".into(), |
| 1411 |
}]; |
| 1412 |
let posts = [BlogPostDashboardRow { |
| 1413 |
id: "p-1".into(), |
| 1414 |
title: "Release notes".into(), |
| 1415 |
slug: "release-notes".into(), |
| 1416 |
status: "Published".into(), |
| 1417 |
status_tone: "success", |
| 1418 |
published_at: "Aug 12, 2026".into(), |
| 1419 |
}]; |
| 1420 |
|
| 1421 |
let html = fragment(SLUG, &catalogue(), &deleted, &posts, &View::default()); |
| 1422 |
|
| 1423 |
assert!(html.contains("Recently Deleted (1)"), "{html}"); |
| 1424 |
assert!(html.contains("/tabs/content/restore/i-9"), "{html}"); |
| 1425 |
assert!(html.contains("Release notes"), "{html}"); |
| 1426 |
assert!(html.contains("/tabs/content/blog/p-1/delete"), "{html}"); |
| 1427 |
assert!(html.contains("Delete this blog post?"), "{html}"); |
| 1428 |
} |
| 1429 |
} |
| 1430 |
|