forge
Explore
Log in

Don't you dare go Hollow

The Import tab lists recent imports and the Imports tab is gone

Browse files at this commit

f8bdb1504c7af09ba04a2ead4ea4090cbcfc1cc0Ahmet Kaan GümüşParent: 1099185
  • ux
    • the Import tab lists recent imports and the Imports tab is gone
Show full message
🚸 ux: the Import tab lists recent imports and the Imports tab is gone
crates/forge-web/src/i18n/migrate.rsmodified+7 -4
@@ -36,7 +36,6 @@ pub enum K {
36 OptionsNote,36 OptionsNote,
37 StartImport,37 StartImport,
38 BulkLink,38 BulkLink,
39- JobsLink,
40 // Bulk import.39 // Bulk import.
41 BulkTitle,40 BulkTitle,
42 BulkIntro,41 BulkIntro,
@@ -54,6 +53,8 @@ pub enum K {
54 // Jobs.53 // Jobs.
55 JobsTitle,54 JobsTitle,
56 NoJobs,55 NoJobs,
56+ RecentImports,
57+ ViewAll,
57 JobQueued,58 JobQueued,
58 JobRunning,59 JobRunning,
59 JobDone,60 JobDone,
@@ -123,7 +124,6 @@ const ALL: &[K] = &[
123 K::OptionsNote,124 K::OptionsNote,
124 K::StartImport,125 K::StartImport,
125 K::BulkLink,126 K::BulkLink,
126- K::JobsLink,
127 K::BulkTitle,127 K::BulkTitle,
128 K::BulkIntro,128 K::BulkIntro,
129 K::BulkOwnerGitHub,129 K::BulkOwnerGitHub,
@@ -139,6 +139,8 @@ const ALL: &[K] = &[
139 K::BulkArchived,139 K::BulkArchived,
140 K::JobsTitle,140 K::JobsTitle,
141 K::NoJobs,141 K::NoJobs,
142+ K::RecentImports,
143+ K::ViewAll,
142 K::JobQueued,144 K::JobQueued,
143 K::JobRunning,145 K::JobRunning,
144 K::JobDone,146 K::JobDone,
@@ -225,7 +227,6 @@ fn pair(key: K) -> (&'static str, &'static str) {
225 ),227 ),
226 K::StartImport => ("Start import", "İçe aktarmayı başlat"),228 K::StartImport => ("Start import", "İçe aktarmayı başlat"),
227 K::BulkLink => ("Import several repositories", "Birden çok depoyu içe aktar"),229 K::BulkLink => ("Import several repositories", "Birden çok depoyu içe aktar"),
228- K::JobsLink => ("Imports", "İçe aktarmalar"),
229 K::BulkTitle => ("Import several repositories", "Birden çok depoyu içe aktar"),230 K::BulkTitle => ("Import several repositories", "Birden çok depoyu içe aktar"),
230 K::BulkIntro => (231 K::BulkIntro => (
231 "List the repositories of a user or organization, tick the ones you want and import them together.",232 "List the repositories of a user or organization, tick the ones you want and import them together.",
@@ -251,8 +252,10 @@ fn pair(key: K) -> (&'static str, &'static str) {
251 K::BulkPrivate => ("private", "özel"),252 K::BulkPrivate => ("private", "özel"),
252 K::BulkFork => ("fork", "çatal"),253 K::BulkFork => ("fork", "çatal"),
253 K::BulkArchived => ("archived", "arşivlenmiş"),254 K::BulkArchived => ("archived", "arşivlenmiş"),
254- K::JobsTitle => ("Imports", "İçe aktarmalar"),255+ K::JobsTitle => ("Import history", "İçe aktarma geçmişi"),
255 K::NoJobs => ("No imports yet.", "Henüz içe aktarma yok."),256 K::NoJobs => ("No imports yet.", "Henüz içe aktarma yok."),
257+ K::RecentImports => ("Recent imports", "Son içe aktarmalar"),
258+ K::ViewAll => ("View all", "Tümünü gör"),
256 K::JobQueued => ("Queued", "Sırada"),259 K::JobQueued => ("Queued", "Sırada"),
257 K::JobRunning => ("Running", "Çalışıyor"),260 K::JobRunning => ("Running", "Çalışıyor"),
258 K::JobDone => ("Done", "Bitti"),261 K::JobDone => ("Done", "Bitti"),
crates/forge-web/src/pages/import.rsmodified+86 -23
@@ -161,7 +161,6 @@ pub(crate) async fn newrepo_tabs(lang: Lang, active: &str) -> Result<impl View>
161 <nav class="import-tabs" aria-label=(g::t(lang, K::ImportTitle))>161 <nav class="import-tabs" aria-label=(g::t(lang, K::ImportTitle))>
162 <a href="/new" class="import-tab" aria-current=(create.then_some("page"))>(g::t(lang, K::TabCreate))</a>162 <a href="/new" class="import-tab" aria-current=(create.then_some("page"))>(g::t(lang, K::TabCreate))</a>
163 <a href="/new/import" class="import-tab" aria-current=(import.then_some("page"))>(g::t(lang, K::TabImport))</a>163 <a href="/new/import" class="import-tab" aria-current=(import.then_some("page"))>(g::t(lang, K::TabImport))</a>
164- <a href="/import" class="import-tab">(g::t(lang, K::JobsLink))</a>
165 </nav>164 </nav>
166 })165 })
167 }166 }
@@ -386,17 +385,41 @@ async fn import_form(
386 })385 })
387 }386 }
388 387
388+/// How many imports the Import tab lists under the form.
389+const RECENT_IMPORTS: usize = 5;
390+
391+/// The GET import page: the form, then the recent imports.
392+#[component]
393+async fn import_home(
394+ lang: Lang,
395+ csrf: String,
396+ draft: Draft,
397+ owners: Vec<String>,
398+ jobs: Vec<(ImportJob, Option<Repo>)>,
399+ more: bool,
400+) -> Result<impl View> {
401+ Ok(view! {
402+ import_form(lang: lang, csrf: csrf.as_str(), draft: draft, error: None, owners: owners)
403+ recent_imports(lang: lang, jobs: jobs, more: more)
404+ })
405+}
406+
389 #[page("/new/import")]407 #[page("/new/import")]
390 async fn import_page(cx: &Cx) -> Result<impl View> {408 async fn import_page(cx: &Cx) -> Result<impl View> {
391 let viewer = require_user(cx).await?;409 let viewer = require_user(cx).await?;
392 let lang = i18n::lang(cx, Some(&viewer.0));410 let lang = i18n::lang(cx, Some(&viewer.0));
393 let query = query_params::<SourceQuery>(cx)?;411 let query = query_params::<SourceQuery>(cx)?;
394 let source = source_of(query.source.as_deref());412 let source = source_of(query.source.as_deref());
395- let owners = owner_choices(app_context::<AppState>(cx), &viewer.0).await?;413+ let state = app_context::<AppState>(cx);
414+ let owners = owner_choices(state, &viewer.0).await?;
396 let csrf = viewer.1.csrf_token.clone();415 let csrf = viewer.1.csrf_token.clone();
416+ // One more than the list shows, so the page knows whether to offer "View all".
417+ let mut jobs = load_job_rows(state, &viewer.0.id, 6).await?;
418+ let more = jobs.len() > RECENT_IMPORTS;
419+ jobs.truncate(RECENT_IMPORTS);
397 Ok(view! { cx =>420 Ok(view! { cx =>
398 shell(title: g::t(lang, K::ImportTitle), viewer: Some(&viewer),421 shell(title: g::t(lang, K::ImportTitle), viewer: Some(&viewer),
399- import_form(lang: lang, csrf: csrf.as_str(), draft: Draft::fresh(source), error: None, owners: owners))422+ import_home(lang: lang, csrf: csrf, draft: Draft::fresh(source), owners: owners, jobs: jobs, more: more))
400 })423 })
401 }424 }
402 425
@@ -948,18 +971,28 @@ fn ago(lang: Lang, stamp: &str) -> String {
948 stamp_to_unix(stamp).map_or_else(String::new, |t| relative_time(lang, t, now_unix()))971 stamp_to_unix(stamp).map_or_else(String::new, |t| relative_time(lang, t, now_unix()))
949 }972 }
950 973
974+/// The user's newest import jobs, each with its repository once it exists.
975+async fn load_job_rows(
976+ state: &AppState,
977+ user_id: &str,
978+ limit: u32,
979+) -> Result<Vec<(ImportJob, Option<Repo>)>> {
980+ let jobs = state.store.list_import_jobs(user_id, limit).await?;
981+ let mut rows = Vec::with_capacity(jobs.len());
982+ for job in jobs {
983+ let repo = match &job.repo_id {
984+ Some(id) => state.store.repo_by_id(id).await?,
985+ None => None,
986+ };
987+ rows.push((job, repo));
988+ }
989+ Ok(rows)
990+}
991+
992+/// The import job rows, shared by the Import history page and the recent list on the Import tab.
951 #[component]993 #[component]
952-async fn jobs_list(lang: Lang, jobs: Vec<(ImportJob, Option<Repo>)>) -> Result<impl View> {994+async fn job_rows(lang: Lang, jobs: Vec<(ImportJob, Option<Repo>)>) -> Result<impl View> {
953- let empty = jobs.is_empty();
954 Ok(view! {995 Ok(view! {
955- newrepo_tabs(lang: lang, active: "jobs")
956- <section class="page-head">
957- <h1>(g::t(lang, K::JobsTitle))</h1>
958- </section>
959- if empty {
960- <p class="muted">(g::t(lang, K::NoJobs))</p>
961- } else {
962- <section class="card">
963 <ul class="item-list import-jobs">996 <ul class="item-list import-jobs">
964 for (job, repo) in jobs.iter() {997 for (job, repo) in jobs.iter() {
965 <li class="item import-job-row">998 <li class="item import-job-row">
@@ -974,6 +1007,44 @@ async fn jobs_list(lang: Lang, jobs: Vec<(ImportJob, Option<Repo>)>) -> Result<i
974 </li>1007 </li>
975 }1008 }
976 </ul>1009 </ul>
1010+ })
1011+}
1012+
1013+/// The few most recent imports, shown under the import form. Nothing renders without any.
1014+/// `more` says there are older ones, which the "View all" link opens.
1015+#[component]
1016+async fn recent_imports(
1017+ lang: Lang,
1018+ jobs: Vec<(ImportJob, Option<Repo>)>,
1019+ more: bool,
1020+) -> Result<impl View> {
1021+ let empty = jobs.is_empty();
1022+ Ok(view! {
1023+ if !empty {
1024+ <section class="card import-recent">
1025+ <h2>(g::t(lang, K::RecentImports))</h2>
1026+ job_rows(lang: lang, jobs: jobs)
1027+ if more {
1028+ <p class="small"><a href="/import">(g::t(lang, K::ViewAll))</a></p>
1029+ }
1030+ </section>
1031+ }
1032+ })
1033+}
1034+
1035+#[component]
1036+async fn jobs_list(lang: Lang, jobs: Vec<(ImportJob, Option<Repo>)>) -> Result<impl View> {
1037+ let empty = jobs.is_empty();
1038+ Ok(view! {
1039+ newrepo_tabs(lang: lang, active: "import")
1040+ <section class="page-head">
1041+ <h1>(g::t(lang, K::JobsTitle))</h1>
1042+ </section>
1043+ if empty {
1044+ <p class="muted">(g::t(lang, K::NoJobs))</p>
1045+ } else {
1046+ <section class="card">
1047+ job_rows(lang: lang, jobs: jobs)
977 </section>1048 </section>
978 }1049 }
979 })1050 })
@@ -984,15 +1055,7 @@ async fn jobs_page(cx: &Cx) -> Result<impl View> {
984 let viewer = require_user(cx).await?;1055 let viewer = require_user(cx).await?;
985 let lang = i18n::lang(cx, Some(&viewer.0));1056 let lang = i18n::lang(cx, Some(&viewer.0));
986 let state = app_context::<AppState>(cx);1057 let state = app_context::<AppState>(cx);
987- let jobs = state.store.list_import_jobs(&viewer.0.id, 50).await?;1058+ let rows = load_job_rows(state, &viewer.0.id, 50).await?;
988- let mut rows = Vec::with_capacity(jobs.len());
989- for job in jobs {
990- let repo = match &job.repo_id {
991- Some(id) => state.store.repo_by_id(id).await?,
992- None => None,
993- };
994- rows.push((job, repo));
995- }
996 Ok(view! { cx =>1059 Ok(view! { cx =>
997 shell(title: g::t(lang, K::JobsTitle), viewer: Some(&viewer), jobs_list(lang: lang, jobs: rows))1060 shell(title: g::t(lang, K::JobsTitle), viewer: Some(&viewer), jobs_list(lang: lang, jobs: rows))
998 })1061 })
@@ -1027,7 +1090,7 @@ async fn job_view(
1027 let state_word = job.state.as_str();1090 let state_word = job.state.as_str();
1028 let empty_log = log.is_empty();1091 let empty_log = log.is_empty();
1029 Ok(view! {1092 Ok(view! {
1030- newrepo_tabs(lang: lang, active: "jobs")1093+ newrepo_tabs(lang: lang, active: "import")
1031 <section class="import-job" data-live=(live.as_deref()) data-live-state=(state_word)>1094 <section class="import-job" data-live=(live.as_deref()) data-live-state=(state_word)>
1032 <header class="newrepo-head">1095 <header class="newrepo-head">
1033 <h1 class="import-job-title">(job.source_ref.as_str())</h1>1096 <h1 class="import-job-title">(job.source_ref.as_str())</h1>
crates/forge-web/src/pages/import_tests.rsmodified+1 -1
@@ -78,7 +78,7 @@ async fn scenario_pages_render(fx: &Fixture) {
78 "/new/import/bulk?source=github",78 "/new/import/bulk?source=github",
79 "Import several repositories",79 "Import several repositories",
80 ),80 ),
81- ("/import", "Imports"),81+ ("/import", "Import history"),
82 ("/settings/export", "Export your data"),82 ("/settings/export", "Export your data"),
83 ] {83 ] {
84 let (status, body) = send(&fx.router, "GET", uri, Some(TOKEN), None).await;84 let (status, body) = send(&fx.router, "GET", uri, Some(TOKEN), None).await;