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 7, 2024
1 parent bb05195 commit 730880d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Header, Body } from '../detail';
import FileDetails from './file-details';
import { MetadataContext } from '../../../metadata';
import { MetadataDetailsProvider } from '../../../metadata/hooks';
import Settings from '../../../metadata/components/metadata-details/settings';

import './index.css';

Expand Down Expand Up @@ -52,7 +53,9 @@ const EmbeddedFileDetails = ({ repoID, repoInfo, dirent, path, onClose, width =
})}
style={{ width }}
>
<Header title={dirent?.name || ''} icon={Utils.getDirentIcon(dirent, true)} onClose={onClose} component={headerComponent} />
<Header title={dirent?.name || ''} icon={Utils.getDirentIcon(dirent, true)} onClose={onClose} component={headerComponent} >
<Settings />
</Header>
<Body>
{dirent && direntDetail && (
<div className="detail-content">
Expand Down
21 changes: 5 additions & 16 deletions frontend/src/metadata/hooks/metadata-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import { SYSTEM_FOLDERS } from '../../constants';
import Column from '../model/column';
import { normalizeFields } from '../components/metadata-details/utils';
import { CellType, EVENT_BUS_TYPE, PREDEFINED_COLUMN_KEYS, PRIVATE_COLUMN_KEY } from '../constants';
import { getCellValueByColumn, getOptionName, getColumnOptionNamesByIds, getColumnOptionNameById, getRecordIdFromRecord, getFileObjIdFromRecord } from '../utils/cell';
import { getCellValueByColumn, getOptionName, getColumnOptionNamesByIds, getColumnOptionNameById, getRecordIdFromRecord,
getFileObjIdFromRecord
} from '../utils/cell';
import tagsAPI from '../../tag/api';
import { getColumnByKey, getColumnOptions, getColumnOriginName } from '../utils/column';
import LocalStorage from '../utils/local-storage';
Expand Down Expand Up @@ -147,20 +149,7 @@ export const MetadataDetailsProvider = ({ repoID, repoInfo, path, dirent, dirent

useEffect(() => {
setLoading(true);
if (!dirent || !direntDetail) {
setRecord(null);
setColumns([]);
setLoading(false);
return;
}

if (!enableMetadata) {
setRecord(null);
setColumns([]);
setLoading(false);
}

if (SYSTEM_FOLDERS.find(folderPath => path.startsWith(folderPath))) {
if (!dirent || !direntDetail || !enableMetadata || SYSTEM_FOLDERS.find(folderPath => path.startsWith(folderPath))) {
setRecord(null);
setColumns([]);
setLoading(false);
Expand All @@ -177,7 +166,7 @@ export const MetadataDetailsProvider = ({ repoID, repoInfo, path, dirent, dirent
metadataAPI.getMetadataRecordInfo(repoID, parentDir, fileName).then(res => {
const { results, metadata } = res.data;
const record = Array.isArray(results) && results.length > 0 ? results[0] : {};
const columns = normalizeFields(metadata, record).map(field => new Column(field));
const columns = normalizeFields(metadata).map(field => new Column(field));
allColumnsRef.current = columns;
setRecord(record);
localStorageRef.current = new LocalStorage(`sf-metadata-detail-settings-${repoID}`);
Expand Down

0 comments on commit 730880d

Please sign in to comment.