From f100dc723f71dcce41d54d15e231e213606a6074 Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Fri, 8 Aug 2025 10:40:47 -0600 Subject: [PATCH] editor pdf exporting --- .../src/components/ui/report/ReportEditor.tsx | 2 +- apps/web/src/components/ui/report/index.ts | 1 - .../ReportPageController.tsx | 5 +--- .../ReportPageController}/editorRegistry.ts | 4 +-- .../ReportPageController/index.ts | 1 + .../ReportThreeDotMenu.tsx | 26 ++++++++++--------- 6 files changed, 19 insertions(+), 20 deletions(-) rename apps/web/src/{components/ui/report => controllers/ReportPageControllers/ReportPageController}/editorRegistry.ts (86%) diff --git a/apps/web/src/components/ui/report/ReportEditor.tsx b/apps/web/src/components/ui/report/ReportEditor.tsx index 6f3b415f9..f3df6af56 100644 --- a/apps/web/src/components/ui/report/ReportEditor.tsx +++ b/apps/web/src/components/ui/report/ReportEditor.tsx @@ -1,6 +1,6 @@ 'use client'; -import React, { useImperativeHandle, useRef } from 'react'; +import React, { useEffect, useImperativeHandle, useRef } from 'react'; import type { Value, AnyPluginConfig } from 'platejs'; import { Plate, type TPlateEditor } from 'platejs/react'; import { EditorContainer } from './EditorContainer'; diff --git a/apps/web/src/components/ui/report/index.ts b/apps/web/src/components/ui/report/index.ts index 769b22cf7..e69de29bb 100644 --- a/apps/web/src/components/ui/report/index.ts +++ b/apps/web/src/components/ui/report/index.ts @@ -1 +0,0 @@ -export { registerReportEditor, unregisterReportEditor, getReportEditor } from './editorRegistry'; \ No newline at end of file diff --git a/apps/web/src/controllers/ReportPageControllers/ReportPageController/ReportPageController.tsx b/apps/web/src/controllers/ReportPageControllers/ReportPageController/ReportPageController.tsx index eab0d590d..ea2e1dac7 100644 --- a/apps/web/src/controllers/ReportPageControllers/ReportPageController/ReportPageController.tsx +++ b/apps/web/src/controllers/ReportPageControllers/ReportPageController/ReportPageController.tsx @@ -9,10 +9,7 @@ import { useDebounceFn } from '@/hooks/useDebounce'; import type { ReportElements } from '@buster/server-shared/reports'; //import DynamicReportEditor from '@/components/ui/report/DynamicReportEditor'; import { ReportEditor, type IReportEditor } from '@/components/ui/report/ReportEditor'; -import { - registerReportEditor, - unregisterReportEditor -} from '@/components/ui/report/editorRegistry'; +import { registerReportEditor, unregisterReportEditor } from './editorRegistry'; import { ReportEditorSkeleton } from '@/components/ui/report/ReportEditorSkeleton'; export const ReportPageController: React.FC<{ diff --git a/apps/web/src/components/ui/report/editorRegistry.ts b/apps/web/src/controllers/ReportPageControllers/ReportPageController/editorRegistry.ts similarity index 86% rename from apps/web/src/components/ui/report/editorRegistry.ts rename to apps/web/src/controllers/ReportPageControllers/ReportPageController/editorRegistry.ts index 814501605..50e249793 100644 --- a/apps/web/src/components/ui/report/editorRegistry.ts +++ b/apps/web/src/controllers/ReportPageControllers/ReportPageController/editorRegistry.ts @@ -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 const reportEditorRegistry = new Map(); @@ -13,4 +13,4 @@ export const unregisterReportEditor = (reportId: string) => { export const getReportEditor = (reportId: string): IReportEditor | undefined => { return reportEditorRegistry.get(reportId); -}; \ No newline at end of file +}; diff --git a/apps/web/src/controllers/ReportPageControllers/ReportPageController/index.ts b/apps/web/src/controllers/ReportPageControllers/ReportPageController/index.ts index c14a541e3..e282785f3 100644 --- a/apps/web/src/controllers/ReportPageControllers/ReportPageController/index.ts +++ b/apps/web/src/controllers/ReportPageControllers/ReportPageController/index.ts @@ -1 +1,2 @@ export * from './ReportPageController'; +export * from './editorRegistry'; diff --git a/apps/web/src/layouts/ChatLayout/FileContainer/FileContainerHeader/ReportContainerHeaderButtons/ReportThreeDotMenu.tsx b/apps/web/src/layouts/ChatLayout/FileContainer/FileContainerHeader/ReportContainerHeaderButtons/ReportThreeDotMenu.tsx index 8f4df0542..51d297dce 100644 --- a/apps/web/src/layouts/ChatLayout/FileContainer/FileContainerHeader/ReportContainerHeaderButtons/ReportThreeDotMenu.tsx +++ b/apps/web/src/layouts/ChatLayout/FileContainer/FileContainerHeader/ReportContainerHeaderButtons/ReportThreeDotMenu.tsx @@ -26,7 +26,7 @@ import { useFavoriteStar } from '@/components/features/list/FavoriteStar'; import { useStatusDropdownContent } from '@/components/features/metrics/StatusBadgeIndicator/useStatusDropdownContent'; import type { VerificationStatus } from '@buster/server-shared/share'; 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 { useExportReport } from '@/components/ui/report/hooks'; @@ -313,20 +313,22 @@ const useDuplicateReportSelectMenu = (): DropdownItem => { // Download as PDF const useDownloadPdfSelectMenu = ({ reportId }: { reportId: string }): DropdownItem => { - const { openErrorMessage, openInfoMessage } = useBusterNotifications(); + const { openErrorMessage } = useBusterNotifications(); const editor = getReportEditor(reportId); const { exportToPdf } = useExportReport(); - const onClick = useMemoizedFn(async () => { - if (!editor) { - openErrorMessage(NodeTypeLabels.failedToExportPdf.label); - return; + const onClick = async () => { + try { + if (!editor) { + openErrorMessage(NodeTypeLabels.failedToExportPdf.label); + return; + } + + await exportToPdf(editor); + } catch (error) { + openErrorMessage('Failed to export PDF'); } - - await exportToPdf(editor); - - // - }); + }; return useMemo( () => ({ @@ -335,6 +337,6 @@ const useDownloadPdfSelectMenu = ({ reportId }: { reportId: string }): DropdownI icon: , onClick }), - [onClick] + [] ); };