Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved: Show TO filters if the facet has orders; disable if none.(#673) #861

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 1 addition & 67 deletions src/components/TransferOrderFilters.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ import {
import { defineComponent, computed } from "vue";
import { albumsOutline, banOutline, barChartOutline, calendarNumberOutline, checkmarkDoneOutline, closeOutline, filterOutline, iceCreamOutline, libraryOutline, pulseOutline, settings, shirtOutline, ticketOutline } from "ionicons/icons";
import { mapGetters, useStore } from 'vuex'
import { escapeSolrSpecialChars, prepareOrderQuery } from '@/utils/solrHelper';
import { UtilService } from '@/services/UtilService';
import { hasError } from '@/adapter';
import logger from '@/logger';
import { translate, useUserStore } from '@hotwax/dxp-components';

export default defineComponent({
Expand All @@ -68,24 +64,14 @@ export default defineComponent({
IonTitle,
IonToolbar
},
props: ["queryString"],
data () {
return {
shipmentMethods: [] as Array<any>,
statuses: [] as Array<any>
}
},
props: ["queryString", "shipmentMethods", "statuses"],
computed: {
...mapGetters({
transferOrders: 'transferorder/getTransferOrders',
getStatusDesc: 'util/getStatusDesc',
getShipmentMethodDesc: 'util/getShipmentMethodDesc',
currentEComStore: 'user/getCurrentEComStore',
})
},
async mounted() {
await this.fetchFilters();
},
unmounted() {
this.store.dispatch('transferorder/clearTransferOrderFilters');
},
Expand Down Expand Up @@ -116,58 +102,6 @@ export default defineComponent({
transferOrdersQuery.viewIndex = 0;
await this.store.dispatch('transferorder/updateTransferOrderQuery', { ...transferOrdersQuery })
},
async fetchFilters() {
let resp: any;
const payload = prepareOrderQuery({
docType: "ORDER",
queryFields: 'orderId',
viewSize: '0', // passed viewSize as 0 to not fetch any data
filters: {
'-orderStatusId': { value: 'ORDER_CREATED' },
orderTypeId: { value: 'TRANSFER_ORDER' },
facilityId: { value: escapeSolrSpecialChars(this.currentFacility?.facilityId) },
productStoreId: { value: this.currentEComStore.productStoreId }
},
facet: {
"shipmentMethodTypeIdFacet":{
"excludeTags":"shipmentMethodTypeIdFilter",
"field":"shipmentMethodTypeId",
"mincount":1,
"limit":-1,
"sort":"index",
"type":"terms",
"facet": {
"ordersCount": "unique(orderId)"
}
},
"orderStatusIdFacet":{
"excludeTags":"orderStatusIdFilter",
"field":"orderStatusId",
"mincount":1,
"limit":-1,
"sort":"index",
"type":"terms",
"facet": {
"ordersCount": "unique(orderId)"
}
}
}
})

try {
resp = await UtilService.fetchTransferOrderFacets(payload);
if (resp.status == 200 && !hasError(resp) && resp.data.facets?.count > 0) {
this.shipmentMethods = resp.data.facets.shipmentMethodTypeIdFacet.buckets
this.statuses = resp.data.facets.orderStatusIdFacet.buckets
this.store.dispatch('util/fetchShipmentMethodTypeDesc', this.shipmentMethods.map((shipmentMethod: any) => shipmentMethod.val))
this.store.dispatch('util/fetchStatusDesc', this.statuses.map((status: any) => status.val))
} else {
throw resp.data;
}
} catch(err) {
logger.error('Failed to fetch transfer order filters.', err)
}
},
},
setup() {
const store = useStore();
Expand Down
72 changes: 68 additions & 4 deletions src/views/TransferOrders.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<template>
<ion-page>
<TransferOrderFilters menu-id="transfer-order-filters" content-id="transfer-order-filters" :queryString="transferOrders.query.queryString" />
<TransferOrderFilters menu-id="transfer-order-filters" content-id="transfer-order-filters" :queryString="transferOrders.query.queryString" :shipmentMethods="shipmentMethods" :statuses="statuses"/>

<ion-header :translucent="true">
<ion-toolbar>
<ion-menu-button menu="start" slot="start" />
<ion-title v-if="!transferOrders.total">{{ transferOrders.total }} {{ translate('orders') }}</ion-title>
<ion-title v-else>{{ transferOrders.list.length }} {{ translate('of') }} {{ transferOrders.total }} {{ translate('orders') }}</ion-title>
<ion-buttons slot="end">
<ion-menu-button menu="transfer-order-filters" :disabled="!transferOrders.total">
<ion-menu-button menu="transfer-order-filters" :disabled="!transferOrderCount">
<ion-icon :icon="optionsOutline" />
</ion-menu-button>
</ion-buttons>
Expand Down Expand Up @@ -78,6 +78,10 @@ import { mapGetters, useStore } from 'vuex';
import { useRouter } from 'vue-router';
import { translate, useUserStore } from '@hotwax/dxp-components';
import { Actions } from '@/authorization'
import { escapeSolrSpecialChars, prepareOrderQuery } from '@/utils/solrHelper';
import { UtilService } from '@/services/UtilService';
import { hasError } from '@/adapter';
import logger from '@/logger';
import TransferOrderFilters from '@/components/TransferOrderFilters.vue'

export default defineComponent({
Expand Down Expand Up @@ -111,14 +115,19 @@ export default defineComponent({
data () {
return {
shipmentMethods: [] as Array<any>,
statuses: [] as Array<any>,
searchedQuery: '',
isScrollingEnabled: false,
hasCompletedTransferOrders: true
hasCompletedTransferOrders: true,
transferOrderCount: 0
}
},
async ionViewWillEnter() {
this.isScrollingEnabled = false;
await this.initialiseTransferOrderQuery();
await this.fetchFilters();
if(this.transferOrderCount) {
await this.initialiseTransferOrderQuery();
}
},
methods: {
getErrorMessage() {
Expand Down Expand Up @@ -169,6 +178,61 @@ export default defineComponent({
await this.store.dispatch('transferorder/updateTransferOrderQuery', { ...transferOrdersQuery })
this.searchedQuery = queryString;
},
async fetchFilters() {
let resp: any;
const payload = prepareOrderQuery({
docType: "ORDER",
queryFields: 'orderId',
viewSize: '0', // passed viewSize as 0 to not fetch any data
filters: {
'-orderStatusId': { value: 'ORDER_CREATED' },
orderTypeId: { value: 'TRANSFER_ORDER' },
facilityId: { value: escapeSolrSpecialChars(this.currentFacility?.facilityId) },
productStoreId: { value: this.currentEComStore.productStoreId }
},
facet: {
"shipmentMethodTypeIdFacet":{
"excludeTags":"shipmentMethodTypeIdFilter",
"field":"shipmentMethodTypeId",
"mincount":1,
"limit":-1,
"sort":"index",
"type":"terms",
"facet": {
"ordersCount": "unique(orderId)"
}
},
"orderStatusIdFacet":{
"excludeTags":"orderStatusIdFilter",
"field":"orderStatusId",
"mincount":1,
"limit":-1,
"sort":"index",
"type":"terms",
"facet": {
"ordersCount": "unique(orderId)"
}
}
}
})

try {
resp = await UtilService.fetchTransferOrderFacets(payload);
if(resp.status == 200 && !hasError(resp)) {
this.transferOrderCount = resp.data.facets?.count
if(this.transferOrderCount) {
this.shipmentMethods = resp.data.facets.shipmentMethodTypeIdFacet.buckets;
this.statuses = resp.data.facets.orderStatusIdFacet.buckets;
this.store.dispatch('util/fetchShipmentMethodTypeDesc', this.shipmentMethods.map((shipmentMethod: any) => shipmentMethod.val));
this.store.dispatch('util/fetchStatusDesc', this.statuses.map((status: any) => status.val));
}
} else {
throw resp.data;
}
} catch(err) {
logger.error('Failed to fetch transfer order filters.', err)
}
},
async initialiseTransferOrderQuery() {
const transferOrdersQuery = JSON.parse(JSON.stringify(this.transferOrders.query))
transferOrdersQuery.viewIndex = 0 // If the size changes, list index should be reintialised
Expand Down
Loading