From b4c1a543dee0f3472a863e7db752b482ca4b67b8 Mon Sep 17 00:00:00 2001 From: Carter Date: Thu, 24 Apr 2025 11:59:23 -0600 Subject: [PATCH] fixed indexing wrong group when getting permissions --- package.json | 2 +- src/pages/Devices.tsx | 11 +++++-- src/pages/Team.tsx | 5 ++- src/providers/pond/groupAPI.tsx | 56 ++++++++++++++++++++++++--------- 4 files changed, 53 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index d465087..1db2791 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "type": "module", "scripts": { "start": "vite", - "start-local": "VITE_AUTH0_AUDIENCE=bxt-dev.api.adaptiveagriculture.ca VITE_APP_API_URL=http://localhost:50052/v1 VITE_APP_WS_URL=ws://localhost:50052/v1/live VITE_APP_BILLING_URL=http://localhost:50053/v1 VITE_APP_RECLUSE_URL=http://localhost:50054/v1 VITE_APP_GITLAB_URL=http://localhost:50055/v1 vite", + "start-local": "VITE_AUTH0_CLIENT_ID=dzJTpqIeMA4Rwk4xujtwPbAO3TY32bM1 VITE_AUTH0_AUDIENCE=bxt-dev.api.adaptiveagriculture.ca VITE_APP_API_URL=http://localhost:50052/v1 VITE_APP_WS_URL=ws://localhost:50052/v1/live VITE_APP_BILLING_URL=http://localhost:50053/v1 VITE_APP_RECLUSE_URL=http://localhost:50054/v1 VITE_APP_GITLAB_URL=http://localhost:50055/v1 vite", "start-dev": "VITE_AUTH0_CLIENT_ID=dzJTpqIeMA4Rwk4xujtwPbAO3TY32bM1 VITE_APP_API_URL=https://bxt-dev.api.adaptiveagriculture.ca/v1 VITE_AUTH0_CLIENT_DOMAIN=brandxtech.auth0.com VITE_AUTH0_AUDIENCE=bxt-dev.api.adaptiveagriculture.ca VITE_AUTH0_DEV_CLIENT_ID=dzJTpqIeMA4Rwk4xujtwPbAO3TY32bM1 vite", "start-staging": "VITE_AUTH0_CLIENT_ID=3ib460VvLwdeyse5iUSQfxkVdQaUmphP VITE_AUTH0_AUDIENCE=stagingapi.brandxtech.ca VITE_AUTH0_CLIENT_DOMAIN=adaptivestaging.us.auth0.com VITE_APP_API_URL=https://stagingapi.brandxtech.ca/v1 VITE_APP_WS_URL=ws://stagingapi.brandxtech.ca/v1/live VITE_APP_AUTH0_CLIENT_DOMAIN=adaptivestaging.us.auth0.com VITE_APP_AUTH0_AUDIENCE=stagingapi.brandxtech.ca vite", "build": "tsc -b && vite build", diff --git a/src/pages/Devices.tsx b/src/pages/Devices.tsx index f37a5c1..3425c00 100644 --- a/src/pages/Devices.tsx +++ b/src/pages/Devices.tsx @@ -120,10 +120,15 @@ export default function Devices() { setGroups(newGroups); }; + const getGroupKey = () => { + return parseInt(tab+1) + } + useEffect(() => { setGroupPermissions([]) if (tab === "all") return - groupAPI.getGroupPermissions(parseInt(tab)).then(resp => { + groupAPI.getGroupPermissions(getGroupKey()).then(resp => { + console.log(resp) setGroupPermissions(resp.data.permissions) }) }, [tab]) @@ -155,7 +160,7 @@ export default function Devices() { if (tab !== "all") { let keys = getContextKeys() //keys.splice(keys.length - 1, 0, getGroup().id().toString()); - keys.push(getGroup().id().toString()); + keys.push(getGroupKey().toString()); return keys } else { return getContextKeys() @@ -376,7 +381,7 @@ export default function Devices() { } const getGroup = () => { - let group = groups[parseInt(tab)] + let group = groups[parseInt(tab+1)] return group } diff --git a/src/pages/Team.tsx b/src/pages/Team.tsx index d720e89..953e2bd 100644 --- a/src/pages/Team.tsx +++ b/src/pages/Team.tsx @@ -162,7 +162,8 @@ export default function TeamPage() { - {team.name()} + {/* {team.name()} */} + {/* */} @@ -215,8 +216,6 @@ export default function TeamPage() { - - {title()} diff --git a/src/providers/pond/groupAPI.tsx b/src/providers/pond/groupAPI.tsx index cb6437e..8166af2 100644 --- a/src/providers/pond/groupAPI.tsx +++ b/src/providers/pond/groupAPI.tsx @@ -42,6 +42,20 @@ export interface IGroupAPIContext { updateGroupPermissions: (id: number, users: User[]) => Promise; } +function buildQueryString(params: Record): string { + // Filter out null, undefined, or empty string values + const validParams = Object.entries(params) + .filter(([_, value]) => value != null && value !== '') + .map(([key, value]) => `${key}=${value}`); + + if (validParams.length === 0) { + return ''; + } + + // Join parameters with '&' and prepend '?' + return `?${validParams.join('&')}`; +} + export const GroupAPIContext = createContext({} as IGroupAPIContext); interface Props {} @@ -53,8 +67,16 @@ export default function GroupProvider(props: PropsWithChildren) { const [{ as }] = useGlobalState(); const addGroup = (group: pond.GroupSettings) => { - let url = pondURL("/groups") - if (as) url = pondURL("/groups?as=" + as) + // let url = pondURL("/groups") + // let keys = getContextKeys() + // let types = getContextTypes() + // if (as) url = pondURL("/groups?as=" + as) + const params = { + keys: getContextKeys(), + types: getContextTypes(), + as: getContextTypes().includes("team") ? undefined : as + } + let url = pondURL(`/groups${buildQueryString(params)}`) return new Promise((resolve, reject) => { post(url, group).then(resp => { return resolve(resp) @@ -157,19 +179,25 @@ export default function GroupProvider(props: PropsWithChildren) { keys?: string[], types?: string[], ) => { - keys = keys ? keys : getContextKeys(); - types = types? types : getContextTypes(); - let url = "/groupPermissions/" + id - if (as) { - url = url + "?as=" + as + - + - (keys ? "?keys=" + keys.toString() : "") + - (types ? "&types=" + types.toString() : "") - } else { - url = url + - (keys ? "?keys=" + keys.toString() : "") + - (types ? "&types=" + types.toString() : "") + // keys = keys ? keys : getContextKeys(); + // types = types? types : getContextTypes(); + // let url = "/groupPermissions/" + id + // if (as) { + // url = url + "?as=" + as + + // + + // (keys ? "?keys=" + keys.toString() : "") + + // (types ? "&types=" + types.toString() : "") + // } else { + // url = url + + // (keys ? "?keys=" + keys.toString() : "") + + // (types ? "&types=" + types.toString() : "") + // } + const params = { + keys: getContextKeys(), + types: getContextTypes(), + as: getContextTypes().includes("team") ? undefined : as, } + let url = `/groupPermissions/${id}${buildQueryString(params)}` return new Promise>((resolve, reject) => { get(pondURL(url)).then(resp => { resp.data = pond.GetPermissionsResponse.fromObject(resp.data)