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

@@ -58,7 +58,12 @@ function AssetRow({
const vendors = entry.vendors?.edges.map((edge) => edge.node) ?? []; const vendors = entry.vendors?.edges.map((edge) => edge.node) ?? [];
return ( return (
<Tr to={`/organizations/${organizationId}/snapshots/${snapshotId}/assets/${entry.id}`}> <Tr
to={
snapshotId ?
`/organizations/${organizationId}/snapshots/${snapshotId}/assets/${entry.id}` : `/organizations/${organizationId}/assets/${entry.id}`
}
>
<Td>{entry.name}</Td> <Td>{entry.name}</Td>
<Td> <Td>
<Badge variant={getAssetTypeVariant(entry.assetType)}> <Badge variant={getAssetTypeVariant(entry.assetType)}>

View File

@@ -98,7 +98,7 @@ export function EditableTable<
onSuccess={toggleAdd} onSuccess={toggleAdd}
/> />
) : ( ) : (
<RowButton onClick={toggleAdd}>{props.addLabel}</RowButton> <RowButton onClick={toggleAdd} type="button">{props.addLabel}</RowButton>
)} )}
</SortableDataTable> </SortableDataTable>
); );

View File

@@ -1,17 +1,17 @@
import { type ReactNode, Suspense } from "react";
import { useEditableCellRef } from "@probo/ui/src/Molecules/Table/EditableCell.tsx";
import { getKey } from "@probo/ui/src/Molecules/Table/utils.ts";
import { useStateWithRef } from "@probo/hooks"; import { useStateWithRef } from "@probo/hooks";
import { useTranslate } from "@probo/i18n";
import { EditableCell, SelectValue, Spinner, selectCell } from "@probo/ui";
import { useEditableCellRef } from "@probo/ui/src/Molecules/Table/EditableCell.tsx";
import { useEditableRowContext } from "@probo/ui/src/Molecules/Table/EditableRow.tsx"; import { useEditableRowContext } from "@probo/ui/src/Molecules/Table/EditableRow.tsx";
import { EditableCell, selectCell, SelectValue, Spinner } from "@probo/ui"; import { getKey } from "@probo/ui/src/Molecules/Table/utils.ts";
import { Command } from "cmdk"; import { Command } from "cmdk";
import { Suspense, type ReactNode } from "react";
import { useLazyLoadQuery } from "react-relay";
import type { import type {
GraphQLTaggedNode, GraphQLTaggedNode,
OperationType, OperationType,
VariablesOf, VariablesOf,
} from "relay-runtime"; } from "relay-runtime";
import { useLazyLoadQuery } from "react-relay";
import { useTranslate } from "@probo/i18n";
type Props<Q extends OperationType, T> = { type Props<Q extends OperationType, T> = {
name: string; name: string;
@@ -30,9 +30,8 @@ export function GraphQLCell<Q extends OperationType, T>(props: Props<Q, T>) {
); );
const cellRef = useEditableCellRef(); const cellRef = useEditableCellRef();
const { __ } = useTranslate(); const { __ } = useTranslate();
const usedKeys = new Set<string>( const filteredValue = Array.isArray(value) ? value.filter(Boolean) : value ? [value] : [];
Array.isArray(value) ? value.map(getKey) : [getKey(value)], const usedKeys = new Set<string>(filteredValue.map(getKey).filter(Boolean) as string[]);
);
const { onUpdate } = useEditableRowContext(); const { onUpdate } = useEditableRowContext();
const onSelect = (item: T) => { const onSelect = (item: T) => {
@@ -122,7 +121,7 @@ function ItemList<Q extends OperationType, T>(
return ( return (
<> <>
{items {items
.filter((item) => !props.usedKeys.has(getKey(item))) .filter((item) => !props.usedKeys.has(getKey(item) ?? ""))
.map((item) => ( .map((item) => (
<Command.Item <Command.Item
key={getKey(item)} key={getKey(item)}

View File

@@ -93,6 +93,7 @@ export function SortableCellHead({
<button <button
className="flex items-center cursor-pointer hover:text-txt-primary" className="flex items-center cursor-pointer hover:text-txt-primary"
onClick={changeOrder} onClick={changeOrder}
type="button"
> >
{children} {children}
<IconChevronTriangleDownSmall <IconChevronTriangleDownSmall

View File

@@ -92,7 +92,6 @@ export function RowButton({
return ( return (
<button <button
{...props} {...props}
type="button"
className={clsx( 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", "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, props.className,

View File

@@ -27,10 +27,10 @@ export const Default: Story = {
}); });
const updateField = (key: string, value: unknown) => { const updateField = (key: string, value: unknown) => {
onUpdate(key, value); onUpdate(key, value);
setState({ setState(prevState => ({
...state, ...prevState,
[key]: value, [key]: value,
}); }));
}; };
return ( return (
<DataTable columns={["1fr", "1fr", "1fr"]}> <DataTable columns={["1fr", "1fr", "1fr"]}>

View File

@@ -33,9 +33,8 @@ export function SelectCell<T>(props: Props<T>) {
); );
const cellRef = useEditableCellRef(); const cellRef = useEditableCellRef();
const { __ } = useTranslate(); const { __ } = useTranslate();
const usedKeys = new Set<string>( const filteredValue = Array.isArray(value) ? value.filter(Boolean) : value ? [value] : [];
Array.isArray(value) ? value.map(getKey) : [getKey(value)], const usedKeys = new Set<string>(filteredValue.map(getKey).filter(Boolean) as string[]);
);
const { onUpdate } = useEditableRowContext(); const { onUpdate } = useEditableRowContext();
const onSelect = (item: T) => { const onSelect = (item: T) => {
@@ -88,7 +87,7 @@ export function SelectCell<T>(props: Props<T>) {
)} )}
<Command.List> <Command.List>
{props.items {props.items
.filter((item) => !usedKeys.has(getKey(item))) .filter((item) => !usedKeys.has(getKey(item) ?? ""))
.map((item) => ( .map((item) => (
<Command.Item <Command.Item
key={getKey(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 ( if (
item && item &&
typeof item === "object" && typeof item === "object" &&
@@ -11,7 +11,7 @@ export function getKey<T>(item: T): string {
return item.toString(); return item.toString();
} }
if (item === undefined) { if (item === undefined) {
return ""; return undefined;
} }
console.error("Cannot compute a key from item", item); console.error("Cannot compute a key from item", item);
return ""; return "";