forked from ddrilling/asb_cloud_front
clean Wells.jsx
This commit is contained in:
parent
89f7de7a49
commit
b968fbf053
@ -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){
|
export default function Wells(props){
|
||||||
const [wells, setWells] = useState([])
|
const [wells, setWells] = useState([])
|
||||||
const [setWellsTree] = useState([]) // wellsTree,
|
|
||||||
const [loader, setLoader] = useState(false)
|
const [loader, setLoader] = useState(false)
|
||||||
const history = useHistory()
|
const history = useHistory()
|
||||||
|
|
||||||
@ -67,10 +36,8 @@ export default function Wells(props){
|
|||||||
setLoader(true)
|
setLoader(true)
|
||||||
try{
|
try{
|
||||||
let newWells = (await WellService.getWells()).map(w =>{return {key:w.id, ...w}})
|
let newWells = (await WellService.getWells()).map(w =>{return {key:w.id, ...w}})
|
||||||
let wellsTree = groupBy(newWells, 'deposit', 'cluster', 'caption')
|
|
||||||
console.log(Wells.wellsTree)
|
console.log(Wells.wellsTree)
|
||||||
setWells( newWells )
|
setWells( newWells )
|
||||||
setWellsTree(wellsTree)
|
|
||||||
}
|
}
|
||||||
catch(e){
|
catch(e){
|
||||||
console.error(`${e.message}`);
|
console.error(`${e.message}`);
|
||||||
|
Loading…
Reference in New Issue
Block a user