Skip to content

Commit

Permalink
Merge pull request #34 from ymaheshwari1/feat/route
Browse files Browse the repository at this point in the history
Fixed: case that on routing page refresh the routing information is not available
  • Loading branch information
ymaheshwari1 authored Jan 20, 2024
2 parents 4a23855 + b7bd5e7 commit 3355230
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 20 deletions.
9 changes: 8 additions & 1 deletion src/services/RoutingService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import api from "@/api"
import logger from "@/logger";
import store from "@/store";
import { hasError, showToast } from "@/utils";

const fetchRoutingGroups = async (payload: any): Promise<any> => {
Expand All @@ -11,6 +10,13 @@ const fetchRoutingGroups = async (payload: any): Promise<any> => {
});
}

const fetchRoutingGroup = async (routingGroupId: string): Promise<any> => {
return api({
url: `groups/${routingGroupId}`,
method: "GET"
});
}

const createRoutingGroup = async (payload: any): Promise<any> => {
return api({
url: "groups",
Expand Down Expand Up @@ -109,6 +115,7 @@ export const OrderRoutingService = {
createRoutingRule,
fetchOrderRoutings,
fetchRoutingFilters,
fetchRoutingGroup,
fetchRoutingGroups,
fetchRoutingRules,
fetchRuleActions,
Expand Down
4 changes: 2 additions & 2 deletions src/store/modules/orderRouting/OrderRoutingState.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { RouteFilter } from "@/types";
import { Group, RouteFilter } from "@/types";

export default interface OrderRoutingState {
groups: Array<any>; // runs
routes: Array<any>;
rules: Array<any>;
currentGroupId: string;
currentGroup: any;
currentRouteId: string;
currentRouteFilters: {
[key: string]: { // conditionTypeEnumId as key
Expand Down
26 changes: 25 additions & 1 deletion src/store/modules/orderRouting/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,31 @@ const actions: ActionTree<OrderRoutingState, RootState> = {
commit(types.ORDER_ROUTING_GROUPS_UPDATED, routingGroups)
},

async setCurrentRoutingGroupId({ commit }, payload) {
async fetchCurrentRoutingGroup({ dispatch, state }, routingGroupId) {
const current = state.currentGroup
if(current.routingGroupId) {
dispatch("setCurrentRoutingGroup", current)
return;
}

let currentGroup = {}

try {
const resp = await OrderRoutingService.fetchRoutingGroup(routingGroupId);

if(!hasError(resp) && resp.data) {
currentGroup = resp.data
} else {
throw resp.data
}
} catch(err) {
logger.error(err);
}

dispatch("setCurrentRoutingGroup", currentGroup)
},

async setCurrentRoutingGroup({ commit }, payload) {
commit(types.ORDER_ROUTING_CURRENT_GROUP_UPDATED, payload)
},

Expand Down
3 changes: 1 addition & 2 deletions src/store/modules/orderRouting/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ const getters: GetterTree<OrderRoutingState, RootState> = {
return state.rules
},
getCurrentRoutingGroup(state) {
const currentRoutingGroup = state.groups?.find((group: Group) => group.routingGroupId === state.currentGroupId)
return currentRoutingGroup ? currentRoutingGroup : {}
return JSON.parse(JSON.stringify(state.currentGroup))
},
getCurrentOrderRouting(state) {
const orderRouting = state.routes?.find((route: Route) => route.orderRoutingId === state.currentRouteId)
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 @@ -4,14 +4,15 @@ import mutations from "./mutations"
import { Module } from "vuex"
import OrderRoutingState from "./OrderRoutingState"
import RootState from "@/store/RootState"
import { Route } from "@/types"

Check warning on line 7 in src/store/modules/orderRouting/index.ts

View workflow job for this annotation

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

'Route' is defined but never used

Check warning on line 7 in src/store/modules/orderRouting/index.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / build_and_deploy

'Route' is defined but never used

Check warning on line 7 in src/store/modules/orderRouting/index.ts

View workflow job for this annotation

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

'Route' is defined but never used

const orderRoutingModule: Module<OrderRoutingState, RootState> = {
namespaced: true,
state: {
groups: [],
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
currentGroup: {},
currentRouteId: '',
currentRouteFilters: {},
ruleConditions: {},
Expand Down
4 changes: 2 additions & 2 deletions src/store/modules/orderRouting/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const mutations: MutationTree<OrderRoutingState> = {
[types.ORDER_ROUTING_RULES_UPDATED](state, payload) {
state.rules = payload
},
[types.ORDER_ROUTING_CURRENT_GROUP_UPDATED](state, groupId) {
state.currentGroupId = groupId
[types.ORDER_ROUTING_CURRENT_GROUP_UPDATED](state, payload) {
state.currentGroup = payload
},
[types.ORDER_ROUTING_CURRENT_ROUTE_UPDATED](state, routeId) {
state.currentRouteId = routeId
Expand Down
9 changes: 2 additions & 7 deletions src/views/BrokeringRoute.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ import { IonBackButton, IonBadge, IonButtons, IonButton, IonCard, IonCardHeader,
import { addCircleOutline, archiveOutline, reorderTwoOutline, saveOutline, timeOutline, timerOutline } from "ionicons/icons"
import { useRouter } from "vue-router";
import { useStore } from "vuex";
import { computed, defineProps, ref } from "vue";
import { computed, defineProps, onMounted, ref } from "vue";

Check warning on line 108 in src/views/BrokeringRoute.vue

View workflow job for this annotation

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

'onMounted' is defined but never used

Check warning on line 108 in src/views/BrokeringRoute.vue

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / build_and_deploy

'onMounted' is defined but never used

Check warning on line 108 in src/views/BrokeringRoute.vue

View workflow job for this annotation

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

'onMounted' is defined but never used
import { Group, Route } from "@/types";
import ArchivedRoutingModal from "@/components/ArchivedRoutingModal.vue"
import emitter from "@/event-bus";
Expand All @@ -130,15 +130,10 @@ const currentRoutingGroup = computed((): Group => store.getters["orderRouting/ge
const orderRoutings = computed(() => store.getters["orderRouting/getOrderRoutings"])
onIonViewWillEnter(async () => {
await store.dispatch("orderRouting/fetchOrderRoutings", props.routingGroupId)
await Promise.all([store.dispatch("orderRouting/fetchOrderRoutings", props.routingGroupId), store.dispatch("orderRouting/fetchCurrentRoutingGroup", props.routingGroupId)])
initializeOrderRoutings();
// On refresh, the groups list is removed thus resulting is not fetching the current group information
if(!currentRoutingGroup.value.routingGroupId) {
await store.dispatch("orderRouting/fetchOrderRoutingGroups")
}
description.value = currentRoutingGroup.value.description ? currentRoutingGroup.value.description : "No description available"
emitter.on("initializeOrderRoutings", initializeOrderRoutings)
})
Expand Down
9 changes: 5 additions & 4 deletions src/views/BrokeringRuns.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<ion-content>
<main v-if="groups.length">
<section>
<ion-card v-for="group in groups" :key="group.routingGroupId" @click="redirect(group.routingGroupId)">
<ion-card v-for="group in groups" :key="group.routingGroupId" @click="redirect(group)">
<ion-card-header>
<ion-card-title>
{{ group.groupName }}
Expand Down Expand Up @@ -46,6 +46,7 @@
</template>

<script setup lang="ts">
import { Group } from "@/types";
import { IonButton, IonButtons, IonCard, IonCardHeader, IonCardTitle, IonContent, IonHeader, IonIcon, IonItem, IonLabel, IonPage, IonTitle, IonToolbar, alertController, onIonViewWillEnter } from "@ionic/vue";
import { addOutline } from "ionicons/icons"
import { computed } from "vue";
Expand Down Expand Up @@ -85,9 +86,9 @@ async function addNewRun() {
return newRunAlert.present();
}
async function redirect(routingGroupId: string) {
await store.dispatch('orderRouting/setCurrentRoutingGroupId', routingGroupId)
router.push(`brokering/${routingGroupId}/routes`)
async function redirect(group: Group) {
await store.dispatch('orderRouting/setCurrentRoutingGroup', group)
router.push(`brokering/${group.routingGroupId}/routes`)
}
</script>
Expand Down

0 comments on commit 3355230

Please sign in to comment.