diff --git a/frontend/src/components/routing/LocationViewSetRouter.tsx b/frontend/src/components/routing/LocationViewSetRouter.tsx index f195f92..6fa00b1 100644 --- a/frontend/src/components/routing/LocationViewSetRouter.tsx +++ b/frontend/src/components/routing/LocationViewSetRouter.tsx @@ -2,19 +2,35 @@ import * as React from "react" import * as ReactDOM from "react-dom" import {ViewSetRouter, ViewSetRouterProps} from "./ViewSetRouter"; import {useLocation} from "@reach/router"; +import {SplitPath, splitPath} from "../../utils/PathSplitter"; +import {Detail} from "../../utils/DjangoTypes"; -interface LocationViewSetRouterProps extends ViewSetRouterProps { - +interface LocationViewSetRouterProps extends ViewSetRouterProps { + pkKey: keyof Resource, + splitPathKey: keyof SplitPath, } -export function LocationViewSetRouter({...props}: LocationViewSetRouterProps): JSX.Element { +export function LocationViewSetRouter({pkKey, splitPathKey, viewSet, ...props}: LocationViewSetRouterProps): JSX.Element { + // Get the current page location const location = useLocation() + // Split the path into multiple segments + const expectedPk = + React.useMemo( + () => splitPath(location.pathname)[splitPathKey], + [location] + ) + // Find the ManagedResource matching the expectedPk + const selection = + React.useMemo( + () => viewSet.resources?.filter(res => res.value[pkKey] === expectedPk)[0], + [viewSet, expectedPk] + ) return ( - + ) }