1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-13 13:50:07 +00:00

feat: rename face recognition view (#7164)

* feat: rename face recognition view

* feat: optimize code

---------

Co-authored-by: 杨国璇 <ygx@Hello-word.local>
This commit is contained in:
杨国璇
2024-12-09 14:13:37 +08:00
committed by GitHub
parent 3918b093fa
commit 3f6c4f3d26
4 changed files with 35 additions and 19 deletions

View File

@@ -7,6 +7,7 @@ import { PRIVATE_FILE_TYPE } from '../../constants';
import { FACE_RECOGNITION_VIEW_ID, VIEW_TYPE } from '../constants'; import { FACE_RECOGNITION_VIEW_ID, VIEW_TYPE } from '../constants';
import { useMetadataStatus } from '../../hooks'; import { useMetadataStatus } from '../../hooks';
import { updateFavicon } from '../utils/favicon'; import { updateFavicon } from '../utils/favicon';
import { getViewName } from '../utils/view';
// This hook provides content related to seahub interaction, such as whether to enable extended attributes, views data, etc. // This hook provides content related to seahub interaction, such as whether to enable extended attributes, views data, etc.
const MetadataContext = React.createContext(null); const MetadataContext = React.createContext(null);
@@ -30,7 +31,7 @@ export const MetadataProvider = ({ repoID, currentPath, repoInfo, hideMetadataVi
const { navigation, views } = res.data; const { navigation, views } = res.data;
if (Array.isArray(views)) { if (Array.isArray(views)) {
views.forEach(view => { views.forEach(view => {
viewsMap.current[view._id] = view; viewsMap.current[view._id] = { ...view, name: getViewName(view) };
}); });
} }
setNavigation(navigation); setNavigation(navigation);
@@ -91,7 +92,7 @@ export const MetadataProvider = ({ repoID, currentPath, repoInfo, hideMetadataVi
const view = res.data.view; const view = res.data.view;
let newNavigation = navigation.slice(0); let newNavigation = navigation.slice(0);
newNavigation.push({ _id: view._id, type: 'view' }); newNavigation.push({ _id: view._id, type: 'view' });
viewsMap.current[view._id] = view; viewsMap.current[view._id] = { ...view, name: getViewName(view) };
setNavigation(newNavigation); setNavigation(newNavigation);
selectView(view); selectView(view);
successCallback && successCallback(); successCallback && successCallback();
@@ -156,7 +157,7 @@ export const MetadataProvider = ({ repoID, currentPath, repoInfo, hideMetadataVi
if (newValue === enableFaceRecognition) return; if (newValue === enableFaceRecognition) return;
if (newValue) { if (newValue) {
toaster.success(gettext('Recognizing portraits. Please refresh the page later.')); toaster.success(gettext('Recognizing portraits. Please refresh the page later.'));
addView(gettext('Photos - classified by people'), VIEW_TYPE.FACE_RECOGNITION, () => {}, () => {}); addView('_people', VIEW_TYPE.FACE_RECOGNITION, () => {}, () => {});
} else { } else {
if (viewsMap.current[FACE_RECOGNITION_VIEW_ID]) { if (viewsMap.current[FACE_RECOGNITION_VIEW_ID]) {
let isSelected = false; let isSelected = false;

View File

@@ -50,9 +50,7 @@ const ViewItem = ({
const operations = useMemo(() => { const operations = useMemo(() => {
if (!canUpdate) return []; if (!canUpdate) return [];
if (view._id === FACE_RECOGNITION_VIEW_ID) { if (view._id === FACE_RECOGNITION_VIEW_ID) {
return [ return [];
{ key: 'rename', value: gettext('Rename') },
];
} }
let value = [ let value = [
{ key: 'rename', value: gettext('Rename') }, { key: 'rename', value: gettext('Rename') },
@@ -240,19 +238,21 @@ const ViewItem = ({
<Icon symbol={VIEW_TYPE_ICON[view.type] || 'table'} className="metadata-views-icon" /> <Icon symbol={VIEW_TYPE_ICON[view.type] || 'table'} className="metadata-views-icon" />
</div> </div>
</div> </div>
<div className="right-icon" id={`metadata-view-dropdown-item-${view._id}`} > {operations.length > 0 && (
{highlight && ( <div className="right-icon" id={`metadata-view-dropdown-item-${view._id}`} >
<ItemDropdownMenu {highlight && (
item={{ name: 'metadata-view' }} <ItemDropdownMenu
toggleClass="sf3-font sf3-font-more" item={{ name: 'metadata-view' }}
freezeItem={freezeItem} toggleClass="sf3-font sf3-font-more"
unfreezeItem={unfreezeItem} freezeItem={freezeItem}
getMenuList={() => operations} unfreezeItem={unfreezeItem}
onMenuItemClick={operationClick} getMenuList={() => operations}
menuStyle={isMobile ? { zIndex: 1050 } : {}} onMenuItemClick={operationClick}
/> menuStyle={isMobile ? { zIndex: 1050 } : {}}
)} />
</div> )}
</div>
)}
</div> </div>
</> </>
); );

View File

@@ -1,7 +1,20 @@
import { gettext } from '../../../utils/constants';
import { VIEW_TYPE } from '../../constants';
import { getValidFilters } from '../filter'; import { getValidFilters } from '../filter';
import { getValidGroupbys } from '../group'; import { getValidGroupbys } from '../group';
import { getValidSorts } from '../sort'; import { getValidSorts } from '../sort';
/**
* Get view name
* @param {object} view e.g. { type, name, _id }
* @returns view name, string
*/
const getViewName = (view = {}) => {
const { type, name } = view;
if (type === VIEW_TYPE.FACE_RECOGNITION) return gettext('People');
return name;
};
/** /**
* Get view by id * Get view by id
* @param {array} views e.g. [{ _id, ... }, ...] * @param {array} views e.g. [{ _id, ... }, ...]
@@ -85,6 +98,7 @@ const getViewShownColumns = (view, columns) => {
}; };
export { export {
getViewName,
getViewById, getViewById,
getViewByName, getViewByName,
isDefaultView, isDefaultView,

View File

@@ -1,4 +1,5 @@
export { export {
getViewName,
getViewById, getViewById,
getViewByName, getViewByName,
isDefaultView, isDefaultView,