mirror of
https://github.com/strapi/strapi.git
synced 2025-10-16 10:33:34 +00:00
Merge pull request #5140 from strapi/fix/select-relations
Fix select relations
This commit is contained in:
commit
8fabde104d
@ -25,8 +25,10 @@
|
|||||||
"postal_coder": {
|
"postal_coder": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"category": {
|
"categories": {
|
||||||
"model": "category"
|
"collection": "category",
|
||||||
|
"via": "addresses",
|
||||||
|
"dominant": true
|
||||||
},
|
},
|
||||||
"cover": {
|
"cover": {
|
||||||
"model": "file",
|
"model": "file",
|
||||||
|
@ -13,6 +13,10 @@
|
|||||||
"attributes": {
|
"attributes": {
|
||||||
"name": {
|
"name": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
},
|
||||||
|
"addresses": {
|
||||||
|
"via": "categories",
|
||||||
|
"collection": "address"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,7 @@ function SelectWrapper({
|
|||||||
const { signal } = abortController;
|
const { signal } = abortController;
|
||||||
const ref = useRef();
|
const ref = useRef();
|
||||||
const startRef = useRef();
|
const startRef = useRef();
|
||||||
|
|
||||||
startRef.current = state._start;
|
startRef.current = state._start;
|
||||||
|
|
||||||
ref.current = async () => {
|
ref.current = async () => {
|
||||||
@ -55,6 +56,9 @@ function SelectWrapper({
|
|||||||
|
|
||||||
if (isEmpty(params._q)) {
|
if (isEmpty(params._q)) {
|
||||||
delete params._q;
|
delete params._q;
|
||||||
|
} else {
|
||||||
|
delete params._limit;
|
||||||
|
delete params._start;
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await request(requestUrl, {
|
const data = await request(requestUrl, {
|
||||||
@ -69,6 +73,7 @@ function SelectWrapper({
|
|||||||
|
|
||||||
if (!isEmpty(params._q)) {
|
if (!isEmpty(params._q)) {
|
||||||
setOptions(formattedData);
|
setOptions(formattedData);
|
||||||
|
setState(prev => ({ ...prev, _start: 0 }));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -97,19 +102,17 @@ function SelectWrapper({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
ref.current();
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
abortController.abort();
|
|
||||||
};
|
|
||||||
}, [ref]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (state._q !== '') {
|
if (state._q !== '') {
|
||||||
ref.current();
|
let timer = setTimeout(() => {
|
||||||
|
ref.current();
|
||||||
|
}, 300);
|
||||||
|
|
||||||
|
return () => clearTimeout(timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ref.current();
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
abortController.abort();
|
abortController.abort();
|
||||||
};
|
};
|
||||||
@ -140,7 +143,7 @@ function SelectWrapper({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onMenuScrollToBottom = () => {
|
const onMenuScrollToBottom = () => {
|
||||||
setState(prevState => ({ ...prevState, _start: prevState._start + 1 }));
|
setState(prevState => ({ ...prevState, _start: prevState._start + 20 }));
|
||||||
};
|
};
|
||||||
|
|
||||||
const isSingle = [
|
const isSingle = [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user