Skip to content

Commit

Permalink
feat(dcellar-web-ui): using table to manage pending and uploading lists
Browse files Browse the repository at this point in the history
  • Loading branch information
devinxl committed Mar 28, 2024
1 parent 4113293 commit 3587213
Show file tree
Hide file tree
Showing 15 changed files with 330 additions and 123 deletions.
1 change: 1 addition & 0 deletions apps/dcellar-web-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"private": false,
"scripts": {
"dev": "node ./scripts/dev.js -p 3200",
"dev1": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,10 @@ export const CreateFolderOperation = memo<CreateFolderOperationProps>(function C
toast.success({
description: (
<>
Folder created successfully! View in{' '}
Folder created successfully!{' '}
{tx && (
<>
View in{' '}
<Link
color="#3C9AF1"
_hover={{ color: '#3C9AF1', textDecoration: 'underline' }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import { find, uniq, without, xor } from 'lodash-es';
import { memo, useCallback } from 'react';
import { OBJECT_ERROR_TYPES, ObjectErrorType } from '../ObjectError';
import Link from 'next/link';
// import { ManageObjectTagsDrawer } from './ManageObjectTagsDrawer';


export type ObjectActionValueType =
| 'marketplace'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ interface TotalFeesProps {
payStoreFeeAddress: string;
refund?: boolean;
expandable?: boolean;
expand?: boolean;
}

// TODO refactor
export const TotalFees = memo<TotalFeesProps>(function TotalFeesItem(props) {
const {
gasFee,
Expand All @@ -33,11 +33,12 @@ export const TotalFees = memo<TotalFeesProps>(function TotalFeesItem(props) {
payStoreFeeAddress = '',
refund = false,
expandable = true,
expand = true,
} = props;
const loginAccount = useAppSelector((root) => root.persist.loginAccount);

const exchangeRate = useAppSelector(selectBnbUsdtExchangeRate);
const { isOpen: isOpenFees, onToggle: onToggleFees } = useDisclosure({ defaultIsOpen: true });
const { isOpen: isOpenFees, onToggle: onToggleFees } = useDisclosure({ defaultIsOpen: expand });
const bankBalance = useAppSelector(selectAvailableBalance(loginAccount));
const staticBalance = useAppSelector(selectAvailableBalance(payStoreFeeAddress));
const paymentAccounts = useAppSelector(selectPaymentAccounts(loginAccount));
Expand Down
52 changes: 4 additions & 48 deletions apps/dcellar-web-ui/src/modules/upload/ListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import styled from '@emotion/styled';
import { Flex, Menu, QListItem } from '@node-real/uikit';
import { Flex, Menu } from '@node-real/uikit';
import cn from 'classnames';
import { isEmpty } from 'lodash-es';
import { ChangeEvent, useMemo } from 'react';

import { NameItem } from './NameItem';
import { PathItem } from './PathItem';

import { IconFont } from '@/components/IconFont';
import { UploadMenuList } from '@/modules/object/components/UploadMenuList';
import { useAppDispatch, useAppSelector } from '@/store';
import { addToWaitQueue, removeFromWaitQueue } from '@/store/slices/global';
import { addToWaitQueue } from '@/store/slices/global';
import { TransferItemTree } from '@/utils/dom';
import { getTimestamp } from '@/utils/time';
import { UploadObjectsList } from './UploadObjectsList';

type ListItemProps = {
path: string;
Expand All @@ -37,10 +35,6 @@ export const ListItem = ({ path, type, handleFolderTree }: ListItemProps) => {
}
}, [objectWaitQueue, type]);

const onRemove = (id: number) => {
dispatch(removeFromWaitQueue({ id }));
};

const onFilesChange = async (e: ChangeEvent<HTMLInputElement>) => {
const files = e.target.files;
if (!files || !files.length) return;
Expand Down Expand Up @@ -112,45 +106,7 @@ export const ListItem = ({ path, type, handleFolderTree }: ListItemProps) => {
</Flex>
</DropContainer>
<Flex width="100%" flexDirection={'column'} alignItems={'center'} display={'flex'}>
{list?.map((selectedFile) => (
<QListItem
key={selectedFile.id}
cursor={'default'}
maxW={'520px'}
h={42}
px={0}
_hover={{
bg: 'opacity1',
}}
right={
<IconFont
onClick={() => onRemove(selectedFile.id)}
w={16}
type="close"
cursor="pointer"
color={'readable.secondary'}
_hover={{
color: 'readable.normal',
}}
/>
}
>
<Flex fontSize={'12px'} alignItems={'center'} justifyContent={'space-between'}>
<NameItem
w={240}
mr={12}
name={selectedFile.name}
msg={selectedFile.msg}
size={selectedFile.size}
/>
<PathItem
lineHeight="normal"
path={`${path}/${selectedFile.relativePath ? selectedFile.relativePath + '/' : ''}`}
textAlign="left"
/>
</Flex>
</QListItem>
))}
{list && list.length > 0 && <UploadObjectsList data={list} path={path} />}
</Flex>
</>
);
Expand Down
54 changes: 54 additions & 0 deletions apps/dcellar-web-ui/src/modules/upload/ObjectUploadStatus.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { UploadObject } from '@/store/slices/global';
import { Flex, Text } from '@node-real/uikit';
import { Loading } from '@/components/common/Loading';
import { UploadProgress } from './UploadProgress';
import { IconFont } from '@/components/IconFont';

export const ObjectUploadStatus = ({ task }: { task: UploadObject }) => {
switch (task.status) {
case 'WAIT':
return (
<>
<Loading iconSize={12} justifyContent={'flex-end'} />
<Text marginLeft={'4px'} fontWeight={400}>
Waiting
</Text>
</>
);
case 'HASH':
return (
<>
<Loading iconSize={12} justifyContent={'flex-end'} />
<Text marginLeft={'4px'} fontWeight={400}>
Hashing
</Text>
</>
);
case 'HASHED':
return <UploadProgress value={0} />;
case 'SIGN':
return <UploadProgress value={0} />;
case 'SIGNED':
return <UploadProgress value={0} />;
case 'UPLOAD':
return <UploadProgress value={task.progress || 0} />;
case 'SEAL':
case 'SEALING':
return (
<>
<Loading iconSize={12} justifyContent={'flex-end'} />
<Text marginLeft={'4px'} fontWeight={400}>
Sealing
</Text>
</>
);
case 'FINISH':
return <IconFont type="colored-success" w={16} mr={8} />;
case 'ERROR':
return <IconFont type="colored-error2" w={20} mr={6} />;
case 'CANCEL':
return <IconFont type="colored-error2" w={20} mr={6} />;
default:
return null;
}
};
3 changes: 1 addition & 2 deletions apps/dcellar-web-ui/src/modules/upload/TaskManagement.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { Box, Text } from '@node-real/uikit';
import { useThrottleFn } from 'ahooks';

import { UploadingObjects } from './UploadingObjects';

import { DCButton } from '@/components/common/DCButton';
import { DCDrawer } from '@/components/common/DCDrawer';
import { Loading } from '@/components/common/Loading';
import { useAppDispatch, useAppSelector } from '@/store';
import { selectHasUploadingTask, setTaskManagement } from '@/store/slices/global';
import { UploadingObjects } from './UploadingObjects';

export const TaskManagement = () => {
const dispatch = useAppDispatch();
Expand Down
4 changes: 3 additions & 1 deletion apps/dcellar-web-ui/src/modules/upload/UploadObjectsFees.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ import { getStoreNetflowRate } from '@/utils/payment';

interface FeesProps {
delegateUpload: boolean;
expand?: boolean;
}

export const UploadObjectsFees = memo<FeesProps>(function Fees({ delegateUpload }) {
export const UploadObjectsFees = memo<FeesProps>(function Fees({ delegateUpload, expand = false }) {
const dispatch = useAppDispatch();
const loginAccount = useAppSelector((root) => root.persist.loginAccount);
const gnfdGasFeesConfig = useAppSelector(selectGnfdGasFeesConfig);
Expand Down Expand Up @@ -148,6 +149,7 @@ export const UploadObjectsFees = memo<FeesProps>(function Fees({ delegateUpload
prepaidFee={storeFee}
settlementFee={settlementFee}
gasFee={gasFee}
expand={expand}
/>
<Text fontSize={'12px'} lineHeight={'16px'} color={'scene.danger.normal'}>
{!isChecking &&
Expand Down
86 changes: 86 additions & 0 deletions apps/dcellar-web-ui/src/modules/upload/UploadObjectsList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { DCTable } from '@/components/common/DCTable';
import { useAppDispatch, useAppSelector } from '@/store';
import { UploadObject, WaitObject, removeFromWaitQueue } from '@/store/slices/global';
import { ColumnProps } from 'antd/es/table';
import React, { use, useState } from 'react';
import { NameItem } from './NameItem';
import { PathItem } from './PathItem';
import { ObjectUploadStatus } from './ObjectUploadStatus';
import { useTableNav } from '@/components/common/DCTable/useTableNav';
import { useCreation } from 'ahooks';
import { chunk } from 'lodash-es';
import { Flex } from '@node-real/uikit';
import { IconFont } from '@/components/IconFont';

const uploadingPageSize = 10;

export const UploadObjectsList = ({ path, data }: { path: string; data: WaitObject[] }) => {
const dispatch = useAppDispatch();
const [pageSize, setPageSize] = useState(10);
const [curPage, setCurPage] = useState(1);
const chunks = useCreation(() => chunk(data, pageSize), [data, pageSize]);
const page = chunks[curPage - 1] || [];
const onRemove = (id: number) => {
dispatch(removeFromWaitQueue({ id }));
};
const columns: ColumnProps<UploadObject>[] = [
{
key: 'name',
title: 'Name',
render: (record) => {
return (
<NameItem name={record.name} size={record.size} msg={record.msg} w={240} task={record} />
);
},
},
{
key: 'path',
title: 'Path',
width: 170,
render: (record) => {
return (
<PathItem
lineHeight="normal"
path={`${path}/${record.relativePath ? record.relativePath + '/' : ''}`}
textAlign="left"
/>
);
},
},
{
key: 'status',
title: 'Status',
width: 70,
render: (record) => {
return (
<IconFont
onClick={() => onRemove(record.id)}
w={16}
type="close"
cursor="pointer"
color={'readable.secondary'}
_hover={{
color: 'readable.normal',
}}
/>
);
},
},
];

const onPageChange = (page: number) => {
setCurPage(page);
};

return (
<DCTable
columns={columns}
dataSource={page}
current={curPage}
total={data.length}
pageSize={uploadingPageSize}
showQuickJumper={true}
pageChange={onPageChange}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,9 @@ export const UploadObjectsOperation = memo<UploadObjectsOperationProps>(
: OBJECT_ERROR_TYPES[E_UNKNOWN];
};

const closeModal = () => {
const cleanup = () => {
onClose();
dispatch(resetWaitQueue());
dispatch(setSignatureAction({}));
};

Expand Down Expand Up @@ -264,7 +265,7 @@ export const UploadObjectsOperation = memo<UploadObjectsOperationProps>(
visibility,
}),
);
closeModal();
cleanup();
// TODO for lock the scroll of main content
setTimeout(() => {
dispatch(setTaskManagement(true));
Expand Down Expand Up @@ -307,9 +308,8 @@ export const UploadObjectsOperation = memo<UploadObjectsOperationProps>(
);

if (!createObjectTx) {
// TODO refactor
dispatch(setupWaitTaskErrorMsg({ id: waitObject.id, errorMsg: _createError }));
closeModal();
cleanup();
return;
}
// const [tagsTx, _tagsError] = await getUpdateObjectTagsTx({
Expand All @@ -335,7 +335,7 @@ export const UploadObjectsOperation = memo<UploadObjectsOperationProps>(
errorMsg: error ?? 'Something went wrong.',
}),
);
closeModal();
cleanup();
return;
}
const createHash = txRes.transactionHash;
Expand Down Expand Up @@ -375,7 +375,7 @@ export const UploadObjectsOperation = memo<UploadObjectsOperationProps>(
);
}

closeModal();
cleanup();
setTimeout(() => {
dispatch(setTaskManagement(true));
}, 400);
Expand Down Expand Up @@ -406,6 +406,7 @@ export const UploadObjectsOperation = memo<UploadObjectsOperationProps>(
const [{ isOver }, drop] = useDrop<DragItemProps, any, DragMonitorProps>({
accept: [NativeTypes.FILE],
async drop({ items }) {
console.log('items', items.length);
const tree = await traverseTransferItems(items);
handleFolderTree(tree);
},
Expand Down
Loading

0 comments on commit 3587213

Please sign in to comment.