fix: reload explorer state when repository identity changes

This commit is contained in:
tdurieux
2026-09-06 10:47:03 +02:00
parent b6c0d3a8ed
commit a27f9f34d6
4 changed files with 25 additions and 5 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"core.min.js": "core.6332b3c288.min.js", "core.min.js": "core.6332b3c288.min.js",
"vendor.min.js": "vendor.1269d561e8.min.js", "vendor.min.js": "vendor.9de44b9059.min.js",
"mermaid.min.js": "mermaid.f848a72d16.min.js", "mermaid.min.js": "mermaid.f848a72d16.min.js",
"all.min.css": "all.99ce8f3e14.min.css" "all.min.css": "all.99ce8f3e14.min.css"
} }
+17 -3
View File
@@ -2719,6 +2719,7 @@ angular
]; ];
$scope.$on("$routeUpdate", function (event, current) { $scope.$on("$routeUpdate", function (event, current) {
if ($scope.repoId != $routeParams.repoId) return init();
if (($routeParams.path || "") == $scope.filePath) { if (($routeParams.path || "") == $scope.filePath) {
return; return;
} }
@@ -2727,9 +2728,6 @@ angular
.split("/") .split("/")
.filter((f) => f && f.trim().length > 0); .filter((f) => f && f.trim().length > 0);
if ($scope.repoId != $routeParams.repoId) {
return init();
}
updateContent(); updateContent();
@@ -2787,23 +2785,28 @@ angular
} }
$scope.fileCounts = null; $scope.fileCounts = null;
$scope.getFiles = function (path) { $scope.getFiles = function (path) {
const repoId = $scope.repoId;
return $http.get( return $http.get(
`/api/repo/${$scope.repoId}/files/?path=${encodeURIComponent(path)}&v=${$scope.options.lastUpdateDate}` `/api/repo/${$scope.repoId}/files/?path=${encodeURIComponent(path)}&v=${$scope.options.lastUpdateDate}`
).then(function (res) { ).then(function (res) {
if (destroyed || repoId !== $scope.repoId) return [];
const normalized = path || ""; const normalized = path || "";
$scope.files = $scope.files.filter((f) => f.path !== normalized); $scope.files = $scope.files.filter((f) => f.path !== normalized);
$scope.files.push(...res.data); $scope.files.push(...res.data);
return res.data; return res.data;
}, function (err) { }, function (err) {
if (destroyed || repoId !== $scope.repoId) return [];
$scope.type = "error"; $scope.type = "error";
$scope.content = (err && err.data && err.data.error) || "unknown_error"; $scope.content = (err && err.data && err.data.error) || "unknown_error";
$scope.files = []; $scope.files = [];
}); });
}; };
function fetchFileCounts() { function fetchFileCounts() {
const repoId = $scope.repoId;
$http.get( $http.get(
`/api/repo/${$scope.repoId}/files/counts` `/api/repo/${$scope.repoId}/files/counts`
).then(function (res) { ).then(function (res) {
if (destroyed || repoId !== $scope.repoId) return;
$scope.fileCounts = res.data; $scope.fileCounts = res.data;
}, function () { }, function () {
$scope.fileCounts = {}; $scope.fileCounts = {};
@@ -2822,8 +2825,11 @@ angular
$scope.$on("$destroy", function () { if (rlCountdownTimer) clearInterval(rlCountdownTimer); }); $scope.$on("$destroy", function () { if (rlCountdownTimer) clearInterval(rlCountdownTimer); });
function getOptions(callback) { function getOptions(callback) {
if (destroyed) return;
const repoId = $scope.repoId;
$http.get(`/api/repo/${$scope.repoId}/options`).then( $http.get(`/api/repo/${$scope.repoId}/options`).then(
(res) => { (res) => {
if (destroyed || repoId !== $scope.repoId) return;
$scope.options = res.data; $scope.options = res.data;
if ($scope.options.url) { if ($scope.options.url) {
window.location = $scope.options.url; window.location = $scope.options.url;
@@ -2834,6 +2840,7 @@ angular
} }
}, },
(err) => { (err) => {
if (destroyed || repoId !== $scope.repoId) return;
var data = err.data || {}; var data = err.data || {};
if (data.error === "rate_limited" && data.resetAt) { if (data.error === "rate_limited" && data.resetAt) {
$scope.type = "rate_limited"; $scope.type = "rate_limited";
@@ -3184,11 +3191,17 @@ angular
function init() { function init() {
contentGeneration++; contentGeneration++;
$scope.files = [];
$scope.content = null;
$scope.fileCounts = null;
$scope.fileSearchQuery = "";
$scope.onFileSearchChange();
$scope.repoId = $routeParams.repoId; $scope.repoId = $routeParams.repoId;
$scope.type = "loading"; $scope.type = "loading";
$scope.filePath = $routeParams.path || ""; $scope.filePath = $routeParams.path || "";
$scope.paths = $scope.filePath.split("/"); $scope.paths = $scope.filePath.split("/");
const repoId = $scope.repoId;
getOptions(function (options) { getOptions(function (options) {
fetchFileCounts(); fetchFileCounts();
var chain = $q.resolve(); var chain = $q.resolve();
@@ -3203,6 +3216,7 @@ angular
}); });
} }
chain.then(function () { chain.then(function () {
if (destroyed || repoId !== $scope.repoId) return;
if ($scope.files.length == 1 && $scope.files[0].name == "") { if ($scope.files.length == 1 && $scope.files[0].name == "") {
$scope.files = []; $scope.files = [];
$scope.type = "empty"; $scope.type = "empty";
+1 -1
View File
File diff suppressed because one or more lines are too long
+6
View File
@@ -85,4 +85,10 @@ describe("frontend production regressions", function () {
h.navigate("fourth.pdf"); third.reject({ status: 500 }); await h.flush(); h.navigate("fourth.pdf"); third.reject({ status: 500 }); await h.flush();
expect(h.scope.type).to.equal("pdf"); expect(h.scope.type).to.equal("pdf");
}); });
it("reloads the repository when only its ID changes", function () {
const h = explorer(); h.scope.files = [{ name: "old", path: "old" }];
h.params.repoId = "new-repo"; h.emit("$routeUpdate");
expect(h.scope.repoId).to.equal("new-repo"); expect(h.scope.files).to.have.length(0);
expect(h.requests.at(-1).url).to.equal("/api/repo/new-repo/options");
});
}); });