Skip to content

Commit f733fb5

Browse files
committed
Changes made by OpsLevel coding agent
1 parent bc48a5a commit f733fb5

6 files changed

Lines changed: 143 additions & 89 deletions

File tree

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const config = {
33
rootDir: "../../../..",
44
setupFiles: ["jest-canvas-mock"],
55
setupFilesAfterEnv: [
6-
"<rootDir>/test/textEncoder.js",
6+
"<rootDir>/test/textEncoder.ts",
77
"<rootDir>/test/jestImports.ts",
88
"<rootDir>/test/resizeObservers.ts",
99
],
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,69 @@
1-
// @ts-nocheck
1+
export interface LevelColor {
2+
text: string;
3+
border: string;
4+
primary: string;
5+
secondary: string;
6+
}
27

3-
const beginner = {
8+
const beginner: LevelColor = {
49
text: "#595959",
510
border: "#D9D9D9",
611
primary: "#F5F5F5",
712
secondary: "#BFBFBF",
813
};
914

10-
const bronze = {
15+
const bronze: LevelColor = {
1116
text: "#FA541C",
1217
border: "#FFBB96",
1318
primary: "#FFF2E8",
1419
secondary: "#FA541C",
1520
};
1621

17-
const silver = {
22+
const silver: LevelColor = {
1823
text: "#1890FF",
1924
border: "#91D5FF",
2025
primary: "#E6F7FF",
2126
secondary: "#40A9FF",
2227
};
2328

24-
const gold = {
29+
const gold: LevelColor = {
2530
text: "#FAAD14",
2631
border: "#FFE58F",
2732
primary: "#FFFBE6",
2833
secondary: "#FFC53D",
2934
};
3035

31-
const platinum = {
36+
const platinum: LevelColor = {
3237
text: "#13C2C2",
3338
border: "#87E8DE",
3439
primary: "#E6FFFB",
3540
secondary: "#13C2C2",
3641
};
3742

38-
const titanium = {
43+
const titanium: LevelColor = {
3944
text: "#722ED1",
4045
border: "#D3ADF7",
4146
primary: "#F9F0FF",
4247
secondary: "#722ED1",
4348
};
4449

45-
const diamond = {
50+
const diamond: LevelColor = {
4651
text: "#2F54EB",
4752
border: "#ADC6FF",
4853
primary: "#F0F5FF",
4954
secondary: "#2F54EB",
5055
};
5156

52-
const ColorMap = {
57+
type ColorMapKey =
58+
| "beginner"
59+
| "bronze"
60+
| "silver"
61+
| "gold"
62+
| "platinum"
63+
| "titanium"
64+
| "diamond";
65+
66+
const ColorMap: Record<ColorMapKey, LevelColor> = {
5367
beginner,
5468
bronze,
5569
silver,
@@ -59,8 +73,8 @@ const ColorMap = {
5973
diamond,
6074
};
6175

62-
const availableColors = (totalLevels) => {
63-
const levelColors = {
76+
const availableColors = (totalLevels: number): ColorMapKey[] => {
77+
const levelColors: Record<ColorMapKey, boolean> = {
6478
beginner: true,
6579
bronze: totalLevels > 3,
6680
silver: totalLevels > 2,
@@ -70,17 +84,22 @@ const availableColors = (totalLevels) => {
7084
diamond: totalLevels > 6,
7185
};
7286

73-
return Object.keys(levelColors).filter((c) => levelColors[c]);
87+
return (Object.keys(levelColors) as ColorMapKey[]).filter(
88+
(c) => levelColors[c],
89+
);
7490
};
7591

7692
// `levelPosition` refers to the level's position relative the other levels in the account. This is not always the
7793
// level's index since it's possible for gaps in level indexes to exist. e.g. for an account
7894
// with levels with indexes 0,1,2,4,5, the corresponding levelPositions would be 0,1,2,3,4
79-
export const levelColor = (totalLevels, levelPosition) => {
95+
export const levelColor = (
96+
totalLevels: number,
97+
levelPosition: number,
98+
): LevelColor => {
8099
const filteredColors = availableColors(totalLevels);
81100
return ColorMap[filteredColors[levelPosition]];
82101
};
83102

84-
export const levelColorPalette = (totalLevels) => {
103+
export const levelColorPalette = (totalLevels: number): LevelColor[] => {
85104
return availableColors(totalLevels).map((color) => ColorMap[color]);
86105
};

src/helpers/maturity_report_helper.js

Lines changed: 0 additions & 72 deletions
This file was deleted.
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import { escape } from "lodash";
2+
3+
interface Level {
4+
name: string;
5+
index?: number;
6+
}
7+
8+
interface LevelEntry {
9+
[key: string]: number;
10+
}
11+
12+
interface ServiceLevelCount {
13+
level: {
14+
name: string;
15+
};
16+
serviceCount: number;
17+
}
18+
19+
interface CategoryLevelCount {
20+
category?: {
21+
id?: string;
22+
name: string;
23+
} | null;
24+
level: {
25+
name: string;
26+
index?: number;
27+
};
28+
serviceCount: number;
29+
}
30+
31+
export const mountInitialLevelArray = (levels: Level[]): LevelEntry[] => {
32+
return levels.map((level) => {
33+
return { [escape(level.name)]: 0 };
34+
});
35+
};
36+
37+
export const updateCategoryAggregateWithLevelCounter = (
38+
aggregate: LevelEntry[],
39+
level: string,
40+
serviceCounter: number,
41+
): LevelEntry[] => {
42+
return aggregate.map((obj) => {
43+
const currentKey = Object.keys(obj)[0];
44+
if (level === currentKey) {
45+
return { [currentKey]: serviceCounter };
46+
}
47+
return obj;
48+
});
49+
};
50+
51+
export const servicesByLevel = (
52+
levels: Level[],
53+
servicesLevelCount: ServiceLevelCount[],
54+
): LevelEntry[] => {
55+
return levels.map((level) => {
56+
const serviceLevelCount = servicesLevelCount.find(
57+
(entry) => entry.level.name === level.name,
58+
);
59+
// serviceLevelCount is undefined when no services exist at that level
60+
return { [escape(level.name)]: serviceLevelCount?.serviceCount || 0 };
61+
});
62+
};
63+
64+
export const levelsByCategory = (
65+
levels: Level[],
66+
categoryLevelCounts: CategoryLevelCount[],
67+
): Record<string, LevelEntry[]> => {
68+
const initialLevelArray = mountInitialLevelArray(levels);
69+
70+
return categoryLevelCounts.reduce(
71+
(acc, categoryLevel) => {
72+
const currentCategory = categoryLevel.category
73+
? categoryLevel.category.name
74+
: "Uncategorized";
75+
const levelName = escape(categoryLevel.level.name);
76+
77+
const categoryAggregate = acc[currentCategory] || initialLevelArray;
78+
const newCategoryAggregate = updateCategoryAggregateWithLevelCounter(
79+
categoryAggregate,
80+
levelName,
81+
categoryLevel.serviceCount,
82+
);
83+
84+
return {
85+
...acc,
86+
[currentCategory]: newCategoryAggregate,
87+
};
88+
},
89+
{} as Record<string, LevelEntry[]>,
90+
);
91+
};
92+
93+
export const fontFamily = [
94+
"-apple-system",
95+
"BlinkMacSystemFont",
96+
"Segoe U",
97+
"PingFang SC",
98+
"Hiragino Sans GB",
99+
"Microsoft YaHei",
100+
"Helvetica Neue",
101+
"Helvetica",
102+
"Arial",
103+
"sans-serif",
104+
"Apple Color Emoji",
105+
"Segoe UI Emoji",
106+
"Segoe UI Symbol",
107+
].join(", ");
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// eslint-disable-next-line no-restricted-imports -- Test configuration overrides
2-
const { TextEncoder, TextDecoder } = require("util");
2+
import { TextEncoder, TextDecoder } from "util";
33

44
// jsdom does not bundle TextEncoder out of the box despite all browsers doing so.
55
// https://stackoverflow.com/questions/68468203/why-am-i-getting-textencoder-is-not-defined-in-jest

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
"checkJs": true,
88
},
99
"types": ["node", "jest", "@testing-library/jest-dom"],
10-
"include": ["src", "test/jestImports.ts"],
10+
"include": ["src", "test/**/*.ts"],
1111
}

0 commit comments

Comments
 (0)