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 {
3636 OptionsNote,
3737 StartImport,
3838 BulkLink,
39- JobsLink,
4039 // Bulk import.
4140 BulkTitle,
4241 BulkIntro,
@@ -54,6 +53,8 @@ pub enum K {
5453 // Jobs.
5554 JobsTitle,
5655 NoJobs,
56+ RecentImports,
57+ ViewAll,
5758 JobQueued,
5859 JobRunning,
5960 JobDone,
@@ -123,7 +124,6 @@ const ALL: &[K] = &[
123124 K::OptionsNote,
124125 K::StartImport,
125126 K::BulkLink,
126- K::JobsLink,
127127 K::BulkTitle,
128128 K::BulkIntro,
129129 K::BulkOwnerGitHub,
@@ -139,6 +139,8 @@ const ALL: &[K] = &[
139139 K::BulkArchived,
140140 K::JobsTitle,
141141 K::NoJobs,
142+ K::RecentImports,
143+ K::ViewAll,
142144 K::JobQueued,
143145 K::JobRunning,
144146 K::JobDone,
@@ -225,7 +227,6 @@ fn pair(key: K) -> (&'static str, &'static str) {
225227 ),
226228 K::StartImport => ("Start import", "İçe aktarmayı başlat"),
227229 K::BulkLink => ("Import several repositories", "Birden çok depoyu içe aktar"),
228- K::JobsLink => ("Imports", "İçe aktarmalar"),
229230 K::BulkTitle => ("Import several repositories", "Birden çok depoyu içe aktar"),
230231 K::BulkIntro => (
231232 "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) {
251252 K::BulkPrivate => ("private", "özel"),
252253 K::BulkFork => ("fork", "çatal"),
253254 K::BulkArchived => ("archived", "arşivlenmiş"),
254- K::JobsTitle => ("Imports", "İçe aktarmalar"),
255+ K::JobsTitle => ("Import history", "İçe aktarma geçmişi"),
255256 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"),
256259 K::JobQueued => ("Queued", "Sırada"),
257260 K::JobRunning => ("Running", "Çalışıyor"),
258261 K::JobDone => ("Done", "Bitti"),
crates/forge-web/src/pages/import.rsmodified+91 -28
@@ -161,7 +161,6 @@ pub(crate) async fn newrepo_tabs(lang: Lang, active: &str) -> Result<impl View>
161161 <nav class="import-tabs" aria-label=(g::t(lang, K::ImportTitle))>
162162 <a href="/new" class="import-tab" aria-current=(create.then_some("page"))>(g::t(lang, K::TabCreate))</a>
163163 <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>
165164 </nav>
166165 })
167166 }
@@ -386,17 +385,41 @@ async fn import_form(
386385 })
387386 }
388387
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+
389407 #[page("/new/import")]
390408 async fn import_page(cx: &Cx) -> Result<impl View> {
391409 let viewer = require_user(cx).await?;
392410 let lang = i18n::lang(cx, Some(&viewer.0));
393411 let query = query_params::<SourceQuery>(cx)?;
394412 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?;
396415 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);
397420 Ok(view! { cx =>
398421 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))
400423 })
401424 }
402425
@@ -948,11 +971,72 @@ fn ago(lang: Lang, stamp: &str) -> String {
948971 stamp_to_unix(stamp).map_or_else(String::new, |t| relative_time(lang, t, now_unix()))
949972 }
950973
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.
993+#[component]
994+async fn job_rows(lang: Lang, jobs: Vec<(ImportJob, Option<Repo>)>) -> Result<impl View> {
995+ Ok(view! {
996+ <ul class="item-list import-jobs">
997+ for (job, repo) in jobs.iter() {
998+ <li class="item import-job-row">
999+ <div class="item-main">
1000+ <a href=(format!("/import/{}", job.id)) class="import-job-name">(job.source_ref.as_str())</a>
1001+ <span class="muted small">(g::t(lang, K::JobStarted)) " " <time data-rel="true" datetime=(job.created_at.as_str())>(ago(lang, &job.created_at))</time></span>
1002+ </div>
1003+ if let Some(repo) = repo {
1004+ <a href=(format!("/{}/{}", repo.owner_name, repo.name)) class="muted small mono">(format!("{}/{}", repo.owner_name, repo.name))</a>
1005+ }
1006+ <span class=(state_badge(lang, job.state).0)>(state_badge(lang, job.state).1)</span>
1007+ </li>
1008+ }
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+
9511035 #[component]
9521036 async fn jobs_list(lang: Lang, jobs: Vec<(ImportJob, Option<Repo>)>) -> Result<impl View> {
9531037 let empty = jobs.is_empty();
9541038 Ok(view! {
955- newrepo_tabs(lang: lang, active: "jobs")
1039+ newrepo_tabs(lang: lang, active: "import")
9561040 <section class="page-head">
9571041 <h1>(g::t(lang, K::JobsTitle))</h1>
9581042 </section>
@@ -960,20 +1044,7 @@ async fn jobs_list(lang: Lang, jobs: Vec<(ImportJob, Option<Repo>)>) -> Result<i
9601044 <p class="muted">(g::t(lang, K::NoJobs))</p>
9611045 } else {
9621046 <section class="card">
963- <ul class="item-list import-jobs">
964- for (job, repo) in jobs.iter() {
965- <li class="item import-job-row">
966- <div class="item-main">
967- <a href=(format!("/import/{}", job.id)) class="import-job-name">(job.source_ref.as_str())</a>
968- <span class="muted small">(g::t(lang, K::JobStarted)) " " <time data-rel="true" datetime=(job.created_at.as_str())>(ago(lang, &job.created_at))</time></span>
969- </div>
970- if let Some(repo) = repo {
971- <a href=(format!("/{}/{}", repo.owner_name, repo.name)) class="muted small mono">(format!("{}/{}", repo.owner_name, repo.name))</a>
972- }
973- <span class=(state_badge(lang, job.state).0)>(state_badge(lang, job.state).1)</span>
974- </li>
975- }
976- </ul>
1047+ job_rows(lang: lang, jobs: jobs)
9771048 </section>
9781049 }
9791050 })
@@ -984,15 +1055,7 @@ async fn jobs_page(cx: &Cx) -> Result<impl View> {
9841055 let viewer = require_user(cx).await?;
9851056 let lang = i18n::lang(cx, Some(&viewer.0));
9861057 let state = app_context::<AppState>(cx);
987- let jobs = state.store.list_import_jobs(&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- }
1058+ let rows = load_job_rows(state, &viewer.0.id, 50).await?;
9961059 Ok(view! { cx =>
9971060 shell(title: g::t(lang, K::JobsTitle), viewer: Some(&viewer), jobs_list(lang: lang, jobs: rows))
9981061 })
@@ -1027,7 +1090,7 @@ async fn job_view(
10271090 let state_word = job.state.as_str();
10281091 let empty_log = log.is_empty();
10291092 Ok(view! {
1030- newrepo_tabs(lang: lang, active: "jobs")
1093+ newrepo_tabs(lang: lang, active: "import")
10311094 <section class="import-job" data-live=(live.as_deref()) data-live-state=(state_word)>
10321095 <header class="newrepo-head">
10331096 <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) {
7878 "/new/import/bulk?source=github",
7979 "Import several repositories",
8080 ),
81- ("/import", "Imports"),
81+ ("/import", "Import history"),
8282 ("/settings/export", "Export your data"),
8383 ] {
8484 let (status, body) = send(&fx.router, "GET", uri, Some(TOKEN), None).await;