mirror of
https://github.com/Telecominfraproject/wlan-cloud-ui.git
synced 2025-10-30 18:27:58 +00:00
Changed location data structure for Auto-Provision
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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 <Loading />;
|
||||
}
|
||||
@@ -77,9 +82,9 @@ const AutoProvision = () => {
|
||||
|
||||
return (
|
||||
<AutoProvisionPage
|
||||
data={data && data.getCustomer}
|
||||
dataLocation={dataLocation && dataLocation.getAllLocations}
|
||||
dataProfile={dataProfile && dataProfile.getAllProfiles.items}
|
||||
data={data?.getCustomer}
|
||||
locationsTree={locationsTree}
|
||||
dataProfile={dataProfile?.getAllProfiles?.items}
|
||||
loadingLocation={loadingLocation}
|
||||
loadingProfile={loadingProfile}
|
||||
errorLocation={errorLocation}
|
||||
|
||||
110
app/utils/locations.js
Normal file
110
app/utils/locations.js
Normal file
@@ -0,0 +1,110 @@
|
||||
import { filter, isEmpty, each } from 'lodash';
|
||||
|
||||
export const NETWORK_NODE = {
|
||||
title: 'Network',
|
||||
id: '0',
|
||||
key: '0',
|
||||
value: '0',
|
||||
name: 'Network',
|
||||
};
|
||||
|
||||
export const formatLocations = (list = [], disableRoot = false) => {
|
||||
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;
|
||||
};
|
||||
Reference in New Issue
Block a user