Skip to content

Commit

Permalink
change delete wiki page UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael18811380328 committed Dec 10, 2024
1 parent 00e8d7b commit e9a06b1
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 21 deletions.
22 changes: 22 additions & 0 deletions frontend/src/components/common/common-undo-tool.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import PropTypes from 'prop-types';
import { gettext } from '../../utils/constants';

function CommonUndoTool(props) {
const style = {
color: 'rgb(71, 184, 129)',
marginLeft: '8px',
paddingBottom: '1px',
borderBottom: '1px solid rgb(71, 184, 129)',
cursor: 'pointer',
};
return (
<span onClick={(e) => {e.stopPropagation(); props.onUndoOperation(e);}} style={style}>{gettext('Undo')}</span>
);
}

CommonUndoTool.propTypes = {
onUndoOperation: PropTypes.func.isRequired,
};

export default CommonUndoTool;
25 changes: 22 additions & 3 deletions frontend/src/pages/wiki2/side-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import deepCopy from 'deep-copy';
import classNames from 'classnames';
import { isWiki2, wikiId, wikiPermission } from '../../utils/constants';
import { isWiki2, wikiId, wikiPermission, gettext } from '../../utils/constants';
import toaster from '../../components/toast';
import Loading from '../../components/loading';
import WikiNav from './wiki-nav/index';
Expand All @@ -15,6 +15,7 @@ import WikiExternalOperations from './wiki-external-operations';
import WikiTrashDialog from './wiki-trash-dialog';
import { DEFAULT_PAGE_NAME } from './constant';
import Wiki2Search from '../../components/search/wiki2-search';
import CommonUndoTool from '../../components/common/common-undo-tool';

import './side-panel.css';

Expand All @@ -40,14 +41,20 @@ class SidePanel extends PureComponent {
};
}

confirmDeletePage = (pageId) => {
onDeletePage = (pageId) => {
const config = deepCopy(this.props.config);
const { pages } = config;
const index = PageUtils.getPageIndexById(pageId, pages);
config.pages.splice(index, 1);
wikiAPI.deleteWiki2Page(wikiId, pageId).then((res) => {
if (res.data.success === true) {
this.props.updateWikiConfig(config);
toaster.success(
<span>
{gettext('xxx page deleted').replace('xxx', pages[index].name)}
<CommonUndoTool onUndoOperation={() => this.revertWikiPage(pageId)} />
</span>
);
}
}).catch((error) => {
let errMessage = Utils.getErrorMsg(error);
Expand All @@ -59,6 +66,18 @@ class SidePanel extends PureComponent {
}
};

revertWikiPage = (pageId) => {
wikiAPI.revertTrashPage(wikiId, pageId).then(res => {
if (res.data.success === true) {
this.props.getWikiConfig();
toaster.success(gettext('Successfully restored 1 item.'));
}
}).catch((error) => {
let errMessage = Utils.getErrorMsg(error);
toaster.danger(errMessage);
});
};

addPageInside = async ({ parentPageId, page_id, name, icon, path, docUuid, successCallback, errorCallback }) => {
const newPage = new Page({ id: page_id, name, icon, path, docUuid });
this.addPage(newPage, parentPageId, successCallback, errorCallback);
Expand Down Expand Up @@ -130,7 +149,7 @@ class SidePanel extends PureComponent {
isEditMode={isWiki2}
navigation={navigation}
pages={pages}
onDeletePage={this.confirmDeletePage}
onDeletePage={this.onDeletePage}
onUpdatePage={onUpdatePage}
setCurrentPage={this.props.setCurrentPage}
onMovePage={this.movePage}
Expand Down
18 changes: 1 addition & 17 deletions frontend/src/pages/wiki2/wiki-nav/pages/page-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import classnames from 'classnames';
import NameEditPopover from '../../common/name-edit-popover';
import NavItemIcon from '../../common/nav-item-icon';
import PageDropdownMenu from './page-dropdownmenu';
import DeleteDialog from '../../common/delete-dialog';
import { gettext, wikiPermission } from '../../../../utils/constants';
import AddNewPageDialog from '../add-new-page-dialog';
import Icon from '../../../../components/icon';
Expand All @@ -20,7 +19,6 @@ class PageItem extends Component {
this.state = {
isShowNameEditor: false,
isShowOperationDropdown: false,
isShowDeleteDialog: false,
isShowInsertPage: false,
isShowAddSiblingPage: false,
insertPosition: '',
Expand Down Expand Up @@ -100,14 +98,6 @@ class PageItem extends Component {
this.setState({ pageName: newName });
};

openDeleteDialog = () => {
this.setState({ isShowDeleteDialog: true });
};

closeDeleteDialog = () => {
this.setState({ isShowDeleteDialog: false });
};

toggleDropdown = () => {
const isShowOperationDropdown = !this.state.isShowOperationDropdown;
this.setState({ isShowOperationDropdown });
Expand Down Expand Up @@ -277,7 +267,7 @@ class PageItem extends Component {
toggle={this.toggleDropdown}
toggleNameEditor={this.toggleNameEditor}
duplicatePage={this.props.duplicatePage}
onDeletePage={this.openDeleteDialog}
onDeletePage={this.props.onDeletePage.bind(this, page.id)}
toggleInsertSiblingPage={this.toggleInsertSiblingPage}
/>
}
Expand All @@ -288,12 +278,6 @@ class PageItem extends Component {
</>
}
</div>
{this.state.isShowDeleteDialog &&
<DeleteDialog
closeDeleteDialog={this.closeDeleteDialog}
handleSubmit={this.props.onDeletePage.bind(this, page.id)}
/>
}
{this.state.isShowInsertPage &&
<AddNewPageDialog
toggle={this.toggleInsertPage}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/wiki2/wiki-trash-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class WikiTrashDialog extends React.Component {
this.getItems(1);
});
};

cleanTrash = () => {
this.toggleCleanTrashDialog();
};
Expand Down Expand Up @@ -237,7 +238,6 @@ class Item extends React.Component {
});
};


render() {
const item = this.props.item;
const { restored, isIconShown } = this.state;
Expand Down

0 comments on commit e9a06b1

Please sign in to comment.