fix(数据表): 树数据表-级联修复,修复级联选择编辑无显示 (#1583)
Reviewed-on: daoyoucloud/tachybase#1583 Co-authored-by: wjh <wwwjh0710@163.com> Co-committed-by: wjh <wwwjh0710@163.com>
This commit is contained in:
parent
4cda546880
commit
725e31871c
@ -45,6 +45,7 @@ const CascadeSelect = connect((props) => {
|
|||||||
const resource = api.resource(collectionField.target);
|
const resource = api.resource(collectionField.target);
|
||||||
const { getCollectionJoinField, getInterface } = useCollectionManager_deprecated();
|
const { getCollectionJoinField, getInterface } = useCollectionManager_deprecated();
|
||||||
const fieldNames = associationField?.componentProps?.fieldNames;
|
const fieldNames = associationField?.componentProps?.fieldNames;
|
||||||
|
const [change, setChange] = useState(false);
|
||||||
const targetField =
|
const targetField =
|
||||||
collectionField?.target &&
|
collectionField?.target &&
|
||||||
fieldNames?.label &&
|
fieldNames?.label &&
|
||||||
@ -57,7 +58,7 @@ const CascadeSelect = connect((props) => {
|
|||||||
}, [targetField]);
|
}, [targetField]);
|
||||||
const field: any = useField();
|
const field: any = useField();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (value) {
|
if (value && !change) {
|
||||||
const values = Array.isArray(value)
|
const values = Array.isArray(value)
|
||||||
? extractLastNonNullValueObjects(
|
? extractLastNonNullValueObjects(
|
||||||
value?.filter((v) => v.value),
|
value?.filter((v) => v.value),
|
||||||
@ -73,7 +74,7 @@ const CascadeSelect = connect((props) => {
|
|||||||
});
|
});
|
||||||
setSelectedOptions(options);
|
setSelectedOptions(options);
|
||||||
}
|
}
|
||||||
}, []);
|
}, [value]);
|
||||||
const mapOptionsToTags = useCallback(
|
const mapOptionsToTags = useCallback(
|
||||||
(options) => {
|
(options) => {
|
||||||
try {
|
try {
|
||||||
@ -140,6 +141,7 @@ const CascadeSelect = connect((props) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleSelect = async (value, option, index) => {
|
const handleSelect = async (value, option, index) => {
|
||||||
|
setChange(true);
|
||||||
const data = await handleGetOptions({ parentId: option?.id });
|
const data = await handleGetOptions({ parentId: option?.id });
|
||||||
const options = [...selectedOptions];
|
const options = [...selectedOptions];
|
||||||
options.splice(index + 1);
|
options.splice(index + 1);
|
||||||
@ -272,6 +274,13 @@ export const InternalCascadeSelect = observer(
|
|||||||
return [{}];
|
return [{}];
|
||||||
};
|
};
|
||||||
const defaultValue = toValue();
|
const defaultValue = toValue();
|
||||||
|
useEffect(() => {
|
||||||
|
const isChange = selectForm.values?.select_array?.filter((value) => value && Object.keys(value).length);
|
||||||
|
if (collectionField.interface !== 'm2o' && props.value && !isChange.length) {
|
||||||
|
const value = extractLastNonNullValueObjects(defaultValue).filter((v) => v && Object.keys(v).length > 0);
|
||||||
|
selectForm.setValues({ select_array: value });
|
||||||
|
}
|
||||||
|
}, [props.value]);
|
||||||
const schema = {
|
const schema = {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
@ -315,26 +324,24 @@ export const InternalCascadeSelect = observer(
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
props.value !== null && (
|
<FormProvider form={selectForm}>
|
||||||
<FormProvider form={selectForm}>
|
{collectionField.interface === 'm2o' ? (
|
||||||
{collectionField.interface === 'm2o' ? (
|
<SchemaComponent
|
||||||
<SchemaComponent
|
components={{ FormItem }}
|
||||||
components={{ FormItem }}
|
schema={{
|
||||||
schema={{
|
...fieldSchema,
|
||||||
...fieldSchema,
|
default: field.value,
|
||||||
default: field.value,
|
title: '',
|
||||||
title: '',
|
'x-component': AssociationCascadeSelect,
|
||||||
'x-component': AssociationCascadeSelect,
|
'x-component-props': {
|
||||||
'x-component-props': {
|
...props,
|
||||||
...props,
|
},
|
||||||
},
|
}}
|
||||||
}}
|
/>
|
||||||
/>
|
) : (
|
||||||
) : (
|
<SchemaField schema={schema} />
|
||||||
<SchemaField schema={schema} />
|
)}
|
||||||
)}
|
</FormProvider>
|
||||||
</FormProvider>
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
{ displayName: 'InternalCascadeSelect' },
|
{ displayName: 'InternalCascadeSelect' },
|
||||||
|
@ -56,12 +56,12 @@ const Cascade = connect((props) => {
|
|||||||
const changOnSelect = fieldSchema['x-component-props']?.changOnSelect || false;
|
const changOnSelect = fieldSchema['x-component-props']?.changOnSelect || false;
|
||||||
const field: any = useField();
|
const field: any = useField();
|
||||||
const [selectedOptions, setSelectedOptions] = useState([]);
|
const [selectedOptions, setSelectedOptions] = useState([]);
|
||||||
const [chang, setChang] = useState(false);
|
const [change, setChange] = useState(false);
|
||||||
const [dataList, setDataList] = useState({});
|
const [dataList, setDataList] = useState({});
|
||||||
const { styles } = useStyles();
|
const { styles } = useStyles();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const propsValue = props.value || fieldSchema['x-component-props'].value;
|
const propsValue = props.value || fieldSchema['x-component-props'].value;
|
||||||
if (!chang && propsValue) {
|
if (!change && propsValue) {
|
||||||
if (!propsValue.parent && !Object.keys(dataList).length) {
|
if (!propsValue.parent && !Object.keys(dataList).length) {
|
||||||
resource
|
resource
|
||||||
.list({
|
.list({
|
||||||
@ -116,7 +116,7 @@ const Cascade = connect((props) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleSelect = async (option) => {
|
const handleSelect = async (option) => {
|
||||||
setChang(true);
|
setChange(true);
|
||||||
if (option) {
|
if (option) {
|
||||||
if (['o2m', 'm2m'].includes(collectionField.interface)) {
|
if (['o2m', 'm2m'].includes(collectionField.interface)) {
|
||||||
const fieldValue = Array.isArray(associationField.fieldValue) ? associationField.fieldValue : [];
|
const fieldValue = Array.isArray(associationField.fieldValue) ? associationField.fieldValue : [];
|
||||||
@ -243,6 +243,13 @@ export const InternalCascader = observer(
|
|||||||
return [{}];
|
return [{}];
|
||||||
};
|
};
|
||||||
const defaultValue = toValue();
|
const defaultValue = toValue();
|
||||||
|
useEffect(() => {
|
||||||
|
const isChange = selectForm.values?.select_array?.filter((value) => value && Object.keys(value).length);
|
||||||
|
if (collectionField.interface !== 'm2o' && props.value && !isChange.length) {
|
||||||
|
selectForm.setInitialValues({ select_array: defaultValue });
|
||||||
|
}
|
||||||
|
}, [props.value]);
|
||||||
|
|
||||||
const schema = {
|
const schema = {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
|
Loading…
Reference in New Issue
Block a user