fix: missing filter for already associated data when adding association data (#6750)

* fix: missing filter for already associated data when adding association collection table

* fix: bug
This commit is contained in:
Katherine 2025-04-23 11:39:54 +08:00 committed by GitHub
parent 174693e219
commit 7340a7d187
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -7,7 +7,7 @@
* For more information, please refer to: https://www.nocobase.com/agreement.
*/
import React, { useState, useContext } from 'react';
import React, { useState, useContext, useEffect } from 'react';
import { RecordPickerProvider, RecordPickerContext } from '../../../schema-component/antd/record-picker';
import {
SchemaComponentOptions,
@ -41,9 +41,16 @@ const useTableSelectorProps = () => {
export const AssociateActionProvider = (props) => {
const [selectedRows, setSelectedRows] = useState([]);
const collection = useCollection();
const { resource, service, block, __parent } = useBlockRequestContext();
const { resource, block, __parent } = useBlockRequestContext();
const actionCtx = useActionContext();
const { isMobile } = useOpenModeContext() || {};
const [associationData, setAssociationData] = useState([]);
useEffect(() => {
resource?.list?.().then((res) => {
setAssociationData(res.data?.data || []);
});
}, [resource]);
const pickerProps = {
size: 'small',
onChange: props?.onChange,
@ -73,8 +80,8 @@ export const AssociateActionProvider = (props) => {
};
const getFilter = () => {
const targetKey = collection?.filterTargetKey || 'id';
if (service.data?.data) {
const list = service.data?.data.map((option) => option[targetKey]).filter(Boolean);
if (associationData) {
const list = associationData.map((option) => option[targetKey]).filter(Boolean);
const filter = list.length ? { $and: [{ [`${targetKey}.$ne`]: list }] } : {};
return filter;
}