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:
parent
b11c22798a
commit
b92e9d1b69
@ -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,
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user