diff --git a/packages/core/client/docs/zh-CN/core/block/demo4.tsx b/packages/core/client/docs/zh-CN/core/block/demo4.tsx index 894b863bb3..9a21638b27 100644 --- a/packages/core/client/docs/zh-CN/core/block/demo4.tsx +++ b/packages/core/client/docs/zh-CN/core/block/demo4.tsx @@ -1,15 +1,15 @@ -import React, { FC, useEffect } from 'react'; import { RecordProviderV2, SchemaComponent, - withSchemaComponentProps, UseDataBlockProps, - useRecordV2, useRecordDataV2, + useRecordV2, + withSchemaComponentProps, } from '@nocobase/client'; -import { createApp } from './createApp'; import { Button, Form, Input, InputNumber } from 'antd'; import { FormProps } from 'antd/lib'; +import React, { FC, useEffect } from 'react'; +import { createApp } from './createApp'; interface DemoFormFieldType { id: number; diff --git a/packages/core/client/docs/zh-CN/core/collection/record-provider.md b/packages/core/client/docs/zh-CN/core/collection/record-provider.md index aed3610f3b..0727bc5461 100644 --- a/packages/core/client/docs/zh-CN/core/collection/record-provider.md +++ b/packages/core/client/docs/zh-CN/core/collection/record-provider.md @@ -11,6 +11,10 @@ interface RecordProviderProps { isNew?: boolean; record?: RecordV2 | DataType; parentRecord?: RecordV2 | DataType; + /** + * 当前记录所属的 collection name + */ + collectionName?: string; } ``` diff --git a/packages/core/client/docs/zh-CN/core/collection/record.md b/packages/core/client/docs/zh-CN/core/collection/record.md index d89e273c7a..2b59e95118 100644 --- a/packages/core/client/docs/zh-CN/core/collection/record.md +++ b/packages/core/client/docs/zh-CN/core/collection/record.md @@ -9,12 +9,17 @@ interface RecordOptions { isNew?: boolean; data?: DataType; parentRecord?: RecordV2; + /** + * 当前记录所属的 collection name + */ + collectionName?: string; } class RecordV2 { public isNew?: boolean; public data?: DataType; public parentRecord?: RecordV2; + public collectionName?: string; constructor(options: RecordOptions) {} setData(data: DataType) { diff --git a/packages/core/client/src/application/collection/Record.ts b/packages/core/client/src/application/collection/Record.ts index 72a9cda802..a924e962cc 100644 --- a/packages/core/client/src/application/collection/Record.ts +++ b/packages/core/client/src/application/collection/Record.ts @@ -2,17 +2,26 @@ export interface RecordOptions { isNew?: boolean; data?: DataType; parentRecord?: RecordV2; + /** + * 当前记录所属的 collection name + */ + collectionName?: string; } export class RecordV2 { public data?: DataType; public parentRecord?: RecordV2; public isNew?: boolean; + /** + * 当前记录所属的 collection name + */ + public collectionName?: string; constructor(options: RecordOptions) { - const { data, parentRecord, isNew } = options; + const { data, parentRecord, isNew, collectionName } = options; this.isNew = isNew; this.data = data; this.parentRecord = parentRecord; + this.collectionName = collectionName; } setData(data: DataType) { diff --git a/packages/core/client/src/application/collection/RecordProvider.tsx b/packages/core/client/src/application/collection/RecordProvider.tsx index d3f9833136..ab25994d79 100644 --- a/packages/core/client/src/application/collection/RecordProvider.tsx +++ b/packages/core/client/src/application/collection/RecordProvider.tsx @@ -9,16 +9,26 @@ export interface RecordProviderProps { isNew?: boolean; record?: RecordV2 | DataType; parentRecord?: RecordV2 | DataType; + /** + * 当前记录所属的 collection name + */ + collectionName?: string; } -export const RecordProviderV2: FC = ({ isNew, record, parentRecord, children }) => { +export const RecordProviderV2: FC = ({ + isNew, + record, + parentRecord, + children, + collectionName, +}) => { const parentRecordValue = useMemo(() => { if (parentRecord) { if (parentRecord instanceof RecordV2) return parentRecord; - return new RecordV2({ data: parentRecord }); + return new RecordV2({ data: parentRecord, collectionName }); } if (record instanceof RecordV2) return record.parentRecord; - }, [parentRecord, record]); + }, [collectionName, parentRecord, record]); const currentRecordValue = useMemo(() => { let res: RecordV2; @@ -27,14 +37,14 @@ export const RecordProviderV2: FC = ({ isNew, record, paren res = record; res.isNew = record.isNew || isNew; } else { - res = new RecordV2({ data: record, isNew }); + res = new RecordV2({ data: record, isNew, collectionName }); } } else { - res = new RecordV2({ isNew }); + res = new RecordV2({ isNew, collectionName }); } res.setParentRecord(parentRecordValue); return res; - }, [parentRecordValue, record, isNew]); + }, [record, parentRecordValue, isNew, collectionName]); return {children}; };