Fix review

Signed-off-by: Émile Ré <nemile.re@gmail.com>
This commit is contained in:
Émile Ré
2025-12-01 20:00:11 +04:00
parent 27ef768438
commit 57e267afe0
8 changed files with 25 additions and 22 deletions

View File

@@ -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,

View File

@@ -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"]}>

View File

@@ -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)}

View File

@@ -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 "";