mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-08 23:19:26 +08:00
Merge branch 'feat/tree-collection' into feat/gantt-block
This commit is contained in:
commit
a0c57a9251
@ -1,11 +1,10 @@
|
||||
import { ArrayField } from '@formily/core';
|
||||
import { Schema, useField, useFieldSchema } from '@formily/react';
|
||||
import uniq from 'lodash/uniq';
|
||||
import React, { createContext, useContext, useEffect } from 'react';
|
||||
import React, { createContext, useContext, useEffect, useState } from 'react';
|
||||
import { useCollectionManager } from '../collection-manager';
|
||||
import { RecordProvider, useRecord } from '../record-provider';
|
||||
import { BlockProvider, RenderChildrenWithAssociationFilter, useBlockRequestContext } from './BlockProvider';
|
||||
import { useFormBlockContext } from './FormBlockProvider';
|
||||
|
||||
export const TableSelectorContext = createContext<any>({});
|
||||
|
||||
@ -13,6 +12,7 @@ const InternalTableSelectorProvider = (props) => {
|
||||
const { params, rowKey, extraFilter } = props;
|
||||
const field = useField();
|
||||
const { resource, service } = useBlockRequestContext();
|
||||
const [expandFlag, setExpandFlag] = useState(false);
|
||||
// if (service.loading) {
|
||||
// return <Spin />;
|
||||
// }
|
||||
@ -26,6 +26,10 @@ const InternalTableSelectorProvider = (props) => {
|
||||
params,
|
||||
extraFilter,
|
||||
rowKey,
|
||||
expandFlag,
|
||||
setExpandFlag: () => {
|
||||
setExpandFlag(!expandFlag);
|
||||
},
|
||||
}}
|
||||
>
|
||||
<RenderChildrenWithAssociationFilter {...props} />
|
||||
@ -103,7 +107,7 @@ export const TableSelectorProvider = (props) => {
|
||||
const record = useRecord();
|
||||
const { getCollection } = useCollectionManager();
|
||||
const collection = getCollection(props.collection);
|
||||
const { treeTable } = fieldSchema['x-decorator-props'];
|
||||
const { treeTable } = fieldSchema?.['x-decorator-props'] || {};
|
||||
const collectionFieldSchema = recursiveParent(fieldSchema, 'CollectionField');
|
||||
const collectionField = getCollectionJoinField(collectionFieldSchema?.['x-collection-field']);
|
||||
const params = { ...props.params };
|
||||
@ -113,6 +117,14 @@ export const TableSelectorProvider = (props) => {
|
||||
}
|
||||
if ((collection as any).template === 'tree' && treeTable !== false) {
|
||||
params['tree'] = true;
|
||||
if (collectionFieldSchema.name === 'parent') {
|
||||
params.filter = {
|
||||
...(params.filter ?? {}),
|
||||
id: {
|
||||
$ne: record.id,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
if (!Object.keys(params).includes('appends')) {
|
||||
params['appends'] = appends;
|
||||
|
@ -10,7 +10,13 @@ import { default as classNames, default as cls } from 'classnames';
|
||||
import React, { RefCallback, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { DndContext, useDesignable } from '../..';
|
||||
import { RecordIndexProvider, RecordProvider, useSchemaInitializer, useTableBlockContext } from '../../../';
|
||||
import {
|
||||
RecordIndexProvider,
|
||||
RecordProvider,
|
||||
useSchemaInitializer,
|
||||
useTableBlockContext,
|
||||
useTableSelectorContext,
|
||||
} from '../../../';
|
||||
import { useACLFieldWhitelist } from '../../../acl/ACLProvider';
|
||||
import { isCollectionFieldComponent, isColumnComponent, extractIndex, getIdsWithChildren } from './utils';
|
||||
|
||||
@ -164,12 +170,14 @@ export const Table: any = observer((props: any) => {
|
||||
required,
|
||||
...others
|
||||
} = { ...others1, ...others2 } as any;
|
||||
const { expandFlag } = useTableBlockContext();
|
||||
const schema = useFieldSchema();
|
||||
const isTableSelector = schema?.parent?.['x-decorator'] === 'TableSelectorProvider';
|
||||
const ctx = isTableSelector ? useTableSelectorContext() : useTableBlockContext();
|
||||
const { expandFlag } = ctx;
|
||||
const onRowDragEnd = useMemoizedFn(others.onRowDragEnd || (() => {}));
|
||||
const paginationProps = usePaginationProps(pagination1, pagination2);
|
||||
const requiredValidator = field.required || required;
|
||||
const schema = useFieldSchema();
|
||||
const { treeTable } = schema?.parent?.['x-decorator-props']||{};
|
||||
const { treeTable } = schema?.parent?.['x-decorator-props'] || {};
|
||||
const [expandedKeys, setExpandesKeys] = useState([]);
|
||||
const [allIncludesChildren, setAllIncludesChildren] = useState([]);
|
||||
useEffect(() => {
|
||||
|
@ -2,8 +2,9 @@ import React from 'react';
|
||||
import { Button } from 'antd';
|
||||
import { css } from '@emotion/css';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useFieldSchema } from '@formily/react';
|
||||
import { ActionInitializer } from './ActionInitializer';
|
||||
import { useTableBlockContext } from '../../';
|
||||
import { useTableBlockContext, useTableSelectorContext } from '../../';
|
||||
import { NodeCollapseOutlined, NodeExpandOutlined } from '@ant-design/icons';
|
||||
|
||||
export const ExpandActionInitializer = (props) => {
|
||||
@ -25,7 +26,7 @@ export const ExpandActionInitializer = (props) => {
|
||||
return <ActionInitializer {...props} schema={schema} />;
|
||||
};
|
||||
|
||||
export const actionDesignerCss = css`
|
||||
const actionDesignerCss = css`
|
||||
position: relative;
|
||||
&:hover {
|
||||
.general-schema-designer {
|
||||
@ -66,7 +67,9 @@ export const actionDesignerCss = css`
|
||||
|
||||
export const ExpandActionComponent = (props) => {
|
||||
const { t } = useTranslation();
|
||||
const ctx = useTableBlockContext();
|
||||
const schema = useFieldSchema();
|
||||
const isTableSelector = schema.parent?.parent?.['x-decorator'] === 'TableSelectorProvider';
|
||||
const ctx = isTableSelector ? useTableSelectorContext() : useTableBlockContext();
|
||||
return (
|
||||
<div className={actionDesignerCss}>
|
||||
{ctx.params['tree'] && (
|
||||
|
Loading…
x
Reference in New Issue
Block a user