fix: customized create action supports tree data for table selection data (#2328)

* fix: customized add action in table selection data supports tree data

* fix: customized add action in table selection data supports tree data
This commit is contained in:
katherinehhh 2023-08-04 11:06:03 +08:00 committed by GitHub
parent 43a75fe599
commit c7a30c314c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,11 +13,23 @@ type VariablesCtx = {
$form?: Record<string, any>; $form?: Record<string, any>;
}; };
function flattenDeep(data, result = []) {
for (let i = 0; i < data?.length; i++) {
const { children, ...rest } = data[i];
result.push(rest);
if (children) {
flattenDeep(children, result);
}
}
return result;
}
export const useVariablesCtx = (): VariablesCtx => { export const useVariablesCtx = (): VariablesCtx => {
const currentUser = useCurrentUserContext(); const currentUser = useCurrentUserContext();
const { field, service, rowKey } = useTableBlockContext(); const { field, service, rowKey } = useTableBlockContext();
const contextData = service?.data?.data?.filter((v) => (field?.data?.selectedRowKeys || [])?.includes(v[rowKey])); const tableData = flattenDeep(service?.data?.data);
return useMemo(() => { return useMemo(() => {
const contextData = tableData?.filter((v) => (field?.data?.selectedRowKeys || [])?.includes(v[rowKey]));
return { return {
$user: currentUser?.data?.data || {}, $user: currentUser?.data?.data || {},
$date: { $date: {