Skip to content

Commit 6fcc765

Browse files
luannmoreiragustavosbarreto
authored andcommitted
refactor(ui): simplify license upload input logic
Replaced duplicated `<v-file-input>` blocks with a single shared input. Added custom validation for file size and extension in a reusable rule. Removed unused License.vue view and redundant license type definition.
1 parent 4c168a2 commit 6fcc765

File tree

4 files changed

+73
-112
lines changed

4 files changed

+73
-112
lines changed

ui/admin/src/components/Settings/SettingsLicense.vue

Lines changed: 19 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -186,36 +186,19 @@
186186
<v-divider class="mb-4 mt-4" />
187187
<h6 class="text-h6 text-center">License Field</h6>
188188

189-
<v-file-input
190-
class="mt-4"
191-
accept=".dat"
192-
show-size
193-
variant="outlined"
194-
label="Select license file"
195-
counter
196-
v-model="currentFile"
197-
:rules="rules"
198-
@change="onAddFiles(currentFile)"
199-
/>
200-
<v-btn v-if="licenseUploadStatus" class="mr-2" variant="outlined" @click="uploadLicense">
201-
Upload
202-
</v-btn>
203-
</div>
204-
205-
<div v-else>
206-
<v-file-input
207-
class="mt-4"
208-
accept=".dat"
209-
show-size
210-
variant="outlined"
211-
label="Select license file"
212-
counter
213-
v-model="currentFile"
214-
:rules="rules"
215-
@change="onAddFiles(currentFile)"
216-
/>
217-
<v-btn class="mr-2" variant="outlined" v-if="licenseUploadStatus" @click="uploadLicense"> Upload </v-btn>
218189
</div>
190+
<v-file-input
191+
class="mt-4"
192+
accept=".dat"
193+
show-size
194+
variant="outlined"
195+
label="Select license file"
196+
counter
197+
v-model="currentFile"
198+
@change="licenseUploadStatus = !!currentFile.length"
199+
:rules="rules"
200+
/>
201+
<v-btn class="mr-2" variant="outlined" @click="uploadLicense"> Upload </v-btn>
219202
</v-container>
220203

221204
</v-card>
@@ -232,15 +215,6 @@ import {
232215
} from "../../interfaces/INotifications";
233216
import { useStore } from "../../store";
234217
235-
type Licensefile = {
236-
lastModified: number;
237-
lastModifiedDate: string;
238-
name: string;
239-
size: number;
240-
type: string;
241-
webkitRelativePath: string;
242-
};
243-
244218
const store = useStore();
245219
246220
const currentFile = ref<Array<File>>([]);
@@ -288,22 +262,21 @@ const formatFeatureValue = (value: number | boolean | undefined) => value === -1
288262
289263
const isBooleanType = (value: number | boolean | undefined) => typeof value === "boolean";
290264
291-
const rules = [
292-
(value: Array<Licensefile>) => !value || (value.length > 0 && value[0].size < 32768) || "License size should be less than 32 Kb!",
293-
];
294-
295-
const onAddFiles = (file: Array<File>) => {
296-
currentFile.value = file;
297-
licenseUploadStatus.value = true;
265+
const validateLicenseFile = (file: File | null): string | boolean => {
266+
if (!file) return true;
267+
if (file.size >= 32 * 1024) return "License size must be less than 32 KB!";
268+
if (!file.name.endsWith(".dat")) return "Only .dat files are allowed!";
269+
return true;
298270
};
299271
272+
const rules = [validateLicenseFile];
273+
300274
const uploadLicense = async () => {
301275
if (currentFile.value) {
302276
try {
303277
await store.dispatch("license/post", currentFile.value);
304278
await store.dispatch("license/get");
305279
store.dispatch("snackbar/showSnackbarSuccessAction", INotificationsSuccess.licenseUpload);
306-
307280
licenseUploadStatus.value = false;
308281
} catch (error) {
309282
console.error("License upload error:", error);

ui/admin/src/store/modules/license.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export const license: Module<LicenseState, State> = {
2626
async get({ commit }) {
2727
const res = await apiLicense.getLicense();
2828
commit("setLicense", res);
29-
return res.data;
3029
},
3130

3231
async post(context, file: File) {

ui/admin/src/views/License.vue

Lines changed: 0 additions & 14 deletions
This file was deleted.

ui/admin/tests/unit/components/License/License/__snapshots__/index.spec.ts.snap

Lines changed: 54 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -668,66 +668,69 @@ exports[`License > Renders the component 1`] = `
668668
</div>
669669
<hr data-v-75f26564="" class="v-divider v-theme--light mb-4 mt-4" aria-orientation="horizontal" role="separator">
670670
<h6 data-v-75f26564="" class="text-h6 text-center">License Field</h6>
671-
<div data-v-75f26564="" class="v-input v-input--horizontal v-input--center-affix v-input--density-default v-theme--light v-locale--is-ltr v-file-input mt-4">
672-
<div class="v-input__prepend">
673-
<!----><i class="mdi-paperclip mdi v-icon notranslate v-theme--light v-icon--size-default v-icon--clickable" role="button" aria-hidden="false" tabindex="0" aria-label="Select license file prepended action"></i>
674-
</div>
675-
<div class="v-input__control">
676-
<div class="v-field v-field--appended v-field--center-affix v-field--variant-outlined v-theme--light v-locale--is-ltr" prepend-icon="$file">
677-
<div class="v-field__overlay"></div>
678-
<div class="v-field__loader">
679-
<div class="v-progress-linear v-theme--light v-locale--is-ltr" style="top: 0px; height: 0px; --v-progress-linear-height: 2px;" role="progressbar" aria-hidden="true" aria-valuemin="0" aria-valuemax="100">
680-
<!---->
681-
<div class="v-progress-linear__background"></div>
682-
<div class="v-progress-linear__buffer" style="width: 0%;"></div>
683-
<transition-stub name="fade-transition" appear="false" persisted="false" css="true">
684-
<div class="v-progress-linear__indeterminate">
685-
<div class="v-progress-linear__indeterminate long"></div>
686-
<div class="v-progress-linear__indeterminate short"></div>
687-
</div>
688-
</transition-stub>
689-
<!---->
690-
</div>
691-
</div>
692-
<!---->
693-
<div class="v-field__field" data-no-activator="">
694-
<!----><label class="v-label v-field-label" for="input-v-7">
695-
<!---->Select license file
696-
</label><input type="file" id="input-v-7" aria-describedby="input-v-7-messages" accept=".dat">
697-
<div class="v-field__input">
698-
<!---->
699-
</div>
700-
</div>
701-
<transition-stub name="expand-x-transition" appear="false" persisted="false" css="true">
702-
<div class="v-field__clearable" style="display: none;"><i class="mdi-close-circle mdi v-icon notranslate v-theme--light v-icon--size-default v-icon--clickable" role="button" aria-hidden="false" tabindex="0" aria-label="Clear Select license file"></i></div>
703-
</transition-stub>
704-
<div class="v-field__append-inner">
671+
</div>
672+
<div data-v-75f26564="" class="v-input v-input--horizontal v-input--center-affix v-input--density-default v-theme--light v-locale--is-ltr v-file-input mt-4">
673+
<div class="v-input__prepend">
674+
<!----><i class="mdi-paperclip mdi v-icon notranslate v-theme--light v-icon--size-default v-icon--clickable" role="button" aria-hidden="false" tabindex="0" aria-label="Select license file prepended action"></i>
675+
</div>
676+
<div class="v-input__control">
677+
<div class="v-field v-field--appended v-field--center-affix v-field--variant-outlined v-theme--light v-locale--is-ltr" prepend-icon="$file">
678+
<div class="v-field__overlay"></div>
679+
<div class="v-field__loader">
680+
<div class="v-progress-linear v-theme--light v-locale--is-ltr" style="top: 0px; height: 0px; --v-progress-linear-height: 2px;" role="progressbar" aria-hidden="true" aria-valuemin="0" aria-valuemax="100">
705681
<!---->
682+
<div class="v-progress-linear__background"></div>
683+
<div class="v-progress-linear__buffer" style="width: 0%;"></div>
684+
<transition-stub name="fade-transition" appear="false" persisted="false" css="true">
685+
<div class="v-progress-linear__indeterminate">
686+
<div class="v-progress-linear__indeterminate long"></div>
687+
<div class="v-progress-linear__indeterminate short"></div>
688+
</div>
689+
</transition-stub>
706690
<!---->
707691
</div>
708-
<div class="v-field__outline">
709-
<div class="v-field__outline__start"></div>
710-
<div class="v-field__outline__notch"><label class="v-label v-field-label v-field-label--floating" aria-hidden="true" for="input-v-7">
711-
<!---->Select license file
712-
</label></div>
713-
<div class="v-field__outline__end"></div>
692+
</div>
693+
<!---->
694+
<div class="v-field__field" data-no-activator="">
695+
<!----><label class="v-label v-field-label" for="input-v-7">
696+
<!---->Select license file
697+
</label><input type="file" id="input-v-7" aria-describedby="input-v-7-messages" accept=".dat">
698+
<div class="v-field__input">
714699
<!---->
715700
</div>
716701
</div>
717-
</div>
718-
<!---->
719-
<div id="input-v-7-messages" class="v-input__details" role="alert" aria-live="polite">
720-
<transition-group-stub name="slide-y-transition" tag="div" appear="false" persisted="false" css="true" class="v-messages">
721-
<!---->
722-
</transition-group-stub>
723-
<!----><span></span>
724-
<transition-stub name="slide-y-transition" appear="false" persisted="false" css="true">
725-
<div class="v-counter" style="display: none;">0 files (0 B in total)</div>
702+
<transition-stub name="expand-x-transition" appear="false" persisted="false" css="true">
703+
<div class="v-field__clearable" style="display: none;"><i class="mdi-close-circle mdi v-icon notranslate v-theme--light v-icon--size-default v-icon--clickable" role="button" aria-hidden="false" tabindex="0" aria-label="Clear Select license file"></i></div>
726704
</transition-stub>
705+
<div class="v-field__append-inner">
706+
<!---->
707+
<!---->
708+
</div>
709+
<div class="v-field__outline">
710+
<div class="v-field__outline__start"></div>
711+
<div class="v-field__outline__notch"><label class="v-label v-field-label v-field-label--floating" aria-hidden="true" for="input-v-7">
712+
<!---->Select license file
713+
</label></div>
714+
<div class="v-field__outline__end"></div>
715+
<!---->
716+
</div>
727717
</div>
728718
</div>
729-
<!--v-if-->
730-
</div>
719+
<!---->
720+
<div id="input-v-7-messages" class="v-input__details" role="alert" aria-live="polite">
721+
<transition-group-stub name="slide-y-transition" tag="div" appear="false" persisted="false" css="true" class="v-messages">
722+
<!---->
723+
</transition-group-stub>
724+
<!----><span></span>
725+
<transition-stub name="slide-y-transition" appear="false" persisted="false" css="true">
726+
<div class="v-counter" style="display: none;">0 files (0 B in total)</div>
727+
</transition-stub>
728+
</div>
729+
</div><button data-v-75f26564="" type="button" class="v-btn v-theme--light v-btn--density-default v-btn--size-default v-btn--variant-outlined mr-2"><span class="v-btn__overlay"></span><span class="v-btn__underlay"></span>
730+
<!----><span class="v-btn__content" data-no-activator=""> Upload </span>
731+
<!---->
732+
<!---->
733+
</button>
731734
</div>
732735
<!---->
733736
<!----><span class="v-card__underlay"></span>

0 commit comments

Comments
 (0)