From c54e887dfd723f2520ffc9e270f0043780b4857d Mon Sep 17 00:00:00 2001 From: Jeroen Branje Date: Mon, 16 Dec 2024 03:24:35 +0100 Subject: [PATCH] feat: Add Assets history table Signed-off-by: Jeroen Branje --- .../common/utils/index.ts | 1 + .../common/utils/utils.ts | 2 + .../modules/AddAssets/AddAssets.actions.ts | 7 ++-- .../modules/UploadedAsset/UploadedAsset.tsx | 39 ++++++++++++------- .../modules/UploadedAssets/UploadedAssets.tsx | 19 +++++++-- .../modules/UploadedAssets/locales/de_DE.json | 6 ++- .../modules/UploadedAssets/locales/en_GB.json | 6 ++- 7 files changed, 58 insertions(+), 22 deletions(-) diff --git a/apps/envited.ascs.digital/common/utils/index.ts b/apps/envited.ascs.digital/common/utils/index.ts index d5566af3..48885cf0 100644 --- a/apps/envited.ascs.digital/common/utils/index.ts +++ b/apps/envited.ascs.digital/common/utils/index.ts @@ -26,6 +26,7 @@ export { segmentsToPath, slugToLabel, isTrustAnchor, + truncateCID, truncateDID, isServer, } from './utils' diff --git a/apps/envited.ascs.digital/common/utils/utils.ts b/apps/envited.ascs.digital/common/utils/utils.ts index d85af8fc..76e313e4 100644 --- a/apps/envited.ascs.digital/common/utils/utils.ts +++ b/apps/envited.ascs.digital/common/utils/utils.ts @@ -76,6 +76,8 @@ export const truncate = (length: number) => export const truncateDID = truncate(20) +export const truncateCID = truncate(10) + export const isServer = () => typeof window === 'undefined' export const addUrn = (type: string) => (uuid: string) => `urn:${type}:${uuid}` diff --git a/apps/envited.ascs.digital/modules/AddAssets/AddAssets.actions.ts b/apps/envited.ascs.digital/modules/AddAssets/AddAssets.actions.ts index 25c60011..cc4a0184 100644 --- a/apps/envited.ascs.digital/modules/AddAssets/AddAssets.actions.ts +++ b/apps/envited.ascs.digital/modules/AddAssets/AddAssets.actions.ts @@ -3,12 +3,13 @@ import { revalidatePath } from 'next/cache' import { isNil } from 'ramda' +import { createFilename } from '../../common/asset/validateAndCreateMetadata.utils' import { getServerSession } from '../../common/auth' -import { getAssetUploadUrl, getUniqueFilename } from '../../common/aws' +import { getAssetUploadUrl } from '../../common/aws' import { ERRORS } from '../../common/constants' import { log } from '../../common/logger' import { insertAsset } from '../../common/serverActions' -import { badRequestError, formatError, internalServerErrorError, slugify, unauthorizedError } from '../../common/utils' +import { badRequestError, formatError, internalServerErrorError, unauthorizedError } from '../../common/utils' export async function addAssetsForm(formData: FormData) { const assets = formData.getAll('assets') as File[] @@ -29,7 +30,7 @@ export async function addAssetsForm(formData: FormData) { const result = assets.map(async (asset: File) => { const arrayBuffer = Buffer.from(await asset.arrayBuffer()) - const uniqueFilename = getUniqueFilename(slugify(asset.name), asset.name) + const uniqueFilename = await createFilename(arrayBuffer) const signedUrl = await getAssetUploadUrl(uniqueFilename) const uploadResult = await fetch(signedUrl, { diff --git a/apps/envited.ascs.digital/modules/UploadedAsset/UploadedAsset.tsx b/apps/envited.ascs.digital/modules/UploadedAsset/UploadedAsset.tsx index 57b4c380..c361e6c6 100644 --- a/apps/envited.ascs.digital/modules/UploadedAsset/UploadedAsset.tsx +++ b/apps/envited.ascs.digital/modules/UploadedAsset/UploadedAsset.tsx @@ -2,8 +2,9 @@ import { LoadingIndicator } from '@envited-x-data-space/design-system' import { TrashIcon } from '@heroicons/react/24/outline' +import { truncateCID } from 'apps/envited.ascs.digital/common/utils' import { useSession } from 'next-auth/react' -import { equals, last, propOr } from 'ramda' +import { equals, propOr } from 'ramda' import { FC, useEffect, useState } from 'react' import { match } from 'ts-pattern' @@ -63,14 +64,7 @@ export const UploadedAsset: FC = ({ assetIdx, asset, metadat return ( -
- {equals(asset.status)(AssetStatus.processing) ? asset.cid : propOr('', 'name')(metadata)} -
-
- {propOr('', 'type')(metadata)} - ยท - {propOr('', 'size')(metadata)} -
+
{truncateCID(asset.cid)}
{assetIdx !== 0 ?
: null} = ({ assetIdx, asset, metadat equals(assetIdx)(0) ? '' : 'border-t border-gray-200' } hidden px-3 py-3.5 text-sm text-gray-500 lg:table-cell`} > - {equals(assetStatus)(AssetStatus.processing) ? <>… : last(propOr('', 'tags')(metadata))} + {equals(asset.status)(AssetStatus.processing) ? <>… : propOr('', 'name')(metadata)} + {equals(asset.status)(AssetStatus.processing) ? <>… : propOr('', 'date')(metadata)} + + {match(assetStatus) .with(AssetStatus.processing, () => ( @@ -93,6 +94,15 @@ export const UploadedAsset: FC = ({ assetIdx, asset, metadat
)) .with(AssetStatus.minted, () => {t('[Status] minted')}) + .with(AssetStatus.rejected, () => {t('[Status] rejected')}) + .otherwise(() => '')} + + + {match(assetStatus) .with(AssetStatus.rejected, () => (
{t('[Status] rejected')} @@ -105,7 +115,7 @@ export const UploadedAsset: FC = ({ assetIdx, asset, metadat
)) - .otherwise(() => ( + .with(AssetStatus.pending, () => (
- ))} + )) + .otherwise(() => '')} {!equals(assetIdx)(0) ?
: null} diff --git a/apps/envited.ascs.digital/modules/UploadedAssets/UploadedAssets.tsx b/apps/envited.ascs.digital/modules/UploadedAssets/UploadedAssets.tsx index 1322bd8f..bf1da895 100644 --- a/apps/envited.ascs.digital/modules/UploadedAssets/UploadedAssets.tsx +++ b/apps/envited.ascs.digital/modules/UploadedAssets/UploadedAssets.tsx @@ -27,15 +27,28 @@ export const UploadedAssets: FC = ({ assets }) => { - {t('[Label] asset')} + {t('[Label] cid')} - {t('[Label] type')} + {t('[Label] name')} - + + {t('[Label] time')} + + + {t('[Label] status')} + + + {t('[Label] action')} {t('[Label] select')} diff --git a/apps/envited.ascs.digital/modules/UploadedAssets/locales/de_DE.json b/apps/envited.ascs.digital/modules/UploadedAssets/locales/de_DE.json index e854d8ab..b6d5245e 100644 --- a/apps/envited.ascs.digital/modules/UploadedAssets/locales/de_DE.json +++ b/apps/envited.ascs.digital/modules/UploadedAssets/locales/de_DE.json @@ -1,10 +1,14 @@ { "[Heading] uploaded assets": "Assets that are uploaded and ready for minting.", "[Description] uploaded assets": "You be able to see a \"preview\" of the asset detail page before you \"mint\" the asset, if there is something incorrect \"delete\" the asset and start over again.", + "[Label] name": "Name", + "[Label] cid": "CID", + "[Label] time": "Time", + "[Label] status": "Status", "[Label] asset": "Asset", "[Label] type": "Type", - "[Label] status": "Status", "[Label] select": "Select", + "[Label] action": "Action", "[Button] mint": "Mint", "[Button] preview": "Preview", "[Button] delete": "Delete" diff --git a/apps/envited.ascs.digital/modules/UploadedAssets/locales/en_GB.json b/apps/envited.ascs.digital/modules/UploadedAssets/locales/en_GB.json index e854d8ab..b6d5245e 100644 --- a/apps/envited.ascs.digital/modules/UploadedAssets/locales/en_GB.json +++ b/apps/envited.ascs.digital/modules/UploadedAssets/locales/en_GB.json @@ -1,10 +1,14 @@ { "[Heading] uploaded assets": "Assets that are uploaded and ready for minting.", "[Description] uploaded assets": "You be able to see a \"preview\" of the asset detail page before you \"mint\" the asset, if there is something incorrect \"delete\" the asset and start over again.", + "[Label] name": "Name", + "[Label] cid": "CID", + "[Label] time": "Time", + "[Label] status": "Status", "[Label] asset": "Asset", "[Label] type": "Type", - "[Label] status": "Status", "[Label] select": "Select", + "[Label] action": "Action", "[Button] mint": "Mint", "[Button] preview": "Preview", "[Button] delete": "Delete"