From 27ef7684383a6f610a7f639cacc19d88b27c2862 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89mile=20R=C3=A9?= Date: Mon, 1 Dec 2025 18:12:21 +0400 Subject: [PATCH] Fix type + assets permissions display logic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Émile Ré --- .../src/components/assets/AssetsTable.tsx | 35 +++++++++---------- ...ssetsTable.tsx => ReadOnlyAssetsTable.tsx} | 2 +- apps/console/src/hooks/useStateWithSchema.ts | 2 +- .../pages/organizations/assets/AssetsPage.tsx | 15 ++++---- 4 files changed, 25 insertions(+), 29 deletions(-) rename apps/console/src/components/assets/{SnapshotAssetsTable.tsx => ReadOnlyAssetsTable.tsx} (98%) diff --git a/apps/console/src/components/assets/AssetsTable.tsx b/apps/console/src/components/assets/AssetsTable.tsx index a906ac69d..44f72eca1 100644 --- a/apps/console/src/components/assets/AssetsTable.tsx +++ b/apps/console/src/components/assets/AssetsTable.tsx @@ -22,7 +22,6 @@ type Props = { AssetsPageFragment$data >; assets: AssetsPageFragment$data["assets"]["edges"][0]["node"][]; - hasAnyAction: boolean; }; const schema = z.object({ @@ -46,7 +45,7 @@ const defaultValue = { } satisfies z.infer; export function AssetsTable(props: Props) { - const { connectionId, pagination, assets, hasAnyAction } = props; + const { connectionId, pagination, assets } = props; const organizationId = useOrganizationId(); const { __ } = useTranslate(); @@ -74,23 +73,21 @@ export function AssetsTable(props: Props) { organizationId, }} action={({ item }) => - hasAnyAction ? ( - - - - - {__("Edit")} - - - deleteAsset(item)} - variant="danger" - icon={IconTrashCan} - > - {__("Delete")} - - - ) : null + + + + + {__("Edit")} + + + deleteAsset(item)} + variant="danger" + icon={IconTrashCan} + > + {__("Delete")} + + } row={({ item }) => ( <> diff --git a/apps/console/src/components/assets/SnapshotAssetsTable.tsx b/apps/console/src/components/assets/ReadOnlyAssetsTable.tsx similarity index 98% rename from apps/console/src/components/assets/SnapshotAssetsTable.tsx rename to apps/console/src/components/assets/ReadOnlyAssetsTable.tsx index 5e8ba0fb7..34b8ead0f 100644 --- a/apps/console/src/components/assets/SnapshotAssetsTable.tsx +++ b/apps/console/src/components/assets/ReadOnlyAssetsTable.tsx @@ -20,7 +20,7 @@ type Props = { assets: AssetEntry[]; }; -export function SnapshotAssetsTable(props: Props) { +export function ReadOnlyAssetsTable(props: Props) { const { pagination, assets } = props; const { __ } = useTranslate(); diff --git a/apps/console/src/hooks/useStateWithSchema.ts b/apps/console/src/hooks/useStateWithSchema.ts index 9be54c130..703297de5 100644 --- a/apps/console/src/hooks/useStateWithSchema.ts +++ b/apps/console/src/hooks/useStateWithSchema.ts @@ -31,7 +31,7 @@ export function useStateWithSchema( value, errors, update: useCallback( - (key: keyof z.infer, value: z.infer[typeof key]) => { + >(key: TKey, value: z.infer[TKey]) => { setState((prevState) => ({ ...prevState, [key]: value })); }, [], diff --git a/apps/console/src/pages/organizations/assets/AssetsPage.tsx b/apps/console/src/pages/organizations/assets/AssetsPage.tsx index 710c06fa2..e5bac48eb 100644 --- a/apps/console/src/pages/organizations/assets/AssetsPage.tsx +++ b/apps/console/src/pages/organizations/assets/AssetsPage.tsx @@ -22,7 +22,7 @@ import { SnapshotBanner } from "/components/SnapshotBanner"; import { CreateAssetDialog } from "./dialogs/CreateAssetDialog"; import { Authorized, isAuthorized } from "/permissions"; import { AssetsTable } from "../../../components/assets/AssetsTable"; -import { SnapshotAssetsTable } from "/components/assets/SnapshotAssetsTable"; +import { ReadOnlyAssetsTable } from "../../../components/assets/ReadOnlyAssetsTable"; const paginatedAssetsFragment = graphql` fragment AssetsPageFragment on Organization @@ -90,10 +90,10 @@ export default function AssetsPage(props: Props) { const assets = pagination.data.assets?.edges.map((edge) => edge.node); const connectionId = pagination.data.assets.__id; - const hasAnyAction = - !isSnapshotMode && - (isAuthorized(organizationId, "Asset", "updateAsset") || - isAuthorized(organizationId, "Asset", "deleteAsset")); + const canWrite = ( + isAuthorized(organizationId, "Asset", "updateAsset") || + isAuthorized(organizationId, "Asset", "deleteAsset") + ); usePageTitle(__("Assets")); return ( @@ -116,14 +116,13 @@ export default function AssetsPage(props: Props) { )} - {isSnapshotMode ? - + {isSnapshotMode || !canWrite ? + : }