Skip to content

Commit e9442ed

Browse files
committed
fix: add multiple metrics
1 parent 57e4ad3 commit e9442ed

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/uiFactory/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export interface UIFactory<H extends string = CommonIssueType> {
4343
countHealthcheckIssuesByType: (issueTrees: IssuesTree[]) => Record<H, number>;
4444
};
4545
hasAccess?: boolean;
46-
yaMetricaId?: number;
46+
yaMetricaMap?: Record<string, number>;
4747
}
4848

4949
export type HandleCreateDB = (params: {clusterName: string}) => Promise<boolean>;

src/utils/yaMetrica.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@ export interface Counter {
77
reachGoal: (...args: unknown[]) => void;
88
}
99

10-
const yaMetricaId = uiFactory.yaMetricaId;
10+
const yaMetricaMap = uiFactory.yaMetricaMap;
1111

1212
class FakeMetrica implements Counter {
13+
name: string;
14+
1315
private warnShown = false;
1416

17+
constructor(name: string) {
18+
this.name = name;
19+
}
20+
1521
hit() {
1622
this.warnOnce();
1723
}
@@ -30,16 +36,17 @@ class FakeMetrica implements Counter {
3036

3137
private warnOnce() {
3238
if (!this.warnShown) {
33-
console.warn('YaMetrica counter is not defined\n');
39+
console.warn(`YaMetrica counter "${this.name}" is not defined\n`);
3440
this.warnShown = true;
3541
}
3642
}
3743
}
3844

39-
export function getMetrica() {
45+
export function getMetrica(name: string) {
46+
const yaMetricaId = yaMetricaMap?.[name];
4047
const metricaInstance = yaMetricaId
4148
? (window[`yaCounter${yaMetricaId}`] as Counter)
4249
: undefined;
4350

44-
return metricaInstance ?? new FakeMetrica();
51+
return metricaInstance ?? new FakeMetrica(name);
4552
}

0 commit comments

Comments
 (0)