You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.4 KiB
54 lines
1.4 KiB
import { getGridTree } from 'actions/base.action'; |
|
import { useEffect, useState } from 'react'; |
|
import { isEmpty, concat, compact } from 'lodash'; |
|
export default function useGrid(params = {}, isEdit) { |
|
const [treeData, setTreeData] = useState([]); |
|
const [gridIds, setGridIds] = useState([]); |
|
useEffect(() => { |
|
getGridTree(Object.assign({ oneLevel: true }, params)).then(setTreeData); |
|
}, []); |
|
// useEffect(() => { |
|
// if (!isEdit) { |
|
// getGridTree({ |
|
// oneLevel: true, |
|
// ...params, |
|
// }).then(setTreeData); |
|
// } |
|
// if (isEdit && isEmpty(gridIds)) { |
|
// getGridTree({ |
|
// oneLevel: true, |
|
// ...params, |
|
// }).then(setTreeData); |
|
// } |
|
// }, []); |
|
// useEffect(() => { |
|
// if (isEdit && !isEmpty(gridIds)) { |
|
// Promise.all( |
|
// ['', ...gridIds].map((item) => |
|
// getGridTree({ |
|
// oneLevel: true, |
|
// gridId: item, |
|
// }), |
|
// ), |
|
// ).then((values) => { |
|
// setTreeData(concat(...compact(values))); |
|
// }); |
|
// } |
|
// }, [gridIds]); |
|
const onLoadData = ({ id, value }) => { |
|
return getGridTree({ |
|
oneLevel: true, |
|
gridId: value, |
|
}).then((data) => { |
|
setTreeData(treeData.concat(data)); |
|
}); |
|
}; |
|
return [ |
|
treeData, |
|
{ |
|
onLoadData, |
|
setGridIds, |
|
gridExpandedKeys: gridIds, |
|
}, |
|
]; |
|
}
|
|
|