Skip to content

Commit

Permalink
add type for serviceMapParams, im
Browse files Browse the repository at this point in the history
prove readability, remove related servics

Signed-off-by: Adam Tackett <[email protected]>
  • Loading branch information
Adam Tackett committed Jan 17, 2025
1 parent 12b46fd commit 7b0b89a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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]);

Expand Down

0 comments on commit 7b0b89a

Please sign in to comment.