mirror of https://github.com/buster-so/buster.git
editor pdf exporting
This commit is contained in:
parent
1317190edf
commit
f100dc723f
|
@ -1,6 +1,6 @@
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import React, { useImperativeHandle, useRef } from 'react';
|
import React, { useEffect, useImperativeHandle, useRef } from 'react';
|
||||||
import type { Value, AnyPluginConfig } from 'platejs';
|
import type { Value, AnyPluginConfig } from 'platejs';
|
||||||
import { Plate, type TPlateEditor } from 'platejs/react';
|
import { Plate, type TPlateEditor } from 'platejs/react';
|
||||||
import { EditorContainer } from './EditorContainer';
|
import { EditorContainer } from './EditorContainer';
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
export { registerReportEditor, unregisterReportEditor, getReportEditor } from './editorRegistry';
|
|
|
@ -9,10 +9,7 @@ import { useDebounceFn } from '@/hooks/useDebounce';
|
||||||
import type { ReportElements } from '@buster/server-shared/reports';
|
import type { ReportElements } from '@buster/server-shared/reports';
|
||||||
//import DynamicReportEditor from '@/components/ui/report/DynamicReportEditor';
|
//import DynamicReportEditor from '@/components/ui/report/DynamicReportEditor';
|
||||||
import { ReportEditor, type IReportEditor } from '@/components/ui/report/ReportEditor';
|
import { ReportEditor, type IReportEditor } from '@/components/ui/report/ReportEditor';
|
||||||
import {
|
import { registerReportEditor, unregisterReportEditor } from './editorRegistry';
|
||||||
registerReportEditor,
|
|
||||||
unregisterReportEditor
|
|
||||||
} from '@/components/ui/report/editorRegistry';
|
|
||||||
import { ReportEditorSkeleton } from '@/components/ui/report/ReportEditorSkeleton';
|
import { ReportEditorSkeleton } from '@/components/ui/report/ReportEditorSkeleton';
|
||||||
|
|
||||||
export const ReportPageController: React.FC<{
|
export const ReportPageController: React.FC<{
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import type { IReportEditor } from './ReportEditor';
|
import type { IReportEditor } from '@/components/ui/report/ReportEditor';
|
||||||
|
|
||||||
// Simple in-memory registry to map reportId -> editor instance
|
// Simple in-memory registry to map reportId -> editor instance
|
||||||
const reportEditorRegistry = new Map<string, IReportEditor>();
|
const reportEditorRegistry = new Map<string, IReportEditor>();
|
||||||
|
@ -13,4 +13,4 @@ export const unregisterReportEditor = (reportId: string) => {
|
||||||
|
|
||||||
export const getReportEditor = (reportId: string): IReportEditor | undefined => {
|
export const getReportEditor = (reportId: string): IReportEditor | undefined => {
|
||||||
return reportEditorRegistry.get(reportId);
|
return reportEditorRegistry.get(reportId);
|
||||||
};
|
};
|
|
@ -1 +1,2 @@
|
||||||
export * from './ReportPageController';
|
export * from './ReportPageController';
|
||||||
|
export * from './editorRegistry';
|
||||||
|
|
|
@ -26,7 +26,7 @@ import { useFavoriteStar } from '@/components/features/list/FavoriteStar';
|
||||||
import { useStatusDropdownContent } from '@/components/features/metrics/StatusBadgeIndicator/useStatusDropdownContent';
|
import { useStatusDropdownContent } from '@/components/features/metrics/StatusBadgeIndicator/useStatusDropdownContent';
|
||||||
import type { VerificationStatus } from '@buster/server-shared/share';
|
import type { VerificationStatus } from '@buster/server-shared/share';
|
||||||
import { useSaveToCollectionsDropdownContent } from '@/components/features/dropdowns/SaveToCollectionsDropdown';
|
import { useSaveToCollectionsDropdownContent } from '@/components/features/dropdowns/SaveToCollectionsDropdown';
|
||||||
import { getReportEditor } from '@/components/ui/report/editorRegistry';
|
import { getReportEditor } from '@/controllers/ReportPageControllers/ReportPageController/editorRegistry';
|
||||||
import { NodeTypeLabels } from '@/components/ui/report/config/labels';
|
import { NodeTypeLabels } from '@/components/ui/report/config/labels';
|
||||||
import { useExportReport } from '@/components/ui/report/hooks';
|
import { useExportReport } from '@/components/ui/report/hooks';
|
||||||
|
|
||||||
|
@ -313,20 +313,22 @@ const useDuplicateReportSelectMenu = (): DropdownItem => {
|
||||||
|
|
||||||
// Download as PDF
|
// Download as PDF
|
||||||
const useDownloadPdfSelectMenu = ({ reportId }: { reportId: string }): DropdownItem => {
|
const useDownloadPdfSelectMenu = ({ reportId }: { reportId: string }): DropdownItem => {
|
||||||
const { openErrorMessage, openInfoMessage } = useBusterNotifications();
|
const { openErrorMessage } = useBusterNotifications();
|
||||||
const editor = getReportEditor(reportId);
|
const editor = getReportEditor(reportId);
|
||||||
const { exportToPdf } = useExportReport();
|
const { exportToPdf } = useExportReport();
|
||||||
|
|
||||||
const onClick = useMemoizedFn(async () => {
|
const onClick = async () => {
|
||||||
if (!editor) {
|
try {
|
||||||
openErrorMessage(NodeTypeLabels.failedToExportPdf.label);
|
if (!editor) {
|
||||||
return;
|
openErrorMessage(NodeTypeLabels.failedToExportPdf.label);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await exportToPdf(editor);
|
||||||
|
} catch (error) {
|
||||||
|
openErrorMessage('Failed to export PDF');
|
||||||
}
|
}
|
||||||
|
};
|
||||||
await exportToPdf(editor);
|
|
||||||
|
|
||||||
//
|
|
||||||
});
|
|
||||||
|
|
||||||
return useMemo(
|
return useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
|
@ -335,6 +337,6 @@ const useDownloadPdfSelectMenu = ({ reportId }: { reportId: string }): DropdownI
|
||||||
icon: <FileText />,
|
icon: <FileText />,
|
||||||
onClick
|
onClick
|
||||||
}),
|
}),
|
||||||
[onClick]
|
[]
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue