Files
coder/site/src/modules/navigation.ts
T
Kayla Washburn-Love 8b6a06dbd5 chore: consolidate ManageSettingsLayout code (#14885)
Clean up a bunch of tangles that only existed to service the
`"multi-organization"` experiment, which has now been removed
2024-10-03 22:00:52 +00:00

33 lines
1.1 KiB
TypeScript

/**
* @fileoverview TODO: centralize navigation code here! URL constants, URL formatting, all of it
*/
import { useEffectEvent } from "hooks/hookPolyfills";
import type { DashboardValue } from "./dashboard/DashboardProvider";
import { useDashboard } from "./dashboard/useDashboard";
type LinkThunk = (state: DashboardValue) => string;
export function useLinks() {
const dashboard = useDashboard();
// Needs to be safe to call `get` from inside of a `useEffect` without causing
// excess triggers from adding it as a dependency.
const get = useEffectEvent((thunk: LinkThunk): string => thunk(dashboard));
return get;
}
export function withFilter(path: string, filter: string) {
return path + (filter ? `?filter=${encodeURIComponent(filter)}` : "");
}
export const linkToAuditing = "/audit";
export const linkToUsers = withFilter("/deployment/users", "status:active");
export const linkToTemplate =
(organizationName: string, templateName: string): LinkThunk =>
(dashboard) =>
dashboard.showOrganizations
? `/templates/${organizationName}/${templateName}`
: `/templates/${templateName}`;