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

feat: self qa issue & escalation-policy-reference-store update #5460

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ const fetchDeleteUserGroup = async (params: UserGroupDeleteUserGroupParameters)
watch([() => storeState.serviceList, () => storeState.selectedUserGroupList], ([nv_service_list, nv_user_group_list]) => {
if (nv_service_list) {
const list: any = [];
Object.values(nv_service_list).forEach((service) => {
if (service && service.data && service.data.members) {
nv_user_group_list.forEach((userGroup) => {
nv_user_group_list.forEach((userGroup) => {
Object.values(nv_service_list).forEach((service) => {
if (service && service.data && service.data.members) {
if (Object.keys(service.data.members).includes('USER_GROUP')) {
if (service.data.members.USER_GROUP.includes(userGroup.user_group_id)) {
list.push({
Expand All @@ -107,8 +107,12 @@ watch([() => storeState.serviceList, () => storeState.selectedUserGroupList], ([
description: userGroup.description,
});
}
});
}
}
});
list.push({
user_group: userGroup.name,
description: userGroup.description,
});
});
if (list.length > 0) {
tableState.filteredItems = Object.values(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ const disableUser = async (userId?: string): Promise<boolean> => {
watch([() => storeState.serviceList, () => storeState.selectedUsers], ([nv_service_list, nv_selected_users]) => {
if (nv_service_list) {
const list: UserListItemType[] | (UserListItemType & { service: string; })[] = [];
Object.values(nv_service_list).forEach((service) => {
if (service && service.data && service.data.members) {
nv_selected_users.forEach((selectedUser) => {
nv_selected_users.forEach((selectedUser) => {
Object.values(nv_service_list).forEach((service) => {
if (service && service.data && service.data.members) {
if (Object.keys(service.data.members).includes('USER')) {
if (selectedUser.user_id && service.data.members.USER.includes(selectedUser.user_id)) {
list.push({
Expand All @@ -178,8 +178,9 @@ watch([() => storeState.serviceList, () => storeState.selectedUsers], ([nv_servi
} else {
list.push(selectedUser);
}
});
}
}
});
list.push(selectedUser);
});
if (list.length > 0) {
state.filteredUniqueItems = Object.values(list.reduce((acc, cur) => {
Expand Down
33 changes: 24 additions & 9 deletions apps/web/src/store/reference/escalation-policy-reference-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@ import { defineStore } from 'pinia';
import { SpaceConnector } from '@cloudforet/core-lib/space-connector';

import type { ListResponse } from '@/schema/_common/api-verbs/list';
import type { EscalationPolicyListParameters } from '@/schema/monitoring/escalation-policy/api-verbs/list';
import type { EscalationPolicyModel } from '@/schema/monitoring/escalation-policy/model';
import type { EscalationPolicyListParameters } from '@/schema/alert-manager/escalation-policy/api-verbs/list';
import type { EscalationPolicyModel } from '@/schema/alert-manager/escalation-policy/model';
import type { EscalationPolicyListParameters as EscalationPolicyListParametersV1 } from '@/schema/monitoring/escalation-policy/api-verbs/list';
import type { EscalationPolicyModel as EscalationPolicyModelV1 } from '@/schema/monitoring/escalation-policy/model';

import { useDomainStore } from '@/store/domain/domain-store';
import type {
ReferenceLoadOptions, ReferenceItem, ReferenceMap, ReferenceTypeInfo,
} from '@/store/reference/type';
import { useUserStore } from '@/store/user/user-store';

import config from '@/lib/config';

import ErrorHandler from '@/common/composables/error/errorHandler';


Expand All @@ -25,6 +30,7 @@ let lastLoadedTime = 0;

export const useEscalationPolicyReferenceStore = defineStore('reference-escalation-policy', () => {
const userStore = useUserStore();
const domainStore = useDomainStore();
const state = reactive({
items: null as EscalationPolicyReferenceMap | null,
});
Expand Down Expand Up @@ -54,13 +60,22 @@ export const useEscalationPolicyReferenceStore = defineStore('reference-escalati

const referenceMap: EscalationPolicyReferenceMap = {};
try {
const response = await SpaceConnector.clientV2.monitoring.escalationPolicy.list<EscalationPolicyListParameters, ListResponse<EscalationPolicyModel>>({
query: {
only: ['escalation_policy_id', 'name', 'resource_group', 'project_id'],
},
}, { timeout: 3000 });

response.results?.forEach((escalationPolicyInfo: EscalationPolicyModel): void => {
const isAlertManagerVersionV2 = (config.get('ADVANCED_SERVICE')?.alert_manager_v2 ?? []).includes(domainStore.state.domainId);
const fetcher = isAlertManagerVersionV2
? SpaceConnector.clientV2.alertManager.escalationPolicy.list<EscalationPolicyListParameters, ListResponse<EscalationPolicyModel>>({
query: {
only: ['escalation_policy_id', 'name', 'service_id'],
},
})
: SpaceConnector.clientV2.monitoring.escalationPolicy.list<EscalationPolicyListParametersV1, ListResponse<EscalationPolicyModelV1>>({
query: {
only: ['escalation_policy_id', 'name', 'resource_group', 'project_id'],
},
});

const response = await fetcher;

response.results?.forEach((escalationPolicyInfo: EscalationPolicyModel|EscalationPolicyModelV1): void => {
referenceMap[escalationPolicyInfo.escalation_policy_id] = {
key: escalationPolicyInfo.escalation_policy_id,
label: escalationPolicyInfo.name,
Expand Down
Loading