Skip to content

Commit

Permalink
Implemented: support to define state for storing order filters(#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
ymaheshwari1 committed Jan 17, 2024
1 parent 5b0b431 commit bb2e984
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/store/modules/orderRouting/OrderRoutingState.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { RouteFilter } from "@/types";

export default interface OrderRoutingState {
groups: Array<any>; // runs
routes: Array<any>;
rules: Array<any>;
currentGroupId: string;
currentRouteId: string;
currentRouteFilters: {
[key: string]: { // conditionTypeEnumId as key
[key: string]: RouteFilter // enumCode/fieldName as key
}
};
}
39 changes: 39 additions & 0 deletions src/store/modules/orderRouting/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { OrderRoutingService } from "@/services/RoutingService"
import { hasError, showToast, sortSequence } from "@/utils"
import * as types from './mutation-types'
import logger from "@/logger"
import { RouteFilter } from "@/types"

const actions: ActionTree<OrderRoutingState, RootState> = {
async fetchOrderRoutingGroups({ commit }) {
Expand Down Expand Up @@ -105,6 +106,44 @@ const actions: ActionTree<OrderRoutingState, RootState> = {
commit(types.ORDER_ROUTING_RULES_UPDATED, routingRules)
},

async fetchRoutingFilters({ commit }, orderRoutingId) {
let routingFilters = [] as any;
// filter groups on the basis of productStoreId
const payload = {
orderRoutingId
}

try {
const resp = await OrderRoutingService.fetchRoutingFilters(payload);

if(!hasError(resp) && resp.data.length) {
routingFilters = resp.data.reduce((filters: any, filter: RouteFilter) => {
if(filters[filter.conditionTypeEnumId]) {
filters[filter.conditionTypeEnumId][filter.fieldName] = filter
} else {
filters[filter.conditionTypeEnumId] = {
[filter.fieldName]: filter
}
}
return filters
}, {})
} else {
throw resp.data
}
} catch(err) {
logger.error(err);
}

const sortEnum = JSON.parse(process.env?.VUE_APP_RULE_ENUMS as string)["SORT"] as any

// As we only need to add support of reordering for sortBy filter
if(routingFilters[sortEnum]?.length) {
routingFilters[sortEnum] = sortSequence(routingFilters[sortEnum])
}

commit(types.ORDER_ROUTING_FILTERS_UPDATED, routingFilters)
},

async setCurrentOrderRoutingId({ commit }, payload) {
commit(types.ORDER_ROUTING_CURRENT_ROUTE_UPDATED, payload)
},
Expand Down
3 changes: 3 additions & 0 deletions src/store/modules/orderRouting/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ const getters: GetterTree<OrderRoutingState, RootState> = {
getCurrentOrderRouting(state) {
const orderRouting = state.routes?.find((route: Route) => route.orderRoutingId === state.currentRouteId)
return orderRouting ? orderRouting : {}
},
getCurrentRouteFilters(state) {
return state.currentRouteFilters
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/store/modules/orderRouting/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const orderRoutingModule: Module<OrderRoutingState, RootState> = {
routes: [],
rules: [],
currentGroupId: '', // choosing only to save id and not whole object, as when updating the state we don't need to care updating the state on two different places
currentRouteId: ''
currentRouteId: '',
currentRouteFilters: {}
},
getters,
actions,
Expand Down
3 changes: 2 additions & 1 deletion src/store/modules/orderRouting/mutation-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export const ORDER_ROUTING_GROUPS_UPDATED = SN_ORDER_ROUTING + "/GROUPS_UPDATED"
export const ORDER_ROUTINGS_UPDATED = SN_ORDER_ROUTING + "/ROUTES_UPDATED"
export const ORDER_ROUTING_RULES_UPDATED = SN_ORDER_ROUTING + "/RULE_UPDATED"
export const ORDER_ROUTING_CURRENT_GROUP_UPDATED = SN_ORDER_ROUTING + "/CURRENT_GROUP_UPDATED"
export const ORDER_ROUTING_CURRENT_ROUTE_UPDATED = SN_ORDER_ROUTING + "/CURRENT_ROUTE_UPDATED"
export const ORDER_ROUTING_CURRENT_ROUTE_UPDATED = SN_ORDER_ROUTING + "/CURRENT_ROUTE_UPDATED"
export const ORDER_ROUTING_FILTERS_UPDATED = SN_ORDER_ROUTING + "/FILTERS_UPDATED"
3 changes: 3 additions & 0 deletions src/store/modules/orderRouting/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ const mutations: MutationTree<OrderRoutingState> = {
},
[types.ORDER_ROUTING_CURRENT_ROUTE_UPDATED](state, routeId) {
state.currentRouteId = routeId
},
[types.ORDER_ROUTING_FILTERS_UPDATED](state, payload) {
state.currentRouteFilters = payload
}
}
export default mutations;

0 comments on commit bb2e984

Please sign in to comment.