mirror of
https://github.com/rowyio/rowy.git
synced 2026-09-03 12:53:55 +02:00
prevent multi select crashing
This commit is contained in:
@@ -58,19 +58,24 @@ export default function MultiSelect({
|
||||
width: dropdownWidth,
|
||||
});
|
||||
|
||||
const sanitisedValue = value.filter(v => v?.length > 0);
|
||||
const sanitisedValue = Array.isArray(value)
|
||||
? value.filter((v) => v?.length > 0)
|
||||
: [value];
|
||||
|
||||
// Transform `option` prop if it’s just strings
|
||||
let options =
|
||||
typeof optionsProp[0] === "string"
|
||||
? (optionsProp as string[]).map(
|
||||
item => ({ label: item, value: item } as OptionType)
|
||||
(item) => ({ label: item, value: item } as OptionType)
|
||||
)
|
||||
: (optionsProp as OptionType[]);
|
||||
// If `freeText` enabled, show the user’s custom fields
|
||||
if (freeText) {
|
||||
// `value` prop is an array of all values. It removes labels
|
||||
const formattedValues = sanitisedValue?.map(x => ({ label: x, value: x }));
|
||||
const formattedValues = sanitisedValue?.map((x) => ({
|
||||
label: x,
|
||||
value: x,
|
||||
}));
|
||||
options = _unionWith(
|
||||
options,
|
||||
formattedValues,
|
||||
@@ -86,7 +91,7 @@ export default function MultiSelect({
|
||||
className={clsx(classes.root, className)}
|
||||
{...TextFieldProps}
|
||||
SelectProps={{
|
||||
renderValue: value => {
|
||||
renderValue: (value) => {
|
||||
const selected = value as string[];
|
||||
if (selected.length === 1 && typeof selected[0] === "string") {
|
||||
const selectedOption = _find(options, { value: selected[0] });
|
||||
@@ -109,7 +114,7 @@ export default function MultiSelect({
|
||||
...TextFieldProps.SelectProps?.MenuProps,
|
||||
},
|
||||
}}
|
||||
ref={el => {
|
||||
ref={(el) => {
|
||||
if (!el) return;
|
||||
const width = el.getBoundingClientRect().width;
|
||||
if (dropdownWidth < width) setDropdownWidth(width);
|
||||
|
||||
@@ -9,7 +9,7 @@ import FormattedChip from "components/FormattedChip";
|
||||
import { FieldType } from "constants/fields";
|
||||
import { useFiretableContext } from "contexts/firetableContext";
|
||||
|
||||
const useStyles = makeStyles(theme =>
|
||||
const useStyles = makeStyles((theme) =>
|
||||
createStyles({
|
||||
root: {
|
||||
minWidth: 0,
|
||||
@@ -63,23 +63,27 @@ export default function MultiSelect({
|
||||
? (([value] as unknown) as string[])
|
||||
: value;
|
||||
// And support transforming array of strings back to string
|
||||
const handleChange = value => onSubmit(isSingle ? value.join(", ") : value);
|
||||
const handleChange = (value) => onSubmit(isSingle ? value.join(", ") : value);
|
||||
|
||||
// Render chips
|
||||
const renderValue = value => (
|
||||
<Grid container spacing={1} wrap="nowrap" className={classes.chipList}>
|
||||
{value?.map(
|
||||
item =>
|
||||
typeof item === "string" && (
|
||||
<Grid item key={item}>
|
||||
<FormattedChip label={item} className={classes.chip} />
|
||||
</Grid>
|
||||
)
|
||||
)}
|
||||
</Grid>
|
||||
);
|
||||
const renderValue = (value) => {
|
||||
//if (Array.isArray(value))
|
||||
return (
|
||||
<Grid container spacing={1} wrap="nowrap" className={classes.chipList}>
|
||||
{value?.map(
|
||||
(item) =>
|
||||
typeof item === "string" && (
|
||||
<Grid item key={item}>
|
||||
<FormattedChip label={item} className={classes.chip} />
|
||||
</Grid>
|
||||
)
|
||||
)}
|
||||
</Grid>
|
||||
);
|
||||
// else
|
||||
};
|
||||
|
||||
const onClick = e => e.stopPropagation();
|
||||
const onClick = (e) => e.stopPropagation();
|
||||
const onClose = () => {
|
||||
if (dataGridRef?.current?.selectCell)
|
||||
dataGridRef.current.selectCell({ rowIdx, idx: column.idx });
|
||||
|
||||
Reference in New Issue
Block a user