diff --git a/package-lock.json b/package-lock.json index 9cdc9f4b..77ac2366 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "wlan-cloud-owprov-ui", - "version": "2.11.0(62)", + "version": "2.11.0(63)", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "wlan-cloud-owprov-ui", - "version": "2.11.0(62)", + "version": "2.11.0(63)", "license": "ISC", "dependencies": { "@chakra-ui/anatomy": "^2.1.1", @@ -5310,9 +5310,9 @@ } }, "node_modules/axios": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.4.0.tgz", - "integrity": "sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA==", + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.1.tgz", + "integrity": "sha512-vfBmhDpKafglh0EldBEbVuoe7DyAavGSLWhuSm5ZSEKQnHhBf0xAAwybbNH1IkrJNGnS/VG4I5yxig1pCEXE4g==", "dependencies": { "follow-redirects": "^1.15.0", "form-data": "^4.0.0", @@ -15677,9 +15677,9 @@ "dev": true }, "axios": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.4.0.tgz", - "integrity": "sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA==", + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.1.tgz", + "integrity": "sha512-vfBmhDpKafglh0EldBEbVuoe7DyAavGSLWhuSm5ZSEKQnHhBf0xAAwybbNH1IkrJNGnS/VG4I5yxig1pCEXE4g==", "requires": { "follow-redirects": "^1.15.0", "form-data": "^4.0.0", diff --git a/package.json b/package.json index e38c0b67..880b70b6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wlan-cloud-owprov-ui", - "version": "2.11.0(62)", + "version": "2.11.0(63)", "description": "", "main": "index.tsx", "scripts": { diff --git a/src/hooks/Network/Entity.ts b/src/hooks/Network/Entity.ts index 08977724..e3d3ec3a 100644 --- a/src/hooks/Network/Entity.ts +++ b/src/hooks/Network/Entity.ts @@ -2,7 +2,6 @@ import { useToast } from '@chakra-ui/react'; import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; import { useTranslation } from 'react-i18next'; import { Entity } from '../../models/Entity'; -import useDefaultPage from '../useDefaultPage'; import { AxiosError } from 'models/Axios'; import { axiosProv, axiosSec } from 'utils/axiosInstances'; @@ -22,13 +21,26 @@ export type TreeEntity = { venues: TreeVenue[]; }; +// Traverse the tree and add a description +export const filterEmptyObjects = (tree: TreeEntity | TreeVenue): TreeEntity | TreeVenue => { + const newTree = { ...tree }; + newTree.children = tree.children.filter((child) => child.uuid !== undefined && child.name !== undefined) as + | TreeEntity[] + | TreeVenue[]; + newTree.venues = tree.venues?.filter((venue) => venue.uuid !== undefined && venue.name !== undefined) as TreeVenue[]; + if (newTree.children) + newTree.children = newTree.children.map((child) => filterEmptyObjects(child)) as TreeEntity[] | TreeVenue[]; + if (newTree.venues) newTree.venues = newTree.venues.map((v) => filterEmptyObjects(v)) as TreeVenue[]; + return newTree; +}; + export const useGetEntityTree = () => { const { t } = useTranslation(); const toast = useToast(); return useQuery( ['get-entity-tree'], - () => axiosProv.get('entity?getTree=true').then(({ data }) => data as TreeEntity), + () => axiosProv.get('entity?getTree=true').then(({ data }) => filterEmptyObjects(data) as TreeEntity), { enabled: axiosProv.defaults.baseURL !== axiosSec.defaults.baseURL, staleTime: Infinity, @@ -129,7 +141,6 @@ export const useGetSelectEntities = ({ select }: { select: string[] }) => { export const useGetEntity = ({ id }: { id?: string }) => { const { t } = useTranslation(); const toast = useToast(); - const goToDefaultPage = useDefaultPage(); return useQuery( ['get-entity', id], @@ -152,7 +163,6 @@ export const useGetEntity = ({ id }: { id?: string }) => { isClosable: true, position: 'top-right', }); - goToDefaultPage(); }, }, );