mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 05:29:26 +08:00
refactor: remove rowKey from table block schema creation (#6792)
* refactor: remove rowKey from table block schema creation * chore: fix unit test
This commit is contained in:
parent
1b4b71bba4
commit
281b813f0c
@ -61,14 +61,11 @@ export const TableBlockInitializer = ({
|
|||||||
|
|
||||||
export const useCreateTableBlock = () => {
|
export const useCreateTableBlock = () => {
|
||||||
const { insert } = useSchemaInitializer();
|
const { insert } = useSchemaInitializer();
|
||||||
const { getCollection } = useCollectionManager_deprecated();
|
|
||||||
|
|
||||||
const createTableBlock = ({ item }) => {
|
const createTableBlock = ({ item }) => {
|
||||||
const collection = getCollection(item.name, item.dataSource);
|
|
||||||
const schema = createTableBlockUISchema({
|
const schema = createTableBlockUISchema({
|
||||||
collectionName: item.name,
|
collectionName: item.name,
|
||||||
dataSource: item.dataSource,
|
dataSource: item.dataSource,
|
||||||
rowKey: collection.filterTargetKey || 'id',
|
|
||||||
});
|
});
|
||||||
insert(schema);
|
insert(schema);
|
||||||
};
|
};
|
||||||
|
@ -17,7 +17,7 @@ vi.mock('@formily/shared', () => {
|
|||||||
|
|
||||||
describe('createTableBLockSchemaV2', () => {
|
describe('createTableBLockSchemaV2', () => {
|
||||||
it('should create a default table block schema with minimum options', () => {
|
it('should create a default table block schema with minimum options', () => {
|
||||||
const options = { dataSource: 'abc', collectionName: 'users', association: 'users.roles', rowKey: 'rowKey' };
|
const options = { dataSource: 'abc', collectionName: 'users', association: 'users.roles' };
|
||||||
const schema = createTableBlockUISchema(options);
|
const schema = createTableBlockUISchema(options);
|
||||||
|
|
||||||
expect(schema).toMatchInlineSnapshot(`
|
expect(schema).toMatchInlineSnapshot(`
|
||||||
@ -85,7 +85,6 @@ describe('createTableBLockSchemaV2', () => {
|
|||||||
"params": {
|
"params": {
|
||||||
"pageSize": 20,
|
"pageSize": 20,
|
||||||
},
|
},
|
||||||
"rowKey": "rowKey",
|
|
||||||
"showIndex": true,
|
"showIndex": true,
|
||||||
},
|
},
|
||||||
"x-filter-targets": [],
|
"x-filter-targets": [],
|
||||||
|
@ -13,10 +13,9 @@ import { uid } from '@formily/shared';
|
|||||||
export const createTableBlockUISchema = (options: {
|
export const createTableBlockUISchema = (options: {
|
||||||
dataSource: string;
|
dataSource: string;
|
||||||
collectionName?: string;
|
collectionName?: string;
|
||||||
rowKey?: string;
|
|
||||||
association?: string;
|
association?: string;
|
||||||
}): ISchema => {
|
}): ISchema => {
|
||||||
const { collectionName, dataSource, rowKey, association } = options;
|
const { collectionName, dataSource, association } = options;
|
||||||
|
|
||||||
if (!dataSource) {
|
if (!dataSource) {
|
||||||
throw new Error('dataSource is required');
|
throw new Error('dataSource is required');
|
||||||
@ -35,7 +34,6 @@ export const createTableBlockUISchema = (options: {
|
|||||||
params: {
|
params: {
|
||||||
pageSize: 20,
|
pageSize: 20,
|
||||||
},
|
},
|
||||||
rowKey,
|
|
||||||
showIndex: true,
|
showIndex: true,
|
||||||
dragSort: false,
|
dragSort: false,
|
||||||
},
|
},
|
||||||
|
@ -11,15 +11,19 @@ import { useFieldSchema } from '@formily/react';
|
|||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
import { useParsedFilter } from '../../../../../block-provider/hooks/useParsedFilter';
|
import { useParsedFilter } from '../../../../../block-provider/hooks/useParsedFilter';
|
||||||
import { useParentRecordCommon } from '../../../useParentRecordCommon';
|
import { useParentRecordCommon } from '../../../useParentRecordCommon';
|
||||||
|
import { useDataSourceManager } from '../../../../../data-source';
|
||||||
|
|
||||||
export const useTableBlockDecoratorProps = (props) => {
|
export const useTableBlockDecoratorProps = (props) => {
|
||||||
const { params, parseVariableLoading } = useTableBlockParams(props);
|
const { params, parseVariableLoading } = useTableBlockParams(props);
|
||||||
const parentRecord = useParentRecordCommon(props.association);
|
const parentRecord = useParentRecordCommon(props.association);
|
||||||
|
const dm = useDataSourceManager();
|
||||||
|
const collection = dm.getDataSource(props.dataSource)?.collectionManager.getCollection(props.collection);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
params,
|
params,
|
||||||
parentRecord,
|
parentRecord,
|
||||||
parseVariableLoading,
|
parseVariableLoading,
|
||||||
|
rowKey: collection?.filterTargetKey || 'id',
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -39,7 +39,6 @@ export const RecordAssociationBlockInitializer = () => {
|
|||||||
} else {
|
} else {
|
||||||
insert(
|
insert(
|
||||||
createTableBlockUISchema({
|
createTableBlockUISchema({
|
||||||
rowKey: collection.filterTargetKey,
|
|
||||||
dataSource: collection.dataSource,
|
dataSource: collection.dataSource,
|
||||||
association: association,
|
association: association,
|
||||||
}),
|
}),
|
||||||
@ -62,7 +61,6 @@ export function useCreateAssociationTableBlock() {
|
|||||||
|
|
||||||
insert(
|
insert(
|
||||||
createTableBlockUISchema({
|
createTableBlockUISchema({
|
||||||
rowKey: collection.filterTargetKey,
|
|
||||||
dataSource: collection.dataSource,
|
dataSource: collection.dataSource,
|
||||||
association: `${field.collectionName}.${field.name}`,
|
association: `${field.collectionName}.${field.name}`,
|
||||||
}),
|
}),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user