Skip to content

Commit

Permalink
[#2123] Fix zoom bug if zUser is undefined (#2126)
Browse files Browse the repository at this point in the history
Fix error thrown when zUser is undefined

Currently, an error is thrown when zUser is defined in c-zoom.vue. This
might be caused by zFilterSearch containing a query that returns no
results. Though this happening through normal user interaction is rare
(editing URL, for example), RepoSense should handle this case
gracefully rather than throwing an error.

Let's fix this bug by resetting the zoom view if the error happens.
  • Loading branch information
jonasongg committed Mar 16, 2024
1 parent c81b30c commit 22992cb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
4 changes: 3 additions & 1 deletion frontend/src/views/c-summary.vue
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,9 @@ export default defineComponent({
if (zIsMerged) {
this.mergeGroupByIndex(filtered, 0);
}
[[info.zUser]] = filtered;
if (filtered.length) [[info.zUser]] = filtered;
info.zFileTypeColors = this.fileTypeColors;
info.isRefreshing = false;
this.$store.commit('updateTabZoomInfo', info);
Expand Down
20 changes: 14 additions & 6 deletions frontend/src/views/c-zoom.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template lang="pug">
#zoom
#zoom(v-if="filteredUser")
.panel-title
span Commits Panel
.toolbar--multiline(v-if="filteredUser.commits.length && totalCommitMessageBodyCount")
Expand Down Expand Up @@ -199,13 +199,13 @@ export default defineComponent({
return (a: Commit, b: Commit) => (this.toReverseSortedCommits ? -1 : 1)
* window.comparator(commitSortFunction)(a, b);
},
filteredUser(): User {
filteredUser(): User | undefined {
const {
zUser, zSince, zUntil, zTimeFrame,
} = this.info;
if (!zUser) {
throw new Error('zUser is not defined');
return undefined;
}
const filteredUser: User = Object.assign({}, zUser);
Expand Down Expand Up @@ -242,11 +242,11 @@ export default defineComponent({
selectedCommits(): Array<Commit> {
if (this.isSelectAllChecked) {
return this.filteredUser.commits;
return this.filteredUser?.commits ?? [];
}
const commits = [] as Array<Commit>;
this.filteredUser.commits.forEach((commit) => {
this.filteredUser?.commits.forEach((commit) => {
const filteredCommit = { ...commit };
filteredCommit.commitResults = [];
commit.commitResults.forEach((slice) => {
Expand Down Expand Up @@ -318,6 +318,12 @@ export default defineComponent({
},
},
created() {
// return if filteredUser is undefined since it won't make sense to render zoom tab
// #zoom-tab is also rendered only if filteredUser is defined
if (!this.filteredUser) {
this.removeZoomHashes();
return;
}
this.initiate();
this.retrieveHashes();
this.setInfoHash();
Expand All @@ -328,7 +334,6 @@ export default defineComponent({
methods: {
initiate() {
// This code crashes if info.zUser is not defined
this.updateFileTypes();
this.selectedFileTypes = this.fileTypes.slice();
},
Expand Down Expand Up @@ -404,6 +409,8 @@ export default defineComponent({
},
updateFileTypes() {
if (!this.filteredUser) return;
const commitsFileTypes = new Set<string>();
this.filteredUser.commits.forEach((commit) => {
commit.commitResults.forEach((slice) => {
Expand Down Expand Up @@ -499,6 +506,7 @@ export default defineComponent({
window.removeHash('zFT');
window.removeHash('zCST');
window.removeHash('zRSC');
window.removeHash('zFR');
window.encodeHash();
},
Expand Down

0 comments on commit 22992cb

Please sign in to comment.