fix(ui): восстанавливать контекст OSPF из URL
This commit is contained in:
1 parent
af05ad5cda
commit
1d522527b4
7 files changed
+130
-44
No files matched your search
@@ -0,0 +1,16 @@
|
||||
export const ospfTabs = ["interfaces", "neighbors", "routes", "bfd"] as const
|
||||
export type OspfTab = typeof ospfTabs[number]
|
||||
export function readOspfUrl(params: URLSearchParams) {
|
||||
const server = params.get("server") ?? "all"
|
||||
const rawTab = params.get("tab") ?? "interfaces"
|
||||
let error: string | null = null
|
||||
if (["server", "tab"].some(key => params.getAll(key).length > 1)) error = "В ссылке повторяется контекст OSPF."
|
||||
else if (!/^[a-zA-Z0-9_.:-]{1,64}$/.test(server)) error = "В ссылке указан некорректный сервер OSPF."
|
||||
else if (!(ospfTabs as readonly string[]).includes(rawTab)) error = "В ссылке указана неизвестная вкладка OSPF."
|
||||
return { server, tab: (ospfTabs as readonly string[]).includes(rawTab) ? rawTab as OspfTab : "interfaces" as OspfTab, error }
|
||||
}
|
||||
export function patchOspfUrl(params: URLSearchParams, changes: Record<string, string | null>) {
|
||||
const next = new URLSearchParams(params)
|
||||
for (const [key,value] of Object.entries(changes)) { if (value === null || value === "") next.delete(key); else next.set(key,value) }
|
||||
return "/ospf" + (next.size ? "?" + next.toString() : "")
|
||||
}
|
||||
Reference in new issue
Block a user