-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Implemented: support to unArchive archived rules (#386)
- Loading branch information
Showing
14 changed files
with
185 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<template> | ||
<ion-accordion-group :value="isReorderActive"> | ||
<ion-accordion value="false"> | ||
<div slot="header" @click="$event.stopImmediatePropagation()"></div> | ||
|
||
<ion-card slot="content"> | ||
<ion-item button lines="full" @click="openArchivedRuleModal()"> | ||
<ion-label>{{ translate("Archived") }}</ion-label> | ||
<ion-badge slot="end" color="medium">{{ archivedRules.length }} {{ translate(archivedRules.length === 1 ? "rule" : "rules") }}</ion-badge> | ||
</ion-item> | ||
</ion-card> | ||
</ion-accordion> | ||
</ion-accordion-group> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { IonAccordion, IonAccordionGroup, IonCard, IonBadge, IonItem, IonLabel, modalController } from '@ionic/vue'; | ||
import ArchivedRuleModal from "@/components/ArchivedRuleModal.vue"; | ||
import { computed } from 'vue'; | ||
import { useStore } from 'vuex'; | ||
import { translate } from '@hotwax/dxp-components'; | ||
import { RuleService } from '@/services/RuleService'; | ||
import { showToast } from '@/utils'; | ||
import emitter from '@/event-bus'; | ||
const store = useStore(); | ||
const archivedRules = computed(() => store.getters["rule/getArchivedRules"]); | ||
const isReorderActive = computed(() => store.getters["rule/isReorderActive"]); | ||
const ruleGroup = computed(() => store.getters["rule/getRuleGroup"]); | ||
async function openArchivedRuleModal() { | ||
const archivedRuleModal = await modalController.create({ | ||
component: ArchivedRuleModal, | ||
componentProps: { | ||
archivedRules: archivedRules.value | ||
} | ||
}) | ||
archivedRuleModal.onDidDismiss().then(async (result) => { | ||
if(result?.data?.rulesToUnarchive?.length) { | ||
emitter.emit("presentLoader") | ||
const rulesToUnarchive = result.data.rulesToUnarchive | ||
const responses = await Promise.allSettled(rulesToUnarchive.map(async (rule: any) => { | ||
rule.statusId = "ATP_RULE_ACTIVE" | ||
await RuleService.updateRule(rule, rule.ruleId) | ||
})) | ||
const hasFailedResponses = responses.some((response: any) => response.status !== "fulfilled") | ||
if(hasFailedResponses) { | ||
showToast(translate("Failed to unarchive some rules.")) | ||
} | ||
await store.dispatch("rule/fetchRules", { ruleGroupId: ruleGroup.value.ruleGroupId }) | ||
emitter.emit("dismissLoader") | ||
} | ||
}) | ||
archivedRuleModal.present(); | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<template> | ||
<ion-header> | ||
<ion-toolbar> | ||
<ion-buttons slot="start"> | ||
<ion-button @click="closeModal"> | ||
<ion-icon slot="icon-only" :icon="closeOutline" /> | ||
</ion-button> | ||
</ion-buttons> | ||
<ion-title>{{ translate("Archived Rules") }}</ion-title> | ||
</ion-toolbar> | ||
</ion-header> | ||
|
||
<ion-content> | ||
<ion-list> | ||
<ion-item v-for="rule in rules" :key="rule.ruleId"> | ||
<ion-label>{{ rule.ruleName }}</ion-label> | ||
<ion-note slot="end" v-if="rule.isArchived">{{ translate("Unarchived") }}</ion-note> | ||
<ion-button slot="end" v-else fill="outline" color="medium" @click="unarchiveRule(rule)">{{ translate("Unarchive") }}</ion-button> | ||
</ion-item> | ||
</ion-list> | ||
<p class="empty-state" v-if="!rules.length"> | ||
{{ translate("No archived rules") }} | ||
</p> | ||
</ion-content> | ||
|
||
<ion-fab vertical="bottom" horizontal="end" slot="fixed"> | ||
<ion-fab-button :disabled="!rulesToUnarchive?.length" @click="save()"> | ||
<ion-icon :icon="saveOutline" /> | ||
</ion-fab-button> | ||
</ion-fab> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { IonButton, IonButtons, IonContent, IonFab, IonFabButton, IonHeader, IonIcon, IonItem, IonLabel, IonList, IonNote, IonTitle, IonToolbar, modalController } from '@ionic/vue'; | ||
import { translate } from '@hotwax/dxp-components'; | ||
import { defineProps, onMounted, ref } from 'vue'; | ||
import { closeOutline, saveOutline } from "ionicons/icons"; | ||
const props = defineProps(["archivedRules"]) | ||
const rulesToUnarchive = ref([]) as any; | ||
const rules = ref([]) as any; | ||
onMounted(() => { | ||
rules.value = JSON.parse(JSON.stringify(props.archivedRules)) | ||
}) | ||
function closeModal() { | ||
modalController.dismiss(); | ||
} | ||
function unarchiveRule(currentRule: any) { | ||
rulesToUnarchive.value.push(currentRule); | ||
currentRule.isArchived = true; | ||
} | ||
function save() { | ||
modalController.dismiss({ dismissed: true, rulesToUnarchive: rulesToUnarchive.value }); | ||
} | ||
</script> | ||
|
||
<style scoped> | ||
ion-content { | ||
--padding-bottom: 80px; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ export default interface RuleState { | |
rules: any; | ||
ruleGroup: any; | ||
isReorderActive: boolean; | ||
archivedRules: any; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.