-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
856d3a7
commit ac9b32d
Showing
8 changed files
with
377 additions
and
1,502 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# Report examples | ||
public/monitoring-tests-reports | ||
public/report_uspace.json | ||
|
||
# Logs | ||
logs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { test, expect } from "vitest"; | ||
import { joinRoutes } from "./reportNavigation"; | ||
|
||
test("Routes are correctly joined", () => { | ||
expect(joinRoutes("/hello/", "/world/")).toBe("/hello/world/"); | ||
expect(joinRoutes("hello", "world")).toBe("hello/world"); | ||
expect(joinRoutes("", "world")).toBe("world"); | ||
expect(joinRoutes("hello", "")).toBe("hello"); | ||
expect(joinRoutes("/", "world")).toBe("/world"); | ||
}); | ||
|
||
test("Routes are correctly joined with numbers", () => { | ||
expect(joinRoutes("/", "0")).toBe("/0"); | ||
expect(joinRoutes("/1", "0")).toBe("/1/0"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,44 @@ | ||
import { RouteObject } from "react-router-dom"; | ||
import { Link, RouteObject } from "react-router-dom"; | ||
import { Capability } from "./capabilityTypes"; | ||
import { CapabilityTable } from "./CapabilityTable"; | ||
|
||
export const joinRoutes = (root: string, child: string): string => { | ||
const cleanChild = child.replace(/^\/+/g, ""); // remove leading slash | ||
if (root === "/") { | ||
return root + cleanChild; | ||
} | ||
const cleanRoot = root.replace(/\/$/, ""); // remove trailing slash | ||
if (!cleanRoot) { | ||
return cleanChild; | ||
} else if (!cleanChild) { | ||
return cleanRoot; | ||
} else { | ||
return `${cleanRoot}/${cleanChild}`; | ||
} | ||
}; | ||
|
||
export const getNavFromCapability = ( | ||
capability: Capability, | ||
path: string = "" | ||
path: string = "/", | ||
fullPath: string = "/" | ||
): RouteObject[] => { | ||
const children = | ||
capability.childCapabilities.flatMap((c, i) => | ||
getNavFromCapability(c, `${path}/${i}`) | ||
getNavFromCapability(c, `${i}`, joinRoutes(fullPath, i.toString())) | ||
) || []; | ||
return [ | ||
{ | ||
path: path, | ||
element: <CapabilityTable capability={capability} />, | ||
handle: { | ||
crumb: () => <Link to={fullPath}>{capability.name}</Link>, | ||
}, | ||
children: [ | ||
{ | ||
index: true, | ||
element: <CapabilityTable capability={capability} />, | ||
}, | ||
...children, | ||
], | ||
}, | ||
...children, | ||
]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.