Skip to content

Commit 8e5dc5c

Browse files
authored
fix(alert-v2): solve service store bug (#5659)
Signed-off-by: samuel.park <[email protected]>
1 parent 91d45d3 commit 8e5dc5c

7 files changed

+13
-15
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1+
import type { ComputedRef } from 'vue';
2+
import { computed } from 'vue';
3+
14
import { useDomainStore } from '@/store/domain/domain-store';
5+
import { pinia } from '@/store/pinia';
26

37
import config from '@/lib/config';
48

59
/* NOTE:
610
* This hook will be removed or refactored once the global config is improved.
711
* */
812

9-
export const useIsAlertManagerV2Enabled = (): boolean => {
10-
const domainStore = useDomainStore();
13+
export const useIsAlertManagerV2Enabled = (): ComputedRef<boolean> => {
14+
const domainStore = useDomainStore(pinia);
1115
const domainStoreState = domainStore.state;
1216

1317
const enabledDomains = config.get('ADVANCED_SERVICE')?.alert_manager_v2 ?? [];
1418

15-
return enabledDomains.includes(domainStoreState.domainId);
19+
return computed(() => enabledDomains.includes(domainStoreState.domainId));
1620
};

apps/web/src/services/project-v1/components/ProjectDetailTabHeader.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ const getProjectAlertActivated = async () => {
343343
344344
/* Watchers */
345345
watch(() => projectDetailPageGetters.projectType, async () => {
346-
if (!isAlertManagerV2Enabled) {
346+
if (!isAlertManagerV2Enabled.value) {
347347
await Promise.allSettled([
348348
getProjectAlertActivated(),
349349
listWebhooks(),

apps/web/src/services/project-v1/pages/ProjectDetailTabPage.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ const singleItemTabState = reactive({
107107
name: PROJECT_ROUTE.DETAIL.TAB.SUMMARY._NAME,
108108
label: i18n.t('PROJECT.DETAIL.TAB_SUMMARY'),
109109
},
110-
...(isAlertManagerV2Enabled ? [] : [
110+
...(isAlertManagerV2Enabled.value ? [] : [
111111
{
112112
name: PROJECT_ROUTE.DETAIL.TAB.ALERT._NAME,
113113
label: i18n.t('PROJECT.DETAIL.TAB_ALERT'),

apps/web/src/services/project-v1/pages/ProjectSummaryPage.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const getProjectAlertConfig = async () => {
5454
};
5555
5656
watch(() => props.id, () => {
57-
if (!isAlertManagerV2Enabled) getProjectAlertConfig();
57+
if (!isAlertManagerV2Enabled.value) getProjectAlertConfig();
5858
}, { immediate: true });
5959
</script>
6060

apps/web/src/store/reference/escalation-policy-reference-store.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const useEscalationPolicyReferenceStore = defineStore('reference-escalati
6060

6161
const referenceMap: EscalationPolicyReferenceMap = {};
6262
try {
63-
const fetcher = isAlertManagerV2Enabled
63+
const fetcher = isAlertManagerV2Enabled.value
6464
? SpaceConnector.clientV2.alertManager.escalationPolicy.list<EscalationPolicyListParameters, ListResponse<EscalationPolicyModel>>({
6565
query: {
6666
only: ['escalation_policy_id', 'name', 'service_id'],

apps/web/src/store/reference/service-reference-store.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@ import type { ListResponse } from '@/api-clients/_common/schema/api-verbs/list';
99
import type { ServiceListParameters } from '@/schema/alert-manager/service/api-verbs/list';
1010
import type { ServiceModel } from '@/schema/alert-manager/service/model';
1111

12-
import { useDomainStore } from '@/store/domain/domain-store';
1312
import type {
1413
ReferenceLoadOptions, ReferenceItem, ReferenceMap,
1514
ReferenceTypeInfo,
1615
} from '@/store/reference/type';
1716
import { useUserStore } from '@/store/user/user-store';
1817

19-
import config from '@/lib/config';
2018
import { useIsAlertManagerV2Enabled } from '@/lib/config/composables/use-is-alert-manager-v2-enabled';
2119
import { MANAGED_VARIABLE_MODELS } from '@/lib/variable-models/managed-model-config/base-managed-model-config';
2220

@@ -30,7 +28,6 @@ let lastLoadedTime = 0;
3028

3129
export const useServiceReferenceStore = defineStore('reference-service', () => {
3230
const userStore = useUserStore();
33-
const domainStore = useDomainStore();
3431
const isAlertManagerV2Enabled = useIsAlertManagerV2Enabled();
3532

3633
const state = reactive({
@@ -52,9 +49,6 @@ export const useServiceReferenceStore = defineStore('reference-service', () => {
5249
});
5350

5451
const load = async (options?: ReferenceLoadOptions) => {
55-
const isAlertManagerVersionV2 = (config.get('ADVANCED_SERVICE')?.alert_manager_v2 ?? []).includes(domainStore.state.domainId);
56-
if (!isAlertManagerVersionV2) return;
57-
5852
const currentTime = new Date().getTime();
5953

6054
if (
@@ -69,7 +63,7 @@ export const useServiceReferenceStore = defineStore('reference-service', () => {
6963
},
7064
};
7165

72-
if (!isAlertManagerV2Enabled) return;
66+
if (!isAlertManagerV2Enabled.value) return;
7367
try {
7468
const { results } = await SpaceConnector.clientV2.alertManager.service.list<ServiceListParameters, ListResponse<ServiceModel>>(params);
7569

apps/web/src/store/reference/webhook-reference-store.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const useWebhookReferenceStore = defineStore('reference-webhook', () => {
6060

6161
const referenceMap: WebhookReferenceMap = {};
6262
try {
63-
const fetcher = isAlertManagerV2Enabled
63+
const fetcher = isAlertManagerV2Enabled.value
6464
? SpaceConnector.clientV2.alertManager.webhook.list<WebhookListParameters, ListResponse<WebhookModel>>
6565
: SpaceConnector.clientV2.monitoring.webhook.list<WebhookListParametersV1, ListResponse<WebhookModelV1>>;
6666

0 commit comments

Comments
 (0)