Skip to content

Commit

Permalink
feat: update code
Browse files Browse the repository at this point in the history
  • Loading branch information
杨国璇 authored and 杨国璇 committed Aug 7, 2024
1 parent 9bda559 commit 8a18758
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import React, { useMemo } from 'react';
import PropTypes from 'prop-types';
import { getDirentPath, getFileParent } from './utils';
import { getDirentPath } from './utils';
import DetailItem from '../detail-item';
import { CellType } from '../../../metadata/metadata-view/_basic';
import { gettext } from '../../../utils/constants';
import { MetadataDetails } from '../../../metadata';

const DirDetails = ({ repoID, repoInfo, dirent, path, direntDetail, ...params }) => {
const parent = useMemo(() => getFileParent(dirent, path), [dirent, path]);
const direntPath = useMemo(() => getDirentPath(dirent, path), [dirent, path]);

return (
<>
<DetailItem field={{ type: CellType.TEXT, name: gettext('Parent folder') }} value={parent} />
<DetailItem field={{ type: 'size', name: gettext('Size') }} value={repoInfo.size} />
<DetailItem field={{ type: CellType.CREATOR, name: gettext('Creator') }} value={repoInfo.owner_email} collaborators={[{
name: repoInfo.owner_name,
contact_email: repoInfo.owner_contact_email,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useCallback, useMemo, useState } from 'react';
import PropTypes from 'prop-types';
import { v4 as uuidV4 } from 'uuid';
import { getDirentPath, getFileParent } from './utils';
import { getDirentPath } from './utils';
import DetailItem from '../detail-item';
import { CellType } from '../../../metadata/metadata-view/_basic';
import { gettext } from '../../../utils/constants';
Expand All @@ -14,7 +14,6 @@ import ObjectUtils from '../../../metadata/metadata-view/utils/object-utils';
const FileDetails = React.memo(({ repoID, repoInfo, dirent, path, direntDetail, onFileTagChanged, repoTags, fileTagList, ...params }) => {
const [isEditFileTagShow, setEditFileTagShow] = useState(false);

const parent = useMemo(() => getFileParent(dirent, path), [dirent, path]);
const direntPath = useMemo(() => getDirentPath(dirent, path), [dirent, path]);
const tagListTitleID = useMemo(() => `detail-list-view-tags-${uuidV4()}`, []);

Expand All @@ -28,7 +27,6 @@ const FileDetails = React.memo(({ repoID, repoInfo, dirent, path, direntDetail,

return (
<>
<DetailItem field={{ type: CellType.TEXT, name: gettext('Parent folder') }} value={parent} />
<DetailItem field={{ type: 'size', name: gettext('Size') }} value={Utils.bytesToSize(direntDetail.size)} />
<DetailItem field={{ type: CellType.LAST_MODIFIER, name: gettext('Last modifier') }} value={direntDetail.last_modifier_email} collaborators={[{
name: direntDetail.last_modifier_name,
Expand Down
34 changes: 19 additions & 15 deletions frontend/src/components/dirent-detail/dirent-details/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,30 +91,34 @@ class DirentDetails extends React.Component {
}
}

render() {
const { dirent, direntDetail, collaborators, collaboratorsCache } = this.state;
renderImage = () => {
const { dirent } = this.state;
if (!dirent) return null;
const { repoID, path, fileTags } = this.props;
const direntName = dirent.name;
const smallIconUrl = Utils.getDirentIcon(dirent);
// let bigIconUrl = Utils.getDirentIcon(dirent, true);
let bigIconUrl = '';
const isImg = Utils.imageCheck(dirent.name);
// const isVideo = Utils.videoCheck(dirent.name);
if (isImg) {
bigIconUrl = `${siteRoot}thumbnail/${repoID}/1024` + Utils.encodePath(`${path === '/' ? '' : path}/${dirent.name}`);
}
if (!isImg) return null;
const { repoID, path } = this.props;
const bigIconUrl = `${siteRoot}thumbnail/${repoID}/1024` + Utils.encodePath(`${path === '/' ? '' : path}/${dirent.name}`);
return (
<div className="detail-image-thumbnail">
<img src={bigIconUrl} alt="" className="thumbnail" />
</div>
);
};

render() {
const { dirent, direntDetail, collaborators, collaboratorsCache } = this.state;
const { repoID, path, fileTags } = this.props;
const direntName = dirent?.name || '';
const smallIconUrl = dirent ? Utils.getDirentIcon(dirent) : '';

return (
<Detail>
<Header title={direntName} icon={smallIconUrl} onClose={this.props.onClose} />
<Body>
{isImg && (
<div className="detail-image-thumbnail">
<img src={bigIconUrl} alt="" className="thumbnail" />
</div>
)}
{direntDetail && (
{this.renderImage()}
{dirent && direntDetail && (
<div className="detail-content">
{dirent.type !== 'file' ? (
<DirDetails
Expand Down
12 changes: 7 additions & 5 deletions frontend/src/components/dirent-detail/dirent-details/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ import { Utils } from '../../../utils/utils';

export const getDirentPath = (dirent, path) => {
if (Utils.isMarkdownFile(path)) return path; // column mode: view file
if (dirent.type === 'dir') return path;
return Utils.joinPath(path, dirent.name);
};

export const getFileParent = (dirent, path) => {
const direntPath = getDirentPath(dirent, path);
if (direntPath === '/') return '/';
const index = direntPath.lastIndexOf('/');
const positionPath = direntPath.slice(0, index);
return positionPath || '/';
let position = '';
if (direntPath !== '/') {
const index = direntPath.lastIndexOf('/');
const positionPath = direntPath.slice(0, index);
position = position + positionPath;
}
return position;
};

0 comments on commit 8a18758

Please sign in to comment.