Skip to content

Commit

Permalink
Merge pull request #42 from ymaheshwari1/feat/run
Browse files Browse the repository at this point in the history
Improved: logic to add some checks when creating new run, fixed issue of routing update on multiple times without refresh, added support to update empty description
  • Loading branch information
ymaheshwari1 authored Jan 26, 2024
2 parents bd2e4d1 + 388e0b0 commit 67d0cdb
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/components/ArchivedRoutingModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ let routings = ref(props.archivedRoutings) as any
let routingsToUpdate = ref([]) as any
function closeModal() {
modalController.dismiss({ dismissed: true, routings: routingsToUpdate.value.concat(routings.value) });
modalController.dismiss({ dismissed: true, routings: routingsToUpdate.value.length ? routingsToUpdate.value.concat(routings.value) : [] });
}
async function updateOrderRouting(routing: Route, fieldToUpdate: string, value: string) {
Expand Down
18 changes: 13 additions & 5 deletions src/store/modules/orderRouting/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const actions: ActionTree<OrderRoutingState, RootState> = {
logger.error(err);
}

if(currentGroup.routings.length) {
if(currentGroup.routings?.length) {
currentGroup.routings = sortSequence(currentGroup.routings)
}

Expand All @@ -83,10 +83,18 @@ const actions: ActionTree<OrderRoutingState, RootState> = {

if(!hasError(resp) && resp?.data.orderRoutingId) {
orderRoutingId = resp.data.orderRoutingId
currentGroup["routings"].push({
...payload,
orderRoutingId
})
// Added check, as when there is no routing we need to create the key as well, but if routings already exist then we just need to push the value
if(currentGroup["routings"]) {
currentGroup["routings"].push({
...payload,
orderRoutingId
})
} else {
currentGroup["routings"] = [{
...payload,
orderRoutingId
}]
}
showToast('New routing created')
}

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

// TODO Use separate files for specific utilities

Expand Down Expand Up @@ -124,4 +125,8 @@ const sortSequence = (sequence: Array<Group | Route | Rule>) => {
return sequence.sort((a, b) => a.sequenceNum - b.sequenceNum)
}

export { showToast, hasError , parseCsv , jsonToCsv, JsonToCsvOption, sortSequence }
const getTime = (time: any) => {
return time ? DateTime.fromMillis(time).toLocaleString(DateTime.DATETIME_MED) : '-';
}

export { getTime, showToast, hasError , parseCsv , jsonToCsv, JsonToCsvOption, sortSequence }
22 changes: 10 additions & 12 deletions src/views/BrokeringRoute.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ import ArchivedRoutingModal from "@/components/ArchivedRoutingModal.vue"
import { OrderRoutingService } from "@/services/RoutingService";
import logger from "@/logger";
import { DateTime } from "luxon";
import { hasError, showToast, sortSequence } from "@/utils";
import { hasError, getTime, showToast, sortSequence } from "@/utils";
const router = useRouter();
const store = useStore();
Expand All @@ -129,7 +129,7 @@ const props = defineProps({
const routingStatus = JSON.parse(process.env?.VUE_APP_ROUTE_STATUS_ENUMS as string)
const cronExpressions = JSON.parse(process.env?.VUE_APP_CRON_EXPRESSIONS as string)
let routingsForReorder = ref([])
let description = ref('')
let description = ref("")
let isDescUpdating = ref(false)
let hasUnsavedChanges = ref(false)
Expand All @@ -143,10 +143,12 @@ onIonViewWillEnter(async () => {
await store.dispatch("orderRouting/fetchCurrentRoutingGroup", props.routingGroupId)
job.value = currentRoutingGroup.value["schedule"] ? JSON.parse(JSON.stringify(currentRoutingGroup.value))["schedule"] : {}
orderRoutings.value = currentRoutingGroup.value["routings"] ? JSON.parse(JSON.stringify(currentRoutingGroup.value))["routings"] : {}
description.value = currentRoutingGroup.value["description"] ? currentRoutingGroup.value["description"] : "No description available"
orderRoutings.value = currentRoutingGroup.value["routings"] ? JSON.parse(JSON.stringify(currentRoutingGroup.value))["routings"] : []
description.value = currentRoutingGroup.value["description"] ? currentRoutingGroup.value["description"] : ""
initializeOrderRoutings();
if(orderRoutings.value.length) {
initializeOrderRoutings();
}
})
onBeforeRouteLeave(async (to) => {
Expand Down Expand Up @@ -183,10 +185,6 @@ function updateCronExpression(event: CustomEvent) {
job.value.cronExpression = event.detail.value
}
function getTime(time: any) {
return time ? DateTime.fromMillis(time).toLocaleString(DateTime.DATETIME_MED) : '-';
}
function initializeOrderRoutings() {
routingsForReorder.value = JSON.parse(JSON.stringify(getActiveAndDraftOrderRoutings()))
}
Expand Down Expand Up @@ -271,7 +269,7 @@ async function createOrderRoute() {
// update the routing order for reordering and the cloned updated routings again
if(orderRoutingId) {
orderRoutings.value = JSON.parse(JSON.stringify(currentRoutingGroup.value["routings"]))
orderRoutings.value = JSON.parse(JSON.stringify(currentRoutingGroup.value))["routings"]
initializeOrderRoutings();
}
}
Expand All @@ -290,7 +288,7 @@ function getArchivedOrderRoutings() {
async function updateGroupDescription() {
// Do not update description, if the desc is unchanged, and we do not have routingGroupId, and description is left empty
if(description.value && props.routingGroupId && currentRoutingGroup.value.description !== description.value) {
if(props.routingGroupId && currentRoutingGroup.value.description !== description.value) {
const routingGroupId = await updateRoutingGroup({ routingGroupId: props.routingGroupId, productStoreId: currentEComStore.value.productStoreId, description: description.value })
if(routingGroupId) {
await store.dispatch("orderRouting/setCurrentGroup", { ...currentRoutingGroup.value, description: description.value })
Expand Down Expand Up @@ -396,7 +394,7 @@ async function saveRoutingGroup() {
const routingGroupId = await updateRoutingGroup(payload)
if(routingGroupId) {
hasUnsavedChanges.value = false
await store.dispatch("orderRouting/setCurrentGroup", { ...currentRoutingGroup.value, routings: orderRoutings.value })
await store.dispatch("orderRouting/setCurrentGroup", { ...currentRoutingGroup.value, routings: JSON.parse(JSON.stringify(orderRoutings.value)) })
}
}
Expand Down
24 changes: 18 additions & 6 deletions src/views/BrokeringRuns.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
<ion-label slot="end">{{ group.runTime ? group.runTime : "-" }}</ion-label>
</ion-item>
<ion-item>
{{ group.createdDate ? group.createdDate : "-" }}
{{ getTime(group.createdDate) }}
</ion-item>
<ion-item>
{{ group.lastUpdatedStamp ? group.lastUpdatedStamp : "-" }}
<ion-item lines="none">
{{ getTime(group.lastUpdatedStamp) }}
</ion-item>
</ion-card>
</section>
Expand All @@ -47,6 +47,7 @@

<script setup lang="ts">
import { Group } from "@/types";
import { getTime, showToast } from "@/utils";
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 All @@ -69,7 +70,13 @@ async function addNewRun() {
text: "Cancel",
role: "cancel"
}, {
text: "Save"
text: "Save",
handler: (data) => {
if(!data.runName?.trim().length) {
showToast("Please enter a valid name")
return false;
}
}
}],
inputs: [{
name: "runName",
Expand All @@ -78,8 +85,13 @@ async function addNewRun() {
})
newRunAlert.onDidDismiss().then((result: any) => {
if(result.data?.values?.runName) {
store.dispatch('orderRouting/createRoutingGroup', result.data.values.runName)
// considering that if we have role, then its negative action and thus not need to create run
if(result.role) {
return;
}
if(result.data?.values?.runName.trim()) {
store.dispatch('orderRouting/createRoutingGroup', result.data.values.runName.trim())
}
})
Expand Down

0 comments on commit 67d0cdb

Please sign in to comment.