Skip to content

Commit

Permalink
fix behavior of uuid input on enter press
Browse files Browse the repository at this point in the history
  • Loading branch information
IshavSohal committed Feb 25, 2025
1 parent be1b434 commit a1c2c09
Showing 1 changed file with 32 additions and 16 deletions.
48 changes: 32 additions & 16 deletions src/components/metadata-editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,7 @@
checkUuid();
"
v-model.trim="uuid"
v-on:keyup.enter="
() => {
generateRemoteConfig()
.then(fetchHistory)
.catch(() => {}); // Prevent grousing in console
}
"
v-on:keyup.enter="handleUuidEnter"
@focus="showDropdown = true"
@blur="showDropdown = false"
@keydown.down.prevent="highlightNext"
Expand Down Expand Up @@ -194,11 +188,7 @@
<!-- Load storyline with the given UUID, if it exists on the server, and also
any history associated with the product that can be found -->
<button
@click="
() => {
generateRemoteConfig().then(fetchHistory);
}
"
@click="handleUuidLoad"
class="editor-button editor-forms-button bg-black text-white ml-3 mr-0"
:class="{ 'input-error': error }"
:disabled="loadStatus === 'loading'"
Expand Down Expand Up @@ -257,7 +247,7 @@
</span>
<div>
<span class="inline-block select-none text-sm">{{
$t(`editor.warning.${warning}`)
$t(`editor.warning.${warning}`, warning === 'uuidNotFound' ? { uuid } : {})
}}</span>
</div>
<br />
Expand Down Expand Up @@ -594,7 +584,7 @@ import {
import { VueSpinnerOval } from 'vue3-spinners';
import { VueFinalModal } from 'vue-final-modal';
import { useUserStore } from '../stores/userStore';
import { computed } from "vue";
import { computed } from 'vue';
import JSZip from 'jszip';
import axios from 'axios';
Expand Down Expand Up @@ -659,7 +649,7 @@ export default class MetadataEditorV extends Vue {
loadingIntoEditor = false;
loadEditor = false;
error = false; // whether an error has occurred
warning: 'none' | 'uuid' | 'rename' | 'blank' = 'none'; // used for duplicate uuid warning
warning: 'none' | 'uuid' | 'rename' | 'blank' | 'uuidNotFound' = 'none'; // used for duplicate uuid warning
configLang = 'en';
currLang = 'en'; // page language
showDropdown = false;
Expand Down Expand Up @@ -763,7 +753,7 @@ export default class MetadataEditorV extends Vue {
// Initialize Storylines config and the configuration structure.
this.configs = { en: undefined, fr: undefined };
this.configFileStructure = undefined;
// set any metadata default values for creating new product
if (!this.loadExisting) {
// set current date as default
Expand Down Expand Up @@ -1092,6 +1082,7 @@ export default class MetadataEditorV extends Vue {
Message.error(this.$t('editor.editMetadata.message.error.noRequestedVersion'));
}
this.error = true;
this.warning = 'uuidNotFound';
this.loadStatus = 'waiting';
this.clearConfig();
// Product was not found, unlock the UUID
Expand All @@ -1105,6 +1096,8 @@ export default class MetadataEditorV extends Vue {
this.configFileStructureHelper(configZip);
// Extend the session on load
this.extendSession();
this.error = false;
this.warning = 'none';
});
});
}
Expand Down Expand Up @@ -2159,6 +2152,29 @@ export default class MetadataEditorV extends Vue {
}
}
async handleUuidEnter(): void {
if (this.editExisting) {
this.handleUuidLoad();
} else {
// UUID is not taken and is not blank so we proceed to editor-main
if (!this.error) {
this.continueToEditor();
} else if (this.warning !== 'none') {
Message.error(this.$t(`editor.warning.${this.warning}`));
}
}
}
handleUuidLoad(): void {
if (this.uuid) {
this.generateRemoteConfig().then(this.fetchHistory);
} else {
this.error = true;
this.warning = 'blank';
Message.error(this.$t(`editor.warning.${this.warning}`));
}
}
highlightNext(): void {
if (this.highlightedIndex < this.getStorylines.length - 1) {
this.highlightedIndex++;
Expand Down

0 comments on commit a1c2c09

Please sign in to comment.