-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathutils.ts
More file actions
69 lines (61 loc) · 1.99 KB
/
utils.ts
File metadata and controls
69 lines (61 loc) · 1.99 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
import type { ModalFuncProps } from "antd/es/modal";
import type { ReactNode } from "react";
import { Severity } from "~/features/common/progress/SeverityGauge/types";
import { pluralize } from "~/features/common/utils";
import { ConfidenceBucket } from "~/types/api/models/ConfidenceBucket";
import { FieldActionType } from "~/types/api/models/FieldActionType";
import {
DEFAULT_CONFIRMATION_PROPS,
FIELD_ACTION_COMPLETED,
} from "./FieldActions.const";
export const getActionModalProps = (
verb: string,
content: ReactNode,
): ModalFuncProps => ({
title: verb,
okText: verb,
content,
...DEFAULT_CONFIRMATION_PROPS,
});
export const getActionSuccessMessage = (
actionType: FieldActionType,
itemCount?: number,
) =>
`${FIELD_ACTION_COMPLETED[actionType]}${pluralize(itemCount ?? 0, "", `${actionType === FieldActionType.ASSIGN_CATEGORIES ? " for" : ""} ${itemCount?.toLocaleString()} resources`)}`;
export const getActionErrorMessage = (actionType: FieldActionType) => {
const actionLabel = actionType === FieldActionType.CLASSIFY
? "Classification"
: FIELD_ACTION_COMPLETED[actionType];
return `${actionLabel} failed${actionType === FieldActionType.CLASSIFY || actionType === FieldActionType.PROMOTE ? ": View summary in the activity tab" : ""}`;
};
const CONFIDENCE_BUCKET_TO_SEVERITY: Record<
ConfidenceBucket,
Severity | undefined
> = {
high: "high",
medium: "medium",
low: "low",
manual: undefined,
} as const;
export function mapConfidenceBucketToSeverity(
confidenceBucket: ConfidenceBucket,
): Severity | undefined {
return CONFIDENCE_BUCKET_TO_SEVERITY[confidenceBucket];
}
export const getMaxSeverity = (
severityList: Severity[],
): Severity | undefined => {
return severityList.reduce(
(agg, current) => {
switch (agg) {
case "high":
return agg;
case "medium":
return current === "high" ? current : agg;
default:
return current || agg;
}
},
undefined as Severity | undefined,
);
};