From 7b0b89a5b7ea3eb0bfd719114dd8637a04c46abf Mon Sep 17 00:00:00 2001 From: Adam Tackett Date: Fri, 17 Jan 2025 12:14:38 -0800 Subject: [PATCH] add type for serviceMapParams, im prove readability, remove related servics Signed-off-by: Adam Tackett --- .../components/common/helper_functions.tsx | 25 ++++++++------ .../components/common/plots/service_map.tsx | 34 ++++++++----------- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/public/components/trace_analytics/components/common/helper_functions.tsx b/public/components/trace_analytics/components/common/helper_functions.tsx index f74864ce5..8a6c8e99a 100644 --- a/public/components/trace_analytics/components/common/helper_functions.tsx +++ b/public/components/trace_analytics/components/common/helper_functions.tsx @@ -208,17 +208,22 @@ function filterGraphBySelectedNode( return { graph: { nodes: connectedNodes, edges: connectedEdges } }; } -// construct vis-js graph from ServiceObject -export function getServiceMapGraph( - map: ServiceObject, - idSelected: 'latency' | 'error_rate' | 'throughput', - ticks: number[], - currService?: string, - relatedServices?: string[], - filterByCurrService?: boolean -) { - if (!relatedServices) relatedServices = Object.keys(map); +interface ServiceMapParams { + map: ServiceObject; + idSelected: 'latency' | 'error_rate' | 'throughput'; + ticks: number[]; + currService?: string; + filterByCurrService?: boolean; +} +// construct vis-js graph from ServiceObject +export function getServiceMapGraph({ + map, + idSelected, + ticks, + currService, + filterByCurrService, +}: ServiceMapParams) { const nodes = Object.keys(map).map((service) => { const value = map[service][idSelected]; let styleOptions; diff --git a/public/components/trace_analytics/components/common/plots/service_map.tsx b/public/components/trace_analytics/components/common/plots/service_map.tsx index f75f1e840..a70cfd899 100644 --- a/public/components/trace_analytics/components/common/plots/service_map.tsx +++ b/public/components/trace_analytics/components/common/plots/service_map.tsx @@ -296,28 +296,25 @@ export function ServiceMap({ if (focusedService !== null) { removeFilter('serviceName', focusedService); setItems( - getServiceMapGraph( - serviceMap, + getServiceMapGraph({ + map: serviceMap, idSelected, ticks, - undefined, - undefined, - false // Show the entire graph without filtering - ) + filterByCurrService: false, + }) ); setFocusedService(null); setInvalid(false); } } else if (serviceMap[service]) { if (focusedService !== service) { - const filteredGraph = getServiceMapGraph( - serviceMap, + const filteredGraph = getServiceMapGraph({ + map: serviceMap, idSelected, ticks, - service, - serviceMap[service]?.relatedServices, - true // Enable filtering to focus on connected nodes - ); + currService: service, + filterByCurrService: true, + }); setItems(filteredGraph); setFocusedService(service); } @@ -369,14 +366,13 @@ export function ServiceMap({ // Adjust graph rendering logic to ensure related services are visible const showRelatedServices = focusedService ? true : filterByCurrService; setItems( - getServiceMapGraph( - serviceMap, + getServiceMapGraph({ + map: serviceMap, idSelected, - calculatedTicks, - focusedService ?? currService, - serviceMap[currService!]?.relatedServices, - showRelatedServices - ) + ticks: calculatedTicks, + currService: focusedService ?? currService, + filterByCurrService: showRelatedServices, + }) ); }, [serviceMap, idSelected, focusedService, filterByCurrService]);