mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 08:21:53 +00:00
refactor(FormV2): add FormWithDataTemplates component (#4551)
* Revert "fix(client): fix data template style (#4536)"
This reverts commit db66090ab2
.
* refactor(FormV2): add FormWithDataTemplates component
* chore: fix failed e2e tests
* chore: make e2e test more stable
This commit is contained in:
parent
f66edb5d27
commit
bab5d40dbe
@ -8,8 +8,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { createForm } from '@formily/core';
|
import { createForm } from '@formily/core';
|
||||||
import { RecursionField, Schema, useField, useFieldSchema } from '@formily/react';
|
import { Schema, useField } from '@formily/react';
|
||||||
import { Spin, theme } from 'antd';
|
import { Spin } from 'antd';
|
||||||
import React, { createContext, useContext, useEffect, useMemo, useRef } from 'react';
|
import React, { createContext, useContext, useEffect, useMemo, useRef } from 'react';
|
||||||
import {
|
import {
|
||||||
CollectionRecord,
|
CollectionRecord,
|
||||||
@ -20,8 +20,7 @@ import {
|
|||||||
import { withDynamicSchemaProps } from '../hoc/withDynamicSchemaProps';
|
import { withDynamicSchemaProps } from '../hoc/withDynamicSchemaProps';
|
||||||
import { useTreeParentRecord } from '../modules/blocks/data-blocks/table/TreeRecordProvider';
|
import { useTreeParentRecord } from '../modules/blocks/data-blocks/table/TreeRecordProvider';
|
||||||
import { RecordProvider } from '../record-provider';
|
import { RecordProvider } from '../record-provider';
|
||||||
import { useActionContext, useDesignable } from '../schema-component';
|
import { useActionContext } from '../schema-component';
|
||||||
import { Templates as DataTemplateSelect } from '../schema-component/antd/form-v2/Templates';
|
|
||||||
import { BlockProvider, useBlockRequestContext } from './BlockProvider';
|
import { BlockProvider, useBlockRequestContext } from './BlockProvider';
|
||||||
import { TemplateBlockProvider } from './TemplateBlockProvider';
|
import { TemplateBlockProvider } from './TemplateBlockProvider';
|
||||||
import { FormActiveFieldsProvider } from './hooks/useFormActiveFields';
|
import { FormActiveFieldsProvider } from './hooks/useFormActiveFields';
|
||||||
@ -95,9 +94,7 @@ const InternalFormBlockProvider = (props) => {
|
|||||||
return (
|
return (
|
||||||
<FormBlockContext.Provider value={formBlockValue}>
|
<FormBlockContext.Provider value={formBlockValue}>
|
||||||
<RecordProvider isNew={record?.isNew} parent={record?.parentRecord?.data} record={record?.data}>
|
<RecordProvider isNew={record?.isNew} parent={record?.parentRecord?.data} record={record?.data}>
|
||||||
<div ref={formBlockRef}>
|
<div ref={formBlockRef}>{props.children}</div>
|
||||||
<RenderChildrenWithDataTemplates form={form} />
|
|
||||||
</div>
|
|
||||||
</RecordProvider>
|
</RecordProvider>
|
||||||
</FormBlockContext.Provider>
|
</FormBlockContext.Provider>
|
||||||
);
|
);
|
||||||
@ -178,20 +175,6 @@ export const useFormBlockProps = () => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const RenderChildrenWithDataTemplates = ({ form }) => {
|
|
||||||
const FieldSchema = useFieldSchema();
|
|
||||||
const { findComponent } = useDesignable();
|
|
||||||
const field = useField();
|
|
||||||
const Component = findComponent(field.component?.[0]) || React.Fragment;
|
|
||||||
const { token } = theme.useToken();
|
|
||||||
return (
|
|
||||||
<Component {...field.componentProps}>
|
|
||||||
<DataTemplateSelect style={{ marginBottom: token.margin }} form={form} />
|
|
||||||
<RecursionField schema={FieldSchema} onlyRenderProperties />
|
|
||||||
</Component>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
|
@ -729,6 +729,8 @@ test.describe('creation form block schema settings', () => {
|
|||||||
'x-index': 1,
|
'x-index': 1,
|
||||||
},
|
},
|
||||||
}).goto();
|
}).goto();
|
||||||
|
|
||||||
|
await page.waitForLoadState('networkidle');
|
||||||
await page.getByLabel('schema-initializer-Grid-page:addBlock').hover();
|
await page.getByLabel('schema-initializer-Grid-page:addBlock').hover();
|
||||||
//使用复制模板
|
//使用复制模板
|
||||||
await page.getByRole('menuitem', { name: 'form Form' }).first().hover();
|
await page.getByRole('menuitem', { name: 'form Form' }).first().hover();
|
||||||
|
@ -0,0 +1,31 @@
|
|||||||
|
/**
|
||||||
|
* This file is part of the NocoBase (R) project.
|
||||||
|
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
||||||
|
* Authors: NocoBase Team.
|
||||||
|
*
|
||||||
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
||||||
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import React from 'react';
|
||||||
|
import { Templates } from '../..';
|
||||||
|
import { useFormBlockContext } from '../../../block-provider/FormBlockProvider';
|
||||||
|
import { withDynamicSchemaProps } from '../../../hoc/withDynamicSchemaProps';
|
||||||
|
import { useToken } from '../../../style';
|
||||||
|
import { Form } from './Form';
|
||||||
|
|
||||||
|
export const FormWithDataTemplates: any = withDynamicSchemaProps(
|
||||||
|
(props) => {
|
||||||
|
const formBlockCtx = useFormBlockContext();
|
||||||
|
const { token } = useToken();
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Templates style={{ marginBottom: token.margin }} form={props.form || formBlockCtx?.form} />
|
||||||
|
<Form {...props} />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'FormWithDataTemplates',
|
||||||
|
},
|
||||||
|
);
|
@ -93,7 +93,7 @@ export const useFormDataTemplates = () => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Templates = ({ style = {}, form }) => {
|
export const Templates = ({ style = {}, form }: { style?: React.CSSProperties; form?: any }) => {
|
||||||
const { token } = useToken();
|
const { token } = useToken();
|
||||||
const { templates, display, enabled, defaultTemplate } = useFormDataTemplates();
|
const { templates, display, enabled, defaultTemplate } = useFormDataTemplates();
|
||||||
const { getCollectionJoinField } = useCollectionManager_deprecated();
|
const { getCollectionJoinField } = useCollectionManager_deprecated();
|
||||||
@ -103,7 +103,7 @@ export const Templates = ({ style = {}, form }) => {
|
|||||||
const api = useAPIClient();
|
const api = useAPIClient();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (enabled && defaultTemplate) {
|
if (enabled && defaultTemplate && form) {
|
||||||
form.__template = true;
|
form.__template = true;
|
||||||
if (defaultTemplate.key === 'duplicate') {
|
if (defaultTemplate.key === 'duplicate') {
|
||||||
handleTemplateDataChange(defaultTemplate.dataId, defaultTemplate);
|
handleTemplateDataChange(defaultTemplate.dataId, defaultTemplate);
|
||||||
|
@ -7,9 +7,9 @@
|
|||||||
* For more information, please refer to: https://www.nocobase.com/agreement.
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Form as FormV2 } from './Form';
|
|
||||||
import { DetailsDesigner, FormDesigner, ReadPrettyFormDesigner } from './Form.Designer';
|
import { DetailsDesigner, FormDesigner, ReadPrettyFormDesigner } from './Form.Designer';
|
||||||
import { FilterDesigner } from './Form.FilterDesigner';
|
import { FilterDesigner } from './Form.FilterDesigner';
|
||||||
|
import { FormWithDataTemplates as FormV2 } from './FormWithDataTemplates';
|
||||||
import { Templates } from './Templates';
|
import { Templates } from './Templates';
|
||||||
export * from './Form.Settings';
|
export * from './Form.Settings';
|
||||||
|
|
||||||
|
@ -439,7 +439,7 @@ test('Collection event Add Data Trigger, determines that the trigger node single
|
|||||||
await page.getByRole('menuitemcheckbox', { name: triggerNodeFieldDisplayName }).click();
|
await page.getByRole('menuitemcheckbox', { name: triggerNodeFieldDisplayName }).click();
|
||||||
const conditionalRightConstant = faker.lorem.words();
|
const conditionalRightConstant = faker.lorem.words();
|
||||||
await page.waitForTimeout(500);
|
await page.waitForTimeout(500);
|
||||||
await page.keyboard.type(`!='${conditionalRightConstant}'`, { delay: 50 });
|
await page.keyboard.type(`!='${conditionalRightConstant}'`, { delay: 100 });
|
||||||
await expect(conditionNode.conditionExpressionEditBox).toHaveText(
|
await expect(conditionNode.conditionExpressionEditBox).toHaveText(
|
||||||
`Trigger variables / Trigger data / ${triggerNodeFieldDisplayName}!='${conditionalRightConstant}'`,
|
`Trigger variables / Trigger data / ${triggerNodeFieldDisplayName}!='${conditionalRightConstant}'`,
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user