fix: should load association data in subform (#3020)

* fix: should load association data in subform

* fix: make test passing

* fix: avoid error
This commit is contained in:
被雨水过滤的空气-Rain 2023-11-10 22:28:05 +08:00 committed by GitHub
parent b11c22798a
commit b92e9d1b69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 12 deletions

View File

@ -15,12 +15,12 @@ import {
import { CollectionProvider, useCollection, useCollectionManager } from '../../../collection-manager';
import { useCompile } from '../../hooks';
import { ActionContextProvider } from '../action';
import { EllipsisWithTooltip } from '../input';
import { FileSelector, Preview } from '../preview';
import { ReadPrettyInternalViewer } from './InternalViewer';
import { useFieldNames, useInsertSchema } from './hooks';
import schema from './schema';
import { flatData, getLabelFormatValue, isShowFilePicker, useLabelUiSchema } from './util';
import { EllipsisWithTooltip } from '../input';
const useTableSelectorProps = () => {
const field: any = useField();
@ -88,7 +88,7 @@ const InternalFileManager = (props) => {
useEffect(() => {
if (value && Object.keys(value).length > 0) {
const opts = (Array.isArray(value) ? value : value ? [value] : []).map((option) => {
const opts = (Array.isArray(value) ? value : value ? [value] : []).filter(Boolean).map((option) => {
const label = option[fieldNames.label];
return {
...option,

View File

@ -21,13 +21,21 @@ const useLazyLoadAssociationFieldOfForm = () => {
const fieldSchema = useFieldSchema();
const variables = useVariables();
const field = useField<Field>();
const { isInAssignFieldValues } = useFlag() || {};
const { isInAssignFieldValues, isInSubForm, isInSubTable } = useFlag() || {};
const { type: formBlockType } = useFormBlockType();
const schemaName = fieldSchema.name.toString();
useEffect(() => {
if (isInAssignFieldValues || formBlockType === 'create') {
const cloneRecord = { ...record };
delete cloneRecord['__parent'];
delete cloneRecord['__collectionName'];
if (
isInAssignFieldValues ||
_.isEmpty(cloneRecord) ||
(formBlockType === 'create' && !isInSubForm && !isInSubTable)
) {
return;
}
@ -37,11 +45,7 @@ const useLazyLoadAssociationFieldOfForm = () => {
return;
}
const cloneRecord = { ...record };
delete cloneRecord['__parent'];
delete cloneRecord['__collectionName'];
if (_.isEmpty(cloneRecord) || !variables || record[schemaName] != null) {
if (!variables || record[schemaName] != null) {
return;
}
@ -70,7 +74,7 @@ const useLazyLoadAssociationFieldOfForm = () => {
.catch((err) => {
console.error(err);
});
}, []);
}, [record]);
};
export default useLazyLoadAssociationFieldOfForm;

View File

@ -288,8 +288,8 @@ export default VariablesProvider;
*/
function shouldToRequest(value) {
// fix https://nocobase.height.app/T-2502
// 兼容对多子表单子表格字段的情况
if (JSON.stringify(value) === '[{}]') {
// 兼容 `对多` 和 `对一` 子表单子表格字段的情况
if (JSON.stringify(value) === '[{}]' || JSON.stringify(value) === '{}') {
return true;
}