Skip to content

Commit

Permalink
[WIFI-13150] Fixed entity tree parsing to ignore empty values
Browse files Browse the repository at this point in the history
Signed-off-by: Charles <[email protected]>
  • Loading branch information
BourqueCharles committed Nov 13, 2023
1 parent 581caa8 commit 708ccc9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wlan-cloud-owprov-ui",
"version": "2.11.0(62)",
"version": "2.11.0(63)",
"description": "",
"main": "index.tsx",
"scripts": {
Expand Down
18 changes: 14 additions & 4 deletions src/hooks/Network/Entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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,
Expand Down Expand Up @@ -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],
Expand All @@ -152,7 +163,6 @@ export const useGetEntity = ({ id }: { id?: string }) => {
isClosable: true,
position: 'top-right',
});
goToDefaultPage();
},
},
);
Expand Down

0 comments on commit 708ccc9

Please sign in to comment.