|
@@ -1,16 +1,22 @@
|
|
|
import React, {
|
|
import React, {
|
|
|
- forwardRef, ForwardRefRenderFunction, useEffect, useImperativeHandle, useRef, useState,
|
|
|
|
|
|
|
+ forwardRef, ForwardRefRenderFunction, useCallback, useEffect, useImperativeHandle, useRef, useState,
|
|
|
} from 'react';
|
|
} from 'react';
|
|
|
|
|
+import { useTranslation } from 'react-i18next';
|
|
|
import { ISelectableAll } from '~/client/interfaces/selectable-all';
|
|
import { ISelectableAll } from '~/client/interfaces/selectable-all';
|
|
|
import AppContainer from '~/client/services/AppContainer';
|
|
import AppContainer from '~/client/services/AppContainer';
|
|
|
|
|
+import { toastSuccess } from '~/client/util/apiNotification';
|
|
|
import { IPageWithMeta } from '~/interfaces/page';
|
|
import { IPageWithMeta } from '~/interfaces/page';
|
|
|
-import { IPageSearchMeta } from '~/interfaces/search';
|
|
|
|
|
|
|
+import { IFormattedSearchResult, IPageSearchMeta } from '~/interfaces/search';
|
|
|
|
|
+import { OnDeletedFunction } from '~/interfaces/ui';
|
|
|
import { useIsGuestUser, useIsSearchServiceConfigured, useIsSearchServiceReachable } from '~/stores/context';
|
|
import { useIsGuestUser, useIsSearchServiceConfigured, useIsSearchServiceReachable } from '~/stores/context';
|
|
|
|
|
+import { IPageForPageDeleteModal, usePageDeleteModal } from '~/stores/modal';
|
|
|
|
|
+import { usePageTreeTermManager } from '~/stores/page-listing';
|
|
|
import { ForceHideMenuItems } from '../Common/Dropdown/PageItemControl';
|
|
import { ForceHideMenuItems } from '../Common/Dropdown/PageItemControl';
|
|
|
|
|
|
|
|
import { SearchResultContent } from '../SearchPage/SearchResultContent';
|
|
import { SearchResultContent } from '../SearchPage/SearchResultContent';
|
|
|
import { SearchResultList } from '../SearchPage/SearchResultList';
|
|
import { SearchResultList } from '../SearchPage/SearchResultList';
|
|
|
|
|
|
|
|
|
|
+
|
|
|
export interface IReturnSelectedPageIds {
|
|
export interface IReturnSelectedPageIds {
|
|
|
getSelectedPageIds?: () => Set<string>,
|
|
getSelectedPageIds?: () => Set<string>,
|
|
|
}
|
|
}
|
|
@@ -206,4 +212,58 @@ const SearchPageBaseSubstance: ForwardRefRenderFunction<ISelectableAll & IReturn
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+type VoidFunction = () => void;
|
|
|
|
|
+
|
|
|
|
|
+export const usePageDeleteModalForBulkDeletion = (
|
|
|
|
|
+ data: IFormattedSearchResult | undefined,
|
|
|
|
|
+ ref: React.MutableRefObject<(ISelectableAll & IReturnSelectedPageIds) | null>,
|
|
|
|
|
+ onDeleted?: OnDeletedFunction,
|
|
|
|
|
+): VoidFunction => {
|
|
|
|
|
+
|
|
|
|
|
+ const { t } = useTranslation();
|
|
|
|
|
+
|
|
|
|
|
+ const { open: openDeleteModal } = usePageDeleteModal();
|
|
|
|
|
+
|
|
|
|
|
+ // for PageTree mutation
|
|
|
|
|
+ const { advance: advancePt } = usePageTreeTermManager();
|
|
|
|
|
+
|
|
|
|
|
+ return () => {
|
|
|
|
|
+ if (data == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const instance = ref.current;
|
|
|
|
|
+ if (instance == null || instance.getSelectedPageIds == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const selectedPageIds = instance.getSelectedPageIds();
|
|
|
|
|
+
|
|
|
|
|
+ if (selectedPageIds.size === 0) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const selectedPages = data.data
|
|
|
|
|
+ .filter(pageWithMeta => selectedPageIds.has(pageWithMeta.pageData._id))
|
|
|
|
|
+ .map(pageWithMeta => ({
|
|
|
|
|
+ pageId: pageWithMeta.pageData._id,
|
|
|
|
|
+ path: pageWithMeta.pageData.path,
|
|
|
|
|
+ revisionId: pageWithMeta.pageData.revision as string,
|
|
|
|
|
+ } as IPageForPageDeleteModal));
|
|
|
|
|
+
|
|
|
|
|
+ openDeleteModal(selectedPages, {
|
|
|
|
|
+ onDeleted: (...args) => {
|
|
|
|
|
+ toastSuccess(args[2] ? t('deleted_pages_completely') : t('deleted_pages'));
|
|
|
|
|
+ advancePt();
|
|
|
|
|
+
|
|
|
|
|
+ if (onDeleted != null) {
|
|
|
|
|
+ onDeleted(...args);
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
export const SearchPageBase = forwardRef(SearchPageBaseSubstance);
|
|
export const SearchPageBase = forwardRef(SearchPageBaseSubstance);
|