mirror of
https://github.com/strapi/strapi.git
synced 2025-08-09 09:14:49 +00:00
parent
65cc815a18
commit
c921bcc063
@ -1,9 +1,9 @@
|
||||
/* eslint-disable react-hooks/exhaustive-deps */
|
||||
import React, { useState, useEffect, useRef, memo } from 'react';
|
||||
import React, { useState, useEffect, useMemo, useRef, memo } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { FormattedMessage } from 'react-intl';
|
||||
import { Link, useLocation } from 'react-router-dom';
|
||||
import { cloneDeep, get, isArray, isEmpty } from 'lodash';
|
||||
import { cloneDeep, findIndex, get, isArray, isEmpty } from 'lodash';
|
||||
import { request } from 'strapi-helper-plugin';
|
||||
import pluginId from '../../pluginId';
|
||||
import useDataManager from '../../hooks/useDataManager';
|
||||
@ -42,6 +42,22 @@ function SelectWrapper({
|
||||
const ref = useRef();
|
||||
const startRef = useRef();
|
||||
|
||||
const filteredOptions = useMemo(() => {
|
||||
return options.filter(option => {
|
||||
if (!isEmpty(value)) {
|
||||
// SelectMany
|
||||
if (Array.isArray(value)) {
|
||||
return findIndex(value, o => o.id === option.value.id) === -1;
|
||||
}
|
||||
|
||||
// SelectOne
|
||||
return get(value, 'id', '') !== option.value.id;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}, [options, value]);
|
||||
|
||||
startRef.current = state._start;
|
||||
|
||||
ref.current = async () => {
|
||||
@ -193,7 +209,7 @@ function SelectWrapper({
|
||||
move={moveRelation}
|
||||
name={name}
|
||||
nextSearch={nextSearch}
|
||||
options={options}
|
||||
options={filteredOptions}
|
||||
onChange={value => {
|
||||
onChange({ target: { name, value: value ? value.value : value } });
|
||||
}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user