clean Wells.jsx

This commit is contained in:
Фролов 2021-05-28 15:56:40 +05:00
parent 89f7de7a49
commit b968fbf053

View File

@ -27,39 +27,8 @@ const columns = [
},
];
const groupBy = (table, ...keys) => {
let key = keys[0]
let groups = table.reduce((rv, item) => {
let keyValue = item[key]
let group = rv.find(o=>o.title === keyValue)
if(!group)
{
group = {
title: keyValue,
value: keys.length === 1 ? item : `${key} ${keyValue} ${item['id']}`,
selectable: keys.length === 1,
children:[]}
rv.push(group)
}
if(keys.length > 1)
group.children.push(item);
return rv;
}, []);
if(keys.length > 1){
for(let group of groups){
group.children = groupBy(group.children, ...keys.slice(1))
}
}
return groups
};
export default function Wells(props){
const [wells, setWells] = useState([])
const [setWellsTree] = useState([]) // wellsTree,
const [loader, setLoader] = useState(false)
const history = useHistory()
@ -67,10 +36,8 @@ export default function Wells(props){
setLoader(true)
try{
let newWells = (await WellService.getWells()).map(w =>{return {key:w.id, ...w}})
let wellsTree = groupBy(newWells, 'deposit', 'cluster', 'caption')
console.log(Wells.wellsTree)
setWells( newWells )
setWellsTree(wellsTree)
}
catch(e){
console.error(`${e.message}`);