@@ -92,7 +92,6 @@ export function RowButton({
|
||||
return (
|
||||
<button
|
||||
{...props}
|
||||
type="button"
|
||||
className={clsx(
|
||||
"py-2 bg-highlight hover:bg-highlight-hover active:bg-highlight-pressed cursor-pointer w-full flex gap-2 items-center justify-center text-sm text-txt-secondary",
|
||||
props.className,
|
||||
|
||||
@@ -27,10 +27,10 @@ export const Default: Story = {
|
||||
});
|
||||
const updateField = (key: string, value: unknown) => {
|
||||
onUpdate(key, value);
|
||||
setState({
|
||||
...state,
|
||||
setState(prevState => ({
|
||||
...prevState,
|
||||
[key]: value,
|
||||
});
|
||||
}));
|
||||
};
|
||||
return (
|
||||
<DataTable columns={["1fr", "1fr", "1fr"]}>
|
||||
|
||||
@@ -33,9 +33,8 @@ export function SelectCell<T>(props: Props<T>) {
|
||||
);
|
||||
const cellRef = useEditableCellRef();
|
||||
const { __ } = useTranslate();
|
||||
const usedKeys = new Set<string>(
|
||||
Array.isArray(value) ? value.map(getKey) : [getKey(value)],
|
||||
);
|
||||
const filteredValue = Array.isArray(value) ? value.filter(Boolean) : value ? [value] : [];
|
||||
const usedKeys = new Set<string>(filteredValue.map(getKey).filter(Boolean) as string[]);
|
||||
const { onUpdate } = useEditableRowContext();
|
||||
|
||||
const onSelect = (item: T) => {
|
||||
@@ -88,7 +87,7 @@ export function SelectCell<T>(props: Props<T>) {
|
||||
)}
|
||||
<Command.List>
|
||||
{props.items
|
||||
.filter((item) => !usedKeys.has(getKey(item)))
|
||||
.filter((item) => !usedKeys.has(getKey(item) ?? ""))
|
||||
.map((item) => (
|
||||
<Command.Item
|
||||
key={getKey(item)}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export function getKey<T>(item: T): string {
|
||||
export function getKey<T>(item: T): string | undefined {
|
||||
if (
|
||||
item &&
|
||||
typeof item === "object" &&
|
||||
@@ -11,7 +11,7 @@ export function getKey<T>(item: T): string {
|
||||
return item.toString();
|
||||
}
|
||||
if (item === undefined) {
|
||||
return "";
|
||||
return undefined;
|
||||
}
|
||||
console.error("Cannot compute a key from item", item);
|
||||
return "";
|
||||
|
||||
Reference in New Issue
Block a user