fix(AssociationSelect): missing field title in details (#1275)
* fix: missing title in default * fix: detail * refactor: avoid nullish
This commit is contained in:
parent
b27e82edf8
commit
ee7185c51c
@ -14,7 +14,7 @@ import {
|
|||||||
useCollectionFilterOptions,
|
useCollectionFilterOptions,
|
||||||
} from '../../../collection-manager';
|
} from '../../../collection-manager';
|
||||||
import { GeneralSchemaDesigner, SchemaSettings } from '../../../schema-settings';
|
import { GeneralSchemaDesigner, SchemaSettings } from '../../../schema-settings';
|
||||||
import { useDesignable, useCompile, useFieldComponentOptions } from '../../hooks';
|
import { useDesignable, useCompile, useFieldComponentOptions, useFieldTitle } from '../../hooks';
|
||||||
import { RemoteSelect, RemoteSelectProps } from '../remote-select';
|
import { RemoteSelect, RemoteSelectProps } from '../remote-select';
|
||||||
import { defaultFieldNames } from '../select';
|
import { defaultFieldNames } from '../select';
|
||||||
import { ReadPretty } from './ReadPretty';
|
import { ReadPretty } from './ReadPretty';
|
||||||
@ -66,12 +66,6 @@ const InternalAssociationSelect = connect(
|
|||||||
}
|
}
|
||||||
}, [props.value, normalizeValues]);
|
}, [props.value, normalizeValues]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!field.title) {
|
|
||||||
field.title = collectionField.uiSchema.title;
|
|
||||||
}
|
|
||||||
}, collectionField.title);
|
|
||||||
|
|
||||||
return <RemoteSelect {...props} objectValue={objectValue} value={value} service={service}></RemoteSelect>;
|
return <RemoteSelect {...props} objectValue={objectValue} value={value} service={service}></RemoteSelect>;
|
||||||
},
|
},
|
||||||
mapProps(
|
mapProps(
|
||||||
@ -118,11 +112,12 @@ AssociationSelect.Designer = () => {
|
|||||||
const initialValue = {
|
const initialValue = {
|
||||||
title: field.title === originalTitle ? undefined : field.title,
|
title: field.title === originalTitle ? undefined : field.title,
|
||||||
};
|
};
|
||||||
const sortFields = useSortFields(collectionField.target);
|
const sortFields = useSortFields(collectionField?.target);
|
||||||
|
|
||||||
const defaultSort = field.componentProps?.service?.params?.sort || [];
|
const defaultSort = field.componentProps?.service?.params?.sort || [];
|
||||||
const defaultFilter = field.componentProps?.service?.params?.filter || {};
|
const defaultFilter = field.componentProps?.service?.params?.filter || {};
|
||||||
const dataSource = useCollectionFilterOptions(collectionField.target);
|
const dataSource = useCollectionFilterOptions(collectionField?.target);
|
||||||
console.log(collectionField?.target, ['CollectionField', 'AssociationSelect'].includes(fieldSchema['x-component']));
|
useFieldTitle();
|
||||||
|
|
||||||
const sort = defaultSort?.map((item: string) => {
|
const sort = defaultSort?.map((item: string) => {
|
||||||
return item.startsWith('-')
|
return item.startsWith('-')
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
import { observer } from '@formily/react';
|
import { observer } from '@formily/react';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import { useFieldTitle } from '../../hooks';
|
||||||
import { RemoteSelect } from '../remote-select';
|
import { RemoteSelect } from '../remote-select';
|
||||||
import useServiceOptions from './useServiceOptions';
|
import useServiceOptions from './useServiceOptions';
|
||||||
|
|
||||||
export const ReadPretty = observer((props: any) => {
|
export const ReadPretty = observer((props: any) => {
|
||||||
const service = useServiceOptions(props);
|
const service = useServiceOptions(props);
|
||||||
|
useFieldTitle();
|
||||||
return <RemoteSelect.ReadPretty {...props} service={service}></RemoteSelect.ReadPretty>;
|
return <RemoteSelect.ReadPretty {...props} service={service}></RemoteSelect.ReadPretty>;
|
||||||
});
|
});
|
||||||
|
@ -6,4 +6,5 @@ export * from './useDesigner';
|
|||||||
export * from './useFieldProps';
|
export * from './useFieldProps';
|
||||||
export * from './useSchemaComponentContext';
|
export * from './useSchemaComponentContext';
|
||||||
export * from './useFieldComponentOptions';
|
export * from './useFieldComponentOptions';
|
||||||
|
export * from './useFieldTitle';
|
||||||
|
|
||||||
|
@ -0,0 +1,17 @@
|
|||||||
|
import { Field } from "@formily/core";
|
||||||
|
import { useField, useFieldSchema } from "@formily/react";
|
||||||
|
import { useEffect } from "react";
|
||||||
|
import { useCollection, useCollectionManager } from "../../collection-manager";
|
||||||
|
|
||||||
|
export const useFieldTitle = () => {
|
||||||
|
const field = useField<Field>();
|
||||||
|
const fieldSchema = useFieldSchema();
|
||||||
|
const { getField, } = useCollection();
|
||||||
|
const { getCollectionJoinField } = useCollectionManager();
|
||||||
|
const collectionField = getField(fieldSchema['name']) || getCollectionJoinField(fieldSchema['x-collection-field']);
|
||||||
|
useEffect(() => {
|
||||||
|
if (!field?.title) {
|
||||||
|
field.title = collectionField?.uiSchema?.title;
|
||||||
|
}
|
||||||
|
}, [collectionField?.uiSchema?.title]);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user