-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy pathFolderActivityFlow.tsx
More file actions
203 lines (172 loc) · 6.38 KB
/
Copy pathFolderActivityFlow.tsx
File metadata and controls
203 lines (172 loc) · 6.38 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import * as d3 from "d3";
import { useEffect, useRef, useMemo } from "react";
import { useShallow } from "zustand/react/shallow";
import Breadcrumbs from "@mui/material/Breadcrumbs";
import Link from "@mui/material/Link";
import Typography from "@mui/material/Typography";
import NavigateNextIcon from "@mui/icons-material/NavigateNext";
import WorkspacePremiumRoundedIcon from "@mui/icons-material/WorkspacePremiumRounded";
import { useDataStore } from "store";
import { DIMENSIONS } from "./FolderActivityFlow.const";
import "./FolderActivityFlow.scss";
import { extractReleaseBasedContributorActivities } from "./FolderActivityFlow.util";
import { renderReleaseVisualization } from "./ReleaseVisualization";
import { useFolderNavigation } from "./useFolderNavigation";
const FolderActivityFlow = () => {
const [totalData] = useDataStore(useShallow((state) => [state.data]));
const svgRef = useRef<SVGSVGElement>(null);
const tooltipRef = useRef<HTMLDivElement>(null);
const containerRef = useRef<HTMLDivElement>(null);
const {
currentPath,
releaseGroups,
releaseTopFolderPaths,
navigateToFolder,
navigateToBreadcrumb,
initializeRootFolders,
getBreadcrumbs,
} = useFolderNavigation(totalData);
useEffect(() => {
initializeRootFolders();
}, [initializeRootFolders]);
const breadcrumbs = useMemo(() => getBreadcrumbs(), [getBreadcrumbs]);
const { topContributorName, releaseRangeLabel } = useMemo(() => {
if (!totalData || totalData.length === 0 || releaseTopFolderPaths.length === 0) {
return {
topContributorName: null,
releaseRangeLabel: "...",
};
}
const currentDepth = currentPath === "" ? 1 : currentPath.split("/").length + 1;
const releaseContributorActivities = extractReleaseBasedContributorActivities(
totalData,
releaseTopFolderPaths,
currentDepth
);
if (releaseContributorActivities.length === 0) {
return {
topContributorName: null,
releaseRangeLabel: "...",
};
}
const contributorClocs = new Map<string, number>();
releaseContributorActivities.forEach((activity) => {
const current = contributorClocs.get(activity.contributorName) || 0;
contributorClocs.set(activity.contributorName, current + activity.changes);
});
let maxCloc = 0;
let mostActiveContributor = "";
contributorClocs.forEach((cloc, name) => {
if (cloc > maxCloc) {
maxCloc = cloc;
mostActiveContributor = name;
}
});
const releaseIndices = Array.from(
new Set(releaseContributorActivities.map((activity) => activity.releaseIndex))
).sort((a, b) => a - b);
const releaseTagByIndex = new Map<number, string>();
releaseContributorActivities.forEach((activity) => {
if (!releaseTagByIndex.has(activity.releaseIndex)) {
releaseTagByIndex.set(activity.releaseIndex, activity.releaseTag);
}
});
const resolvedTags = releaseIndices.map((index) => {
const tag = releaseTagByIndex.get(index);
return tag && tag.trim().length > 0 ? tag : `Release ${index}`;
});
const firstReleaseLabel = resolvedTags[0] || "...";
const lastReleaseLabel = resolvedTags[resolvedTags.length - 1] || firstReleaseLabel;
const rangeLabel = resolvedTags.length <= 1 ? firstReleaseLabel : `${firstReleaseLabel} to ${lastReleaseLabel}`;
return {
topContributorName: mostActiveContributor || null,
releaseRangeLabel: rangeLabel || "...",
};
}, [totalData, releaseTopFolderPaths, currentPath]);
useEffect(() => {
if (!totalData || totalData.length === 0) {
return;
}
if (releaseGroups.length === 0 || releaseTopFolderPaths.length === 0) {
return;
}
const svg = d3
.select(svgRef.current)
.attr("width", (containerRef.current?.clientWidth || DIMENSIONS.width) - 100)
.attr("height", DIMENSIONS.height);
//activity가 있는 폴더 카운트
const currentDepth = currentPath === "" ? 1 : currentPath.split("/").length + 1;
const releaseContributorActivities = extractReleaseBasedContributorActivities(
totalData,
releaseTopFolderPaths,
currentDepth
);
svg.selectAll("*").remove();
if (releaseContributorActivities.length === 0) {
const chartWidth = (containerRef.current?.clientWidth || DIMENSIONS.width) - 100;
svg
.append("text")
.attr("x", chartWidth / 2)
.attr("y", DIMENSIONS.height / 2)
.attr("text-anchor", "middle")
.attr("dominant-baseline", "middle")
.text("No release activity data available")
.style("font-size", "14px")
.style("fill", "#6c757d");
return;
}
renderReleaseVisualization({
svg,
releaseContributorActivities,
releaseTopFolderPaths,
tooltipRef,
onFolderClick: navigateToFolder,
});
}, [totalData, releaseGroups, releaseTopFolderPaths, navigateToFolder, currentPath]);
const topContributorLabel = topContributorName || "...";
return (
<div
className="folder-activity-flow"
ref={containerRef}
>
<div className="folder-activity-flow__head">
<Breadcrumbs
separator={<NavigateNextIcon fontSize="small" />}
aria-label="breadcrumb"
className="folder-activity-flow__breadcrumb"
>
{breadcrumbs.map((crumb, index) => {
const isLast = index === breadcrumbs.length - 1;
if (isLast) {
return <Typography key={crumb}>{crumb}</Typography>;
}
return (
<Link
key={crumb}
underline="none"
component="button"
onClick={() => navigateToBreadcrumb(index, breadcrumbs.length)}
>
{crumb}
</Link>
);
})}
</Breadcrumbs>
<div className="folder-activity-flow__title">
<WorkspacePremiumRoundedIcon className="folder-activity-flow__title-icon" />
<span className="folder-activity-flow__title-text">Top contributor is {topContributorLabel}</span>
</div>
<div className="folder-activity-flow__subtitle">{releaseRangeLabel}</div>
</div>
<svg
className="folder-activity-flow__chart"
ref={svgRef}
/>
<div
className="folder-activity-flow__tooltip"
ref={tooltipRef}
/>
</div>
);
};
export default FolderActivityFlow;