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 21, 2025
1 parent be1b434 commit 66f450b
Show file tree
Hide file tree
Showing 2 changed files with 33 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' | 'blankExisting' | '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 = 'blankExisting';
Message.error(this.$t(`editor.warning.${this.warning}`));
}
}
highlightNext(): void {
if (this.highlightedIndex < this.getStorylines.length - 1) {
this.highlightedIndex++;
Expand Down
1 change: 1 addition & 0 deletions src/lang/lang.csv
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ editor.metadata.uuidInstructions,"Please enter the UUID of an existing storyline
editor.metadata.newUuidInstructions,"Enter a unique ID for your new storyline. One has been auto-generated for you, but you can also enter your own.",1,"Entrez un identifiant unique pour votre nouveau scénario. Un a été généré automatiquement pour vous, mais vous pouvez également saisir le vôtre.",0
editor.warning.rename,UUID already in use. Please choose a different ID.,1,UUID déjà utilisé. Veuillez choisir un autre identifiant.,0
editor.warning.blank,UUID field cannot be blank. Please enter a unique UUID.,1,Le champ UUID ne peut pas être vide. Veuillez saisir un UUID unique.,0
editor.warning.blankExisting,UUID field cannot be blank. Please enter a valid UUID to proceed.,1,Le champ UUID ne peut pas être vide. Veuillez saisir un UUID valide pour continuer.,0
editor.warning.renameFailed,Failed to rename product.,1,Échec du renommage du produit.,0
editor.changeUuid,Click here to change UUID,1,Cliquez ici pour changer,0
editor.title,Title,1,Titre,1
Expand Down

0 comments on commit 66f450b

Please sign in to comment.