added a teams link to the breadcrumbs trail when the team page was used to navigate to something (the team is in the url)

This commit is contained in:
csawatzky 2025-03-06 12:30:16 -06:00
parent b0274ad639
commit b6c1f44e03
3 changed files with 36 additions and 10 deletions

View file

@ -219,6 +219,10 @@ export default function SmartBreadcrumb(props: Props) {
return binsPath() + "/" + binID(); return binsPath() + "/" + binID();
}; };
const teamsPath = (): string => {
return "/teams";
}
const getBreadcrumbMap = (): { [key: string]: string } => { const getBreadcrumbMap = (): { [key: string]: string } => {
const { groupName, deviceName, componentName, reportTarget, binName } = props; const { groupName, deviceName, componentName, reportTarget, binName } = props;
const deviceLabel: string = deviceName ? deviceName : "Device " + deviceID(); const deviceLabel: string = deviceName ? deviceName : "Device " + deviceID();
@ -248,7 +252,8 @@ export default function SmartBreadcrumb(props: Props) {
[firmwarePath()]: "Firmware", [firmwarePath()]: "Firmware",
[usersPath()]: "Users", [usersPath()]: "Users",
[binsPath()]: "Bins", [binsPath()]: "Bins",
[binPath()]: binLabel [binPath()]: binLabel,
[teamsPath()]: "Teams"
}; };
}; };
@ -258,7 +263,7 @@ export default function SmartBreadcrumb(props: Props) {
const breadcrumbLinks = (): ReactNode[] => { const breadcrumbLinks = (): ReactNode[] => {
const breadcrumbMap = getBreadcrumbMap(); const breadcrumbMap = getBreadcrumbMap();
// console.log(breadcrumbMap) //console.log(breadcrumbMap)
let links: ReactNode[] = []; let links: ReactNode[] = [];
let pathnames = location.pathname.split("/").filter((x: any) => x); let pathnames = location.pathname.split("/").filter((x: any) => x);
@ -277,10 +282,13 @@ export default function SmartBreadcrumb(props: Props) {
const lastPath = index === pathnames.length - 1; const lastPath = index === pathnames.length - 1;
//console.log(lastPath) //console.log(lastPath)
const to = `/${pathnames.slice(0, index + 1).join("/")}`; const to = `/${pathnames.slice(0, index + 1).join("/")}`;
//console.log("to: " + to)
let label = breadcrumbMap[to]; let label = breadcrumbMap[to];
//console.log("label: "+label)
let result = to.split("/").filter(str => str !== ""); let result = to.split("/").filter(str => str !== "");
//console.log("result: " + result.toString())
if (!label) { if (!label) {
//console.log("no label")
if (result.length > 1) { if (result.length > 1) {
if (result[result.length - 1] !== "components") { if (result[result.length - 1] !== "components") {
label = breadcrumbMap["/" + result[result.length - 1]]; label = breadcrumbMap["/" + result[result.length - 1]];
@ -292,11 +300,12 @@ export default function SmartBreadcrumb(props: Props) {
} }
if (!blacklist.includes(to) && label) { if (!blacklist.includes(to) && label) {
//console.log("push link")
links.push(linkComponent(to, label, lastPath)); links.push(linkComponent(to, label, lastPath));
} }
}); });
//console.log(links)
return links; return links;
}; };

View file

@ -219,7 +219,7 @@ export default function DeviceComponent() {
true true
); );
let userPromise = userAPI.getUser(user.settings.id, deviceScope(deviceID.toString())); let userPromise = userAPI.getUser(user.settings.id, deviceScope(deviceID.toString()));
let prefPromise = deviceAPI.listDeviceComponentPreferences(deviceID); let prefPromise = deviceAPI.listDeviceComponentPreferences(deviceID, getContextKeys().slice(0, -1), getContextTypes().slice(0, -1));
Promise.all([componentsPromise, userPromise, prefPromise]) Promise.all([componentsPromise, userPromise, prefPromise])
.then((responses: any) => { .then((responses: any) => {
const rawComponents: Array<any> = or(responses[0].data.components, []).sort( const rawComponents: Array<any> = or(responses[0].data.components, []).sort(

View file

@ -173,11 +173,20 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
let url = pondURL( let url = pondURL(
"/devices/" + "/devices/" +
id + id +
"?as=" + as + (keys ? "?keys=" + keys.toString() : "") +
(keys ? "&keys=" + keys.toString() : "") +
(types ? "&types=" + types.toString() : ""), (types ? "&types=" + types.toString() : ""),
demo demo
); );
if (as) {
url = pondURL(
"/devices/" +
id +
"?as=" + as +
(keys ? "&keys=" + keys.toString() : "") +
(types ? "&types=" + types.toString() : ""),
demo
);
}
return new Promise<AxiosResponse<pond.Device>>((resolve, reject) => { return new Promise<AxiosResponse<pond.Device>>((resolve, reject) => {
get<pond.Device>(url).then(resp => { get<pond.Device>(url).then(resp => {
resp.data = pond.Device.fromObject(resp.data) resp.data = pond.Device.fromObject(resp.data)
@ -498,11 +507,19 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
let url = pondURL( let url = pondURL(
"/devices/" + "/devices/" +
id + id +
"/componentPreferences?as=" + "/componentPreferences" +
as + (keys ? "?keys=" + keys.toString() : "") +
(keys ? "&keys=" + keys.toString() : "") +
(types ? "&types=" + types.toString() : "") (types ? "&types=" + types.toString() : "")
) )
if (as) {
url = pondURL(
"/devices/" +
id +
"/componentPreferences?as=" + as +
(keys ? "&keys=" + keys.toString() : "") +
(types ? "&types=" + types.toString() : "")
)
}
return new Promise<AxiosResponse<pond.ListDeviceComponentPreferencesResponse>>((resolve, reject) => { return new Promise<AxiosResponse<pond.ListDeviceComponentPreferencesResponse>>((resolve, reject) => {
get<pond.ListDeviceComponentPreferencesResponse>(url).then(resp => { get<pond.ListDeviceComponentPreferencesResponse>(url).then(resp => {
resp.data = pond.ListDeviceComponentPreferencesResponse.fromObject(resp.data) resp.data = pond.ListDeviceComponentPreferencesResponse.fromObject(resp.data)