Skip to content

Commit

Permalink
Group insights by displayName
Browse files Browse the repository at this point in the history
  • Loading branch information
kshmidt-digma committed Nov 7, 2023
1 parent 4139fff commit 169a877
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
31 changes: 15 additions & 16 deletions ui/src/components/Assets/AssetInsights/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const getInsightTypeOrderPriority = (type: string): number => {
[InsightType.SpanDurationBreakdown]: 68
};

return insightOrderPriorityMap[type] || Infinity;
return insightOrderPriorityMap[type] || -Infinity;
};

const renderInsightCard = (
Expand Down Expand Up @@ -214,7 +214,7 @@ const sortInsightGroupsByName = (a: InsightGroup, b: InsightGroup) => {
};

export const AssetInsights = (props: AssetInsightsProps) => {
const [insights, setInsights] = useState<InsightGroup[]>();
const [insightGroups, setInsightGroups] = useState<InsightGroup[]>();
const previousEnvironment = usePrevious(props.environment);
const insightsContainerRef = useRef<HTMLDivElement>(null);
const theme = useTheme();
Expand Down Expand Up @@ -284,25 +284,24 @@ export const AssetInsights = (props: AssetInsightsProps) => {
continue;
}

const insightSpanCodeObjectId = insight.spanInfo?.spanCodeObjectId;
const insightDisplayName = insight.spanInfo?.displayName;

if (
!insightSpanCodeObjectId ||
insightSpanCodeObjectId === spanCodeObjectId
) {
if (!insightDisplayName || insightDisplayName === displayName) {
ungroupedInsights.push(insight);
continue;
}

if (!spanInsightGroups[spanCodeObjectId]) {
spanInsightGroups[spanCodeObjectId] = [];
if (!spanInsightGroups[insightDisplayName]) {
spanInsightGroups[insightDisplayName] = [];
}

spanInsightGroups[spanCodeObjectId].push(insight);
spanInsightGroups[insightDisplayName].push(insight);
}

setInsights([
{ insights: ungroupedInsights },
setInsightGroups([
...(ungroupedInsights.length > 0
? [{ insights: ungroupedInsights }]
: []),
// Span insight groups
...Object.values(spanInsightGroups)
.map((x) => ({
Expand All @@ -312,7 +311,7 @@ export const AssetInsights = (props: AssetInsightsProps) => {
}))
.sort(sortInsightGroupsByName)
]);
}, [spanCodeObjectId, props.environment]);
}, [displayName, spanCodeObjectId, props.environment]);

useEffect(() => {
void fetchInsights();
Expand All @@ -326,7 +325,7 @@ export const AssetInsights = (props: AssetInsightsProps) => {
return () => {
window.clearTimeout(timer);
};
}, [insights, fetchInsights]);
}, [insightGroups, fetchInsights]);

useEffect(() => {
if (insightsContainerRef.current) {
Expand Down Expand Up @@ -376,9 +375,9 @@ export const AssetInsights = (props: AssetInsightsProps) => {
</s.Breadcrumbs>
</s.Header>
<s.ContentContainer>
{insights ? (
{insightGroups ? (
<s.InsightsContainer ref={insightsContainerRef}>
{insights.map((x) => (
{insightGroups.map((x) => (
<s.InsightGroup key={x.name || "__ungrouped"}>
{x.name && (
<s.InsightGroupName>
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/Assets/AssetInsights/typeGuards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
SpanInsight,
SpanNPlusOneInsight,
SpanScalingBadlyInsight,
SpanUsagesInsight,
SpanUsagesInsight
} from "./types";

export const isSpanInsight = (
Expand Down

0 comments on commit 169a877

Please sign in to comment.