mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-04 21:19:27 +08:00
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:
parent
174693e219
commit
7340a7d187
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user