Skip to content

Commit

Permalink
feat(dcellar-web-ui): create on chain object can only be replace orig…
Browse files Browse the repository at this point in the history
…inal object
  • Loading branch information
aiden-cao committed Apr 25, 2024
1 parent 2eb7b7b commit 0ca69e3
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions apps/dcellar-web-ui/src/modules/upload/UploadObjectsList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DCTable } from '@/components/common/DCTable';
import { useAppDispatch } from '@/store';
import { useAppDispatch, useAppSelector } from '@/store';
import { WaitObject, removeFromWaitQueue, toggleObjectReplaceState } from '@/store/slices/global';
import { ColumnProps } from 'antd/es/table';
import React, { useState } from 'react';
Expand All @@ -13,11 +13,13 @@ import { Text } from '@node-real/uikit';
import { E_OBJECT_NAME_EXISTS } from '@/facade/error';
import { getObjectErrorMsg } from '@/utils/object';
import { DELEGATE_UPLOAD } from '@/store/slices/object';
import { DCTooltip } from '@/components/common/DCTooltip';

const uploadingPageSize = 10;

export const UploadObjectsList = ({ path, data }: { path: string; data: WaitObject[] }) => {
const dispatch = useAppDispatch();
const objectRecords = useAppSelector((root) => root.object.objectRecords);
const [pageSize] = useState(10);
const [curPage, setCurPage] = useState(1);
const chunks = useCreation(() => chunk(data, pageSize), [data, pageSize]);
Expand Down Expand Up @@ -82,16 +84,33 @@ export const UploadObjectsList = ({ path, data }: { path: string; data: WaitObje
record.msg === getObjectErrorMsg(E_OBJECT_NAME_EXISTS).title;

if (!replaceable) return null;

const prefix = `${path}/${record.relativePath ? record.relativePath + '/' : ''}`;
const createOnChainObject = objectRecords[`${prefix}${record.name}`];
const objectChanged =
createOnChainObject &&
createOnChainObject.ObjectInfo.ObjectStatus !== 1 &&
createOnChainObject.ObjectInfo.PayloadSize !== record.size;

return (
<DCButton
variant={'link'}
size={'sm'}
fontSize={'12'}
fontWeight={400}
onClick={() => updateObjectReplaceState(record.id)}
<DCTooltip
title={
objectChanged
? "Please upload the original object as this objects' info already created on chain."
: ''
}
>
{record.isUpdate ? 'Undo' : 'Replace'}
</DCButton>
<DCButton
disabled={objectChanged}
variant={'link'}
size={'sm'}
fontSize={'12'}
fontWeight={400}
onClick={() => updateObjectReplaceState(record.id)}
>
{record.isUpdate ? 'Undo' : 'Replace'}
</DCButton>
</DCTooltip>
);
},
},
Expand Down

0 comments on commit 0ca69e3

Please sign in to comment.