fix(dashboard): the Lieferkette's document links go to the portal's origin (#1054) (#1061)
CI / Check (push) Skipped
CI / Agent integration (push) Skipped
CI / Detect Changes (push) Successful in 3s
CI / Deploy Agent (push) Skipped
CI / Deploy Docs (push) Skipped
CI / Deploy MCP (push) Skipped
CI / Deploy Dashboard (push) Successful in 3m47s

This commit was merged in pull request #1061.
This commit is contained in:
sharang committed 2026-11-19 11:32:21 +00:00
1 parent f06a347dd7
commit 835bc3fc98
1 file changed
+31 -1
+31 -1
View File
@@ -821,7 +821,7 @@ fn ChainView(chain: SupplyChainDto, layout: LayoutDto) -> Element {
ProjectDocs {
key: "{id}",
id: id.to_string(),
portal_url: portal_url.trim_end_matches('/').to_string(),
portal_url: portal_origin(&portal_url).to_string(),
can_write,
}
Link { class: "chain-panel-link", to: Route::MachinePage { id: id.to_string(), tab: String::new() }, {tx::OPEN_PRODUCT.get(lang)} }
@@ -832,6 +832,19 @@ fn ChainView(chain: SupplyChainDto, layout: LayoutDto) -> Element {
}
}
/// The scheme and host of `url`, without a path: what the portal's own paths
/// (`/{slug}/dokumente/…`) go after. `PORTAL_URL` may point at a page of the
/// portal (on stage, the workspace's dashboard), not at its root.
fn portal_origin(url: &str) -> &str {
let Some(scheme_end) = url.find("://") else {
return url.trim_end_matches('/');
};
let host_start = scheme_end + 3;
url[host_start..]
.find('/')
.map_or(url, |slash| &url[..host_start + slash])
}
/// A file size as people read it: "340 KB", "1,2 MB".
fn size_text(bytes: u64, lang: Lang) -> String {
const KB: f64 = 1024.0;
@@ -1136,6 +1149,23 @@ mod tests {
assert!(folded_keys(&c).is_empty());
}
#[test]
fn a_documents_path_goes_after_the_portals_origin() {
assert_eq!(
portal_origin("https://app-stage.breakpilot.com/sharna/dashboard"),
"https://app-stage.breakpilot.com"
);
assert_eq!(
portal_origin("https://app.breakpilot.com/"),
"https://app.breakpilot.com"
);
assert_eq!(
portal_origin("http://127.0.0.1:9999"),
"http://127.0.0.1:9999"
);
assert_eq!(portal_origin(""), "");
}
#[test]
fn a_file_size_reads_in_the_language() {
assert_eq!(size_text(1_258_291, Lang::De), "1,2 MB");