Skip to content

Commit 7adcfa6

Browse files
committed
core: frontend: version: Add check in manual file
* Add extra validation step to avoid calling upload function without any kind of file selected, this causes a small UI glitch because the visibility changes fast, now it should validate if there are files selected and inform user if needed
1 parent 5d8f5f6 commit 7adcfa6

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

core/frontend/src/components/version-chooser/VersionChooser.vue

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@
147147
id="file"
148148
show-size
149149
accept=".tar"
150+
:rules="[is_file_input_not_empty]"
151+
:error-messages="file_input_error"
150152
label="File input"
151153
/>
152154
<v-progress-linear
@@ -158,7 +160,7 @@
158160
v-if="!disable_upload_controls"
159161
color="primary"
160162
class="mr-2 mb-4"
161-
@click="upload()"
163+
@click="validateInputFileForm() && upload()"
162164
v-text="'Upload'"
163165
/>
164166

@@ -253,6 +255,7 @@ export default Vue.extend({
253255
default_repository,
254256
selected_image: default_repository,
255257
deleting: '', // image currently being deleted, if any
258+
file_input_error: '',
256259
}
257260
},
258261
computed: {
@@ -262,6 +265,9 @@ export default Vue.extend({
262265
totalPages(): number {
263266
return Math.ceil(this.available_versions.remote.length / 10)
264267
},
268+
input_file_required_message(): string {
269+
return 'File is required'
270+
},
265271
},
266272
mounted() {
267273
this.loadCurrentVersion()
@@ -430,14 +436,14 @@ export default Vue.extend({
430436
return remote_counterpart.sha !== image.sha && remote_counterpart.sha !== null
431437
},
432438
async upload() {
433-
this.disable_upload_controls = true
434-
const { files } = document.getElementById('file') as HTMLInputElement
435-
if (files !== null) {
439+
const file = this.get_input_file()
440+
if (file !== null) {
441+
this.disable_upload_controls = true
436442
await back_axios({
437443
method: 'POST',
438444
url: '/version-chooser/v1.0/version/load/',
439445
timeout: 15 * 60 * 1000, // Wait for 15min
440-
data: files[0],
446+
data: file,
441447
headers: { 'Content-Type': 'undefined' },
442448
onUploadProgress: (event) => {
443449
this.upload_percentage = Math.round(100 * (event.loaded / event.total))
@@ -596,6 +602,28 @@ export default Vue.extend({
596602
}
597603
return this.available_versions.local.some((image) => image.sha === sha)
598604
},
605+
get_input_file(): File | null {
606+
const { files } = document.getElementById('file') as HTMLInputElement
607+
608+
if (files !== null && files.length > 0) {
609+
return files[0]
610+
}
611+
612+
return null
613+
},
614+
is_file_input_not_empty(v: File | null): true | string {
615+
this.file_input_error = ''
616+
return !!v || this.input_file_required_message
617+
},
618+
validateInputFileForm(): boolean {
619+
const valid = this.get_input_file() != null
620+
621+
if (!valid) {
622+
this.file_input_error = this.input_file_required_message
623+
}
624+
625+
return valid
626+
},
599627
},
600628
})
601629
</script>

0 commit comments

Comments
 (0)