Skip to content

Commit 0956894

Browse files
committed
[FIX] Persist all branches list after filtering
1 parent 2147623 commit 0956894

File tree

5 files changed

+32
-16
lines changed

5 files changed

+32
-16
lines changed

js/fetchCommits.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,16 @@ async function fetchCommits() {
142142
if (await fetchCommitsPage(repoOwner, repoName, "NONE")) {
143143
console.log("--FETCHED BRANCHES--");
144144
console.log("--COST : '" + APIcost + "'--");
145+
var allBranchesObject = {}
145146
branches = branches.map(branch => {
146147
heads.push({
147148
name: branch.name,
148149
oid: branch.target.history.edges[0].node.oid,
149150
});
151+
allBranchesObject[branch.name] = branch.target.history.edges[0].node.oid;
150152
branch.target.history.edges[0].node.isHead = true;
151153
return branch;
152154
})
153-
await sortCommits(branches, heads);
155+
await sortCommits(branches, heads, allBranchesObject);
154156
}
155157
}

js/fetchFilteredCommits.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22

3-
async function fetchFilteredCommits(selectedBranchNames, selectedBranches) {
3+
async function fetchFilteredCommits(selectedBranchNames, selectedBranches, allBranches) {
44
var branches = [];
55
// Recurcively call this function unti all the branches are fetched
66
// (GitHub API has a limit of 100 branches per request)
@@ -156,9 +156,11 @@ async function fetchFilteredCommits(selectedBranchNames, selectedBranches) {
156156
branch.target.history.edges[0].node.isHead = true;
157157
return branch;
158158
})
159-
await sortCommits(branches, heads);
159+
await sortCommits(branches, heads, allBranches);
160+
}
161+
else {
162+
console.log("Fetch failure");
160163
}
161-
console.log("Fetch failure");
162164
}
163165

164166
// Branch names of git allows a lot of flexibiliity in variable naming

js/setBranchOptions.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
function setBranchOptions(branches, selectedBranchNames) {
1+
function setBranchOptions(branches, selectedBranchNames, allBranches) {
22
var branchesContainer = document.getElementById("branches-list-parent");
33
var existingChild = branchesContainer.children[0];
44

5-
var branchNames =new Set()
6-
for (var branch in branches) {
5+
var branchNames = new Set()
6+
for (var branch in allBranches) {
77
var branchname = branch;
88
branchNames.add(branchname);
99
}
@@ -59,13 +59,13 @@ function setBranchOptions(branches, selectedBranchNames) {
5959

6060
var branchFilterButton = document.getElementById("branch-filter-button");
6161
var selectedBranchCommitIds = []
62-
62+
6363
branchFilterButton.addEventListener("click", () => {
6464
selectedBranchCommitIds = [];
6565
for (var branch of selectedBranchNames) {
66-
selectedBranchCommitIds.push(branches[branch]);
66+
selectedBranchCommitIds.push(allBranches[branch]);
6767
}
6868
showCommitsLoading();
69-
fetchFilteredCommits(selectedBranchNames, selectedBranchCommitIds);
69+
fetchFilteredCommits(selectedBranchNames, selectedBranchCommitIds, allBranches);
7070
});
7171
}

js/showCommits.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ async function getCommitDetails(repoOwner, repoName, commits, allCommits) {
144144
return ([commits, allCommits]);
145145
}
146146

147-
async function showCommits(commits, branchNames, allCommits, heads, pageNo) {
147+
async function showCommits(commits, branchNames, allCommits, heads, pageNo, allBranches) {
148148
var presentUrl = window.location.href;
149149
var repoOwner = presentUrl.split('/')[3];
150150
var repoName = presentUrl.split('/')[4];
@@ -207,7 +207,7 @@ async function showCommits(commits, branchNames, allCommits, heads, pageNo) {
207207

208208
// Display the branches filter dropdown button with default value only (All branches)
209209
await loadBranchesButton();
210-
setBranchOptions(branchNames, Object.keys(branchNames));
210+
setBranchOptions(branchNames, Object.keys(branchNames), allBranches);
211211
contentView.appendChild(commitsOutsideContainer);
212212

213213
addNextPageButton(commits, branchNames, allCommits, heads, pageNo);

js/sortCommits.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ const parseDate = dateString => {
1010
return new Date(Date.UTC(+b[0], +b[1] - 1, +b[2], +b[3] + hrOffset, +b[4] + minOffset, +b[5], +b[6] || 0));
1111
};
1212

13-
async function sortCommits(branches, heads) {
13+
async function sortCommits(branches, heads, allBranches) {
1414
var branchNames = {};
1515
var commitsObject = {};
16+
var allBranchNames = {};
1617

1718
// The branches array contains the name of branch as well as
1819
// the commit history (latest 10 per branch) on the branch
@@ -50,19 +51,30 @@ async function sortCommits(branches, heads) {
5051
if (brancesInThisCommit != undefined) {
5152
brancesInThisCommit.forEach(thisBranch => {
5253
// if (!branchNames.includes(thisBranch)) {
53-
// branchNames.push(thisBranch);
54+
// branchNames.push(thisBranch);
5455
// }
5556
branchNames[thisBranch] = "";
57+
allBranchNames[thisBranch] = "";
5658
});
5759
}
5860
});
5961

60-
for(var branch of branches){
62+
for (var branch of branches) {
6163
branchNames[branch.name] = branch.target.history.edges[0].node.oid;
6264
}
65+
// TODO: This is hacky. The variable allBranches is not standardised throughout project.
66+
// Sometimes it is array, sometimes it is object. Fix this at the source instead of here.
67+
if (typeof allBranches == "array") {
68+
for (var branch of allBranches) {
69+
allBranchNames[branch.name] = branch.target.history.edges[0].node.oid;
70+
}
71+
}
72+
else {
73+
allBranchNames = allBranches;
74+
}
6375

6476
console.log("--COMMITS FOR THIS PAGE ARE--");
6577
console.log(commitsObject.slice(0, 10));
66-
await showCommits(commitsObject.slice(0, 10), branchNames, commits, heads, 1);
78+
await showCommits(commitsObject.slice(0, 10), branchNames, commits, heads, 1, allBranchNames);
6779
showLegend(heads);
6880
}

0 commit comments

Comments
 (0)