Skip to content

Commit

Permalink
update url redirection for services for the table and expanded view a…
Browse files Browse the repository at this point in the history
…ctions

Signed-off-by: Adam Tackett <[email protected]>
  • Loading branch information
Adam Tackett committed Jan 14, 2025
1 parent 1b99e7f commit 2f32933
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -292,14 +292,6 @@ export function getServiceMapGraph(
return { graph: { nodes, edges } };
}

// returns flattened targetResource as an array for all traceGroups
export function getServiceMapTargetResources(map: ServiceObject, serviceName: string) {
return ([] as string[]).concat.apply(
[],
[...map[serviceName].traceGroups.map((traceGroup) => [...traceGroup.targetResource])]
);
}

export function calculateTicks(min: number, max: number, numTicks = 5): number[] {
if (min >= max) return calculateTicks(0, Math.max(1, max), numTicks);
min = Math.floor(min);
Expand Down Expand Up @@ -608,14 +600,25 @@ export const getServiceIndices = (mode: TraceAnalyticsMode) => {
}
};

export const generateServiceUrl = (service: string, dataSourceId: string) => {
const url = `#/services?serviceId=${encodeURIComponent(service)}`;
export const generateServiceUrl = (
service: string,
dataSourceId: string,
mode?: TraceAnalyticsMode
): string => {
// Construct the base URL with the serviceId
let url = `#/services?serviceId=${encodeURIComponent(service)}`;

// Append the datasourceId if provided
if (dataSourceId && dataSourceId !== '') {
return `${url}&datasourceId=${encodeURIComponent(dataSourceId)}`;
url += `&datasourceId=${encodeURIComponent(dataSourceId)}`;
}

// Append the mode parameter
if (mode) {
url += `&mode=${encodeURIComponent(mode)}`;
}

return `${url}&datasourceId=`;
return url;
};

interface FullScreenWrapperProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ describe('Services table component', () => {

it('redirects to the correct URL when the service link is clicked', () => {
const mockDataSourceId = 'mock-data-source-id';
const mockMode = 'data_prepper';
const tableItems = [
{
name: 'checkoutservice',
Expand Down Expand Up @@ -161,7 +162,7 @@ describe('Services table component', () => {

serviceLink.simulate('click');

const expectedUrl = generateServiceUrl('checkoutservice', mockDataSourceId);
const expectedUrl = generateServiceUrl('checkoutservice', mockDataSourceId, mockMode);
expect(window.location.href).toBe(expectedUrl);

window.location = originalLocation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export function ServiceView(props: ServiceViewProps) {
}, [props.serviceName, props.setDataSourceMenuSelectable]);

const redirectToServicePage = (service: string) => {
window.location.href = generateServiceUrl(service, props.dataSourceMDSId[0].id);
window.location.href = generateServiceUrl(service, props.dataSourceMDSId[0].id, mode);
};

const onClickConnectedService = (service: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export function ServicesTable(props: ServicesTableProps) {
if (page === 'app') {
setCurrentSelectedService(serviceName);
} else {
window.location.href = generateServiceUrl(serviceName, dataSourceMDSId[0].id);
window.location.href = generateServiceUrl(serviceName, dataSourceMDSId[0].id, props.mode);
}
};

Expand Down

0 comments on commit 2f32933

Please sign in to comment.