Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(objectstorage): regex #4296

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 9 additions & 40 deletions frontend/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/providers/objectstorage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"echarts": "^5.4.3",
"echarts-for-react": "^3.0.2",
"framer-motion": "^10.16.4",
"fuse.js": "^7.0.0",
"i18next": "^22.5.1",
"js-yaml": "^4.1.0",
"jszip": "^3.10.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
ButtonGroup,
Center,
Checkbox,
CheckboxGroup,
Flex,
FlexProps,
HStack,
Expand All @@ -31,6 +30,7 @@ import {
Tr,
useCheckboxGroup
} from '@chakra-ui/react';
import Fuse from 'fuse.js';
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { useTranslation } from 'next-i18next';
import PathLink from './PathLink';
Expand All @@ -46,9 +46,8 @@ import { GetObjectCommand, _Object } from '@aws-sdk/client-s3';
import { useToast } from '@/hooks/useToast';
import { useEffect, useState } from 'react';
import ArrowDownSLineIcon from '../Icons/ArrowDownSLineIcon';
import { formatBytes, searchText, useCopyData } from '@/utils/tools';
import { formatBytes, useCopyData } from '@/utils/tools';
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
import { useRouter } from 'next/router';
import { format } from 'date-fns';
import DeleteFileModal from '../common/modal/DeleteFileModal';
import DeleteSingleFileModal from '../common/modal/DeleteSingleFileModal';
Expand All @@ -75,6 +74,9 @@ export default function FileManager({ ...styles }: FlexProps) {
const [ContinuationToken, setContinuationToken] = useState<string | undefined>(undefined);
const [searchVal, setSearchVal] = useState('');
const [MaxKeys, setMaxKeys] = useState(20);
const { toast } = useToast();
const setPrefix = useOssStore((s) => s.setPrefix);
const queryClient = useQueryClient();
const clearPage = () => {
setpageStack([]);
setContinuationToken(undefined);
Expand Down Expand Up @@ -104,8 +106,6 @@ export default function FileManager({ ...styles }: FlexProps) {
useEffect(() => {
deleteCheckBoxGroupState.setValue([]);
}, [bucket, prefix, pageStack, ContinuationToken]);
const { toast } = useToast();
const queryClient = useQueryClient();
const deleteMutation = useMutation({
mutationFn: deleteObject(s3client!),
onSuccess() {
Expand All @@ -125,7 +125,6 @@ export default function FileManager({ ...styles }: FlexProps) {
});
}
});
const setPrefix = useOssStore((s) => s.setPrefix);
const deleteEntry = (file: EntryType) => {
if (!s3client || !bucket?.name) return;
if (!file.isDir) {
Expand Down Expand Up @@ -161,6 +160,7 @@ export default function FileManager({ ...styles }: FlexProps) {
.filter((v) => v.trim() !== '') || [];
if (relativePath.length === 0) return [];
const fileName = relativePath[0];
if (fileName === FolderPlaceholder) return [];
const fileNameArr = fileName.split('.');
return [
{
Expand All @@ -184,9 +184,25 @@ export default function FileManager({ ...styles }: FlexProps) {
isDir: true
})) || [])
];
const fuse = new Fuse(fileList, {
keys: ['fileName']
});
if (prefix.length > 0)
fileList.unshift({
LastModified: undefined,
fileName: '..',
Key: [prefix, '..'].join('/'),
Size: 0,
type: 'link',
isDir: true
});
const fuseList = fuse.search(searchVal);
// --------
// budle delete
const deleteCheckBoxGroupState = useCheckboxGroup({
defaultValue: []
});

const multiDeleteEntry = async (_keyList: string[]) => {
if (!s3client || !bucket?.name) return;
const objs = fileList.filter((file) => _keyList.includes(file.Key) && file.type !== 'link');
Expand Down Expand Up @@ -227,15 +243,6 @@ export default function FileManager({ ...styles }: FlexProps) {
trueFileList.every((f) => deleteCheckBoxGroupState.value.includes(f.Key));
const someDelete =
trueFileList.some((f) => deleteCheckBoxGroupState.value.includes(f.Key)) && !allDelete;
if (prefix.length > 0)
fileList.unshift({
LastModified: undefined,
fileName: '..',
Key: [prefix, '..'].join('/'),
Size: 0,
type: 'link',
isDir: true
});
return (
<Flex direction={'column'} {...styles}>
<HStack w="full" my="16px" mb="25px">
Expand Down Expand Up @@ -343,114 +350,103 @@ export default function FileManager({ ...styles }: FlexProps) {
}
}}
>
{fileList
.filter((file) => file.fileName !== FolderPlaceholder)
.filter((file) => !!searchText(searchVal)(file.fileName))
.map((file) => (
<Tr
key={file.fileName}
_hover={{
bgColor: 'white_.600'
}}
onClick={() => {
if (!file.isDir) return;
clearPage();
deleteCheckBoxGroupState.setValue([]);
if (file.type === 'link') {
const targetPrefix = [...prefix];
targetPrefix.pop();
setPrefix(targetPrefix);
} else setPrefix([...prefix, file.fileName]);
}}
cursor={file.isDir ? 'pointer' : 'initial'}
>
<Td>
<HStack gap="10px">
{!(file.type === 'link' && file.isDir) && (
<Box onClick={(e) => e.stopPropagation()}>
<Checkbox
{...deleteCheckBoxGroupState.getCheckboxProps({ value: file.Key })}
/>
</Box>
)}
{
// isdir
file.isDir ? (
<FolderIcon boxSize={'20px'} color="blue.600" />
) : (
<FileIcon boxSize={'20px'} color="purple.500" />
)
}
<Text color="grayModern.900">{file.fileName}</Text>
</HStack>
</Td>
<Td>{file.isDir ? '--' : formatBytes(file.Size || 0).toString()}</Td>
<Td>{file.type}</Td>
<Td>
{file.LastModified ? format(file.LastModified, 'yyyy/MM/dd hh:mm') : ''}
</Td>
<Td isNumeric>
<ButtonGroup variant={'white-bg-icon'} color={'grayModern.900'}>
{!file.isDir && (
<IconButton
icon={<VisibityIcon boxSize={'14px'} />}
p="5px"
onClick={(e) => {
e.stopPropagation();
if (!s3client || !Bucket) return;
getSignedUrl(
s3client,
new GetObjectCommand({ Bucket, Key: file.Key })
)
.then((url) => {
window.open(new URL(url));
})
.catch((err) => {
toast({
status: 'error',
title: 'get url error'
});
});
}}
aria-label={'preview'}
{(searchVal == '' ? fileList : fuseList.map((v) => v.item)).map((file) => (
<Tr
key={file.fileName}
_hover={{
bgColor: 'white_.600'
}}
onClick={() => {
if (!file.isDir) return;
clearPage();
deleteCheckBoxGroupState.setValue([]);
if (file.type === 'link') {
const targetPrefix = [...prefix];
targetPrefix.pop();
setPrefix(targetPrefix);
} else setPrefix([...prefix, file.fileName]);
}}
cursor={file.isDir ? 'pointer' : 'initial'}
>
<Td>
<HStack gap="10px">
{!(file.type === 'link' && file.isDir) && (
<Box onClick={(e) => e.stopPropagation()}>
<Checkbox
{...deleteCheckBoxGroupState.getCheckboxProps({ value: file.Key })}
/>
)}
{!file.isDir && (
<IconButton
icon={<LinkIcon boxSize={'14px'} />}
p="5px"
onClick={(e) => {
e.stopPropagation();
if (!s3client || !Bucket) return;
getSignedUrl(
s3client,
new GetObjectCommand({ Bucket, Key: file.Key })
)
.then((url) => {
copyData(url);
})
.catch((err) => {
toast({
status: 'error',
title: 'get url error'
});
</Box>
)}
{
// isdir
file.isDir ? (
<FolderIcon boxSize={'20px'} color="blue.600" />
) : (
<FileIcon boxSize={'20px'} color="purple.500" />
)
}
<Text color="grayModern.900">{file.fileName}</Text>
</HStack>
</Td>
<Td>{file.isDir ? '--' : formatBytes(file.Size || 0).toString()}</Td>
<Td>{file.type}</Td>
<Td>{file.LastModified ? format(file.LastModified, 'yyyy/MM/dd hh:mm') : ''}</Td>
<Td isNumeric>
<ButtonGroup variant={'white-bg-icon'} color={'grayModern.900'}>
{!file.isDir && (
<IconButton
icon={<VisibityIcon boxSize={'14px'} />}
p="5px"
onClick={(e) => {
e.stopPropagation();
if (!s3client || !Bucket) return;
getSignedUrl(s3client, new GetObjectCommand({ Bucket, Key: file.Key }))
.then((url) => {
window.open(new URL(url));
})
.catch((err) => {
toast({
status: 'error',
title: 'get url error'
});
}}
aria-label={'link'}
/>
)}
{!(file.isDir && file.type === 'link') && (
<DeleteSingleFileModal
aria-label={'delete'}
onDelete={() => {
deleteEntry(file);
}}
/>
)}
</ButtonGroup>
</Td>
</Tr>
))}
});
}}
aria-label={'preview'}
/>
)}
{!file.isDir && (
<IconButton
icon={<LinkIcon boxSize={'14px'} />}
p="5px"
onClick={(e) => {
e.stopPropagation();
if (!s3client || !Bucket) return;
getSignedUrl(s3client, new GetObjectCommand({ Bucket, Key: file.Key }))
.then((url) => {
copyData(url);
})
.catch((err) => {
toast({
status: 'error',
title: 'get url error'
});
});
}}
aria-label={'link'}
/>
)}
{!(file.isDir && file.type === 'link') && (
<DeleteSingleFileModal
aria-label={'delete'}
onDelete={() => {
deleteEntry(file);
}}
/>
)}
</ButtonGroup>
</Td>
</Tr>
))}
</Tbody>
</Table>
{fileList.length === 0 && (
Expand Down
Loading