-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace Wikit Textarea with Codex Textarea component (#771)
* Replace Wikit Textarea with Codex Textarea component Bug: T347190 * Fix v-model and add functionality * Remove this.form.itemsInput in favor of new v-model syntax * Fix errors * Remove trailing comma * Update browser tests * Update Home.vue * Update Home.spec.js * Put textarea in a wrapper component * Adjust tests to new TextareaHome component * Fix linting * Move MAX_NUM_IDS to TextArea component * Fix indentation * Rename component to ItemIdSearchTextarea * [WiP] rewrite component using Composition API * Commit unsuccesful testing export of i18n :( * Adjust i18n plugin to composition API with useI18n * Refactor global variable MAX_NUM_IDS to vue3 format * Fix typescript errors * Update HomeState to use the new ValidationError type * Add spaces between methods * Change name of internationalizaton plugin variable * Remove unneeded options in createI18n plugin
- Loading branch information
Showing
10 changed files
with
309 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<template> | ||
<cdx-field | ||
:status="validationError ? validationError.type : 'default'" | ||
:messages="validationError ? validationError.message : null" | ||
> | ||
<div class="progress-bar-wrapper"> | ||
<cdx-progress-bar v-if="loading" :aria-label="$i18n('item-form-progress-bar-aria-label')" /> | ||
</div> | ||
<cdx-text-area | ||
:label="$i18n('item-form-id-input-label')" | ||
:placeholder="$i18n('item-form-id-input-placeholder')" | ||
:rows="8" | ||
:status="validationError ? validationError.type : 'default'" | ||
v-model="textareaInputValue" | ||
/> | ||
</cdx-field> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { ref, inject } from 'vue'; | ||
import { Ref } from 'vue'; | ||
import { useI18n } from 'vue-banana-i18n'; | ||
import { useStore } from '../store'; | ||
import { CdxTextArea, CdxField, CdxProgressBar } from "@wikimedia/codex"; | ||
import ValidationError from '../types/ValidationError'; | ||
// Run it with compat mode | ||
// https://v3-migration.vuejs.org/breaking-changes/v-model.html | ||
CdxTextArea.compatConfig = { | ||
...CdxTextArea.compatConfig, | ||
COMPONENT_V_MODEL: false, | ||
}; | ||
const validationError: Ref<ValidationError> = ref(null); | ||
const messages = useI18n(); | ||
const store = useStore(); | ||
const textareaInputValue = ref(store.lastSearchedIds); | ||
const MAX_NUM_IDS = inject('MAX_NUM_IDS'); | ||
defineProps<{loading: boolean}>(); | ||
function splitInput(): Array<string> { | ||
return textareaInputValue.value.split( '\n' ); | ||
} | ||
function sanitizeArray(): Array<string> { | ||
// this filter function removes all falsy values | ||
// see: https://stackoverflow.com/a/281335/1619792 | ||
return splitInput().filter(x => x); | ||
} | ||
function serializeInput(): string { | ||
return sanitizeArray().join('|'); | ||
} | ||
function validate(): void { | ||
validationError.value = null; | ||
const typeError = 'error'; | ||
const rules = [{ | ||
check: (ids: Array<string>) => ids.length < 1, | ||
type: typeError, | ||
message: { [typeError]: messages.i18n('item-form-error-message-empty') as string } | ||
}, | ||
{ | ||
check: (ids: Array<string>) => ids.length > (MAX_NUM_IDS as number), | ||
type: typeError, | ||
message: { [typeError]: messages.i18n('item-form-error-message-max', MAX_NUM_IDS) as string } | ||
}, | ||
{ | ||
check: (ids: Array<string>) => !ids.every(value => /^[Qq]\d+$/.test( value.trim() )), | ||
type: typeError, | ||
message: { [typeError]: messages.i18n('item-form-error-message-invalid') as string } | ||
}]; | ||
const sanitized = sanitizeArray(); | ||
for(const {check, type, message} of rules){ | ||
if(check(sanitized)){ | ||
validationError.value = { type, message }; | ||
return; | ||
} | ||
} | ||
} | ||
defineExpose({validate, serializeInput, validationError}); | ||
</script> | ||
|
||
<style lang="scss"> | ||
.cdx-field__control { | ||
position: relative; | ||
width: 100%; | ||
.progress-bar-wrapper { | ||
position: absolute; | ||
top: 50%; | ||
width: 100%; | ||
.cdx-progress-bar { | ||
width: 50%; | ||
margin: auto; | ||
} | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
type ValidationError = { | ||
type: string, | ||
message: { [key : string] : string } | ||
} | ||
|
||
export default ValidationError; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.