From c6208d234c1e85872c98259c0ce99db7f7212088 Mon Sep 17 00:00:00 2001 From: Yash Maheshwari Date: Thu, 4 Apr 2024 18:26:26 +0530 Subject: [PATCH] Implemented: support to disable the save button if there are no changes in the filter options(#140) --- .../AddInventoryFilterOptionsModal.vue | 17 ++++++++++++++++- src/components/AddOrderRouteFilterOptions.vue | 17 ++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/components/AddInventoryFilterOptionsModal.vue b/src/components/AddInventoryFilterOptionsModal.vue index e271d53..48130d8 100644 --- a/src/components/AddInventoryFilterOptionsModal.vue +++ b/src/components/AddInventoryFilterOptionsModal.vue @@ -16,7 +16,7 @@ - + @@ -58,6 +58,8 @@ const props = defineProps({ }) let inventoryRuleConditions = ref({}) as any let enumerations = ref([]) as any +let areFiltersUpdated = ref(false) + const hiddenOptions = ["IIP_MSMNT_SYSTEM"] // managing this object, as we have some filters for which we need to have its associated filter, like in this case when we have PROXIMITY we also need to add MEASUREMENT_SYSTEM(this is not available on UI for selection and included in hiddenOptions) const associatedOptions = { IIP_PROXIMITY: { enum: "IIP_MSMNT_SYSTEM", defaultValue: "IMPERIAL" }} as any @@ -67,6 +69,17 @@ onMounted(() => { enumerations.value = Object.values(enums.value[props.parentEnumId]).filter((enumeration: any) => !hiddenOptions.includes(enumeration.enumId)) }) +function checkFilters() { + areFiltersUpdated.value = false; + areFiltersUpdated.value = Object.keys(inventoryRuleConditions.value).some((options: string) => { + return !props.ruleConditions[options] + }) + + areFiltersUpdated.value = areFiltersUpdated.value ? areFiltersUpdated.value : Object.keys(props.ruleConditions).some((options: string) => { + return !inventoryRuleConditions.value[options] + }) +} + function addConditionOption(condition: any) { const isConditionOptionAlreadyApplied = isConditionOptionSelected(condition.enumCode)?.fieldName const associatedEnum = enums.value[props.parentEnumId][associatedOptions[condition.enumId]?.enum] @@ -101,6 +114,8 @@ function addConditionOption(condition: any) { }) } } + + checkFilters() } function saveConditionOptions() { diff --git a/src/components/AddOrderRouteFilterOptions.vue b/src/components/AddOrderRouteFilterOptions.vue index 537732c..a173721 100644 --- a/src/components/AddOrderRouteFilterOptions.vue +++ b/src/components/AddOrderRouteFilterOptions.vue @@ -16,7 +16,7 @@ - + @@ -57,12 +57,25 @@ const props = defineProps({ } }) let routingFilters = ref({}) as any +let areFiltersUpdated = ref(false) onMounted(() => { routingFilters.value = props.orderRoutingFilters ? JSON.parse(JSON.stringify(props.orderRoutingFilters)) : {} }) +function checkFilters() { + areFiltersUpdated.value = false; + areFiltersUpdated.value = Object.keys(routingFilters.value).some((options: string) => { + return !props.orderRoutingFilters[options] + }) + + areFiltersUpdated.value = areFiltersUpdated.value ? areFiltersUpdated.value : Object.keys(props.orderRoutingFilters).some((options: string) => { + return !routingFilters.value[options] + }) +} + function addSortOption(sort: any) { + const isSortOptionAlreadyApplied = isSortOptionSelected(sort.enumCode)?.fieldName if(isSortOptionAlreadyApplied) { @@ -83,6 +96,8 @@ function addSortOption(sort: any) { } } } + + checkFilters() } function saveSortOptions() {