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

Implemented: support to make the runs page dynamic(#17) #19

Merged
merged 11 commits into from
Jan 16, 2024
Merged
22 changes: 22 additions & 0 deletions src/services/RoutingService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import api from "@/api"

const fetchRoutingGroups = async (payload: any): Promise<any> => {
return api({
url: "groups",
method: "GET",
query: payload
});
}

const createRoutingGroup = async (payload: any): Promise<any> => {
return api({
url: "groups",
method: "POST",
data: payload
})
}

export const OrderRoutingService = {
createRoutingGroup,
fetchRoutingGroups
}
3 changes: 3 additions & 0 deletions src/store/RootState.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import UtilState from "./modules/util/UtilState";

export default interface RootState {
user: any;
util: UtilState;
}
8 changes: 6 additions & 2 deletions src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import actions from "./actions"
import RootState from "./RootState"
import createPersistedState from "vuex-persistedstate";
import userModule from "./modules/user";
import utilModule from "./modules/util"
import orderRoutingModule from "./modules/orderRouting"

// TODO check how to register it from the components only
// Handle same module registering multiple time on page refresh
Expand All @@ -13,7 +15,7 @@ import userModule from "./modules/user";
const state: any = {}

const persistState = createPersistedState({
paths: ["user"],
paths: ["user", "util"],
fetchBeforeUse: true
})

Expand All @@ -25,7 +27,9 @@ const store = createStore<RootState>({
getters,
plugins: [ persistState ],
modules: {
"user": userModule
"user": userModule,
"util": utilModule,
"orderRouting": orderRoutingModule
},
})

Expand Down
7 changes: 7 additions & 0 deletions src/store/modules/orderRouting/OrderRoutingState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default interface OrderRoutingState {
groups: Array<any>; // runs
routes: Array<any>;
rule: Array<any>;
currentGroupId: string;
currentRouteId: string;
}
52 changes: 52 additions & 0 deletions src/store/modules/orderRouting/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { ActionTree } from "vuex"
import RootState from "@/store/RootState"
import OrderRoutingState from "./OrderRoutingState"
import { OrderRoutingService } from "@/services/RoutingService"
import { hasError, showToast, sortSequence } from "@/utils"
import * as types from './mutation-types'

const actions: ActionTree<OrderRoutingState, RootState> = {
async fetchOrderRoutingGroups({ commit }) {
let routingGroups = [] as any;
// filter groups on the basis of productStoreId
const payload = {}

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

if(!hasError(resp) && resp.data.length) {
routingGroups = resp.data
} else {
throw resp.data
}
} catch(err) {
console.log(err);

Check warning on line 23 in src/store/modules/orderRouting/actions.ts

View workflow job for this annotation

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

Unexpected console statement

Check warning on line 23 in src/store/modules/orderRouting/actions.ts

View workflow job for this annotation

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

Unexpected console statement
}

if(routingGroups.length) {
routingGroups = sortSequence(routingGroups)
}

commit(types.ORDER_ROUTING_GROUPS_UPDATED, routingGroups)
},

async createRoutingGroup({ dispatch }, groupName) {
const payload = {
groupName,
productStoreId: "STORE"
}
try {
const resp = await OrderRoutingService.createRoutingGroup(payload)

if(!hasError(resp)) {
showToast('Brokering run created')
dispatch("fetchOrderRoutingGroups")
}
} catch(err) {
showToast("Failed to create brokering run")
console.log('err', err)

Check warning on line 47 in src/store/modules/orderRouting/actions.ts

View workflow job for this annotation

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

Unexpected console statement

Check warning on line 47 in src/store/modules/orderRouting/actions.ts

View workflow job for this annotation

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

Unexpected console statement
}
}
}

export default actions;
11 changes: 11 additions & 0 deletions src/store/modules/orderRouting/getters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { GetterTree } from "vuex"
import OrderRoutingState from "./OrderRoutingState"
import RootState from "@/store/RootState"

const getters: GetterTree<OrderRoutingState, RootState> = {
getRoutingGroups(state) {
return state.groups
}
}

export default getters;
22 changes: 22 additions & 0 deletions src/store/modules/orderRouting/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import actions from "./actions"
import getters from "./getters"
import mutations from "./mutations"
import { Module } from "vuex"
import OrderRoutingState from "./OrderRoutingState"
import RootState from "@/store/RootState"

const orderRoutingModule: Module<OrderRoutingState, RootState> = {
namespaced: true,
state: {
groups: [],
routes: [],
rule: [],
currentGroupId: '',
currentRouteId: ''
},
getters,
actions,
mutations,
}

export default orderRoutingModule;
6 changes: 6 additions & 0 deletions src/store/modules/orderRouting/mutation-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const SN_ORDER_ROUTING = "orderRouting"
export const ORDER_ROUTING_GROUPS_UPDATED = SN_ORDER_ROUTING + "/GROUPS_UPDATED"
export const ORDER_ROUTING_ROUTES_UPDATED = SN_ORDER_ROUTING + "/ROUTES_UPDATED"
export const ORDER_ROUTING_RULE_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"
22 changes: 22 additions & 0 deletions src/store/modules/orderRouting/mutations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { MutationTree } from "vuex"
import OrderRoutingState from "./OrderRoutingState"
import * as types from "./mutation-types"

const mutations: MutationTree<OrderRoutingState> = {
[types.ORDER_ROUTING_GROUPS_UPDATED](state, payload) {
state.groups = payload
},
[types.ORDER_ROUTING_ROUTES_UPDATED](state, payload) {
state.routes = payload
},
[types.ORDER_ROUTING_RULE_UPDATED](state, payload) {
state.rule = payload
},
[types.ORDER_ROUTING_CURRENT_GROUP_UPDATED](state, groupId) {
state.currentGroupId = groupId
},
[types.ORDER_ROUTING_CURRENT_ROUTE_UPDATED](state, routeId) {
state.currentRouteId = routeId
}
}
export default mutations;
5 changes: 5 additions & 0 deletions src/store/modules/util/UtilState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Enumeration } from "@/types";

export default interface UtilState {
enums: Array<Enumeration>
}
7 changes: 7 additions & 0 deletions src/store/modules/util/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { ActionTree } from "vuex"
import RootState from "@/store/RootState"
import UtilState from "./UtilState"

const actions: ActionTree<UtilState, RootState> = {}

export default actions;
7 changes: 7 additions & 0 deletions src/store/modules/util/getters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { GetterTree } from "vuex"
import UtilState from "./UtilState"
import RootState from "@/store/RootState"

const getters: GetterTree<UtilState, RootState> = {}

export default getters;
18 changes: 18 additions & 0 deletions src/store/modules/util/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import actions from "./actions"
import getters from "./getters"
import mutations from "./mutations"
import { Module } from "vuex"
import UtilState from "./UtilState"
import RootState from "@/store/RootState"

const utilModule: Module<UtilState, RootState> = {
namespaced: true,
state: {
enums: [],
},
getters,
actions,
mutations,
}

export default utilModule;
2 changes: 2 additions & 0 deletions src/store/modules/util/mutation-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const SN_UTIL = "util"
export const UTIL_ENUMS_UPDATED = SN_UTIL + "/ENUMS_UPDATED"
10 changes: 10 additions & 0 deletions src/store/modules/util/mutations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { MutationTree } from "vuex"
import UtilState from "./UtilState"
import * as types from "./mutation-types"

const mutations: MutationTree<UtilState> = {
[types.UTIL_ENUMS_UPDATED](state, payload) {
state.enums = payload
}
}
export default mutations;
52 changes: 52 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
type Enumeration = {
enumId: string,
enumTypeId: string,
enumCode: string,
sequenceId: string,
description: string,
enumName: string,
sequenceNum: number
}

type Group = {
routingGroupId: string,
productStoreId: string,
groupName: string,
sequenceNum: number,
description: string,
createdByUser: string,
createdDate: string,
lastUpdatedStamp: string,
}

type Route = {
orderRoutingId: string,
routingGroupId: string,
statusId: string,
routingName: string,
sequenceNum: number,
description: string,
createdByUser: string,
createdDate: string,
lastUpdatedStamp: string
}

type Rule = {
routingRuleId: string,
orderRoutingId: string,
ruleName: string,
statusId: string,
sequenceNum: number,
assignmentEnumId: string,
fulfillEntireShipGroup: string,
createdDate: string,
createdByUser: string,
lastUpdatedStamp: string
}

export {
Enumeration,
Group,
Route,
Rule
}
7 changes: 6 additions & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import saveAs from "file-saver";
import { toastController } from "@ionic/vue";
import Papa from "papaparse"
import { Group, Route, Rule } from "@/types";

// TODO Use separate files for specific utilities

Expand Down Expand Up @@ -117,4 +118,8 @@ const jsonToCsv = (file: any, options: JsonToCsvOption = {}) => {
return blob;
}

export { showToast, hasError , parseCsv , jsonToCsv, JsonToCsvOption }
const sortSequence = (sequence: Array<Group | Route | Rule>) => {
return sequence.sort((a, b) => a.sequenceNum - b.sequenceNum)
}

export { showToast, hasError , parseCsv , jsonToCsv, JsonToCsvOption, sortSequence }
Loading
Loading