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

Md copy view (#6598)

* duplicate md view

* optimize code

* optimize code

* Update metadata_manage.py

* Update metadata_manage.py

---------

Co-authored-by: 孙永强 <11704063+s-yongqiang@user.noreply.gitee.com>
Co-authored-by: r350178982 <32759763+r350178982@users.noreply.github.com>
This commit is contained in:
awu0403
2024-08-28 16:06:47 +08:00
committed by GitHub
parent 055a6c7814
commit 99c58486f7
7 changed files with 97 additions and 4 deletions

View File

@@ -118,6 +118,12 @@ class MetadataManagerAPI {
return this._sendPostRequest(url, params, { headers: { 'Content-type': 'application/json' } });
};
duplicateView = (repoID, viewId) => {
const url = this.server + '/api/v2.1/repos/' + repoID + '/metadata/duplicate-view/';
const params = { view_id: viewId };
return this._sendPostRequest(url, params, { headers: { 'Content-type': 'application/json' } });
};
modifyView = (repoID, viewId, viewData) => {
const url = this.server + '/api/v2.1/repos/' + repoID + '/metadata/views/';
const params = {

View File

@@ -120,6 +120,20 @@ export const MetadataProvider = ({ repoID, hideMetadataView, selectMetadataView,
});
}, [navigation, repoID, viewsMap, selectView]);
const duplicateView = useCallback((viewId) => {
metadataAPI.duplicateView(repoID, viewId).then(res => {
const view = res.data.view;
let newNavigation = navigation.slice(0);
newNavigation.push({ _id: view._id, type: 'view' });
viewsMap.current[view._id] = view;
setNavigation(newNavigation);
selectView(view);
}).catch(error => {
const errorMsg = Utils.getErrorMsg(error);
toaster.danger(errorMsg);
});
}, [navigation, repoID, viewsMap, selectView]);
const deleteView = useCallback((viewId, isSelected) => {
metadataAPI.deleteView(repoID, viewId).then(res => {
const newNavigation = navigation.filter(item => item._id !== viewId);
@@ -170,6 +184,7 @@ export const MetadataProvider = ({ repoID, hideMetadataView, selectMetadataView,
viewsMap: viewsMap.current,
selectView,
addView,
duplicateView,
deleteView,
updateView,
moveView,

View File

@@ -23,6 +23,7 @@ const MetadataTreeView = ({ userPerm, currentPath }) => {
viewsMap,
selectView,
addView,
duplicateView,
deleteView,
updateView,
moveView
@@ -122,6 +123,7 @@ const MetadataTreeView = ({ userPerm, currentPath }) => {
view={view}
onClick={(view) => selectView(view, isSelected)}
onDelete={() => deleteView(view._id, isSelected)}
onCopy={() => duplicateView(view._id)}
onUpdate={(update, successCallback, failCallback) => onUpdateView(view._id, update, successCallback, failCallback)}
onMove={moveView}
/>);

View File

@@ -16,6 +16,7 @@ const ViewItem = ({
view,
onClick,
onDelete,
onCopy,
onUpdate,
onMove,
}) => {
@@ -38,6 +39,7 @@ const ViewItem = ({
if (!canUpdate) return [];
let value = [
{ key: 'rename', value: gettext('Rename') },
{ key: 'duplicate', value: gettext('Duplicate') }
];
if (canDelete) {
value.push({ key: 'delete', value: gettext('Delete') });
@@ -75,11 +77,16 @@ const ViewItem = ({
return;
}
if (operationKey === 'duplicate') {
onCopy();
return;
}
if (operationKey === 'delete') {
onDelete();
return;
}
}, [onDelete]);
}, [onDelete, onCopy]);
const closeRenamePopover = useCallback((event) => {
event.stopPropagation();