Skip to content

Commit

Permalink
show people name in path (#7281)
Browse files Browse the repository at this point in the history
* show people name in path

* optimize

* optimize

* optimize

* feat: optimize code

---------

Co-authored-by: zhouwenxuan <[email protected]>
Co-authored-by: 杨国璇 <[email protected]>
  • Loading branch information
3 people authored Jan 3, 2025
1 parent 3795c05 commit db287cc
Show file tree
Hide file tree
Showing 15 changed files with 110 additions and 121 deletions.
109 changes: 49 additions & 60 deletions frontend/src/components/cur-dir-path/dir-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { siteRoot, gettext } from '../../utils/constants';
import { Utils } from '../../utils/utils';
import { PRIVATE_FILE_TYPE } from '../../constants';
import { debounce } from '../../metadata/utils/common';
import { EVENT_BUS_TYPE } from '../../metadata/constants';
import { EVENT_BUS_TYPE, FACE_RECOGNITION_VIEW_ID } from '../../metadata/constants';

const propTypes = {
currentRepoInfo: PropTypes.object.isRequired,
Expand Down Expand Up @@ -118,63 +118,59 @@ class DirPath extends React.Component {
});
};

handelRefresh = debounce(() => {
handleRefresh = debounce(() => {
window.sfMetadataContext.eventBus.dispatch(EVENT_BUS_TYPE.RELOAD_DATA);
}, 200);

turnViewPathToLink = (pathList) => {
if (!Array.isArray(pathList) || pathList.length === 0) return null;
const [, , viewId, children] = pathList;
const isViewSupportClick = viewId === FACE_RECOGNITION_VIEW_ID && children;
return (
<>
<span className="path-split">/</span>
<span className="path-item">{gettext('Views')}</span>
<span className="path-split">/</span>
<span className="path-item" role={isViewSupportClick ? 'button' : null} onClick={isViewSupportClick ? this.handleRefresh : () => {}}>
<MetadataViewName id={viewId} />
</span>
{children && (
<>
<span className="path-split">/</span>
<span className="path-item">{children}</span>
</>
)}
<div className="path-item-refresh" id="sf-metadata-view-refresh" onClick={this.handleRefresh}>
<i className="sf3-font sf3-font-refresh"></i>
<UncontrolledTooltip target="sf-metadata-view-refresh" placement="bottom">
{gettext('Refresh the view')}
</UncontrolledTooltip>
</div>
</>
);
};

turnTagPathToLink = (pathList) => {
if (!Array.isArray(pathList) || pathList.length === 0) return null;
const [, , tagId] = pathList;
return (
<>
<span className="path-split">/</span>
<span className="path-item">{gettext('Tags')}</span>
<span className="path-split">/</span>
<TagViewName id={tagId} />
</>
);
};

turnPathToLink = (path) => {
path = path[path.length - 1] === '/' ? path.slice(0, path.length - 1) : path;
let pathList = path.split('/');
const pathList = path.split('/');
if (pathList.includes(PRIVATE_FILE_TYPE.FILE_EXTENDED_PROPERTIES)) return this.turnViewPathToLink(pathList);
if (pathList.includes(PRIVATE_FILE_TYPE.TAGS_PROPERTIES)) return this.turnTagPathToLink(pathList);
let nodePath = '';
if (pathList.length === 2 && !pathList[0] && [PRIVATE_FILE_TYPE.FILE_EXTENDED_PROPERTIES, PRIVATE_FILE_TYPE.TAGS_PROPERTIES].includes(pathList[1])) {
return null;
}
let pathElem = pathList.map((item, index) => {
if (item === '') {
return null;
}
if (index === pathList.length - 2 && item === PRIVATE_FILE_TYPE.FILE_EXTENDED_PROPERTIES) {
return (
<Fragment key={index}>
<span className="path-split">/</span>
<span className="path-item">{gettext('Views')}</span>
</Fragment>
);
}

if (index === pathList.length - 2 && item === PRIVATE_FILE_TYPE.TAGS_PROPERTIES) {
return (
<Fragment key={index}>
<span className="path-split">/</span>
<span className="path-item">{gettext('Tags')}</span>
</Fragment>
);
}

if (index === pathList.length - 1 && pathList[pathList.length - 2] === PRIVATE_FILE_TYPE.FILE_EXTENDED_PROPERTIES) {
return (
<Fragment key={index}>
<span className="path-split">/</span>
<span className="path-item"><MetadataViewName id={item} /></span>
<div className="path-item-refresh" id="sf-metadata-view-refresh" onClick={this.handelRefresh}>
<i className="sf3-font sf3-font-refresh"></i>
<UncontrolledTooltip target="sf-metadata-view-refresh" placement="bottom">
{gettext('Refresh the view')}
</UncontrolledTooltip>
</div>
</Fragment>
);
}

if (index === pathList.length - 1 && pathList[pathList.length - 2] === PRIVATE_FILE_TYPE.TAGS_PROPERTIES) {
return (
<Fragment key={index}>
<span className="path-split">/</span>
<TagViewName id={item} />
</Fragment>
);
}

if (item === '') return null;
if (index === (pathList.length - 1)) {
return (
<Fragment key={index}>
Expand Down Expand Up @@ -221,16 +217,9 @@ class DirPath extends React.Component {
return pathElem;
};

isViewMetadata = () => {
const { currentPath } = this.props;
const path = currentPath[currentPath.length - 1] === '/' ? currentPath.slice(0, currentPath.length - 1) : currentPath;
const pathList = path.split('/');
return pathList[pathList.length - 2] === PRIVATE_FILE_TYPE.FILE_EXTENDED_PROPERTIES;
};

render() {
let { currentPath, repoName } = this.props;
let pathElem = this.turnPathToLink(currentPath);
const { currentPath, repoName } = this.props;
const pathElem = this.turnPathToLink(currentPath);
return (
<div className="path-container dir-view-path">
<span className="cur-view-path-btn mr-1" onClick={this.props.toggleTreePanel}>
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/components/dir-view-mode/dir-column-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const propTypes = {
onItemsScroll: PropTypes.func.isRequired,
eventBus: PropTypes.object,
updateCurrentDirent: PropTypes.func.isRequired,
updateCurrentPath: PropTypes.func,
};

class DirColumnView extends React.Component {
Expand Down Expand Up @@ -211,6 +212,7 @@ class DirColumnView extends React.Component {
addFolder={this.props.onAddFolder}
updateCurrentDirent={this.props.updateCurrentDirent}
showDirentDetail={this.props.showDirentDetail}
updateCurrentPath={this.props.updateCurrentPath}
/>
)}
{currentMode === TAGS_MODE && (
Expand Down
10 changes: 7 additions & 3 deletions frontend/src/components/dirent-detail/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ObjectUtils from '../../metadata/utils/object-utils';
import { MetadataContext } from '../../metadata';
import { PRIVATE_FILE_TYPE } from '../../constants';
import { METADATA_MODE, TAGS_MODE } from '../dir-view-mode/constants';
import { FACE_RECOGNITION_VIEW_ID } from '../../metadata/constants';

const Detail = React.memo(({ repoID, path, currentMode, dirent, currentRepoInfo, repoTags, fileTags, onClose, onFileTagChanged }) => {
const isView = useMemo(() => currentMode === METADATA_MODE || path.startsWith('/' + PRIVATE_FILE_TYPE.FILE_EXTENDED_PROPERTIES), [currentMode, path]);
Expand All @@ -30,9 +31,12 @@ const Detail = React.memo(({ repoID, path, currentMode, dirent, currentRepoInfo,

if (isTag) return null;

if (isView) {
const viewId = path.split('/').pop();
if (!dirent) return (<ViewDetails viewId={viewId} onClose={onClose} />);
if (isView && !dirent) {
const pathParts = path.split('/');
const [, , viewId, children] = pathParts;
if (!viewId) return null;
if (viewId === FACE_RECOGNITION_VIEW_ID && !children) return null;
return (<ViewDetails viewId={viewId} onClose={onClose} />);
}

if (path === '/' && !dirent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ const FaceRecognitionViewToolbar = ({ readOnly, isCustomPermission, onToggleDeta
columns={viewColumns}
modifySorts={modifySorts}
/>
{!isCustomPermission && (
<div className="cur-view-path-btn ml-2" onClick={onToggleDetail}>
<span className="sf3-font sf3-font-info" aria-label={gettext('Properties')} title={gettext('Properties')}></span>
</div>
)}
</>
)}
{!isCustomPermission && (
<div className="cur-view-path-btn ml-2" onClick={onToggleDetail}>
<span className="sf3-font sf3-font-info" aria-label={gettext('Properties')} title={gettext('Properties')}></span>
</div>
)}
</div>
<div className="sf-metadata-tool-right-operations"></div>
</>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/metadata/constants/z-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
export const CELL_MASK = 1;
export const TABLE_MAIN_INTERVAL = 1;
export const RESIZE_HANDLE = 1;
export const SEQUENCE_COLUMN = 1;
export const SEQUENCE_COLUMN = 2;

// higher than unfrozen header cell(0), RESIZE_HANDLE
export const FROZEN_HEADER_CELL = 2;
Expand Down
1 change: 1 addition & 0 deletions frontend/src/metadata/hooks/metadata-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ export const MetadataViewProvider = ({
insertColumn,
updateFileTags,
addFolder: params.addFolder,
updateCurrentPath: params.updateCurrentPath,
}}
>
{children}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/metadata/hooks/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ export const MetadataProvider = ({ repoID, currentPath, repoInfo, selectMetadata
if (idViewMap[FACE_RECOGNITION_VIEW_ID]) {
let isSelected = false;
if (currentPath.includes('/' + PRIVATE_FILE_TYPE.FILE_EXTENDED_PROPERTIES + '/')) {
const currentViewId = currentPath.split('/').pop();
const [, , currentViewId] = currentPath.split('/');
isSelected = currentViewId === FACE_RECOGNITION_VIEW_ID;
}
const folders = navigation.filter((nav) => nav.type === VIEWS_TYPE_FOLDER);
Expand Down Expand Up @@ -428,7 +428,7 @@ export const MetadataProvider = ({ repoID, currentPath, repoInfo, selectMetadata

useEffect(() => {
if (!currentPath.includes('/' + PRIVATE_FILE_TYPE.FILE_EXTENDED_PROPERTIES + '/')) return;
const currentViewId = currentPath.split('/').pop();
const [, , currentViewId] = currentPath.split('/');
const currentView = idViewMap[currentViewId];
if (currentView) {
document.title = `${currentView.name} - Seafile`;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/metadata/metadata-tree-view/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ const MetadataTreeView = ({ userPerm, currentPath }) => {

const renderView = (view) => {
const viewPath = '/' + PRIVATE_FILE_TYPE.FILE_EXTENDED_PROPERTIES + '/' + view._id;
const isSelected = currentPath === viewPath;
const isSelected = currentPath.includes(viewPath);
return (
<ViewItem
key={`metadata-views-folder-${view._id}`}
Expand Down
11 changes: 11 additions & 0 deletions frontend/src/metadata/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,17 @@ class Store {
this.applyOperation(operation);
}

modifyLocalView(update) {
const type = OPERATION_TYPE.MODIFY_LOCAL_VIEW;
const operation = this.createOperation({
type,
update,
repo_id: this.repoId,
view_id: this.viewId,
});
this.applyOperation(operation);
}

modifyGroupbys(groupbys) {
const type = OPERATION_TYPE.MODIFY_GROUPBYS;
const operation = this.createOperation({
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/metadata/store/operations/apply.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ export default function apply(data, operation) {
data.view.hidden_columns = hidden_columns;
return data;
}
case OPERATION_TYPE.MODIFY_LOCAL_VIEW: {
const { update } = operation;
data.view = { ...data.view, ...update };
return data;
}
case OPERATION_TYPE.INSERT_COLUMN: {
const { column } = operation;
const newColumn = new Column(column);
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/metadata/store/operations/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const OPERATION_TYPE = {
MODIFY_GROUPBYS: 'modify_groupbys',
MODIFY_HIDDEN_COLUMNS: 'modify_hidden_columns',
MODIFY_SETTINGS: 'modify_settings',
MODIFY_LOCAL_VIEW: 'modify_local_view',

// column
INSERT_COLUMN: 'insert_column',
Expand Down Expand Up @@ -56,6 +57,7 @@ export const OPERATION_ATTRIBUTES = {
[OPERATION_TYPE.MODIFY_SORTS]: ['repo_id', 'view_id', 'sorts'],
[OPERATION_TYPE.MODIFY_GROUPBYS]: ['repo_id', 'view_id', 'groupbys'],
[OPERATION_TYPE.MODIFY_HIDDEN_COLUMNS]: ['repo_id', 'view_id', 'hidden_columns'],
[OPERATION_TYPE.MODIFY_LOCAL_VIEW]: ['repo_id', 'view_id', 'update'],

[OPERATION_TYPE.INSERT_COLUMN]: ['repo_id', 'name', 'column_type', 'column_key', 'data', 'column'],
[OPERATION_TYPE.RENAME_COLUMN]: ['repo_id', 'column_key', 'new_name', 'old_name'],
Expand Down Expand Up @@ -91,6 +93,7 @@ export const LOCAL_APPLY_OPERATION_TYPE = [
OPERATION_TYPE.MODIFY_LOCAL_RECORD,
OPERATION_TYPE.MODIFY_LOCAL_COLUMN_DATA,
OPERATION_TYPE.DELETE_PEOPLE_PHOTOS,
OPERATION_TYPE.MODIFY_LOCAL_VIEW,
];

// apply operation after exec operation on the server
Expand Down
19 changes: 15 additions & 4 deletions frontend/src/metadata/views/face-recognition/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import React, { useCallback, useMemo, useRef, useState } from 'react';
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { useMetadataView } from '../../hooks/metadata-view';
import Peoples from './peoples';
import PeoplePhotos from './person-photos';
import { gettext } from '../../../utils/constants';
import { PRIVATE_FILE_TYPE } from '../../../constants';
import { FACE_RECOGNITION_VIEW_ID } from '../../constants';

import './index.css';

const FaceRecognition = () => {
const [showPeopleFaces, setShowPeopleFaces] = useState(false);
const peopleRef = useRef(null);

const { metadata, store, updateCurrentDirent } = useMetadataView();
const { metadata, store, updateCurrentDirent, updateCurrentPath } = useMetadataView();

const peoples = useMemo(() => {
if (!Array.isArray(metadata.rows) || metadata.rows.length === 0) return [];
Expand All @@ -26,19 +29,27 @@ const FaceRecognition = () => {

const openPeople = useCallback((people) => {
peopleRef.current = people;
const name = people._is_someone ? (people._name || gettext('Person image')) : gettext('Unknown people');
updateCurrentPath(`/${PRIVATE_FILE_TYPE.FILE_EXTENDED_PROPERTIES}/${FACE_RECOGNITION_VIEW_ID}/${name}`);
setShowPeopleFaces(true);
}, []);
}, [updateCurrentPath]);

const closePeople = useCallback(() => {
peopleRef.current = null;
setShowPeopleFaces(false);
updateCurrentDirent();
}, [updateCurrentDirent]);
updateCurrentPath(`/${PRIVATE_FILE_TYPE.FILE_EXTENDED_PROPERTIES}/${FACE_RECOGNITION_VIEW_ID}`);
}, [updateCurrentDirent, updateCurrentPath]);

const onRename = useCallback((id, newName, oldName) => {
store.renamePeopleName(id, newName, oldName);
}, [store]);

useEffect(() => {
updateCurrentPath(`/${PRIVATE_FILE_TYPE.FILE_EXTENDED_PROPERTIES}/${FACE_RECOGNITION_VIEW_ID}`);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

return (
<div className="sf-metadata-container">
{showPeopleFaces ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@
overflow-y: hidden !important;
}

.sf-metadata-people-photos-container .sf-metadata-people-photos-header {
height: 48px;
display: flex;
align-items: center;
padding: 0 16px;
border-bottom: 1px solid #eee;
}

.sf-metadata-people-photos-container .sf-metadata-icon-btn {
margin-left: -4px;
border-radius: 3px;
Expand All @@ -21,35 +13,6 @@
cursor: pointer;
}

.sf-metadata-people-photos-container .sf-metadata-people-photos-header .sf-metadata-people-photos-header-back {
font-size: 14px;
height: 24px;
min-width: 24px;
display: flex;
align-items: center;
justify-content: center;
margin-left: -5px;
border-radius: 3px;
}

.sf-metadata-people-photos-container .sf-metadata-people-photos-header .sf-metadata-people-photos-header-back:hover {
background-color: #EFEFEF;
cursor: pointer;
}

.sf-metadata-people-photos-container .sf-metadata-people-photos-header-back .sf3-font-arrow {
color: #666;
font-size: 14px !important;
}

.sf-metadata-people-photos-container .sf-metadata-people-photos-header .sf-metadata-people-name {
margin-left: 4px;
flex: 1;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}

.sf-metadata-people-photos-container .sf-metadata-gallery-container {
height: calc(100% - 48px);
}
Loading

0 comments on commit db287cc

Please sign in to comment.