Skip to content

Commit

Permalink
feat: optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
杨国璇 authored and 杨国璇 committed Dec 27, 2024
1 parent 8ef8109 commit 5833f30
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
17 changes: 7 additions & 10 deletions frontend/src/metadata/components/metadata-details/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import DetailItem from '../../../components/dirent-detail/detail-item';
import { Utils } from '../../../utils/utils';
import { getCellValueByColumn, getFileNameFromRecord } from '../../utils/cell';
import { gettext } from '../../../utils/constants';
import { PRIVATE_COLUMN_KEY } from '../../constants';
import { PRIVATE_COLUMN_KEY, IMAGE_PRIVATE_COLUMN_KEYS } from '../../constants';
import Location from './location';
import { useMetadataDetails } from '../../hooks';
import { checkIsDir } from '../../utils/row';
Expand All @@ -24,26 +24,23 @@ const MetadataDetails = () => {
if (!record._id) return null;

const fileName = getFileNameFromRecord(record);
const isImage = record && (Utils.imageCheck(fileName) || Utils.videoCheck(fileName));
const isDir = record && checkIsDir(record);
const isImage = Utils.imageCheck(fileName) || Utils.videoCheck(fileName);
const isDir = checkIsDir(record);

return (
<>
{displayColumns.map(field => {
if (field.key === PRIVATE_COLUMN_KEY.LOCATION && isImage) {
return (<Location key={field.key} position={getCellValueByColumn(record, field)} />);
const value = getCellValueByColumn(record, field);
if (field.key === PRIVATE_COLUMN_KEY.LOCATION && isImage && value) {
return (<Location key={field.key} position={value} />);
}

let canEdit = canModifyRecord && field.editable;
if (!isImage && canEdit && field.key === PRIVATE_COLUMN_KEY.CAPTURE_TIME) {
canEdit = false;
} else if (field.key === PRIVATE_COLUMN_KEY.LOCATION && !isImage) {
if (!isImage && IMAGE_PRIVATE_COLUMN_KEYS.includes(field.key)) {
canEdit = false;
} else if (field.key === PRIVATE_COLUMN_KEY.TAGS && isDir) {
canEdit = false;
}

const value = getCellValueByColumn(record, field);
return (
<DetailItem key={field.key} field={field} readonly={!canEdit}>
{canEdit ? (
Expand Down
1 change: 1 addition & 0 deletions frontend/src/metadata/constants/column/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export {
EDITABLE_PRIVATE_COLUMN_KEYS,
EDITABLE_DATA_PRIVATE_COLUMN_KEYS,
DELETABLE_PRIVATE_COLUMN_KEY,
IMAGE_PRIVATE_COLUMN_KEYS,
} from './private';

export {
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/metadata/constants/column/private.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,8 @@ export const DELETABLE_PRIVATE_COLUMN_KEY = [
PRIVATE_COLUMN_KEY.OWNER,
PRIVATE_COLUMN_KEY.FILE_RATE,
];

export const IMAGE_PRIVATE_COLUMN_KEYS = [
PRIVATE_COLUMN_KEY.CAPTURE_TIME,
PRIVATE_COLUMN_KEY.LOCATION,
];

0 comments on commit 5833f30

Please sign in to comment.