-
Notifications
You must be signed in to change notification settings - Fork 26
refactor DeletedMessageGroups view data handling into a store #2692
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
Open
PhilBastian
wants to merge
3
commits into
message_store_initialisation
Choose a base branch
from
deletedmessagegroups_store
base: message_store_initialisation
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,169 +1,36 @@ | ||
| <script setup lang="ts"> | ||
| import { onMounted, onUnmounted, ref } from "vue"; | ||
| import { useRoute, useRouter } from "vue-router"; | ||
| import { ref, watch } from "vue"; | ||
| import { useRouter } from "vue-router"; | ||
| import { useShowToast } from "../../composables/toast"; | ||
| import createMessageGroupClient from "./messageGroupClient"; | ||
| import { useCookies } from "vue3-cookies"; | ||
| import NoData from "../NoData.vue"; | ||
| import TimeSince from "../TimeSince.vue"; | ||
| import LicenseNotExpired from "../../components/LicenseNotExpired.vue"; | ||
| import ServiceControlAvailable from "../ServiceControlAvailable.vue"; | ||
| import ConfirmDialog from "../ConfirmDialog.vue"; | ||
| import routeLinks from "@/router/routeLinks"; | ||
| import FailureGroupView from "@/resources/FailureGroupView"; | ||
| import { TYPE } from "vue-toastification"; | ||
| import MetadataItem from "@/components/MetadataItem.vue"; | ||
| import ActionButton from "@/components/ActionButton.vue"; | ||
| import { faArrowRotateRight, faEnvelope } from "@fortawesome/free-solid-svg-icons"; | ||
| import { faClock } from "@fortawesome/free-regular-svg-icons"; | ||
| import { useServiceControlStore } from "@/stores/ServiceControlStore"; | ||
| const statusesForRestoreOperation = ["restorestarted", "restoreprogressing", "restorefinalizing", "restorecompleted"] as const; | ||
| type RestoreOperationStatus = (typeof statusesForRestoreOperation)[number]; | ||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| const otherStatuses = ["none", "working"] as const; | ||
| type Status = RestoreOperationStatus | (typeof otherStatuses)[number]; | ||
| interface WorkflowState { | ||
| status: Status; | ||
| total?: number; | ||
| failed?: boolean; | ||
| message?: string; | ||
| } | ||
| interface ExtendedFailureGroupView extends FailureGroupView { | ||
| index: number; | ||
| need_user_acknowledgement?: boolean; | ||
| workflow_state: WorkflowState; | ||
| operation_remaining_count?: number; | ||
| hover2?: boolean; | ||
| hover3?: boolean; | ||
| operation_start_time?: string; | ||
| last_operation_completion_time?: string; | ||
| } | ||
| import { useDeletedMessageGroupsStore, statusesForRestoreOperation, ExtendedFailureGroupView, Status } from "@/stores/DeletedMessageGroupsStore"; | ||
| import { useStoreAutoRefresh } from "@/composables/useAutoRefresh"; | ||
| import { storeToRefs } from "pinia"; | ||
| let pollingFaster = false; | ||
| const archiveGroups = ref<ExtendedFailureGroupView[]>([]); | ||
| const undismissedRestoreGroups = ref<ExtendedFailureGroupView[]>([]); | ||
| const loadingData = ref(true); | ||
| const initialLoadComplete = ref(false); | ||
| const emit = defineEmits<{ | ||
| InitialLoadComplete: []; | ||
| }>(); | ||
| let refreshInterval: number | undefined = undefined; | ||
| const route = useRoute(); | ||
| const { autoRefresh, isRefreshing, updateInterval } = useStoreAutoRefresh("deletedMessageGroups", useDeletedMessageGroupsStore, 5000); | ||
| const { store } = autoRefresh(); | ||
| const { archiveGroups, classifiers, selectedClassifier } = storeToRefs(store); | ||
| const router = useRouter(); | ||
| const showRestoreGroupModal = ref(false); | ||
| const selectedGroup = ref<ExtendedFailureGroupView>(); | ||
| const serviceControlStore = useServiceControlStore(); | ||
| const messageGroupClient = createMessageGroupClient(); | ||
| const groupRestoreSuccessful = ref<boolean | null>(null); | ||
| const selectedClassifier = ref<string | null>(null); | ||
| const classifiers = ref<string[]>([]); | ||
| async function getGroupingClassifiers() { | ||
| const [, data] = await serviceControlStore.fetchTypedFromServiceControl<string[]>("recoverability/classifiers"); | ||
| classifiers.value = data; | ||
| } | ||
| function saveDefaultGroupingClassifier(classifier: string) { | ||
| const cookies = useCookies().cookies; | ||
| cookies.set("archived_groups_classification", classifier); | ||
| } | ||
| async function classifierChanged(classifier: string) { | ||
| saveDefaultGroupingClassifier(classifier); | ||
| store.setGrouping(classifier); | ||
| selectedClassifier.value = classifier; | ||
| archiveGroups.value = []; | ||
| await loadArchivedMessageGroups(classifier); | ||
| } | ||
| async function getArchiveGroups(classifier: string) { | ||
| //get all deleted message groups | ||
| const [, result] = await serviceControlStore.fetchTypedFromServiceControl<FailureGroupView[]>(`errors/groups/${classifier}`); | ||
| if (result.length === 0 && undismissedRestoreGroups.value.length > 0) { | ||
| undismissedRestoreGroups.value.forEach((deletedGroup) => { | ||
| deletedGroup.need_user_acknowledgement = true; | ||
| deletedGroup.workflow_state.status = "restorecompleted"; | ||
| }); | ||
| } | ||
| undismissedRestoreGroups.value.forEach((deletedGroup) => { | ||
| if (!result.find((group) => group.id === deletedGroup.id)) { | ||
| deletedGroup.need_user_acknowledgement = true; | ||
| deletedGroup.workflow_state.status = "restorecompleted"; | ||
| } | ||
| }); | ||
| // need a map in some ui state for controlling animations | ||
| const mappedResults = result | ||
| .filter((group) => !undismissedRestoreGroups.value.find((deletedGroup) => deletedGroup.id === group.id)) | ||
| .map(initializeGroupState) | ||
| .concat(undismissedRestoreGroups.value); | ||
| let maxIndex = archiveGroups.value.reduce((currentMax, currentGroup) => Math.max(currentMax, currentGroup.index), 0); | ||
| mappedResults.forEach((serverGroup) => { | ||
| const previousGroup = archiveGroups.value.find((oldGroup) => oldGroup.id === serverGroup.id); | ||
| if (previousGroup) { | ||
| serverGroup.index = previousGroup.index; | ||
| } else { | ||
| serverGroup.index = ++maxIndex; | ||
| } | ||
| }); | ||
| archiveGroups.value = mappedResults.sort((group1, group2) => { | ||
| return group1.index - group2.index; | ||
| }); | ||
| } | ||
| function initializeGroupState(group: FailureGroupView): ExtendedFailureGroupView { | ||
| return { | ||
| index: 0, | ||
| workflow_state: createWorkflowState("none"), | ||
| ...group, | ||
| }; | ||
| } | ||
| function loadDefaultGroupingClassifier() { | ||
| const cookies = useCookies().cookies; | ||
| const cookieGrouping = cookies.get("archived_groups_classification"); | ||
| if (cookieGrouping) { | ||
| return cookieGrouping; | ||
| } | ||
| return null; | ||
| } | ||
| async function loadArchivedMessageGroups(groupBy: string | null = null) { | ||
| loadingData.value = true; | ||
| if (!initialLoadComplete.value || !groupBy) { | ||
| groupBy = loadDefaultGroupingClassifier(); | ||
| } | ||
| await getArchiveGroups(groupBy ?? (route.query.deletedGroupBy as string)); | ||
| loadingData.value = false; | ||
| initialLoadComplete.value = true; | ||
| emit("InitialLoadComplete"); | ||
| } | ||
| //create workflow state | ||
| function createWorkflowState(optionalStatus?: Status, optionalTotal?: number, optionalFailed?: boolean): WorkflowState { | ||
| if (optionalTotal && optionalTotal <= 1) { | ||
| optionalTotal = optionalTotal * 100; | ||
| } | ||
| return { | ||
| status: optionalStatus ?? "working", | ||
| total: optionalTotal ?? 0, | ||
| failed: optionalFailed ?? false, | ||
| }; | ||
| await store.refresh(); | ||
| } | ||
| //Restore operation | ||
|
|
@@ -176,18 +43,14 @@ function showRestoreGroupDialog(group: ExtendedFailureGroupView) { | |
| async function restoreGroup() { | ||
| const group = selectedGroup.value; | ||
| if (group) { | ||
| // We're starting a restore, poll more frequently | ||
| changeRefreshInterval(1000); | ||
| undismissedRestoreGroups.value.push(group); | ||
| group.workflow_state = { status: "restorestarted", message: "Restore request initiated..." }; | ||
| group.operation_start_time = new Date().toUTCString(); | ||
| const result = await messageGroupClient.restoreGroup(group.id); | ||
| if (messageGroupClient.isError(result)) { | ||
| const { result, errorMessage } = await store.restoreGroup(group); | ||
| if (!result) { | ||
| groupRestoreSuccessful.value = false; | ||
| useShowToast(TYPE.ERROR, "Error", `Failed to restore the group: ${result.message}`); | ||
| useShowToast(TYPE.ERROR, "Error", `Failed to restore the group: ${errorMessage}`); | ||
| } else { | ||
| // We're starting a restore, poll more frequently | ||
| pollingFaster = true; | ||
| updateInterval(1000); | ||
| groupRestoreSuccessful.value = true; | ||
| useShowToast(TYPE.INFO, "Info", "Group restore started..."); | ||
| } | ||
|
|
@@ -211,20 +74,6 @@ function getClassesForRestoreOperation(stepStatus: Status, currentStatus: Status | |
| return getClasses(stepStatus, currentStatus, statusesForRestoreOperation); | ||
| } | ||
| const acknowledgeGroup = function (dismissedGroup: FailureGroupView) { | ||
| undismissedRestoreGroups.value.splice( | ||
| undismissedRestoreGroups.value.findIndex((group) => { | ||
| return group.id === dismissedGroup.id; | ||
| }), | ||
| 1 | ||
| ); | ||
| archiveGroups.value.splice( | ||
| archiveGroups.value.findIndex((group) => group.id === dismissedGroup.id), | ||
| 1 | ||
| ); | ||
| }; | ||
| function isBeingRestored(status: Status) { | ||
| return (statusesForRestoreOperation as readonly Status[]).includes(status); | ||
| } | ||
|
|
@@ -237,44 +86,17 @@ function isRestoreInProgress() { | |
| return archiveGroups.value.some((group) => group.workflow_state.status !== "none" && group.workflow_state.status !== "restorecompleted"); | ||
| } | ||
| function changeRefreshInterval(milliseconds: number) { | ||
| if (refreshInterval) { | ||
| clearInterval(refreshInterval); | ||
| } | ||
| refreshInterval = window.setInterval(() => { | ||
| // If we're currently polling at 5 seconds and there is a restore in progress, then change the polling interval to poll every 1 second | ||
| if (!pollingFaster && isRestoreInProgress()) { | ||
| changeRefreshInterval(1000); | ||
| pollingFaster = true; | ||
| } else if (pollingFaster && !isRestoreInProgress()) { | ||
| // if we're currently polling every 1 second and all restores are done, change polling frequency back to every 5 seconds | ||
| changeRefreshInterval(5000); | ||
| pollingFaster = false; | ||
| } | ||
| loadArchivedMessageGroups(); | ||
| }, milliseconds); | ||
| } | ||
| onUnmounted(() => { | ||
| if (refreshInterval) { | ||
| clearInterval(refreshInterval); | ||
| watch(isRefreshing, () => { | ||
| // If we're currently polling at 5 seconds and there is a restore in progress, then change the polling interval to poll every 1 second | ||
| if (!pollingFaster && isRestoreInProgress()) { | ||
| pollingFaster = true; | ||
| updateInterval(1000); | ||
| } else if (pollingFaster && !isRestoreInProgress()) { | ||
| // if we're currently polling every 1 second and all restores are done, change polling frequency back to every 5 seconds | ||
| pollingFaster = false; | ||
| updateInterval(5000); | ||
| } | ||
| }); | ||
| onMounted(async () => { | ||
| await getGroupingClassifiers(); | ||
| let savedClassifier = loadDefaultGroupingClassifier(); | ||
| if (!savedClassifier) { | ||
| savedClassifier = classifiers.value[0]; | ||
| } | ||
| selectedClassifier.value = savedClassifier; | ||
| await loadArchivedMessageGroups(); | ||
| changeRefreshInterval(5000); | ||
| }); | ||
| </script> | ||
|
|
||
| <template> | ||
|
|
@@ -307,31 +129,23 @@ onMounted(async () => { | |
| <div> | ||
| <div class="row"> | ||
| <div class="col-sm-12"> | ||
| <no-data v-if="archiveGroups.length === 0 && !loadingData" title="message groups" message="There are currently no grouped message failures"></no-data> | ||
| <no-data v-if="archiveGroups.length === 0 && !isRefreshing" title="message groups" message="There are currently no grouped message failures"></no-data> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div class="row"> | ||
| <div class="col-sm-12 no-mobile-side-padding"> | ||
| <div v-if="archiveGroups.length > 0"> | ||
| <div | ||
| :class="`row box box-group wf-${group.workflow_state.status} repeat-modify deleted-message-group`" | ||
| v-for="(group, index) in archiveGroups" | ||
| :key="index" | ||
| :disabled="group.count == 0" | ||
| @mouseenter="group.hover2 = true" | ||
| @mouseleave="group.hover2 = false" | ||
| @click.prevent="navigateToGroup(group.id)" | ||
| > | ||
| <div :class="`row box box-group wf-${group.workflow_state.status} repeat-modify deleted-message-group`" v-for="(group, index) in archiveGroups" :key="index" :disabled="group.count == 0" @click.prevent="navigateToGroup(group.id)"> | ||
| <div class="col-sm-12 no-mobile-side-padding"> | ||
| <div class="row"> | ||
| <div class="col-sm-12 no-side-padding"> | ||
| <div class="row box-header"> | ||
| <div class="col-sm-12 no-side-padding"> | ||
| <p class="lead break" v-bind:class="{ 'msg-type-hover': group.hover2, 'msg-type-hover-off': group.hover3 }">{{ group.title }}</p> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these classes are not defined anywhere. Whatever functionality they previously implemented has likely been missing since the switch from AngularJS |
||
| <p class="lead break">{{ group.title }}</p> | ||
| <p class="metadata" v-if="!isBeingRestored(group.workflow_state.status)"> | ||
| <MetadataItem :icon="faEnvelope"> | ||
| {{ group.count }} message<span v-if="group.count > 1">s</span> | ||
| <span>{{ group.count }} message<span v-if="group.count > 1">s</span></span> | ||
| <span v-if="group.operation_remaining_count"> (currently restoring {{ group.operation_remaining_count }} </span> | ||
| </MetadataItem> | ||
|
|
||
|
|
@@ -357,8 +171,6 @@ onMounted(async () => { | |
| size="sm" | ||
| :icon="faArrowRotateRight" | ||
| :disabled="group.count === 0 || isBeingRestored(group.workflow_state.status)" | ||
| @mouseenter="group.hover3 = true" | ||
| @mouseleave="group.hover3 = false" | ||
| v-if="archiveGroups.length > 0" | ||
| @click.stop="showRestoreGroupDialog(group)" | ||
| > | ||
|
|
@@ -378,7 +190,7 @@ onMounted(async () => { | |
| </li> | ||
| <li v-if="group.workflow_state.status === 'restorecompleted'"> | ||
| <div class="retry-completed bulk-retry-progress-status">Restore request completed</div> | ||
| <button type="button" class="btn btn-default btn-primary btn-xs btn-retry-dismiss" v-if="group.need_user_acknowledgement == true" @click.stop="acknowledgeGroup(group)">Dismiss</button> | ||
| <button type="button" class="btn btn-default btn-primary btn-xs btn-retry-dismiss" v-if="group.need_user_acknowledgement == true" @click.stop="store.acknowledgeGroup(group)">Dismiss</button> | ||
| </li> | ||
| </ul> | ||
| <div class="op-metadata"> | ||
|
|
||
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bugfix: auditlist was incrementing the count on every change of interval