From 2bda7566b473f556dc5e00e0690c4c7187b7ff9f Mon Sep 17 00:00:00 2001 From: John Paul Date: Sat, 18 Jun 2022 01:19:15 -0400 Subject: [PATCH] Reset version page state when currently selected version changes (#543) * reset versions state on current version change * 'mode' should not be reset --- pages/_type/_id/version.vue | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/pages/_type/_id/version.vue b/pages/_type/_id/version.vue index 598042c80..8d2dca8f5 100644 --- a/pages/_type/_id/version.vue +++ b/pages/_type/_id/version.vue @@ -616,7 +616,6 @@ export default { mode: 'version', primaryFile: {}, version: {}, - popup_data: null, changelogViewMode: 'source', @@ -652,7 +651,19 @@ export default { } }, methods: { + reset() { + this.changelogViewMode = 'source' + this.dependencyAddMode = 'project' + this.newDependencyId = '' + this.newDependencyType = 'required' + + this.primaryFile = {} + this.version = {} + this.newFiles = [] + this.deleteFiles = [] + }, async setVersion() { + this.reset() const path = this.$route.name.split('-') this.mode = path[path.length - 1] @@ -687,11 +698,8 @@ export default { ) this.version = JSON.parse(JSON.stringify(this.version)) - this.primaryFile = this.version.files.find((file) => file.primary) - - if (!this.primaryFile) { - this.primaryFile = this.version.files[0] - } + this.primaryFile = + this.version.files.find((file) => file.primary) ?? this.version.files[0] if (!this.version.changelog && this.version.changelog_url) { this.version.changelog = ( @@ -845,10 +853,7 @@ export default { const formData = new FormData() - const fileParts = [] - for (let i = 0; i < this.newFiles.length; i++) { - fileParts.push(this.newFiles[i].name.concat('-' + i)) - } + const fileParts = this.newFiles.map((f, idx) => `${f.name}-${idx}`) const newVersion = { project_id: this.version.project_id,