fix: data filtering and formula field value errors after subtable record selection (#4547)

* fix: data filter issue after selecting records in subtable

* fix: bug

* fix: bug

* fix: bug

* fix: bug
This commit is contained in:
Katherine 2024-06-04 11:05:42 +08:00 committed by GitHub
parent 1b1930b328
commit e842cd4cab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 7 deletions

View File

@ -99,20 +99,19 @@ export const SubTable: any = observer(
}; };
const usePickActionProps = () => { const usePickActionProps = () => {
const { setVisible } = useActionContext(); const { setVisible } = useActionContext();
const { selectedRows, options, collectionField } = useContext(RecordPickerContext); const { selectedRows, setSelectedRows } = useContext(RecordPickerContext);
return { return {
onClick() { onClick() {
const selectData = unionBy(selectedRows, options, collectionField?.targetKey || 'id'); selectedRows.map((v) => field.value.push(markRecordAsNew({ ...v })));
const data = field.value || [];
field.value = uniqBy(data.concat(selectData), collectionField?.targetKey || 'id');
field.onInput(field.value); field.onInput(field.value);
setSelectedRows([]);
setVisible(false); setVisible(false);
}, },
}; };
}; };
const getFilter = () => { const getFilter = () => {
const targetKey = collectionField?.targetKey || 'id'; const targetKey = collectionField?.targetKey || 'id';
const list = options.map((option) => option[targetKey]).filter(Boolean); const list = (field.value || []).map((option) => option[targetKey]).filter(Boolean);
const filter = list.length ? { $and: [{ [`${targetKey}.$ne`]: list }] } : {}; const filter = list.length ? { $and: [{ [`${targetKey}.$ne`]: list }] } : {};
return filter; return filter;
}; };

View File

@ -75,7 +75,6 @@ export function Result(props) {
const fieldName = fieldPath.split('.')[0]; const fieldName = fieldPath.split('.')[0];
const index = parseInt(fieldPath.split('.')?.[1]); const index = parseInt(fieldPath.split('.')?.[1]);
const ctx = useContext(ActionContext); const ctx = useContext(ActionContext);
useEffect(() => { useEffect(() => {
setEditingValue(value); setEditingValue(value);
}, [value]); }, [value]);
@ -85,7 +84,8 @@ export function Result(props) {
if ( if (
(fieldSchema.name as string).indexOf('.') >= 0 || (fieldSchema.name as string).indexOf('.') >= 0 ||
!formBlockContext?.form || !formBlockContext?.form ||
formBlockContext.form?.readPretty formBlockContext.form?.readPretty ||
fieldSchema['x-decorator'] !== 'FormItem'
) { ) {
return; return;
} }