mirror of
https://github.com/strapi/strapi.git
synced 2025-08-10 17:58:07 +00:00
parent
65cc815a18
commit
c921bcc063
@ -1,9 +1,9 @@
|
|||||||
/* eslint-disable react-hooks/exhaustive-deps */
|
/* 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 PropTypes from 'prop-types';
|
||||||
import { FormattedMessage } from 'react-intl';
|
import { FormattedMessage } from 'react-intl';
|
||||||
import { Link, useLocation } from 'react-router-dom';
|
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 { request } from 'strapi-helper-plugin';
|
||||||
import pluginId from '../../pluginId';
|
import pluginId from '../../pluginId';
|
||||||
import useDataManager from '../../hooks/useDataManager';
|
import useDataManager from '../../hooks/useDataManager';
|
||||||
@ -42,6 +42,22 @@ function SelectWrapper({
|
|||||||
const ref = useRef();
|
const ref = useRef();
|
||||||
const startRef = 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;
|
startRef.current = state._start;
|
||||||
|
|
||||||
ref.current = async () => {
|
ref.current = async () => {
|
||||||
@ -193,7 +209,7 @@ function SelectWrapper({
|
|||||||
move={moveRelation}
|
move={moveRelation}
|
||||||
name={name}
|
name={name}
|
||||||
nextSearch={nextSearch}
|
nextSearch={nextSearch}
|
||||||
options={options}
|
options={filteredOptions}
|
||||||
onChange={value => {
|
onChange={value => {
|
||||||
onChange({ target: { name, value: value ? value.value : value } });
|
onChange({ target: { name, value: value ? value.value : value } });
|
||||||
}}
|
}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user