Skip to content

Commit

Permalink
feat: delete record expand
Browse files Browse the repository at this point in the history
  • Loading branch information
杨国璇 authored and 杨国璇 committed Aug 5, 2024
1 parent a6f9060 commit 060f34a
Show file tree
Hide file tree
Showing 21 changed files with 26 additions and 647 deletions.
2 changes: 1 addition & 1 deletion frontend/src/components/dirent-detail/detail-item/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ DetailItem.defaultProps = {

DetailItem.propTypes = {
field: PropTypes.object.isRequired,
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.array, PropTypes.object]),
value: PropTypes.any,
children: PropTypes.any,
valueId: PropTypes.string,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const DirDetails = ({ repoID, repoInfo, dirent, direntType, path, direntDetail }
}]} />
<DetailItem field={{ type: CellType.MTIME, name: gettext('Last modified time') }} value={direntDetail.mtime} />
{window.app.pageOptions.enableMetadataManagement && (
<MetadataDetails repoID={repoID} filePath={direntPath} direntType={direntType} direntDetail={direntDetail} />
<MetadataDetails repoID={repoID} filePath={direntPath} direntType={direntType} />
)}
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const FileDetails = ({ repoID, repoInfo, dirent, path, direntDetail, direntType,
</DetailItem>
)}
{window.app.pageOptions.enableMetadataManagement && (
<MetadataDetails repoID={repoID} filePath={direntPath} direntType={direntType} direntDetail={direntDetail} />
<MetadataDetails repoID={repoID} filePath={direntPath} direntType={direntType} />
)}
{isEditFileTagShow &&
<EditFileTagPopover
Expand Down
36 changes: 18 additions & 18 deletions frontend/src/components/dirent-detail/dirent-details/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useEffect, useRef, useState } from 'react';
import React, { useCallback, useEffect, useState } from 'react';
import PropTypes from 'prop-types';
import { siteRoot } from '../../../utils/constants';
import { seafileAPI } from '../../../utils/seafile-api';
Expand All @@ -11,29 +11,29 @@ import FileDetails from './file-details';

import './index.css';

const DirentDetails = ({ dirent, path, repoID, currentRepoInfo, repoTags, fileTags, onItemDetailsClose, onFileTagChanged }) => {
const DirentDetails = React.memo(({ dirent: propsDirent, path, repoID, currentRepoInfo, repoTags, fileTags, onItemDetailsClose, onFileTagChanged }) => {
const [direntType, setDirentType] = useState('');
const [direntDetail, setDirentDetail] = useState('');
const [folderDirent, setFolderDirent] = useState(null);
const direntRef = useRef(null);
const [dirent, setDirent] = useState(null);

const updateDetailView = useCallback((repoID, dirent, direntPath) => {
const apiName = dirent.type === 'file' ? 'getFileInfo' : 'getDirInfo';
seafileAPI[apiName](repoID, direntPath).then(res => {
setDirentType(dirent.type === 'file' ? 'file' : 'dir');
setDirentDetail(res.data);
setDirent(dirent);
}).catch(error => {
const errMessage = Utils.getErrorMsg(error);
toaster.danger(errMessage);
});
}, []);

useEffect(() => {
if (direntRef.current && dirent === direntRef.current) return;
direntRef.current = dirent;
if (dirent) {
const direntPath = Utils.joinPath(path, dirent.name);
updateDetailView(repoID, dirent, direntPath);
console.log('index 组件更新');

Check warning on line 32 in frontend/src/components/dirent-detail/dirent-details/index.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected console statement
setDirent(null);
if (propsDirent) {
const direntPath = Utils.joinPath(path, propsDirent.name);
updateDetailView(repoID, propsDirent, direntPath);
return;
}
const dirPath = Utils.getDirName(path);
Expand All @@ -47,25 +47,25 @@ const DirentDetails = ({ dirent, path, repoID, currentRepoInfo, repoTags, fileTa
break;
}
}
setFolderDirent(folderDirent);
updateDetailView(repoID, folderDirent, path);
}).catch(error => {
const errMessage = Utils.getErrorMsg(error);
toaster.danger(errMessage);
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [dirent, path, repoID]);
}, [propsDirent, path]);

if (!dirent && !folderDirent) return '';
const direntName = dirent ? dirent.name : folderDirent.name;
const smallIconUrl = dirent ? Utils.getDirentIcon(dirent) : Utils.getDirentIcon(folderDirent);
if (!dirent) return null;
const direntName = dirent.name;
const smallIconUrl = Utils.getDirentIcon(dirent);
// let bigIconUrl = dirent ? Utils.getDirentIcon(dirent, true) : Utils.getDirentIcon(folderDirent, true);
let bigIconUrl = '';
const isImg = dirent ? Utils.imageCheck(dirent.name) : Utils.imageCheck(folderDirent.name);
const isImg = Utils.imageCheck(dirent.name);
// const isVideo = dirent ? Utils.videoCheck(dirent.name) : Utils.videoCheck(folderDirent.name);
if (isImg) {
bigIconUrl = `${siteRoot}thumbnail/${repoID}/1024` + Utils.encodePath(`${path === '/' ? '' : path}/${dirent.name}`);
}

return (
<div className="detail-container">
<Header title={direntName} icon={smallIconUrl} onClose={onItemDetailsClose} />
Expand All @@ -81,7 +81,7 @@ const DirentDetails = ({ dirent, path, repoID, currentRepoInfo, repoTags, fileTa
<DirDetails
repoID={repoID}
repoInfo={currentRepoInfo}
dirent={dirent || folderDirent}
dirent={dirent}
direntType={direntType}
direntDetail={direntDetail}
path={path}
Expand All @@ -90,7 +90,7 @@ const DirentDetails = ({ dirent, path, repoID, currentRepoInfo, repoTags, fileTa
<FileDetails
repoID={repoID}
repoInfo={currentRepoInfo}
dirent={dirent || folderDirent}
dirent={dirent}
direntType={direntType}
path={path}
direntDetail={direntDetail}
Expand All @@ -104,7 +104,7 @@ const DirentDetails = ({ dirent, path, repoID, currentRepoInfo, repoTags, fileTa
</div>
</div>
);
};
});

DirentDetails.propTypes = {
repoID: PropTypes.string.isRequired,
Expand Down
11 changes: 3 additions & 8 deletions frontend/src/metadata/metadata-details/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useMemo, useState } from 'react';
import React, { useEffect, useState } from 'react';
import PropTypes from 'prop-types';
import { Utils } from '../../utils/utils';
import metadataAPI from '../api';
Expand All @@ -7,14 +7,9 @@ import { normalizeFields, getCellValueByColumn } from './utils';
import toaster from '../../components/toast';
import DetailItem from '../../components/dirent-detail/detail-item';

const MetadataDetails = ({ repoID, filePath, direntType, direntDetail, emptyTip }) => {
const MetadataDetails = React.memo(({ repoID, filePath, direntType, emptyTip }) => {
const [isLoading, setLoading] = useState(true);
const [metadata, setMetadata] = useState({ record: {}, fields: [] });
const isEmptyFile = useMemo(() => {
if (direntType === 'dir') return false;
const direntDetailId = direntDetail?.id || '';
return direntDetailId === '0'.repeat(direntDetailId.length);
}, [direntDetail, direntType]);

useEffect(() => {
setLoading(true);
Expand Down Expand Up @@ -44,7 +39,7 @@ const MetadataDetails = ({ repoID, filePath, direntType, direntDetail, emptyTip
const value = getCellValueByColumn(record, field);
return (<DetailItem key={field.key} field={field} value={value} emptyTip={emptyTip}/>);
});
};
});

MetadataDetails.propTypes = {
repoID: PropTypes.string,
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/metadata/metadata-view/components/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import DeleteConfirmDialog from './delete-confirm-dialog';
import RecordDetailsDialog from './record-details-dialog';
import Table from './table';

export {
DeleteConfirmDialog,
RecordDetailsDialog,
Table,
};

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 060f34a

Please sign in to comment.