Skip to content

Commit

Permalink
metadata table image use thumbnail
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael18811380328 committed Oct 14, 2024
1 parent 71ddac5 commit 60ef9a7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
20 changes: 17 additions & 3 deletions frontend/src/metadata/components/cell-formatter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,22 @@ import PropTypes from 'prop-types';
import { Formatter } from '@seafile/sf-metadata-ui-component';
import { useCollaborators } from '../../hooks';
import { Utils } from '../../../utils/utils';
import { siteRoot, thumbnailDefaultSize } from '../../../utils/constants';

const CellFormatter = ({ readonly, value, field, ...params }) => {
const CellFormatter = ({ readonly, value, field, record, ...params }) => {
const { collaborators, collaboratorsCache, updateCollaboratorsCache, queryUser } = useCollaborators();

const getFileIconUrl = useMemo((filename) => {
if (Utils.imageCheck(filename)) {
const path = Utils.encodePath(Utils.joinPath(record._parent_dir, filename));
const repoID = window.sfMetadataStore.repoId;
const thumbnail = `${siteRoot}thumbnail/${repoID}/${thumbnailDefaultSize}${path}`;
return thumbnail;
} else {
return Utils.getFileIconUrl(filename);
}
}, [record]);

const props = useMemo(() => {
return {
collaborators,
Expand All @@ -15,10 +28,10 @@ const CellFormatter = ({ readonly, value, field, ...params }) => {
value,
field,
queryUserAPI: queryUser,
getFileIconUrl: Utils.getFileIconUrl,
getFileIconUrl,
getFolderIconUrl: Utils.getFolderIconUrl,
};
}, [readonly, value, field, collaborators, collaboratorsCache, updateCollaboratorsCache, queryUser]);
}, [readonly, value, field, collaborators, collaboratorsCache, updateCollaboratorsCache, queryUser, getFileIconUrl]);

return (
<Formatter { ...props } { ...params } />
Expand All @@ -29,6 +42,7 @@ CellFormatter.propTypes = {
readonly: PropTypes.bool,
value: PropTypes.any,
field: PropTypes.object.isRequired,
record: PropTypes.object.isRequired,
};

export default CellFormatter;
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const Formatter = ({ isCellSelected, isDir, field, value, onChange, record }) =>
if (type === CellType.RATE && cellEditAble) {
return (<RateEditor isCellSelected={isCellSelected} value={value} field={field} onChange={onChange} />);
}
return (<CellFormatter readonly={true} value={value} field={field} isDir={isDir} />);
return (<CellFormatter readonly={true} value={value} field={field} isDir={isDir} record={record} />);
};

Formatter.propTypes = {
Expand Down

0 comments on commit 60ef9a7

Please sign in to comment.