Closed ryomahan closed 1 year ago
Yes I am aware o this issue. Have to figure it out as this is material-ui component.
@atompie I have tried some methods and now it do like the gif
// 1. make loading as React State
// - const loading = open && typeof options !== "undefined" && options?.length >= 0
const [loading, setLoading] = React.useState(false)
// 2. manually control loading value in handleLoading
const handleLoading = async () => {
if (mounted.current) {
if (isObject(endpoint)) {
setProgress(true)
try {
setOpen(true)
// open loading before the first request
setLoading(true)
// simulated request delay
await new Promise(r => setTimeout(r, 2000))
const response = await asyncRemote(endpoint, token)
if (response && mounted.current) {
let options = convertResponseToAutoCompleteOptions(response)
if (Array.isArray(defaultValueSet) && defaultValueSet.length > 0) {
options = defaultValueSet.concat(options)
}
if (typeof options !== "undefined" && options !== null) {
setOptions(options)
} else {
setOptions([])
}
setError(null)
}
} catch (e) {
if (mounted.current && e) {
const errors = getError(e)
setError(errors[0]?.msg)
}
} finally {
// close loading when all is done
setLoading(false)
if (mounted.current) {
setProgress(false)
}
}
} else {
if (mounted.current && Array.isArray(defaultValueSet) && defaultValueSet.length > 0) {
setOptions(defaultValueSet)
setOpen(true)
}
}
}
}
// 3. add noOptionsText prop for Autocomplete component to custom no data message
Hope it's useful.
@ryomahan IT look really good. I like the option when it says no data found. Could you make it into PR. We have to go through PR process to make sure that you agree to MIT license your code.
Of course, I'll submit it later.
@atompie I submit it on #246
Done in 0.7.3
When we select some resource from backend, if es don't have the resource, the selector UI well always show loading that will make user think it is a network problem.
Replace [Loading] with [None of resource] or [an add button], maybe a good choice.