Merge pull request 'refactor: remove x-compoent-custom' (#490) from fix_name_error into @hera/dev
Reviewed-on: daoyoucloud/tachycode#490
This commit is contained in:
commit
629b334422
@ -1,14 +1,11 @@
|
|||||||
import React, { useMemo } from 'react';
|
import React, { useMemo } from 'react';
|
||||||
import { Cascader } from 'antd';
|
import { Cascader } from 'antd';
|
||||||
import { connect, useFieldSchema } from '@formily/react';
|
import { connect } from '@formily/react';
|
||||||
import { useCollectionManager, useRequest } from '@nocobase/client';
|
import { useCollectionManager, useRequest } from '@nocobase/client';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
|
||||||
const AssociationCascader = connect((props) => {
|
const AssociationCascader = connect((props) => {
|
||||||
const { fieldNames } = props;
|
const { fieldNames, collection, associationField } = props;
|
||||||
const fieldSchema = useFieldSchema();
|
|
||||||
const collection = fieldSchema['collectionName'];
|
|
||||||
const associationField = props.associationField;
|
|
||||||
const cm = useCollectionManager();
|
const cm = useCollectionManager();
|
||||||
const titleField = cm.getCollection(collection).titleField;
|
const titleField = cm.getCollection(collection).titleField;
|
||||||
const joinTitleField = cm.getCollection(collection + '.' + associationField).titleField;
|
const joinTitleField = cm.getCollection(collection + '.' + associationField).titleField;
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { AutoComplete as AntdAutoComplete } from 'antd';
|
import { AutoComplete as AntdAutoComplete } from 'antd';
|
||||||
import { connect, useFieldSchema, useForm } from '@formily/react';
|
import { connect, useFieldSchema } from '@formily/react';
|
||||||
import { useAPIClient, useDesigner, useRequest } from '@nocobase/client';
|
import { useAPIClient } from '@nocobase/client';
|
||||||
import { useAsyncEffect } from 'ahooks';
|
import { useAsyncEffect } from 'ahooks';
|
||||||
import { fuzzysearch } from '../../utils';
|
import { fuzzysearch } from '../../utils';
|
||||||
|
|
||||||
export const AutoComplete = connect((props) => {
|
export const AutoComplete = connect((props) => {
|
||||||
|
const { fieldNames, params: fieldFilter } = props;
|
||||||
const fieldSchema = useFieldSchema();
|
const fieldSchema = useFieldSchema();
|
||||||
const fieldNames = props.fieldNames || fieldSchema['x-component-props'].fieldNames;
|
|
||||||
const fieldFilter = props.params;
|
|
||||||
const [defultValue, setDefultValue] = useState([]);
|
const [defultValue, setDefultValue] = useState([]);
|
||||||
const api = useAPIClient();
|
const api = useAPIClient();
|
||||||
const [options, setOptions] = useState([]);
|
const [options, setOptions] = useState([]);
|
||||||
|
@ -143,9 +143,8 @@ const useLabelOptions = (others) => {
|
|||||||
const fieldSchema = useFieldSchema();
|
const fieldSchema = useFieldSchema();
|
||||||
const { getField } = useCollection_deprecated();
|
const { getField } = useCollection_deprecated();
|
||||||
const collectionField = useMemo(() => getField(fieldSchema.name), [fieldSchema.name]);
|
const collectionField = useMemo(() => getField(fieldSchema.name), [fieldSchema.name]);
|
||||||
const collectionName = fieldSchema['x-compoent-custom'] ? fieldSchema['name'].toString().slice(7) : '';
|
|
||||||
const request = {
|
const request = {
|
||||||
resource: collectionField ? collectionField?.target : collectionName,
|
resource: collectionField?.target,
|
||||||
action: 'list',
|
action: 'list',
|
||||||
params: {
|
params: {
|
||||||
pageSize: 99999,
|
pageSize: 99999,
|
||||||
@ -208,9 +207,8 @@ const InternalSelect = connect(
|
|||||||
if (mode && !['multiple', 'tags'].includes(mode)) {
|
if (mode && !['multiple', 'tags'].includes(mode)) {
|
||||||
mode = undefined;
|
mode = undefined;
|
||||||
}
|
}
|
||||||
const fieldSchema = useFieldSchema();
|
|
||||||
const modifiedProps = useLabelOptions(others);
|
const modifiedProps = useLabelOptions(others);
|
||||||
if (objectValue || fieldSchema['x-compoent-custom']) {
|
if (objectValue) {
|
||||||
return (
|
return (
|
||||||
<ObjectSelect
|
<ObjectSelect
|
||||||
rawOptions={rawOptions}
|
rawOptions={rawOptions}
|
||||||
|
@ -298,8 +298,8 @@ export const FilterCustomItemInitializer: React.FC<{
|
|||||||
value: 'name',
|
value: 'name',
|
||||||
},
|
},
|
||||||
associationField,
|
associationField,
|
||||||
|
collection,
|
||||||
},
|
},
|
||||||
'x-compoent-custom': true,
|
|
||||||
collectionName: collection,
|
collectionName: collection,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@ -350,7 +350,6 @@ export const FilterItemCustomDesigner: React.FC = () => {
|
|||||||
{component === 'Select' || component === 'AutoComplete' ? <SchemaSettingCollection /> : null}
|
{component === 'Select' || component === 'AutoComplete' ? <SchemaSettingCollection /> : null}
|
||||||
{component === 'Select' || component === 'AutoComplete' ? <SchemaSettingComponent /> : null}
|
{component === 'Select' || component === 'AutoComplete' ? <SchemaSettingComponent /> : null}
|
||||||
{component === 'Select' || component === 'AutoComplete' ? <EditTitleField /> : null}
|
{component === 'Select' || component === 'AutoComplete' ? <EditTitleField /> : null}
|
||||||
{component === 'Select' || component === 'AutoComplete' ? <EditFormulaTitleField /> : null}
|
|
||||||
<EditDefaultValue />
|
<EditDefaultValue />
|
||||||
<SchemaSettingsDivider />
|
<SchemaSettingsDivider />
|
||||||
<SchemaSettingsRemove
|
<SchemaSettingsRemove
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Field } from '@formily/core';
|
import { Field } from '@formily/core';
|
||||||
import { ISchema, useField, useFieldSchema, useForm } from '@formily/react';
|
import { ISchema, useField, useFieldSchema } from '@formily/react';
|
||||||
import {
|
import {
|
||||||
getShouldChange,
|
getShouldChange,
|
||||||
SchemaComponent,
|
SchemaComponent,
|
||||||
@ -24,24 +24,21 @@ import {
|
|||||||
VariableScopeProvider,
|
VariableScopeProvider,
|
||||||
} from '@nocobase/client';
|
} from '@nocobase/client';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import React, { useCallback, useContext, useEffect, useMemo } from 'react';
|
import React, { useCallback, useEffect, useMemo } from 'react';
|
||||||
import { useTranslation } from '../locale';
|
import { useTranslation } from '../locale';
|
||||||
import { FormFilterScope } from '../components/filter-form/FormFilterScope';
|
import { FormFilterScope } from '../components/filter-form/FormFilterScope';
|
||||||
import { useFieldComponents } from '../schema-initializer';
|
import { useFieldComponents } from '../schema-initializer';
|
||||||
import { useMemoizedFn } from 'ahooks';
|
import { useMemoizedFn } from 'ahooks';
|
||||||
import { fieldsCollection } from '@nocobase/plugin-collection-manager';
|
|
||||||
|
|
||||||
export const useFormulaTitleOptions = () => {
|
export const useFormulaTitleOptions = () => {
|
||||||
const compile = useCompile();
|
const compile = useCompile();
|
||||||
const { getCollectionJoinField, getCollectionFields } = useCollectionManager_deprecated();
|
const { getCollectionJoinField, getCollectionFields } = useCollectionManager_deprecated();
|
||||||
const { getField } = useCollection_deprecated();
|
const { getField } = useCollection_deprecated();
|
||||||
const fieldSchema = useFieldSchema();
|
const fieldSchema = useFieldSchema();
|
||||||
const { t } = useTranslation();
|
|
||||||
const { dn } = useDesignable();
|
|
||||||
const collectionManage = useCollectionManager_deprecated();
|
const collectionManage = useCollectionManager_deprecated();
|
||||||
const collectionManageField = fieldSchema['x-compoent-custom']
|
const collectionManageField = collectionManage.collections.filter(
|
||||||
? collectionManage.collections.filter((value) => value.name === fieldSchema['x-decorator-props'])[0]
|
(value) => value.name === fieldSchema['x-decorator-props'],
|
||||||
: {};
|
)[0];
|
||||||
const collectionField = getField(fieldSchema['name']) || getCollectionJoinField(fieldSchema['x-collection-field']);
|
const collectionField = getField(fieldSchema['name']) || getCollectionJoinField(fieldSchema['x-collection-field']);
|
||||||
let fields = [];
|
let fields = [];
|
||||||
if (collectionField) {
|
if (collectionField) {
|
||||||
@ -82,10 +79,9 @@ export const useFormulaTitleVisible = () => {
|
|||||||
// FIXME 这里现在只有当设置为 select,默认为 select 的时候看不到
|
// FIXME 这里现在只有当设置为 select,默认为 select 的时候看不到
|
||||||
return (
|
return (
|
||||||
options.length > 0 &&
|
options.length > 0 &&
|
||||||
((fieldSchema['x-component-props']?.mode === 'Select' &&
|
fieldSchema['x-component-props']?.mode === 'Select' &&
|
||||||
fieldSchema['x-component-props']?.fieldNames?.value !== undefined &&
|
fieldSchema['x-component-props']?.fieldNames?.value !== undefined &&
|
||||||
fieldSchema['x-component'] === 'CollectionField') ||
|
fieldSchema['x-component'] === 'CollectionField'
|
||||||
fieldSchema['x-compoent-custom'])
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -305,7 +301,8 @@ export const EditTitleField = () => {
|
|||||||
const { dn } = useDesignable();
|
const { dn } = useDesignable();
|
||||||
const compile = useCompile();
|
const compile = useCompile();
|
||||||
const collectionManage = useCollectionManager_deprecated();
|
const collectionManage = useCollectionManager_deprecated();
|
||||||
const collectionManageField = fieldSchema['x-compoent-custom']
|
const isCustomFilterItem = ((fieldSchema?.name as string) ?? '').startsWith('custom.');
|
||||||
|
const collectionManageField = isCustomFilterItem
|
||||||
? collectionManage.collections.filter((value) => value.name === fieldSchema['x-decorator-props'])[0]
|
? collectionManage.collections.filter((value) => value.name === fieldSchema['x-decorator-props'])[0]
|
||||||
: {};
|
: {};
|
||||||
const collectionField = getField(fieldSchema['name']) || getCollectionJoinField(fieldSchema['x-collection-field']);
|
const collectionField = getField(fieldSchema['name']) || getCollectionJoinField(fieldSchema['x-collection-field']);
|
||||||
@ -324,8 +321,7 @@ export const EditTitleField = () => {
|
|||||||
label: compile(field?.uiSchema?.title) || field?.name,
|
label: compile(field?.uiSchema?.title) || field?.name,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return options.length > 0 &&
|
return options.length > 0 && (fieldSchema['x-component'] === 'CollectionField' || isCustomFilterItem) ? (
|
||||||
(fieldSchema['x-component'] === 'CollectionField' || fieldSchema['x-compoent-custom']) ? (
|
|
||||||
<SchemaSettingsSelectItem
|
<SchemaSettingsSelectItem
|
||||||
key="title-field"
|
key="title-field"
|
||||||
title={t('Title field')}
|
title={t('Title field')}
|
||||||
|
Loading…
Reference in New Issue
Block a user