Skip to content

Commit

Permalink
Merge pull request #348 from amansinghbais/347-all-facilities-support
Browse files Browse the repository at this point in the history
Implemented: support for all facilities/channels selection while rule creation and updation (#347)
  • Loading branch information
ymaheshwari1 authored Jun 3, 2024
2 parents a317030 + bbb839e commit 966d221
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 67 deletions.
11 changes: 7 additions & 4 deletions src/components/RuleItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

<template v-else>
<ion-item-divider color="light">
<ion-label>{{ translate("Facility groups") }}</ion-label>
<ion-label>{{ translate("Facilities") }}</ion-label>
</ion-item-divider>

<ion-item v-if="isRuleConditionAvailable('ENTCT_ATP_FAC_GROUPS', 'facilityGroupId', 'in')">
Expand Down Expand Up @@ -109,9 +109,9 @@
</template>

<script setup lang="ts">
import { IonAccordion, IonAccordionGroup, IonButton, IonCard, IonCardHeader, IonCardSubtitle, IonCardTitle, IonChip, IonIcon, IonItem, IonItemDivider, IonLabel, IonList, IonReorder, IonToggle, alertController } from '@ionic/vue';
import { IonAccordion, IonAccordionGroup, IonButton, IonCard, IonCardHeader, IonCardSubtitle, IonCardTitle, IonChip, IonIcon, IonItem, IonItemDivider, IonLabel, IonReorder, IonToggle, alertController } from '@ionic/vue';
import { computed, defineProps, onMounted, ref } from 'vue';
import { archiveOutline, checkmarkDoneCircleOutline, chevronDownOutline, chevronUpOutline, closeCircleOutline, globeOutline, pulseOutline, sendOutline, shirtOutline, storefrontOutline } from 'ionicons/icons';
import { archiveOutline, checkmarkDoneCircleOutline, closeCircleOutline, globeOutline, pulseOutline, sendOutline, shirtOutline, storefrontOutline } from 'ionicons/icons';
import { useRouter } from 'vue-router';
import { translate } from '@/i18n';
import { RuleService } from '@/services/RuleService';
Expand All @@ -127,7 +127,6 @@ const props = defineProps(["rule", "ruleIndex"])
const total = computed(() => store.getters["rule/getTotalRulesCount"])
const configFacilities = computed(() => store.getters["util/getConfigFacilities"])
const facilityGroups = computed(() => store.getters["util/getFacilityGroups"])
const rules = computed(() => store.getters["rule/getRules"]);
const isReorderActive = computed(() => store.getters["rule/isReorderActive"]);
const selectedSegment = computed(() => store.getters["util/getSelectedSegment"])
Expand Down Expand Up @@ -271,6 +270,8 @@ function getRuleConditions(conditionTypeEnumId: string, fieldName?: string, oper
if(fieldName && operator) {
const condition = props.rule.ruleConditions.find((condition: any) => condition.conditionTypeEnumId === conditionTypeEnumId && condition.fieldName === fieldName && condition.operator === operator)
if(condition && conditionTypeEnumId === 'ENTCT_ATP_FAC_GROUPS') {
if(condition.fieldValue === "ALL") return translate("All facility groups selected");
let facilityGroupIds = condition?.fieldValue.split(",")
facilityGroupIds = facilityGroupIds.map((id: string) => {
let group = facilityGroups.value.find((group: any) => group.facilityGroupId === id)
Expand All @@ -284,6 +285,8 @@ function getRuleConditions(conditionTypeEnumId: string, fieldName?: string, oper
const condition = props.rule.ruleConditions.find((condition: any) => condition.conditionTypeEnumId === conditionTypeEnumId)
if(condition && condition.fieldValue) {
if(condition.fieldValue === "ALL") return translate("All channels selected");
let facilities = condition?.fieldValue.split(",")
facilities = facilities.map((id: string) => {
let facility = configFacilities.value.find((facility: any) => facility.facilityId === id)
Expand Down
7 changes: 6 additions & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"A store repesents a company or a unique catalog of products. If your OMS is connected to multiple eCommerce stores sellling different collections of products, you may have multiple Product Stores set up in HotWax Commerce.": "A store repesents a company or a unique catalog of products. If your OMS is connected to multiple eCommerce stores sellling different collections of products, you may have multiple Product Stores set up in HotWax Commerce.",
"add": "add",
"Add": "Add",
"All channels selected": "All channels selected",
"All facilities selected": "All facilities selected",
"All facility groups selected": "All facility groups selected",
"All products selected.": "All products selected.",
"Any page made on this page will be lost. You will not be able to reverse this action.": "Any page made on this page will be lost. You will not be able to reverse this action.",
"App": "App",
Expand Down Expand Up @@ -96,7 +99,7 @@
"Filter stores": "Filter stores",
"ID": "ID",
"Import product thresholds": "Import product thresholds",
"Include facility groups": "Included facility groups",
"Include facility groups": "Include facility groups",
"Included": "Included",
"Internal ID cannot be more than 20 characters.": "Internal ID cannot be more than 20 characters.",
"Inventory channels": "Inventory channels",
Expand Down Expand Up @@ -211,6 +214,8 @@
"Search": "Search {label}",
"Search for to find results": "Search for {label} to find results",
"Select": "Select {label}",
"Select all channels": "Select all channels",
"Select all facilities": "Select all facilities",
"Select all variants": "Select all variants",
"Select CSV": "Select CSV",
"Selected products": "Selected products",
Expand Down
2 changes: 1 addition & 1 deletion src/services/UtilService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import api, {client} from '@/api';
import api from '@/api';

const fetchFacets = async (payload: any): Promise<any> => {
return api({
Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/channel/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import store from "@/store"

const actions: ActionTree<ChannelState, RootState> = {

async fetchInventoryChannels ({ commit, state, dispatch }) {
async fetchInventoryChannels ({ commit, dispatch }) {
let resp = {} as any;
let inventoryChannels = [] as any

Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/util/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const actions: ActionTree<UtilState, RootState> = {
commit(types.UTIL_FACILITY_GROUPS_UPDATED, facilityGroups)
},

async updateAppliedFilters ({ commit, state }, payload) {
async updateAppliedFilters ({ commit }, payload) {
commit(types.UTIL_APPLIED_FILTERS_UPDATED, payload)
},

Expand Down
13 changes: 11 additions & 2 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,19 @@ const generateRuleActions = (ruleId: string, actionTypeEnumId: string, actionVal
return condition
}

const generateRuleConditions = (ruleId: string, conditionTypeEnumId: string, appliedFilters: any, selectedFac: any) => {
const generateRuleConditions = (ruleId: string, conditionTypeEnumId: string, appliedFilters: any, selectedFac: any, areAllSelected: boolean) => {
const conditions = [];

if(conditionTypeEnumId === "ENTCT_ATP_FACILITIES") {
if(areAllSelected) {
conditions.push({
"ruleId": ruleId,
conditionTypeEnumId,
"fieldName": conditionTypeEnumId === "ENTCT_ATP_FACILITIES" ? "facilityId" : "facilityGroupId",
"operator": "in",
"fieldValue": "ALL",
"multiValued": "Y"
})
} else if(conditionTypeEnumId === "ENTCT_ATP_FACILITIES") {
conditions.push({
"ruleId": ruleId,
conditionTypeEnumId,
Expand Down
39 changes: 25 additions & 14 deletions src/views/CreateUpdateSafetyStockRule.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,14 @@
<h1>{{ translate("Facilities") }} <ion-text color="danger">*</ion-text></h1>
</div>

<section>
<ion-item lines="none">
<ion-toggle v-model="formData.areAllFacilitiesSelected">{{ translate("Select all facilities") }}</ion-toggle>
</ion-item>
</section>

<section v-if="facilityGroups.length">
<ion-card>
<ion-card :disabled="formData.areAllFacilitiesSelected">
<ion-item lines="none">
<ion-label>{{ translate("Included") }} <ion-text color="danger">*</ion-text></ion-label>
<ion-button fill="clear" @click="openProductFacilityGroupModal('included')">
Expand All @@ -52,7 +58,7 @@
</ion-card-content>
</ion-card>

<ion-card>
<ion-card :disabled="formData.areAllFacilitiesSelected">
<ion-item lines="none">
<ion-label>{{ translate("Excluded") }}</ion-label>
<ion-button fill="clear" @click="openProductFacilityGroupModal('excluded')">
Expand Down Expand Up @@ -84,7 +90,7 @@
</template>

<script setup lang="ts">
import { IonBackButton, IonButton, IonCard, IonCardContent, IonCardHeader, IonCardTitle, IonChip, IonContent, IonFab, IonFabButton, IonHeader, IonIcon, IonInput, IonItem, IonLabel, IonNote, IonPage, IonText, IonTitle, IonToolbar, modalController, onIonViewDidEnter , onIonViewWillLeave } from '@ionic/vue';
import { IonBackButton, IonButton, IonCard, IonCardContent, IonCardHeader, IonCardTitle, IonChip, IonContent, IonFab, IonFabButton, IonHeader, IonIcon, IonInput, IonItem, IonLabel, IonNote, IonPage, IonText, IonTitle, IonToggle, IonToolbar, modalController, onIonViewDidEnter , onIonViewWillLeave } from '@ionic/vue';
import { addCircleOutline, closeCircle, saveOutline } from 'ionicons/icons'
import { translate } from "@/i18n";
import ProductFilters from '@/components/ProductFilters.vue';
Expand All @@ -106,7 +112,8 @@ const formData = ref({
selectedFacilityGroups: {
included: [],
excluded: []
}
},
areAllFacilitiesSelected: false
}) as any;
const currentRule = ref({}) as any;
const props = defineProps(["ruleId"]);
Expand All @@ -133,12 +140,15 @@ onIonViewDidEnter(async () => {
formData.value.safetyStock = currentRule.value.ruleActions[0]?.fieldValue ? currentRule.value.ruleActions[0].fieldValue : ''
const includedGroups = currentRule.value.ruleConditions.find((condition: any) => condition.conditionTypeEnumId === "ENTCT_ATP_FAC_GROUPS" && condition.operator === "in")
const includedGroupIds = includedGroups?.fieldValue ? includedGroups.fieldValue.split(",") : []
formData.value.selectedFacilityGroups.included = facilityGroups.value.filter((group: any) => includedGroupIds.includes(group.facilityGroupId));
const excludedGroups = currentRule.value.ruleConditions.find((condition: any) => condition.conditionTypeEnumId === "ENTCT_ATP_FAC_GROUPS" && condition.operator === "not-in")
const excludedGroupIds = excludedGroups?.fieldValue ? excludedGroups.fieldValue.split(",") : []
formData.value.selectedFacilityGroups.excluded = facilityGroups.value.filter((group: any) => excludedGroupIds.includes(group.facilityGroupId));
if(includedGroups?.fieldValue === "ALL") formData.value.areAllFacilitiesSelected = true;
else {
const includedGroupIds = includedGroups?.fieldValue ? includedGroups.fieldValue.split(",") : []
formData.value.selectedFacilityGroups.included = facilityGroups.value.filter((group: any) => includedGroupIds.includes(group.facilityGroupId));
const excludedGroups = currentRule.value.ruleConditions.find((condition: any) => condition.conditionTypeEnumId === "ENTCT_ATP_FAC_GROUPS" && condition.operator === "not-in")
const excludedGroupIds = excludedGroups?.fieldValue ? excludedGroups.fieldValue.split(",") : []
formData.value.selectedFacilityGroups.excluded = facilityGroups.value.filter((group: any) => excludedGroupIds.includes(group.facilityGroupId));
}
const currentAppliedFilters = JSON.parse(JSON.stringify(appliedFilters.value))
currentRule.value.ruleConditions.map((condition: any) => {
Expand Down Expand Up @@ -223,7 +233,7 @@ async function createRule() {
const rule = await RuleService.createRule(params)
await RuleService.updateRule({
...params,
"ruleConditions": generateRuleConditions(rule.ruleId, "ENTCT_ATP_FAC_GROUPS", appliedFilters.value, formData.value.selectedFacilityGroups),
"ruleConditions": generateRuleConditions(rule.ruleId, "ENTCT_ATP_FAC_GROUPS", appliedFilters.value, formData.value.selectedFacilityGroups, formData.value.areAllFacilitiesSelected),
"ruleActions": generateRuleActions(rule.ruleId, "ATP_SAFETY_STOCK", formData.value.safetyStock, false, [])
}, rule.ruleId);
Expand All @@ -242,14 +252,15 @@ async function updateRule() {
if(!isRuleValid()) return;
const currentRuleConditions = JSON.parse(JSON.stringify(currentRule.value.ruleConditions));
const updatedRuleConditions = generateRuleConditions(props.ruleId, "ENTCT_ATP_FAC_GROUPS", appliedFilters.value, formData.value.selectedFacilityGroups);
const conditionsToRemove = currentRuleConditions.filter((condition: any) => !updatedRuleConditions.some((updatedCondition: any) => condition.conditionTypeEnumId === updatedCondition.conditionTypeEnumId && condition.fieldName === updatedCondition.fieldName && condition.operator === updatedCondition.operator))
const updatedRuleConditions = generateRuleConditions(props.ruleId, "ENTCT_ATP_FAC_GROUPS", appliedFilters.value, formData.value.selectedFacilityGroups, formData.value.areAllFacilitiesSelected);
updatedRuleConditions.map((updatedCondition: any) => {
const current = currentRuleConditions.find((condition: any) => condition.conditionTypeEnumId === updatedCondition.conditionTypeEnumId && condition.fieldName === updatedCondition.fieldName && condition.operator === updatedCondition.operator);
if(current) updatedCondition["conditionSeqId"] = current.conditionSeqId;
})
const conditionsToRemove = currentRuleConditions.filter((condition: any) => !updatedRuleConditions.some((updatedCondition: any) => condition.conditionTypeEnumId === updatedCondition.conditionTypeEnumId && condition.fieldName === updatedCondition.fieldName && condition.operator === updatedCondition.operator && condition.conditionSeqId === updatedCondition.conditionSeqId))
try {
await RuleService.updateRule({
...currentRule.value,
Expand Down Expand Up @@ -282,7 +293,7 @@ function isRuleValid() {
return false;
}
if(!formData.value.selectedFacilityGroups.included.length) {
if(!formData.value.areAllFacilitiesSelected && !formData.value.selectedFacilityGroups.included.length) {
showToast(translate("Please include atleast one facility."))
return false;
}
Expand Down
Loading

0 comments on commit 966d221

Please sign in to comment.