Add loader to attribute picker (#1182)
* wip multiselectfield loader * restyled spinner display * get rid of redundant debouncer * wip * wip multiselectfield loader * restyled spinner display * get rid of redundant debouncer * remove redundant prop Co-authored-by: Magdalena Markusik <magdalena.markusik@mirumee.com>
This commit is contained in:
parent
3bd83c3731
commit
8e1dc4e12d
4 changed files with 37 additions and 45 deletions
|
@ -181,7 +181,7 @@ const MultiAutocompleteSelectFieldComponent: React.FC<MultiAutocompleteSelectFie
|
||||||
fullWidth={true}
|
fullWidth={true}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
/>
|
/>
|
||||||
{isOpen && (!!inputValue || !!choices.length) && (
|
{isOpen && (
|
||||||
<MultiAutocompleteSelectFieldContent
|
<MultiAutocompleteSelectFieldContent
|
||||||
add={
|
add={
|
||||||
add && {
|
add && {
|
||||||
|
@ -249,16 +249,12 @@ const MultiAutocompleteSelectField: React.FC<MultiAutocompleteSelectFieldProps>
|
||||||
|
|
||||||
if (fetchChoices) {
|
if (fetchChoices) {
|
||||||
return (
|
return (
|
||||||
<DebounceAutocomplete debounceFn={fetchChoices}>
|
|
||||||
{debounceFn => (
|
|
||||||
<MultiAutocompleteSelectFieldComponent
|
<MultiAutocompleteSelectFieldComponent
|
||||||
testId={testId}
|
testId={testId}
|
||||||
choices={choices}
|
choices={choices}
|
||||||
{...props}
|
{...props}
|
||||||
fetchChoices={debounceFn}
|
fetchChoices={fetchChoices}
|
||||||
/>
|
/>
|
||||||
)}
|
|
||||||
</DebounceAutocomplete>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -125,7 +125,8 @@ const useStyles = makeStyles(
|
||||||
progress: {},
|
progress: {},
|
||||||
progressContainer: {
|
progressContainer: {
|
||||||
display: "flex",
|
display: "flex",
|
||||||
justifyContent: "center"
|
justifyContent: "center",
|
||||||
|
padding: `${theme.spacing(1)}px 0`
|
||||||
},
|
},
|
||||||
root: {
|
root: {
|
||||||
borderBottomLeftRadius: 8,
|
borderBottomLeftRadius: 8,
|
||||||
|
@ -173,7 +174,6 @@ const MultiAutocompleteSelectFieldContent: React.FC<MultiAutocompleteSelectField
|
||||||
inputValue,
|
inputValue,
|
||||||
onFetchMore
|
onFetchMore
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
if (!!add && !!displayCustomValue) {
|
if (!!add && !!displayCustomValue) {
|
||||||
throw new Error("Add and custom value cannot be displayed simultaneously");
|
throw new Error("Add and custom value cannot be displayed simultaneously");
|
||||||
}
|
}
|
||||||
|
@ -198,12 +198,12 @@ const MultiAutocompleteSelectFieldContent: React.FC<MultiAutocompleteSelectField
|
||||||
}
|
}
|
||||||
}, [loading]);
|
}, [loading]);
|
||||||
|
|
||||||
|
const hasValuesToDisplay =
|
||||||
|
displayValues.length > 0 || displayCustomValue || choices.length > 0;
|
||||||
return (
|
return (
|
||||||
<Paper className={classes.root}>
|
<Paper className={classes.root}>
|
||||||
|
{hasValuesToDisplay && (
|
||||||
<div className={classes.content} ref={anchor}>
|
<div className={classes.content} ref={anchor}>
|
||||||
{choices.length > 0 ||
|
|
||||||
displayValues.length > 0 ||
|
|
||||||
displayCustomValue ? (
|
|
||||||
<>
|
<>
|
||||||
{add && (
|
{add && (
|
||||||
<MenuItem
|
<MenuItem
|
||||||
|
@ -298,25 +298,26 @@ const MultiAutocompleteSelectFieldContent: React.FC<MultiAutocompleteSelectField
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
{hasMore && (
|
</>
|
||||||
<>
|
|
||||||
<Hr className={classes.hr} />
|
|
||||||
<div className={classes.progressContainer}>
|
|
||||||
<CircularProgress className={classes.progress} size={24} />
|
|
||||||
</div>
|
</div>
|
||||||
</>
|
|
||||||
)}
|
)}
|
||||||
</>
|
{!loading && !hasValuesToDisplay && (
|
||||||
) : (
|
|
||||||
<MenuItem
|
<MenuItem
|
||||||
disabled={true}
|
disabled={true}
|
||||||
component="div"
|
component="div"
|
||||||
data-test="multiautocomplete-select-no-options"
|
data-test="multiautocomplete-select-no-options"
|
||||||
>
|
>
|
||||||
<FormattedMessage defaultMessage="No results found" />
|
<FormattedMessage defaultMessage={"No results found"} />
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
)}
|
)}
|
||||||
|
{(hasMore || loading) && (
|
||||||
|
<>
|
||||||
|
{hasMore && <Hr className={classes.hr} />}
|
||||||
|
<div className={classes.progressContainer}>
|
||||||
|
<CircularProgress className={classes.progress} size={24} />
|
||||||
</div>
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
{choices.length > maxMenuItems && (
|
{choices.length > maxMenuItems && (
|
||||||
<div className={classes.arrowContainer}>
|
<div className={classes.arrowContainer}>
|
||||||
<div
|
<div
|
||||||
|
|
|
@ -242,15 +242,11 @@ const SingleAutocompleteSelectField: React.FC<SingleAutocompleteSelectFieldProps
|
||||||
|
|
||||||
if (fetchChoices) {
|
if (fetchChoices) {
|
||||||
return (
|
return (
|
||||||
<DebounceAutocomplete debounceFn={fetchChoices}>
|
|
||||||
{debounceFn => (
|
|
||||||
<SingleAutocompleteSelectFieldComponent
|
<SingleAutocompleteSelectFieldComponent
|
||||||
choices={choices}
|
choices={choices}
|
||||||
{...rest}
|
{...rest}
|
||||||
fetchChoices={debounceFn}
|
fetchChoices={fetchChoices}
|
||||||
/>
|
/>
|
||||||
)}
|
|
||||||
</DebounceAutocomplete>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,6 @@ function createAttributeValueSearchHandler(
|
||||||
search("");
|
search("");
|
||||||
}
|
}
|
||||||
}, [state.id]);
|
}, [state.id]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
loadMore,
|
loadMore,
|
||||||
search: handleSearch,
|
search: handleSearch,
|
||||||
|
|
Loading…
Reference in a new issue