forked from guacsec/trustify-ui
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodel-utils.ts
More file actions
110 lines (101 loc) · 2.67 KB
/
model-utils.ts
File metadata and controls
110 lines (101 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import type React from "react";
import type { ProgressProps } from "@patternfly/react-core";
import {
SeverityCriticalIcon,
SeverityImportantIcon,
SeverityMinorIcon,
SeverityModerateIcon,
SeverityNoneIcon,
SeverityUndefinedIcon,
} from "@patternfly/react-icons";
import {
t_global_icon_color_severity_critical_default as criticalColor,
t_global_icon_color_severity_important_default as importantColor,
t_global_icon_color_severity_minor_default as minorColor,
t_global_icon_color_severity_moderate_default as moderateColor,
t_global_icon_color_severity_none_default as noneColor,
t_global_icon_color_severity_undefined_default as undefinedColor,
} from "@patternfly/react-tokens";
import type { ExtendedSeverity, Label } from "./models";
type ListType = {
[key in ExtendedSeverity]: {
name: string;
color: { name: string; value: string; var: string };
progressProps: Pick<ProgressProps, "variant">;
// biome-ignore lint/suspicious/noExplicitAny: allowed
icon: React.ComponentType<any>;
};
};
export const severityList: ListType = {
unknown: {
name: "Unknown",
color: undefinedColor,
progressProps: { variant: undefined },
icon: SeverityUndefinedIcon,
},
none: {
name: "None",
color: noneColor,
progressProps: { variant: undefined },
icon: SeverityNoneIcon,
},
low: {
name: "Low",
color: minorColor,
progressProps: { variant: undefined },
icon: SeverityMinorIcon,
},
medium: {
name: "Medium",
color: moderateColor,
progressProps: { variant: "warning" },
icon: SeverityModerateIcon,
},
high: {
name: "High",
color: importantColor,
progressProps: { variant: "danger" },
icon: SeverityImportantIcon,
},
critical: {
name: "Critical",
color: criticalColor,
progressProps: { variant: "danger" },
icon: SeverityCriticalIcon,
},
};
export const getSeverityPriority = (val: ExtendedSeverity) => {
switch (val) {
case "unknown":
return 1;
case "none":
return 2;
case "low":
return 3;
case "medium":
return 4;
case "high":
return 5;
case "critical":
return 6;
default:
return 0;
}
};
export function compareBySeverityFn<T>(
severityExtractor: (elem: T) => ExtendedSeverity,
) {
return (a: T, b: T) => {
return (
getSeverityPriority(severityExtractor(a)) -
getSeverityPriority(severityExtractor(b))
);
};
}
export const joinKeyValueAsString = ({ key, value }: Label): string => {
return `${value ? `${key}=${value}` : `${key}`}`;
};
export const splitStringAsKeyValue = (v: string): Label => {
const [key, value] = v.split("=");
return { key, value: value ?? "" };
};