mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-09 23:49:27 +08:00
refactor: external data source collection manager (#4193)
* refactor: data source collection manager * refactor: data source collection manager
This commit is contained in:
parent
402e14500a
commit
c5d8a7e251
@ -16,7 +16,7 @@ export class PasswordFieldInterface extends CollectionFieldInterface {
|
|||||||
'x-component': 'Password',
|
'x-component': 'Password',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
availableTypes = ['password'];
|
availableTypes = ['password', 'string'];
|
||||||
hasDefaultValue = true;
|
hasDefaultValue = true;
|
||||||
properties = {
|
properties = {
|
||||||
...defaultProps,
|
...defaultProps,
|
||||||
|
@ -84,6 +84,32 @@ export const CollectionFields = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const dm = useDataSourceManager();
|
const dm = useDataSourceManager();
|
||||||
|
|
||||||
|
let isProcessing = false;
|
||||||
|
const queue = [];
|
||||||
|
|
||||||
|
const processQueue = async () => {
|
||||||
|
if (isProcessing) return;
|
||||||
|
if (queue.length === 0) return;
|
||||||
|
|
||||||
|
isProcessing = true;
|
||||||
|
const { value, filterByTk, flag } = queue.shift();
|
||||||
|
|
||||||
|
try {
|
||||||
|
await handleFieldChange(value, filterByTk, flag);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error processing handleFieldChange:', error);
|
||||||
|
} finally {
|
||||||
|
isProcessing = false;
|
||||||
|
processQueue();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const enqueueChange = (value, filterByTk, flag) => {
|
||||||
|
queue.push({ value, filterByTk, flag });
|
||||||
|
processQueue();
|
||||||
|
};
|
||||||
|
|
||||||
const handleFieldChange = async (value, filterByTk, flag = true) => {
|
const handleFieldChange = async (value, filterByTk, flag = true) => {
|
||||||
await api.request({
|
await api.request({
|
||||||
url: `dataSourcesCollections/${dataSourceKey}.${name}/fields:update?filterByTk=${filterByTk}`,
|
url: `dataSourcesCollections/${dataSourceKey}.${name}/fields:update?filterByTk=${filterByTk}`,
|
||||||
@ -173,7 +199,7 @@ export const CollectionFields = () => {
|
|||||||
scope={{
|
scope={{
|
||||||
useDataSource,
|
useDataSource,
|
||||||
useTitleFieldProps,
|
useTitleFieldProps,
|
||||||
handleFieldChange,
|
enqueueChange,
|
||||||
useDestroyActionAndRefreshCM,
|
useDestroyActionAndRefreshCM,
|
||||||
useBulkDestroyActionAndRefreshCM,
|
useBulkDestroyActionAndRefreshCM,
|
||||||
loadCollections,
|
loadCollections,
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
import { observer, useForm, useField } from '@formily/react';
|
import { observer, useForm, useField } from '@formily/react';
|
||||||
import { Select, Tag } from 'antd';
|
import { Select, Tag } from 'antd';
|
||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { useCompile, useCollectionManager_deprecated, useRecord, useFieldInterfaceOptions } from '@nocobase/client';
|
import {
|
||||||
|
useCompile,
|
||||||
|
useCollectionManager_deprecated,
|
||||||
|
useFieldInterfaceOptions,
|
||||||
|
useCollectionRecord,
|
||||||
|
} from '@nocobase/client';
|
||||||
|
|
||||||
const getInterfaceOptions = (data, type) => {
|
const getInterfaceOptions = (data, type) => {
|
||||||
const interfaceOptions = [];
|
const interfaceOptions = [];
|
||||||
@ -26,17 +31,14 @@ const isValueInOptions = (value, options) => {
|
|||||||
export const CollectionFieldInterfaceSelect = observer(
|
export const CollectionFieldInterfaceSelect = observer(
|
||||||
(props: any) => {
|
(props: any) => {
|
||||||
const { value, handleFieldChange } = props;
|
const { value, handleFieldChange } = props;
|
||||||
const record = useRecord();
|
const { data: record } = useCollectionRecord() as any;
|
||||||
const { getInterface } = useCollectionManager_deprecated();
|
const { getInterface } = useCollectionManager_deprecated();
|
||||||
const compile = useCompile();
|
const compile = useCompile();
|
||||||
const initOptions = useFieldInterfaceOptions();
|
const initOptions = useFieldInterfaceOptions();
|
||||||
const data = getInterfaceOptions(initOptions, record.type);
|
const data = getInterfaceOptions(initOptions, record.type);
|
||||||
const form = useForm();
|
|
||||||
const field = useField();
|
|
||||||
const [selectValue, setSelectValue] = useState(value);
|
const [selectValue, setSelectValue] = useState(value);
|
||||||
const [options, setOptions] = useState(data);
|
const [options, setOptions] = useState(data);
|
||||||
const targetRecord = Object.values(form.values)?.[0]?.[field.index];
|
const targetType = record.type;
|
||||||
const targetType = targetRecord?.type || record.type;
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
//只有一个选项的时候选中该选项
|
//只有一个选项的时候选中该选项
|
||||||
if (options.length === 1 && options[0]?.children?.length === 1) {
|
if (options.length === 1 && options[0]?.children?.length === 1) {
|
||||||
@ -71,8 +73,6 @@ export const CollectionFieldInterfaceSelect = observer(
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (record?.possibleTypes) {
|
if (record?.possibleTypes) {
|
||||||
const targetRecord = Object.values(form.values)?.[0]?.[field.index];
|
|
||||||
const targetType = targetRecord?.type || record.type;
|
|
||||||
const newOptions = getInterfaceOptions(initOptions, targetType);
|
const newOptions = getInterfaceOptions(initOptions, targetType);
|
||||||
setOptions(newOptions);
|
setOptions(newOptions);
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,7 @@ export const fieldsTableSchema: ISchema = {
|
|||||||
type: 'string',
|
type: 'string',
|
||||||
'x-component': 'FieldTitleInput',
|
'x-component': 'FieldTitleInput',
|
||||||
'x-component-props': {
|
'x-component-props': {
|
||||||
handleFieldChange: '{{handleFieldChange}}',
|
handleFieldChange: '{{enqueueChange}}',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -167,7 +167,7 @@ export const fieldsTableSchema: ISchema = {
|
|||||||
type: {
|
type: {
|
||||||
'x-component': 'FieldType',
|
'x-component': 'FieldType',
|
||||||
'x-component-props': {
|
'x-component-props': {
|
||||||
handleFieldChange: '{{handleFieldChange}}',
|
handleFieldChange: '{{enqueueChange}}',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -181,7 +181,7 @@ export const fieldsTableSchema: ISchema = {
|
|||||||
interface: {
|
interface: {
|
||||||
'x-component': 'CollectionFieldInterfaceSelect',
|
'x-component': 'CollectionFieldInterfaceSelect',
|
||||||
'x-component-props': {
|
'x-component-props': {
|
||||||
handleFieldChange: '{{handleFieldChange}}',
|
handleFieldChange: '{{enqueueChange}}',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user