|
@@ -1,16 +1,16 @@
|
|
|
import { useCallback, useEffect } from 'react';
|
|
import { useCallback, useEffect } from 'react';
|
|
|
|
|
|
|
|
-import EventEmitter from 'events';
|
|
|
|
|
|
|
+import type EventEmitter from 'events';
|
|
|
|
|
|
|
|
-import MarkdownTable from '~/client/models/MarkdownTable';
|
|
|
|
|
-import { useSaveOrUpdate } from '~/client/services/page-operation';
|
|
|
|
|
|
|
+import type MarkdownTable from '~/client/models/MarkdownTable';
|
|
|
import { getMarkdownTableFromLine, replaceMarkdownTableInMarkdown } from '~/components/Page/markdown-table-util-for-view';
|
|
import { getMarkdownTableFromLine, replaceMarkdownTableInMarkdown } from '~/components/Page/markdown-table-util-for-view';
|
|
|
-import type { OptionsToSave } from '~/interfaces/page-operation';
|
|
|
|
|
import { useShareLinkId } from '~/stores/context';
|
|
import { useShareLinkId } from '~/stores/context';
|
|
|
import { useHandsontableModal } from '~/stores/modal';
|
|
import { useHandsontableModal } from '~/stores/modal';
|
|
|
-import { useSWRxCurrentPage, useSWRxTagsInfo } from '~/stores/page';
|
|
|
|
|
|
|
+import { useSWRxCurrentPage } from '~/stores/page';
|
|
|
import loggerFactory from '~/utils/logger';
|
|
import loggerFactory from '~/utils/logger';
|
|
|
|
|
|
|
|
|
|
+import { updatePage } from '../page-operation';
|
|
|
|
|
+
|
|
|
|
|
|
|
|
const logger = loggerFactory('growi:cli:side-effects:useHandsontableModalLauncherForView');
|
|
const logger = loggerFactory('growi:cli:side-effects:useHandsontableModalLauncherForView');
|
|
|
|
|
|
|
@@ -32,8 +32,6 @@ export const useHandsontableModalLauncherForView = (opts?: {
|
|
|
|
|
|
|
|
const { open: openHandsontableModal } = useHandsontableModal();
|
|
const { open: openHandsontableModal } = useHandsontableModal();
|
|
|
|
|
|
|
|
- const saveOrUpdate = useSaveOrUpdate();
|
|
|
|
|
-
|
|
|
|
|
const saveByHandsontableModal = useCallback(async(table: MarkdownTable, bol: number, eol: number) => {
|
|
const saveByHandsontableModal = useCallback(async(table: MarkdownTable, bol: number, eol: number) => {
|
|
|
if (currentPage == null || shareLinkId != null) {
|
|
if (currentPage == null || shareLinkId != null) {
|
|
|
return;
|
|
return;
|
|
@@ -42,28 +40,13 @@ export const useHandsontableModalLauncherForView = (opts?: {
|
|
|
const currentMarkdown = currentPage.revision.body;
|
|
const currentMarkdown = currentPage.revision.body;
|
|
|
const newMarkdown = replaceMarkdownTableInMarkdown(table, currentMarkdown, bol, eol);
|
|
const newMarkdown = replaceMarkdownTableInMarkdown(table, currentMarkdown, bol, eol);
|
|
|
|
|
|
|
|
- const grantUserGroupIds = currentPage.grantedGroups.map((g) => {
|
|
|
|
|
- return {
|
|
|
|
|
- type: g.type,
|
|
|
|
|
- item: g.item._id,
|
|
|
|
|
- };
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- const optionsToSave: OptionsToSave = {
|
|
|
|
|
- isSlackEnabled: false,
|
|
|
|
|
- slackChannels: '',
|
|
|
|
|
- grant: currentPage.grant,
|
|
|
|
|
- // grantUserGroupIds,
|
|
|
|
|
- // pageTags: tagsInfo.tags,
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
try {
|
|
try {
|
|
|
const currentRevisionId = currentPage.revision._id;
|
|
const currentRevisionId = currentPage.revision._id;
|
|
|
- await saveOrUpdate(
|
|
|
|
|
- newMarkdown,
|
|
|
|
|
- { pageId: currentPage._id, path: currentPage.path, revisionId: currentRevisionId },
|
|
|
|
|
- optionsToSave,
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ await updatePage({
|
|
|
|
|
+ pageId: currentPage._id,
|
|
|
|
|
+ revisionId: currentRevisionId,
|
|
|
|
|
+ body: newMarkdown,
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
opts?.onSaveSuccess?.();
|
|
opts?.onSaveSuccess?.();
|
|
|
}
|
|
}
|
|
@@ -71,7 +54,7 @@ export const useHandsontableModalLauncherForView = (opts?: {
|
|
|
logger.error('failed to save', error);
|
|
logger.error('failed to save', error);
|
|
|
opts?.onSaveError?.(error);
|
|
opts?.onSaveError?.(error);
|
|
|
}
|
|
}
|
|
|
- }, [currentPage, opts, saveOrUpdate, shareLinkId]);
|
|
|
|
|
|
|
+ }, [currentPage, opts, shareLinkId]);
|
|
|
|
|
|
|
|
|
|
|
|
|
// set handler to open HandsonTableModal
|
|
// set handler to open HandsonTableModal
|