fix(content): 重试面板画可读名,不再只有站点 id (M191 r1 P2-1)
复审 P2-1:面板原来只画 `P7dR8mSH` 这种项目键,用户拿到的是一串哈希。
可读名其实都在手边,只是没进 DTO——现在补上,按复审给的**最小修法**做,没扩散:
- `InstallFailureView` 加 `label: String`(**语言中立**:站点标题或文件名),
配 `line()` 统一决定「名字 (id)」还是「只有 id」(名字为空时不编造)。
`detail`(core 中文散文)**依旧不进界面**——那会踩 i18n R2。
- `plan::label_of` 三个来源,零额外请求:
根项目 → 请求里的 `title`;计划里有节点(下载失败)→ `node.file.filename`;
都没有(解析 404 / 不兼容的前置)→ 空,界面退回只画 id(复审认这条兜底)。
- 计划被记住时连显示名一起记(`plan::remember` 多一个 `title`),于是重试那一轮
面板头与失败名单沿用的是同一个名字(顺手收掉复审 N5 的「重试时面板头显示 id」)。
- N2:删掉新加的 `ContentInstallDismiss`,复用既有的 `DownloadDismiss`(同一句话不立两条 key)。
- 行数/clippy:`collect` 的参数捆成 `Placement{dir,title}`(9 个参数超限);
`plan.rs` 加完 `label_of` 到 429 行,把「记住的计划」表纯搬移到 `plan/remembered.rs`(363 + 82)。
守门(真跑红再还原):
- 把 `label_of` 置空 ⇒ `the_retry_list_shows_a_readable_name_not_just_the_project_id` 红
(三行全变成 `["AANobbMI","P7dR8mSH","1eAoo2KR"]`);
- 审阅指出的另一半判据也补上了:`Done` + 残留名单 ⇒ 必须不画;现在**只去掉**
`stage != Failed` 那一半就红(之前只去掉它仍是全绿,报告的表述不准,已改)。
This commit is contained in:
1 parent
5a52f38f35
commit
961ff453a0
11 files changed
+326
-104
No files matched your search
@@ -40,21 +40,26 @@ fn retry_failure(instance: &str, catalog: Catalog) -> Option<RetryPanel> {
|
||||
files_total: 4,
|
||||
..InstallProgressView::new()
|
||||
};
|
||||
// 三种可显示性各一条,与 host 侧 `plan::label_of` 的三种情况同形:
|
||||
// 根项目 = 请求里的标题、下载失败 = 文件名、解析 404 = 没有名字(只画 id)。
|
||||
progress.retry = vec![
|
||||
InstallFailureView::new(
|
||||
"AANobbMI",
|
||||
"Sodium",
|
||||
InstallFailureKind::Unreachable,
|
||||
"下载 sodium-fabric-0.6.0.jar 失败(online_not_connected):连不上 cdn.modrinth.com",
|
||||
),
|
||||
InstallFailureView::new(
|
||||
"P7dR8mSH",
|
||||
"",
|
||||
InstallFailureKind::Incompatible,
|
||||
"没有匹配所选游戏版本/加载器(1.20.1 / fabric)的版本",
|
||||
),
|
||||
InstallFailureView::new(
|
||||
"1eAoo2KR",
|
||||
"fabric-api-0.92.2+1.20.1.jar",
|
||||
InstallFailureKind::Unreachable,
|
||||
"取版本失败(online_not_found):HTTP 404",
|
||||
),
|
||||
InstallFailureView::new(
|
||||
"AANobbMI",
|
||||
InstallFailureKind::Unreachable,
|
||||
"下载 fabric-api.jar 失败(online_not_connected):连不上 cdn.modrinth.com",
|
||||
"下载 fabric-api-0.92.2+1.20.1.jar 失败(online_not_connected):连不上 cdn.modrinth.com",
|
||||
),
|
||||
];
|
||||
RetryPanel::of(&progress, catalog)
|
||||
@@ -321,7 +326,20 @@ mod tests {
|
||||
assert!(panel.has_both_tiers(), "{:?}", panel.groups);
|
||||
assert_eq!(
|
||||
panel.items_of(unlucky_presenter::dto::InstallFailureKind::Unreachable),
|
||||
Some(["1eAoo2KR".to_string(), "AANobbMI".to_string()].as_slice())
|
||||
Some(
|
||||
[
|
||||
// 根项目:名字来自请求标题
|
||||
"Sodium (AANobbMI)".to_string(),
|
||||
// 下载失败:名字来自文件名
|
||||
"fabric-api-0.92.2+1.20.1.jar (1eAoo2KR)".to_string(),
|
||||
]
|
||||
.as_slice()
|
||||
)
|
||||
);
|
||||
// 拿不到名的那一档(解析 404 / 不兼容):只画 id,不编名字
|
||||
assert_eq!(
|
||||
panel.items_of(unlucky_presenter::dto::InstallFailureKind::Incompatible),
|
||||
Some(["P7dR8mSH".to_string()].as_slice())
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -7,12 +7,16 @@
|
||||
//! ```text
|
||||
//! 安装未完成 —— 3 项没装上
|
||||
//! 不兼容所选版本/加载器
|
||||
//! P7dR8mSH
|
||||
//! P7dR8mSH ← 拿不到名字时只画 id(合理兜底)
|
||||
//! 取不到(网络 / 项目不存在)
|
||||
//! 1eAoo2KR、AANobbMI
|
||||
//! Sodium (AANobbMI) ← 根项目:名字来自请求标题
|
||||
//! fabric-api-0.92.2.jar (1eAoo2KR) ← 下载失败:名字来自文件名
|
||||
//! [只重试这 3 个] [关闭]
|
||||
//! ```
|
||||
//!
|
||||
//! 每行是 `InstallFailureView::line()` 的结果(名字优先、id 次要)。名字是**语言中立**的站点
|
||||
//! 标题或文件名,不是 core 的中文散文——那条线(i18n R2)踩了就回不去。
|
||||
//!
|
||||
//! ## 三条判据(都落在 [`RetryPanel::of`],纯函数,用例直接钉)
|
||||
//!
|
||||
//! 1. **全成功不渲染**:`retry` 名单空 ⇒ `None` ⇒ 视图里连按钮都不存在(不是置灰);
|
||||
@@ -27,8 +31,8 @@
|
||||
|
||||
use unlucky_i18n::{Catalog, Key};
|
||||
use unlucky_presenter::dto::{
|
||||
ContentInstallRequest, ContentSource, InstallFailureKind, InstallProgressView, InstallStage,
|
||||
LoaderKind,
|
||||
ContentInstallRequest, ContentSource, InstallFailureKind, InstallFailureView,
|
||||
InstallProgressView, InstallStage, LoaderKind,
|
||||
};
|
||||
|
||||
/// 面板上的一个档位分组。
|
||||
@@ -38,7 +42,7 @@ pub struct RetryGroup {
|
||||
pub kind: InstallFailureKind,
|
||||
/// 这一档的标题 key(不硬编码中文)
|
||||
pub title: Key,
|
||||
/// 这一档的项目键(顺序 = 计划里的顺序)
|
||||
/// 这一档要画的每一行(`名字 (id)`;拿不到名字时就只有 id,顺序 = 计划里的顺序)
|
||||
pub items: Vec<String>,
|
||||
}
|
||||
|
||||
@@ -80,7 +84,7 @@ impl RetryPanel {
|
||||
title: title_of(kind),
|
||||
items: progress
|
||||
.retry_of(kind)
|
||||
.map(|item| item.project.clone())
|
||||
.map(InstallFailureView::line)
|
||||
.collect(),
|
||||
})
|
||||
.filter(|group| !group.items.is_empty())
|
||||
|
||||
@@ -20,14 +20,22 @@ fn failed_progress() -> unlucky_presenter::dto::InstallProgressView {
|
||||
files_total: 4,
|
||||
..InstallProgressView::new()
|
||||
};
|
||||
// 三种可显示性各一条(与 `plan::label_of` 的三种情况同形):
|
||||
// 根项目用请求里的标题、下载失败用文件名、拿不到名的只画 id。
|
||||
progress.retry = vec![
|
||||
InstallFailureView::new(
|
||||
"AANobbMI",
|
||||
"Sodium",
|
||||
InstallFailureKind::Unreachable,
|
||||
"连不上 CDN",
|
||||
),
|
||||
InstallFailureView::new(
|
||||
"P7dR8mSH",
|
||||
"fabric-api.jar",
|
||||
InstallFailureKind::Incompatible,
|
||||
"没有匹配的版本",
|
||||
),
|
||||
InstallFailureView::new("1eAoo2KR", InstallFailureKind::Unreachable, "HTTP 404"),
|
||||
InstallFailureView::new("AANobbMI", InstallFailureKind::Unreachable, "连不上 CDN"),
|
||||
InstallFailureView::new("1eAoo2KR", "", InstallFailureKind::Unreachable, "HTTP 404"),
|
||||
];
|
||||
progress
|
||||
}
|
||||
@@ -41,13 +49,21 @@ fn the_two_tiers_are_two_groups_with_two_labels() {
|
||||
let panel = RetryPanel::of(&failed_progress(), Lang::En.catalog()).expect("有失败项就有面板");
|
||||
assert_eq!(panel.total, 3);
|
||||
assert!(panel.has_both_tiers(), "{:?}", panel.groups);
|
||||
// **P2-1 的守门**:有名字的画「名字 (id)」,没有名字的才只画 id
|
||||
assert_eq!(
|
||||
panel.items_of(InstallFailureKind::Incompatible),
|
||||
Some(["P7dR8mSH".to_string()].as_slice())
|
||||
Some(["fabric-api.jar (P7dR8mSH)".to_string()].as_slice())
|
||||
);
|
||||
assert_eq!(
|
||||
panel.items_of(InstallFailureKind::Unreachable),
|
||||
Some(["1eAoo2KR".to_string(), "AANobbMI".to_string()].as_slice())
|
||||
Some(["Sodium (AANobbMI)".to_string(), "1eAoo2KR".to_string()].as_slice())
|
||||
);
|
||||
// 变异守门:把标签置空 ⇒ 这一行退回裸 id,上面两条立刻红
|
||||
assert!(
|
||||
panel
|
||||
.items_of(InstallFailureKind::Unreachable)
|
||||
.is_some_and(|items| items[0].starts_with("Sodium")),
|
||||
"根项目必须显示请求里的标题,不是 id"
|
||||
);
|
||||
let titles: Vec<Key> = panel.groups.iter().map(|group| group.title).collect();
|
||||
assert_ne!(titles[0], titles[1], "两档的标题 key 不许是同一个");
|
||||
@@ -71,6 +87,7 @@ fn an_empty_tier_does_not_get_a_group() {
|
||||
};
|
||||
progress.retry = vec![InstallFailureView::new(
|
||||
"P7dR8mSH",
|
||||
"fabric-api.jar",
|
||||
InstallFailureKind::Incompatible,
|
||||
"没有匹配的版本",
|
||||
)];
|
||||
@@ -101,7 +118,19 @@ fn a_fully_successful_install_has_no_retry_surface_at_all() {
|
||||
assert!(model.panel.is_none());
|
||||
assert!(model.retry_install_request().is_none());
|
||||
|
||||
// 失败但没有名单(例如整合包那条本地失败)同样不画:没有可重试的东西
|
||||
// 判据是**两半**:`Failed` **且** 名单非空。第一半单独钉住——就算快照里残留了名单
|
||||
// (不该发生,host 成功时会清),`Done` 也不画(r1 复审指出:只去掉这一半曾全绿)。
|
||||
let mut stale = InstallProgressView {
|
||||
stage: InstallStage::Done,
|
||||
..InstallProgressView::new()
|
||||
};
|
||||
stale.retry = failed_progress().retry;
|
||||
assert!(
|
||||
RetryPanel::of(&stale, Lang::En.catalog()).is_none(),
|
||||
"Done 态不许画重试面板(判据是「失败且有名单」,不是「有名单」)"
|
||||
);
|
||||
|
||||
// 第二半:失败但没有名单(例如整合包那条本地失败)同样不画:没有可重试的东西
|
||||
let mut failed = InstallProgressView {
|
||||
stage: InstallStage::Failed,
|
||||
..InstallProgressView::new()
|
||||
|
||||
@@ -101,8 +101,9 @@ pub(crate) fn retry_panel<'a>(
|
||||
),
|
||||
buttons::text(
|
||||
ui,
|
||||
// 复用下载页那条现有的「关闭」:同一句话不另立一条要同步的 key(r1 复审 N2)
|
||||
Button::new(
|
||||
catalog.text(Key::ContentInstallDismiss),
|
||||
catalog.text(Key::DownloadDismiss),
|
||||
PageMessage::CancelInstall
|
||||
),
|
||||
),
|
||||
|
||||
Reference in new issue
Block a user