Skip to content

Commit

Permalink
Merge pull request #458 from hotwax/#457_mappings
Browse files Browse the repository at this point in the history
Mapping creation/selection fixes
  • Loading branch information
ravilodhi committed Sep 19, 2024
2 parents b5c68f9 + f94215d commit 6079b3d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 15 deletions.
48 changes: 37 additions & 11 deletions src/components/CreateMappingModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,21 @@
<ion-input :label="translate('Mapping name')" :placeholder="translate('Field mapping name')" v-model="mappingName" />
</ion-item>

<ion-content class="ion-padding">
<ion-content>
<div>
<ion-list>
<ion-item :key="field" v-for="(fieldValues, field) in getFields()">
<ion-item-divider>
<ion-label>{{ translate("Required") }} </ion-label>
</ion-item-divider>
<ion-item :key="field" v-for="(fieldValues, field) in getFields(fields, true)">
<ion-select :label="translate(fieldValues.label)" interface="popover" :placeholder = "translate('Select')" v-model="fieldMapping[field]">
<ion-select-option :key="index" v-for="(prop, index) in fileColumns">{{ prop }}</ion-select-option>
</ion-select>
</ion-item>
<ion-item-divider>
<ion-label>{{ translate("Optional") }} </ion-label>
</ion-item-divider>
<ion-item :key="field" v-for="(fieldValues, field) in getFields(fields, false)">
<ion-select :label="translate(fieldValues.label)" interface="popover" :placeholder = "translate('Select')" v-model="fieldMapping[field]">
<ion-select-option :key="index" v-for="(prop, index) in fileColumns">{{ prop }}</ion-select-option>
</ion-select>
Expand All @@ -42,13 +53,14 @@ import {
IonHeader,
IonIcon,
IonInput,
IonItem,
IonItemDivider,
IonLabel,
IonSelect,
IonSelectOption,
IonTitle,
IonToolbar,
IonItem,
IonList,
onIonViewDidEnter,
modalController
} from '@ionic/vue';
Expand All @@ -67,34 +79,43 @@ let mappingName = ref(null)
let fieldMapping = ref ({})
let fileColumns = ref([])
let identificationTypeId = ref('SKU')

Check warning on line 81 in src/components/CreateMappingModal.vue

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (18.x)

'identificationTypeId' is assigned a value but never used

Check warning on line 81 in src/components/CreateMappingModal.vue

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / build_and_deploy

'identificationTypeId' is assigned a value but never used

Check warning on line 81 in src/components/CreateMappingModal.vue

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (20.x)

'identificationTypeId' is assigned a value but never used
const fields = process.env["VUE_APP_MAPPING_INVCOUNT"] ? JSON.parse(process.env["VUE_APP_MAPPING_INVCOUNT"]) : {}
onMounted(() => {
fieldMapping.value = { ...props.seletedFieldMapping }
fileColumns.value = Object.keys(props.content[0]);
})
function getFields() {
const fields = process.env["VUE_APP_MAPPING_" + props.mappingType];
return fields ? JSON.parse(fields) : {};
function getFields(fields, required = true) {
return Object.keys(fields).reduce((result, key) => {
if (fields[key].required === required) {
result[key] = fields[key];
}
return result;
}, {});
}
function closeModal() {
modalController.dismiss({ dismissed: true });
}
async function saveMapping() {
if(!mappingName.value) {
if(!mappingName.value || !mappingName.value.trim()) {
showToast(translate("Enter mapping name"));
return
}
if (!areAllFieldsSelected()) {
showToast(translate("Map all fields"));
showToast(translate("Map all required fields"));
return
}
const id = generateUniqueMappingPrefId();
await store.dispatch("user/createFieldMapping", { id, name: mappingName.value, value: fieldMapping.value, mappingType: props.mappingType })
closeModal();
}
function areAllFieldsSelected() {
return Object.values(fieldMapping.value).every(field => field !== "");
const requiredFields = Object.keys(getFields(fields, true));
const selectedFields = Object.keys(fieldMapping.value).filter(key => fieldMapping.value[key] !== '')
return requiredFields.every(field => selectedFields.includes(field));
}
//Todo: Generating unique identifiers as we are currently storing in local storage. Need to remove it as we will be storing data on server.
Expand All @@ -103,4 +124,9 @@ function generateUniqueMappingPrefId() {
return !fieldMappings.value[id] ? id : this.generateUniqueMappingPrefId();
}
</script>
</script>
<style scoped>
ion-content {
--padding-bottom: 80px;
}
</style>
1 change: 1 addition & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
"Line status": "Line status",
"Make sure all the columns are mapped correctly.": "Make sure all the columns are mapped correctly.",
"Make sure you've reviewed the products and their counts before uploading them for review": "Make sure you've reviewed the products and their counts before uploading them for review",
"Map all required fields": "Map all required fields",
"Mapping name": "Mapping name",
"New mapping": "New mapping",
"No cycle counts found": "No cycle counts found",
Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/count/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ const actions: ActionTree<CountState, RootState> = {
const resp = await CountService.fetchCycleCountImportSystemMessages({
systemMessageTypeId: "ImportInventoryCounts",
initDate_from: fifteenMinutesEarlier.toMillis(),
orderByField: 'processedDate desc,initDate desc',
orderByField: 'initDate desc, processedDate desc',
pageSize: 10
})
if (!hasError(resp)) {
Expand Down
9 changes: 6 additions & 3 deletions src/views/BulkUpload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<ion-icon :icon="addOutline" />
<ion-label>{{ translate("New mapping") }}</ion-label>
</ion-chip>
<ion-chip :disabled="!content.length" v-for="(mapping, index) in fieldMappings('INVCOUNT') ?? []" :key="index" @click="mapFields(mapping)" outline="true">
<ion-chip :disabled="!content.length" v-for="(mapping, index) in fieldMappings('INVCOUNT') ?? []" :key="index" @click="mapFields(mapping, index)" :outline="selectedMappingId != index">
{{ mapping.name }}
</ion-chip>
</div>
Expand Down Expand Up @@ -129,6 +129,7 @@ let fileName = ref(null)
let content = ref([])
let fieldMapping = ref({})
let fileColumns = ref([])
let selectedMappingId = ref(null)
const fileUploaded = ref(false);
const fields = process.env["VUE_APP_MAPPING_INVCOUNT"] ? JSON.parse(process.env["VUE_APP_MAPPING_INVCOUNT"]) : {}
Expand All @@ -154,6 +155,8 @@ function resetDefaults() {
uploadedFile.value = {}
content.value = []
fileName.value = null
file.value.value = ''
selectedMappingId.value = null
}
function extractFilename(filePath) {
if (!filePath) {
Expand Down Expand Up @@ -265,7 +268,6 @@ async function save(){
throw resp.data
}
resetDefaults()
file.value.value = ''
await store.dispatch('count/fetchCycleCountImportSystemMessages')
showToast(translate("The cycle counts file uploaded successfully."))
}).catch(() => {
Expand All @@ -277,7 +279,7 @@ async function save(){
});
return alert.present();
}
function mapFields(mapping) {
function mapFields(mapping, mappingId) {
const fieldMappingData = JSON.parse(JSON.stringify(mapping));
// TODO: Store an object in this.content variable, so everytime when accessing it, we don't need to use 0th index
Expand All @@ -295,6 +297,7 @@ function mapFields(mapping) {
}
})
fieldMapping.value = fieldMappingData.value;
selectedMappingId.value = mappingId
}
function areAllFieldsSelected() {
const requiredFields = Object.keys(getFilteredFields(fields, true));
Expand Down

0 comments on commit 6079b3d

Please sign in to comment.