|
|
@@ -3,7 +3,6 @@
|
|
|
import React from 'react';
|
|
|
import PropTypes from 'prop-types';
|
|
|
import { withTranslation } from 'react-i18next';
|
|
|
-import toastr from 'toastr';
|
|
|
|
|
|
import { withUnstatedContainers } from './UnstatedUtils';
|
|
|
import AppContainer from '~/client/services/AppContainer';
|
|
|
@@ -12,7 +11,7 @@ import SearchPageLayout from './SearchPage/SearchPageLayout';
|
|
|
import SearchResultContent from './SearchPage/SearchResultContent';
|
|
|
import SearchResultList from './SearchPage/SearchResultList';
|
|
|
import SearchControl from './SearchPage/SearchControl';
|
|
|
-import DeletePageListModal from './SearchPage/DeletePageListModal';
|
|
|
+import PageDeleteModal from './PageDeleteModal';
|
|
|
|
|
|
import { CheckboxType } from '../interfaces/search';
|
|
|
|
|
|
@@ -20,16 +19,6 @@ export const specificPathNames = {
|
|
|
user: '/user',
|
|
|
trash: '/trash',
|
|
|
};
|
|
|
-
|
|
|
-const toastrOption = {
|
|
|
- closeButton: true,
|
|
|
- progressBar: true,
|
|
|
- newestOnTop: false,
|
|
|
- showDuration: '100',
|
|
|
- hideDuration: '100',
|
|
|
- timeOut: '3000',
|
|
|
-};
|
|
|
-
|
|
|
class SearchPage extends React.Component {
|
|
|
|
|
|
constructor(props) {
|
|
|
@@ -50,6 +39,8 @@ class SearchPage extends React.Component {
|
|
|
excludeUsersHome: true,
|
|
|
excludeTrash: true,
|
|
|
selectAllCheckboxType: CheckboxType.NONE_CHECKED,
|
|
|
+ isDeleteConfirmModalShown: false,
|
|
|
+ deleteTargetPageIds: new Set(),
|
|
|
};
|
|
|
|
|
|
this.changeURL = this.changeURL.bind(this);
|
|
|
@@ -61,10 +52,9 @@ class SearchPage extends React.Component {
|
|
|
this.onExcludeTrash = this.onExcludeTrash.bind(this);
|
|
|
this.onPagingNumberChanged = this.onPagingNumberChanged.bind(this);
|
|
|
this.onPagingLimitChanged = this.onPagingLimitChanged.bind(this);
|
|
|
- this.deleteSelectedPages = this.deleteSelectedPages.bind(this);
|
|
|
- this.onClickDeleteAllButton = this.onClickDeleteAllButton.bind(this);
|
|
|
- this.onCloseDeleteConfirmModal = this.onCloseDeleteConfirmModal.bind(this);
|
|
|
- this.onChangeDeleteCompletely = this.onChangeDeleteCompletely.bind(this);
|
|
|
+ this.deleteSinglePageButtonHandler = this.deleteSinglePageButtonHandler.bind(this);
|
|
|
+ this.deleteAllPagesButtonHandler = this.deleteAllPagesButtonHandler.bind(this);
|
|
|
+ this.closeDeleteConfirmModalHandler = this.closeDeleteConfirmModalHandler.bind(this);
|
|
|
}
|
|
|
|
|
|
componentDidMount() {
|
|
|
@@ -238,54 +228,30 @@ class SearchPage extends React.Component {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
- getSelectedPages() {
|
|
|
- return this.state.searchResults.filter((page) => {
|
|
|
- return Array.from(this.state.selectedPagesIdList).find(id => id === page.pageData._id);
|
|
|
+ getSelectedPagesToDelete() {
|
|
|
+ const filteredPages = this.state.searchResults.filter((page) => {
|
|
|
+ return Array.from(this.state.deleteTargetPageIds).find(id => id === page.pageData._id);
|
|
|
});
|
|
|
+ return filteredPages.map(page => ({
|
|
|
+ pageId: page.pageData._id,
|
|
|
+ revisionId: page.pageData.revision,
|
|
|
+ path: page.pageData.path,
|
|
|
+ }));
|
|
|
}
|
|
|
|
|
|
- onClickDeleteAllButton() {
|
|
|
- if (this.state.selectedPagesIdList.size === 0) { return }
|
|
|
+ deleteSinglePageButtonHandler(pageId) {
|
|
|
+ this.setState({ deleteTargetPageIds: new Set([pageId]) });
|
|
|
this.setState({ isDeleteConfirmModalShown: true });
|
|
|
}
|
|
|
|
|
|
- onCloseDeleteConfirmModal() {
|
|
|
- this.setState({ isDeleteConfirmModalShown: false });
|
|
|
- }
|
|
|
-
|
|
|
- onChangeDeleteCompletely() {
|
|
|
- this.setState({ isDeleteCompletely: !this.state.isDeleteCompletely });
|
|
|
+ deleteAllPagesButtonHandler() {
|
|
|
+ if (this.state.selectedPagesIdList.size === 0) { return }
|
|
|
+ this.setState({ deleteTargetPageIds: this.state.selectedPagesIdList });
|
|
|
+ this.setState({ isDeleteConfirmModalShown: true });
|
|
|
}
|
|
|
|
|
|
- async deleteSelectedPages() {
|
|
|
- const { t } = this.props;
|
|
|
- toastr.warning(t('search_result.currently_not_implemented'));
|
|
|
- // const deleteCompletely = this.state.isDeleteCompletely || null;
|
|
|
- try {
|
|
|
-
|
|
|
- // const selectedPages = this.getSelectedPages();
|
|
|
-
|
|
|
- // ************** replace these code that remove pages with code that does bulk remove **************
|
|
|
- // Todo: https://redmine.weseek.co.jp/issues/82220
|
|
|
- // await Promise.all(selectedPages.map(async(page) => {
|
|
|
- // const removePageParams = { page_id: page._id, revision_id: page.revision, completely: deleteCompletely };
|
|
|
- // try {
|
|
|
- // const res = await this.props.appContainer.apiPost('/pages.remove', removePageParams);
|
|
|
- // if (res.ok) { this.state.selectedPagesIdList.delete(page) }
|
|
|
- // }
|
|
|
- // catch (err) {
|
|
|
- // this.setState({ errorMessageForDeleting: err.message });
|
|
|
- // throw new Error(err.message);
|
|
|
- // }
|
|
|
- // }));
|
|
|
- // **************************************************************************************************
|
|
|
-
|
|
|
- this.search({ keyword: this.state.searchedKeyword });
|
|
|
- this.onCloseDeleteConfirmModal();
|
|
|
- }
|
|
|
- catch (err) {
|
|
|
- toastr.error(err, 'Error occured', { toastrOption });
|
|
|
- }
|
|
|
+ closeDeleteConfirmModalHandler() {
|
|
|
+ this.setState({ isDeleteConfirmModalShown: false });
|
|
|
}
|
|
|
|
|
|
renderSearchResultContent = () => {
|
|
|
@@ -311,6 +277,7 @@ class SearchPage extends React.Component {
|
|
|
onClickSearchResultItem={this.selectPage}
|
|
|
onClickCheckbox={this.toggleCheckBox}
|
|
|
onPagingNumberChanged={this.onPagingNumberChanged}
|
|
|
+ onClickDeleteButton={this.deleteSinglePageButtonHandler}
|
|
|
/>
|
|
|
);
|
|
|
}
|
|
|
@@ -326,7 +293,7 @@ class SearchPage extends React.Component {
|
|
|
onExcludeTrash={this.onExcludeTrash}
|
|
|
onClickSelectAllCheckbox={this.toggleAllCheckBox}
|
|
|
selectAllCheckboxType={this.state.selectAllCheckboxType}
|
|
|
- onClickDeleteAllButton={this.onClickDeleteAllButton}
|
|
|
+ onClickDeleteAllButton={this.deleteAllPagesButtonHandler}
|
|
|
>
|
|
|
</SearchControl>
|
|
|
);
|
|
|
@@ -345,14 +312,10 @@ class SearchPage extends React.Component {
|
|
|
initialPagingLimit={this.props.appContainer.config.pageLimitationL || 50}
|
|
|
>
|
|
|
</SearchPageLayout>
|
|
|
- <DeletePageListModal
|
|
|
- isShown={this.state.isDeleteConfirmModalShown}
|
|
|
- pages={this.getSelectedPages()}
|
|
|
- errorMessage={this.state.errorMessageForDeleting}
|
|
|
- cancel={this.onCloseDeleteConfirmModal}
|
|
|
- confirmedToDelete={this.deleteSelectedPages}
|
|
|
- isDeleteCompletely={this.state.isDeleteCompletely}
|
|
|
- onChangeDeleteCompletely={this.onChangeDeleteCompletely}
|
|
|
+ <PageDeleteModal
|
|
|
+ isOpen={this.state.isDeleteConfirmModalShown}
|
|
|
+ onClose={this.closeDeleteConfirmModalHandler}
|
|
|
+ pages={this.getSelectedPagesToDelete()}
|
|
|
/>
|
|
|
</div>
|
|
|
);
|