Skip to content
Snippets Groups Projects
Commit ca037f27 authored by Timothee P's avatar Timothee P :sunflower:
Browse files

fix boolean as string from csv and ecape single quote to query prerecorded list value

parent 88bb82db
No related branches found
No related tags found
1 merge request!706REDMINE_ISSUE-18740 | Export signalements - Liste de valeurs pré-enregistrées n'ont pas la bonne forme
......@@ -505,7 +505,7 @@ export default {
selectPrerecordedValue(e) {
this.selectedPrerecordedValue = e;
this.prerecordedListSearchQuery = null;
this.updateStore_extra_form({ target: { value: this.selectedPrerecordedValue } });
this.updateStore_extra_form({ target: { value: this.selectedPrerecordedValue.label } });
},
clearPrerecordedValue() {
......
......@@ -384,6 +384,7 @@
<script>
import { csv } from 'csvtojson';
import { escape } from 'lodash';
import { mapActions, mapMutations, mapGetters, mapState } from 'vuex';
import { formatStringDate, transformProperties } from '@/utils';
......@@ -549,10 +550,11 @@ export default {
this.showImport = !this.showImport;
},
async checkPreRecordedValue(fieldLabel, listName) {
// query existing prerecordedvalues with label
await this.GET_SELECTED_PRERECORDED_LIST_VALUES({ name: listName, pattern: fieldLabel });
// check if the value exist in available pre_recorded_values
async checkPreRecordedValue(fieldValue, listName) {
const fieldLabel = fieldValue.label || fieldValue;
// query existing prerecorded list values (with label to limit results in response, there could be many) and escape special characters, since single quote causes error in backend
await this.GET_SELECTED_PRERECORDED_LIST_VALUES({ name: listName, pattern: escape(fieldLabel) });
// check if the value exist in available prerecorded list values
return this.selectedPrerecordedListValues[listName].some((el) => el.label === fieldLabel);
},
......@@ -570,6 +572,9 @@ export default {
const properties = feature.properties || feature;
if (name in properties) {
let fieldInFeature = properties[name];
if (field_type === 'boolean') { // in csv booleans are capitalized string that need to be translated in javascript syntax
fieldInFeature = fieldInFeature === 'True' ? true : (fieldInFeature === 'False' ? false : fieldInFeature);
}
const customType = transformProperties(fieldInFeature);
//* if custom field value is not defined or not null or in case of prerecorded list with defined value => then check validity of field type
if (fieldInFeature !== null && fieldInFeature !== '' && fieldInFeature !== undefined) {
......@@ -582,10 +587,10 @@ export default {
return false;
}
} else if (field_type === 'pre_recorded_list') {
if (typeof fieldInFeature === 'string') { // data from CSV come as string
if (typeof fieldInFeature === 'string' && fieldInFeature.includes('label')) { // data from CSV might come as stringified object
fieldInFeature = JSON.parse(fieldInFeature.replaceAll('\'', '"'));
}
const isPreRecordedValue = await this.checkPreRecordedValue(fieldInFeature.label, options[0]);
const isPreRecordedValue = await this.checkPreRecordedValue(fieldInFeature, options[0]);
if (!isPreRecordedValue) {
this.importError = `Le fichier est invalide: la valeur [ ${fieldInFeature.label} ] ne fait pas partie des valeurs pré-enregistrées
pour le champ personnalisé "${name}".`;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment