-
Notifications
You must be signed in to change notification settings - Fork 229
Expand file tree
/
Copy pathMethodClassifications.tsx
More file actions
60 lines (52 loc) · 1.55 KB
/
MethodClassifications.tsx
File metadata and controls
60 lines (52 loc) · 1.55 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
import { useMemo } from "react";
import type { Method } from "../../model-editor/method";
import { CallClassification } from "../../model-editor/method";
import { styled } from "styled-components";
import { Tag } from "../common/Tag";
const ClassificationsContainer = styled.div`
display: inline-flex;
flex-direction: row;
gap: 0.5rem;
`;
const ClassificationTag = styled(Tag)`
font-size: 0.75em;
white-space: nowrap;
`;
type Props = {
method: Method;
};
export const MethodClassifications = ({ method }: Props) => {
const allUsageClassifications = useMemo(
() =>
new Set(
method.usages.map((usage) => {
return usage.classification;
}),
),
[method.usages],
);
const inSource = allUsageClassifications.has(CallClassification.Source);
const inTest = allUsageClassifications.has(CallClassification.Test);
const inGenerated = allUsageClassifications.has(CallClassification.Generated);
const tooltip = useMemo(() => {
if (inTest && inGenerated) {
return "This method is only used from test and generated code";
}
if (inTest) {
return "This method is only used from test code";
}
if (inGenerated) {
return "This method is only used from generated code";
}
return "";
}, [inTest, inGenerated]);
if (inSource) {
return null;
}
return (
<ClassificationsContainer title={tooltip}>
{inTest && <ClassificationTag>Test</ClassificationTag>}
{inGenerated && <ClassificationTag>Generated</ClassificationTag>}
</ClassificationsContainer>
);
};