This commit is contained in:
soupette 2019-10-01 16:25:08 +02:00
parent ea0b72fe00
commit 2dc5df9595
3 changed files with 13 additions and 4 deletions

View File

@ -16,9 +16,10 @@ function ListItem({
moveRelation, moveRelation,
nextSearch, nextSearch,
onRemove, onRemove,
source,
targetModel, targetModel,
}) { }) {
const to = `/plugins/${pluginId}/${targetModel}/${data.id}?redirectUrl=${nextSearch}`; const to = `/plugins/${pluginId}/${targetModel}/${data.id}?source=${source}&redirectUrl=${nextSearch}`;
const originalIndex = findRelation(data.id).index; const originalIndex = findRelation(data.id).index;
const [{ isDragging }, drag, preview] = useDrag({ const [{ isDragging }, drag, preview] = useDrag({
@ -72,6 +73,7 @@ ListItem.propTypes = {
moveRelation: PropTypes.func, moveRelation: PropTypes.func,
nextSearch: PropTypes.string, nextSearch: PropTypes.string,
onRemove: PropTypes.func, onRemove: PropTypes.func,
source: PropTypes.string.isRequired,
targetModel: PropTypes.string, targetModel: PropTypes.string,
}; };

View File

@ -23,6 +23,7 @@ function SelectMany({
onRemove, onRemove,
options, options,
placeholder, placeholder,
source,
targetModel, targetModel,
value, value,
}) { }) {
@ -62,7 +63,8 @@ function SelectMany({
id={name} id={name}
filterOption={(candidate, input) => { filterOption={(candidate, input) => {
if (!isEmpty(value)) { if (!isEmpty(value)) {
const isSelected = value.findIndex(item => item.id === candidate.value.id) !== -1; const isSelected =
value.findIndex(item => item.id === candidate.value.id) !== -1;
if (isSelected) { if (isSelected) {
return false; return false;
} }
@ -98,6 +100,7 @@ function SelectMany({
moveRelation={moveRelation} moveRelation={moveRelation}
nextSearch={nextSearch} nextSearch={nextSearch}
onRemove={() => onRemove(`${name}.${index}`)} onRemove={() => onRemove(`${name}.${index}`)}
source={source}
targetModel={targetModel} targetModel={targetModel}
/> />
))} ))}
@ -111,6 +114,7 @@ function SelectMany({
SelectMany.defaultProps = { SelectMany.defaultProps = {
move: () => {}, move: () => {},
source: 'content-manager',
value: null, value: null,
}; };
@ -128,6 +132,7 @@ SelectMany.propTypes = {
onRemove: PropTypes.func.isRequired, onRemove: PropTypes.func.isRequired,
options: PropTypes.array.isRequired, options: PropTypes.array.isRequired,
placeholder: PropTypes.node.isRequired, placeholder: PropTypes.node.isRequired,
source: PropTypes.string,
targetModel: PropTypes.string.isRequired, targetModel: PropTypes.string.isRequired,
value: PropTypes.array, value: PropTypes.array,
}; };

View File

@ -32,11 +32,12 @@ function SelectWrapper({
pathname, pathname,
search, search,
} = useEditView(); } = useEditView();
const source = isEmpty(plugin) ? 'content-manager' : plugin;
const [state, setState] = useState({ const [state, setState] = useState({
_q: '', _q: '',
_limit: 20, _limit: 20,
_start: 0, _start: 0,
source: isEmpty(plugin) ? 'content-manager' : plugin, source,
}); });
const [options, setOptions] = useState([]); const [options, setOptions] = useState([]);
const [isLoading, setIsLoading] = useState(true); const [isLoading, setIsLoading] = useState(true);
@ -128,7 +129,7 @@ function SelectWrapper({
const nextSearch = `${pathname}${search}`; const nextSearch = `${pathname}${search}`;
const to = `/plugins/${pluginId}/${targetModel}/${ const to = `/plugins/${pluginId}/${targetModel}/${
value ? value.id : null value ? value.id : null
}?redirectUrl=${nextSearch}`; }?source=${source}&redirectUrl=${nextSearch}`;
const link = const link =
value === null || value === null ||
value === undefined || value === undefined ||
@ -185,6 +186,7 @@ function SelectWrapper({
placeholder placeholder
) )
} }
source={source}
targetModel={targetModel} targetModel={targetModel}
value={value} value={value}
/> />