diff --git a/app/containers/Network/containers/BulkEditAccessPoints/index.js b/app/containers/Network/containers/BulkEditAccessPoints/index.js index 1f41e0f..7acaaab 100644 --- a/app/containers/Network/containers/BulkEditAccessPoints/index.js +++ b/app/containers/Network/containers/BulkEditAccessPoints/index.js @@ -6,6 +6,8 @@ import { useLazyQuery, useMutation } from '@apollo/client'; import { BulkEditAccessPoints, sortRadioTypes } from '@tip-wlan/wlan-cloud-ui-library'; import { USER_FRIENDLY_RADIOS } from 'constants/index'; +import { getBreadcrumbPath, getLocationPath } from 'utils/locations'; + import { FILTER_EQUIPMENT_BULK_EDIT_APS } from 'graphql/queries'; import { UPDATE_EQUIPMENT_BULK } from 'graphql/mutations'; @@ -168,75 +170,6 @@ const formatRadioFrequencies = ({ return frequencies; }; -const getBreadcrumbPath = (id, locations) => { - const locationsPath = []; - const treeRecurse = (parentNodeId, node) => { - if (node.id === parentNodeId) { - locationsPath.unshift(node); - return node; - } - if (node.children) { - let parent; - node.children.some(i => { - parent = treeRecurse(parentNodeId, i); - return parent; - }); - if (parent) { - locationsPath.unshift(node); - } - return parent; - } - return null; - }; - - treeRecurse(id, { - id: 0, - children: locations, - }); - - return locationsPath; -}; - -const getLocationPath = (selectedId, locations) => { - const locationsPath = []; - - const treeRecurse = (parentNodeId, node) => { - if (node.id === parentNodeId) { - locationsPath.unshift(node.id); - - if (node.children) { - const flatten = children => { - children.forEach(i => { - locationsPath.unshift(i.id); - if (i.children) { - flatten(i.children); - } - }); - }; - - flatten(node.children); - } - return node; - } - if (node.children) { - let parent; - node.children.some(i => { - parent = treeRecurse(parentNodeId, i); - return parent; - }); - return parent; - } - - return null; - }; - - if (selectedId) { - treeRecurse(selectedId, { id: 0, children: locations }); - } - - return locationsPath; -}; - const BulkEditAPs = ({ locations, checkedLocations }) => { const { id } = useParams(); const { customerId } = useContext(UserContext); diff --git a/app/containers/System/containers/AutoProvision/index.js b/app/containers/System/containers/AutoProvision/index.js index 5b1b94c..a24c2fb 100644 --- a/app/containers/System/containers/AutoProvision/index.js +++ b/app/containers/System/containers/AutoProvision/index.js @@ -1,4 +1,4 @@ -import React, { useContext } from 'react'; +import React, { useContext, useMemo } from 'react'; import { useQuery, useMutation } from '@apollo/client'; import { Alert, notification } from 'antd'; import { AutoProvision as AutoProvisionPage, Loading } from '@tip-wlan/wlan-cloud-ui-library'; @@ -7,6 +7,7 @@ import UserContext from 'contexts/UserContext'; import { GET_CUSTOMER, GET_ALL_LOCATIONS, GET_ALL_PROFILES } from 'graphql/queries'; import { UPDATE_CUSTOMER } from 'graphql/mutations'; import { fetchMoreProfiles } from 'graphql/functions'; +import { formatLocations } from 'utils/locations'; const AutoProvision = () => { const { customerId } = useContext(UserContext); @@ -65,6 +66,10 @@ const AutoProvision = () => { fetchMoreProfiles(e, dataProfile, fetchMore); }; + const locationsTree = useMemo(() => { + return formatLocations(dataLocation?.getAllLocations, true); + }, [dataLocation?.getAllLocations]); + if (loading) { return ; } @@ -77,9 +82,9 @@ const AutoProvision = () => { return ( { + function unflatten(array, p) { + let tree = []; + const parent = typeof p !== 'undefined' ? p : { id: '0' }; + let children = filter(array, child => child.parentId === parent.id); + children = children.map(c => ({ + title: c.name, + value: `${c.id}`, + key: c.id, + isLeaf: false, + ...c, + })); + if (!isEmpty(children)) { + if (parent.id === '0') { + tree = children; + } else { + parent.children = children; + } + each(children, child => unflatten(array, child)); + } + return tree; + } + + return [ + { + ...NETWORK_NODE, + ...(disableRoot && { disabled: true }), + children: unflatten(list), + }, + ]; +}; + +export const getBreadcrumbPath = (id, locations) => { + const locationsPath = []; + const treeRecurse = (parentNodeId, node) => { + if (node.id === parentNodeId) { + locationsPath.unshift(node); + return node; + } + if (node.children) { + let parent; + node.children.some(i => { + parent = treeRecurse(parentNodeId, i); + return parent; + }); + if (parent) { + locationsPath.unshift(node); + } + return parent; + } + return null; + }; + + treeRecurse(id, { + id: 0, + children: locations, + }); + + return locationsPath; +}; + +export const getLocationPath = (selectedId, locations) => { + const locationsPath = []; + + const treeRecurse = (parentNodeId, node) => { + if (node.id === parentNodeId) { + locationsPath.unshift(node.id); + + if (node.children) { + const flatten = children => { + children.forEach(i => { + locationsPath.unshift(i.id); + if (i.children) { + flatten(i.children); + } + }); + }; + + flatten(node.children); + } + return node; + } + if (node.children) { + let parent; + node.children.some(i => { + parent = treeRecurse(parentNodeId, i); + return parent; + }); + return parent; + } + + return null; + }; + + if (selectedId) { + treeRecurse(selectedId, { id: 0, children: locations }); + } + + return locationsPath; +};