From e9e6d4a8171426c62cd9029f58b0d3981ca0e1d2 Mon Sep 17 00:00:00 2001
From: Zeke Zhang <958414905@qq.com>
Date: Thu, 8 Feb 2024 09:11:38 +0800
Subject: [PATCH] refactor(RecordV2): remove collectionName
---
.../data-block/DataBlockRequestProvider.tsx | 13 ++-------
.../client/src/data-source/record/Record.ts | 11 +-------
.../src/data-source/record/RecordProvider.tsx | 27 +++++--------------
3 files changed, 9 insertions(+), 42 deletions(-)
diff --git a/packages/core/client/src/data-source/data-block/DataBlockRequestProvider.tsx b/packages/core/client/src/data-source/data-block/DataBlockRequestProvider.tsx
index a2c6705cf9..3d506198d7 100644
--- a/packages/core/client/src/data-source/data-block/DataBlockRequestProvider.tsx
+++ b/packages/core/client/src/data-source/data-block/DataBlockRequestProvider.tsx
@@ -1,7 +1,6 @@
import { useDeepCompareEffect, useUpdateEffect } from 'ahooks';
import React, { FC, createContext, useContext } from 'react';
-import { isString } from 'lodash';
import { UseRequestResult, useAPIClient, useRequest } from '../../api-client';
import { RecordProviderV2, RecordV2 } from '../record';
import { AllDataBlockPropsV2, useDataBlockPropsV2 } from './DataBlockProvider';
@@ -110,11 +109,7 @@ export const BlockRequestProviderV2: FC = ({ children }) => {
{children}
@@ -122,11 +117,7 @@ export const BlockRequestProviderV2: FC = ({ children }) => {
{children}
diff --git a/packages/core/client/src/data-source/record/Record.ts b/packages/core/client/src/data-source/record/Record.ts
index 547d7c905e..78082d819a 100644
--- a/packages/core/client/src/data-source/record/Record.ts
+++ b/packages/core/client/src/data-source/record/Record.ts
@@ -2,26 +2,17 @@ export interface RecordOptionsV2 {
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: RecordOptionsV2) {
- const { data, parentRecord, isNew, collectionName } = options;
+ const { data, parentRecord, isNew } = options;
this.isNew = isNew;
this.data = data;
this.parentRecord = parentRecord;
- this.collectionName = collectionName;
}
setData(data: DataType) {
diff --git a/packages/core/client/src/data-source/record/RecordProvider.tsx b/packages/core/client/src/data-source/record/RecordProvider.tsx
index db22c16e68..7fba0d7013 100644
--- a/packages/core/client/src/data-source/record/RecordProvider.tsx
+++ b/packages/core/client/src/data-source/record/RecordProvider.tsx
@@ -9,31 +9,16 @@ export interface RecordProviderPropsV2 {
isNew?: boolean;
record?: RecordV2 | DataType;
parentRecord?: RecordV2 | DataType;
- /**
- * 当前记录所属的 collection name
- */
- collectionName?: string;
- /**
- * 当前记录所属的父级 collection name
- */
- parentCollectionName?: string;
}
-export const RecordProviderV2: FC = ({
- isNew,
- record,
- parentRecord,
- children,
- collectionName,
- parentCollectionName,
-}) => {
+export const RecordProviderV2: FC = ({ isNew, record, parentRecord, children }) => {
const parentRecordValue = useMemo(() => {
if (parentRecord) {
if (parentRecord instanceof RecordV2) return parentRecord;
- return new RecordV2({ data: parentRecord, collectionName: parentCollectionName });
+ return new RecordV2({ data: parentRecord });
}
if (record instanceof RecordV2) return record.parentRecord;
- }, [parentCollectionName, parentRecord, record]);
+ }, [parentRecord, record]);
const currentRecordValue = useMemo(() => {
let res: RecordV2;
@@ -42,14 +27,14 @@ export const RecordProviderV2: FC = ({
res = record;
res.isNew = record.isNew || isNew;
} else {
- res = new RecordV2({ data: record, isNew, collectionName });
+ res = new RecordV2({ data: record, isNew });
}
} else {
- res = new RecordV2({ isNew, collectionName });
+ res = new RecordV2({ isNew });
}
res.setParentRecord(parentRecordValue);
return res;
- }, [record, parentRecordValue, isNew, collectionName]);
+ }, [record, parentRecordValue, isNew]);
return {children};
};