mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-15 20:17:22 +00:00
refactor: rename basepath to admin_basepath and normalize admin paths
This commit is contained in:
@@ -9,7 +9,7 @@ import { Message } from "ui/components/display/Message";
|
||||
import { useNavigate } from "ui/lib/routes";
|
||||
|
||||
export type BkndAdminOptions = {
|
||||
basepath?: string;
|
||||
admin_basepath?: string;
|
||||
logo_return_path?: string;
|
||||
theme?: AppTheme;
|
||||
};
|
||||
@@ -169,7 +169,7 @@ export function useBkndOptions(): BkndAdminOptions {
|
||||
const ctx = useContext(BkndContext);
|
||||
return (
|
||||
ctx.options ?? {
|
||||
basepath: "/",
|
||||
admin_basepath: "/",
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,23 @@ import type { BkndAdminOptions } from "ui/client/BkndProvider";
|
||||
|
||||
export type AppType = ReturnType<App["toJSON"]>;
|
||||
|
||||
/**
|
||||
* Normalize admin path by removing duplicate slashes and ensuring proper format
|
||||
* @param path - The path to normalize
|
||||
* @returns Normalized path
|
||||
* @private
|
||||
*/
|
||||
function normalizeAdminPath(path: string): string {
|
||||
// Remove duplicate slashes
|
||||
const normalized = path.replace(/\/+/g, "/");
|
||||
// Don't remove trailing slash if it's the only character or if path ends with entity/
|
||||
if (normalized === "/" || normalized.endsWith("/entity/")) {
|
||||
return normalized;
|
||||
}
|
||||
// Remove trailing slash for other paths
|
||||
return normalized.replace(/\/$/, "") || "/";
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduced version of the App class for frontend use
|
||||
* @todo: remove this class
|
||||
@@ -68,20 +85,19 @@ export class AppReduced {
|
||||
|
||||
get options() {
|
||||
return {
|
||||
basepath: "",
|
||||
admin_basepath: "",
|
||||
logo_return_path: "/",
|
||||
...this._options,
|
||||
};
|
||||
}
|
||||
|
||||
getSettingsPath(path: string[] = []): string {
|
||||
const base = `~/${this.options.basepath}/settings`.replace(/\/+/g, "/");
|
||||
return [base, ...path].join("/");
|
||||
const base = `~/${this.options.admin_basepath}/settings`
|
||||
return normalizeAdminPath([base, ...path].join("/"));
|
||||
}
|
||||
|
||||
getAbsolutePath(path?: string): string {
|
||||
const { basepath } = this.options;
|
||||
return (path ? `~/${basepath}/${path}` : `~/${basepath}`).replace(/\/+/g, "/");
|
||||
return normalizeAdminPath((path ? `~/${this.options.admin_basepath}/${path}` : `~/${this.options.admin_basepath}`));
|
||||
}
|
||||
|
||||
getAuthConfig() {
|
||||
|
||||
Reference in New Issue
Block a user