fixed linking between groups and devices

This commit is contained in:
Carter 2025-01-07 14:53:43 -06:00
parent 77fb5a6bcf
commit 8fc8745862
3 changed files with 12 additions and 5 deletions

View file

@ -84,7 +84,6 @@ export default function SmartBreadcrumb(props: Props) {
} }
} }
const regexMatch = or(location.pathname.match(/\/groups\/([^/]+)/), []) const regexMatch = or(location.pathname.match(/\/groups\/([^/]+)/), [])
// console.log(or(regexMatch[1], "0").toString())
return or(regexMatch[1], "0").toString(); return or(regexMatch[1], "0").toString();
}; };

View file

@ -200,13 +200,21 @@ export default function Devices() {
setLimit(event.target.value); setLimit(event.target.value);
}; };
const appendToUrl = (appendage: number | string) => { // const appendToUrl = (appendage: number | string) => {
// const basePath = location.pathname.replace(/\/$/, "");
// return(`${basePath}/${appendage}`);
// };
const prependToUrl = (prependage: number | string) => {
console.log(location.pathname)
const basePath = location.pathname.replace(/\/$/, ""); const basePath = location.pathname.replace(/\/$/, "");
return(`${basePath}/${appendage}`); return(`/${prependage}/${basePath}`.replace(/\/{2,}/g, "/").replace(/(\/[^/]+)\/\1+/g, "$1"));
}; };
const toDevice = (device: Device) => { const toDevice = (device: Device) => {
navigate(appendToUrl(or(device.settings?.deviceId, "")), { state: {device: device} }) let url = prependToUrl(getGroup() ? "groups/" + getGroup().id() : "")
url = url + "/" + device.id()
navigate(url, { replace: true, state: {device: device} })
}; };
const handleTabChange = (_event: React.SyntheticEvent, newValue: string) => { const handleTabChange = (_event: React.SyntheticEvent, newValue: string) => {

View file

@ -135,7 +135,7 @@ export default function GroupPage() {
}, [group, limit, page, order, orderBy, search]) }, [group, limit, page, order, orderBy, search])
const toDevice = (device: Device) => { const toDevice = (device: Device) => {
navigate(appendToUrl(or(device.settings?.deviceId, "")), { state: {device: device} }) navigate(appendToUrl(or("devices/"+device.settings?.deviceId, "")), { state: {device: device} })
}; };
const columns = (): Column<Device>[] => { const columns = (): Column<Device>[] => {