From d0cefdee2f81b44fbc72ebf1529541fc6747f0fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89mile=20R=C3=A9?= Date: Mon, 1 Dec 2025 15:54:33 +0400 Subject: [PATCH] Fix cubic review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Émile Ré --- .../src/components/table/VendorsCell.tsx | 1 + apps/console/src/hooks/graph/AssetGraph.ts | 10 ++-- .../organizations/assets/AssetDetailsPage.tsx | 53 ++++++++++--------- packages/ui/src/Atoms/DataTable/DataTable.tsx | 6 ++- packages/ui/src/Atoms/Select/Select.tsx | 5 +- packages/ui/src/Molecules/Table/TextCell.tsx | 6 ++- 6 files changed, 43 insertions(+), 38 deletions(-) diff --git a/apps/console/src/components/table/VendorsCell.tsx b/apps/console/src/components/table/VendorsCell.tsx index 634a84e44..6987becf8 100644 --- a/apps/console/src/components/table/VendorsCell.tsx +++ b/apps/console/src/components/table/VendorsCell.tsx @@ -54,6 +54,7 @@ function VendorBadge({ diff --git a/apps/console/src/hooks/graph/AssetGraph.ts b/apps/console/src/hooks/graph/AssetGraph.ts index 6bd534abd..636618a99 100644 --- a/apps/console/src/hooks/graph/AssetGraph.ts +++ b/apps/console/src/hooks/graph/AssetGraph.ts @@ -121,17 +121,13 @@ export const deleteAssetMutation = graphql` `; export const useDeleteAsset = ( - asset?: { id?: string; name?: string }, - connectionId?: string, + asset: { id?: string; name?: string }, + connectionId: string, ) => { const [mutate] = useMutation(deleteAssetMutation); const confirm = useConfirm(); const { __ } = useTranslate(); - if (!asset) { - return () => {}; - } - return () => { if (!asset.id || !asset.name) { return alert(__("Failed to delete asset: missing id or name")); @@ -141,7 +137,7 @@ export const useDeleteAsset = ( promisifyMutation(mutate)({ variables: { input: { - assetId: asset.id!, + assetId: asset.id, }, connections: [connectionId], }, diff --git a/apps/console/src/pages/organizations/assets/AssetDetailsPage.tsx b/apps/console/src/pages/organizations/assets/AssetDetailsPage.tsx index 777c1ff5b..2d2859382 100644 --- a/apps/console/src/pages/organizations/assets/AssetDetailsPage.tsx +++ b/apps/console/src/pages/organizations/assets/AssetDetailsPage.tsx @@ -1,13 +1,5 @@ -import { - ConnectionHandler, - usePreloadedQuery, - type PreloadedQuery, -} from "react-relay"; -import { - assetNodeQuery, - useDeleteAsset, - useUpdateAsset, -} from "../../../hooks/graph/AssetGraph"; +import { getAssetTypeVariant, validateSnapshotConsistency } from "@probo/helpers"; +import { useTranslate } from "@probo/i18n"; import { ActionDropdown, Badge, @@ -18,16 +10,25 @@ import { IconTrashCan, Option, } from "@probo/ui"; -import { useTranslate } from "@probo/i18n"; -import { useOrganizationId } from "/hooks/useOrganizationId"; +import { + ConnectionHandler, + usePreloadedQuery, + type PreloadedQuery, +} from "react-relay"; import { useParams } from "react-router"; +import z from "zod"; +import { + assetNodeQuery, + useDeleteAsset, + useUpdateAsset, +} from "../../../hooks/graph/AssetGraph"; +import { SnapshotBanner } from "/components/SnapshotBanner"; import { ControlledField } from "/components/form/ControlledField"; import { PeopleSelectField } from "/components/form/PeopleSelectField"; import { VendorsMultiSelectField } from "/components/form/VendorsMultiSelectField"; +import type { AssetGraphNodeQuery } from "/hooks/graph/__generated__/AssetGraphNodeQuery.graphql"; import { useFormWithSchema } from "/hooks/useFormWithSchema"; -import z from "zod"; -import { getAssetTypeVariant, validateSnapshotConsistency } from "@probo/helpers"; -import { SnapshotBanner } from "/components/SnapshotBanner"; +import { useOrganizationId } from "/hooks/useOrganizationId"; import { Authorized } from "/permissions"; const updateAssetSchema = z.object({ @@ -40,18 +41,18 @@ const updateAssetSchema = z.object({ }); type Props = { - queryRef: PreloadedQuery; + queryRef: PreloadedQuery; }; export default function AssetDetailsPage(props: Props) { - const asset = usePreloadedQuery(assetNodeQuery, props.queryRef); + const asset = usePreloadedQuery(assetNodeQuery, props.queryRef); const assetEntry = asset.node; const { __ } = useTranslate(); const organizationId = useOrganizationId(); const { snapshotId } = useParams<{ snapshotId?: string }>(); const isSnapshotMode = Boolean(snapshotId); - if (!assetEntry) { + if (!assetEntry || !assetEntry.id) { return
{__("Asset not found")}
; } @@ -64,16 +65,16 @@ export default function AssetDetailsPage(props: Props) { ); const deleteAsset = useDeleteAsset(assetEntry, connectionId); - const vendors = assetEntry?.vendors?.edges.map((edge: any) => edge.node) ?? []; + const vendors = assetEntry.vendors?.edges.map((edge: any) => edge.node) ?? []; const vendorIds = vendors.map((vendor: any) => vendor.id); const { control, formState, handleSubmit, register, reset } = useFormWithSchema(updateAssetSchema, { defaultValues: { - name: assetEntry?.name || "", - amount: assetEntry?.amount || 0, - assetType: assetEntry?.assetType || "VIRTUAL", - dataTypesStored: assetEntry?.dataTypesStored || "", - ownerId: assetEntry?.owner?.id || "", + name: assetEntry.name || "", + amount: assetEntry.amount || 0, + assetType: assetEntry.assetType || "VIRTUAL", + dataTypesStored: assetEntry.dataTypesStored || "", + ownerId: assetEntry.owner?.id || "", vendorIds: vendorIds, }, }); @@ -82,7 +83,7 @@ export default function AssetDetailsPage(props: Props) { const onSubmit = handleSubmit(async (formData) => { await updateAsset({ - id: assetEntry?.id, + id: assetEntry.id!, ...formData, }); reset(formData); @@ -110,7 +111,7 @@ export default function AssetDetailsPage(props: Props) {
{assetEntry?.name}
- + {assetEntry?.assetType === "PHYSICAL" ? __("Physical") : __("Virtual")}
diff --git a/packages/ui/src/Atoms/DataTable/DataTable.tsx b/packages/ui/src/Atoms/DataTable/DataTable.tsx index 9e6d40c14..2fda1869d 100644 --- a/packages/ui/src/Atoms/DataTable/DataTable.tsx +++ b/packages/ui/src/Atoms/DataTable/DataTable.tsx @@ -97,7 +97,11 @@ export function RowButton({ "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, )} - style={{ gridColumnEnd: -1, gridColumnStart: 1 }} + style={{ + gridColumnEnd: -1, + gridColumnStart: 1, + ...props.style, + }} > {children} diff --git a/packages/ui/src/Atoms/Select/Select.tsx b/packages/ui/src/Atoms/Select/Select.tsx index 5cd3830e2..926aeeb54 100644 --- a/packages/ui/src/Atoms/Select/Select.tsx +++ b/packages/ui/src/Atoms/Select/Select.tsx @@ -146,12 +146,13 @@ export function Select({ {onSearch && ( diff --git a/packages/ui/src/Molecules/Table/TextCell.tsx b/packages/ui/src/Molecules/Table/TextCell.tsx index 6c742a1f0..7c39cd6b8 100644 --- a/packages/ui/src/Molecules/Table/TextCell.tsx +++ b/packages/ui/src/Molecules/Table/TextCell.tsx @@ -24,8 +24,10 @@ export function TextCell(props: Props) { if (props.required && inputValue === "") { return; } - setValue(inputValue); - onUpdate(props.name, inputValue); + if (inputValue !== props.defaultValue) { + setValue(inputValue); + onUpdate(props.name, inputValue); + } }; return (