Merge pull request #692 from buster-so/nate/pdf-hot-fix

Nate/pdf hot fix
This commit is contained in:
Nate Kelley 2025-08-08 17:37:08 -06:00 committed by GitHub
commit 948db75df8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 29 additions and 23 deletions

View File

@ -5,5 +5,5 @@ export default async function Page(props: { params: Promise<{ reportId: string }
const { reportId } = params; const { reportId } = params;
return <ReportPageController reportId={reportId} />; return <ReportPageController reportId={reportId} mode="default" />;
} }

View File

@ -10,13 +10,13 @@ export const MetricContent = React.memo(
({ ({
metricId, metricId,
metricVersionNumber, metricVersionNumber,
isBaseElement = false, isExportMode = false,
readOnly = false readOnly = false
}: { }: {
metricId: string; metricId: string;
metricVersionNumber: number | undefined; metricVersionNumber: number | undefined;
readOnly?: boolean; readOnly?: boolean;
isBaseElement?: boolean; isExportMode?: boolean;
}) => { }) => {
const chatId = useChatLayoutContextSelector((x) => x.chatId); const chatId = useChatLayoutContextSelector((x) => x.chatId);
const reportId = useChatLayoutContextSelector((x) => x.reportId) || ''; const reportId = useChatLayoutContextSelector((x) => x.reportId) || '';
@ -24,9 +24,9 @@ export const MetricContent = React.memo(
const ref = useRef<HTMLDivElement>(null); const ref = useRef<HTMLDivElement>(null);
const [inViewport] = useInViewport(ref, { const [inViewport] = useInViewport(ref, {
threshold: isBaseElement ? 0 : 0.33 threshold: 0.33
}); });
const renderChart = inViewport; const renderChart = inViewport || isExportMode;
const { const {
data: metric, data: metric,
@ -72,8 +72,9 @@ export const MetricContent = React.memo(
return ( return (
<MetricCard <MetricCard
ref={ref}
metricLink={link} metricLink={link}
animate={!isBaseElement} animate={!isExportMode}
metricId={metricId} metricId={metricId}
readOnly={readOnly} readOnly={readOnly}
isDragOverlay={false} isDragOverlay={false}

View File

@ -30,18 +30,15 @@ export const MetricElement = withHOC(
const metricId = props.element.metricId; const metricId = props.element.metricId;
const metricVersionNumber = props.element.metricVersionNumber; const metricVersionNumber = props.element.metricVersionNumber;
const readOnly = useReadOnly(); const readOnly = useReadOnly();
console.log(props.editor.getOptionsStore(GlobalVariablePlugin));
console.log(props.editor.getOptions(GlobalVariablePlugin));
const mode = props.editor.getOption(GlobalVariablePlugin, 'mode'); const mode = props.editor.getOption(GlobalVariablePlugin, 'mode');
console.log('mode', mode);
const content = metricId ? ( const content = metricId ? (
<MetricResizeContainer> <MetricResizeContainer>
<MetricContent <MetricContent
metricId={metricId} metricId={metricId}
metricVersionNumber={metricVersionNumber} metricVersionNumber={metricVersionNumber}
readOnly={readOnly} readOnly={readOnly}
isExportMode={mode === 'export'}
/> />
</MetricResizeContainer> </MetricResizeContainer>
) : ( ) : (

View File

@ -5,13 +5,12 @@ import { useEditorRef, usePlateEditor, type TPlateEditor } from 'platejs/react';
import { useMemo } from 'react'; import { useMemo } from 'react';
import { EditorKit } from './editor-kit'; import { EditorKit } from './editor-kit';
import { FIXED_TOOLBAR_KIT_KEY } from './plugins/fixed-toolbar-kit'; import { FIXED_TOOLBAR_KIT_KEY } from './plugins/fixed-toolbar-kit';
import { CUSTOM_KEYS } from './config/keys';
import { GlobalVariablePlugin } from './plugins/global-variable-kit'; import { GlobalVariablePlugin } from './plugins/global-variable-kit';
export const useReportEditor = ({ export const useReportEditor = ({
value, value,
disabled, disabled,
mode, mode = 'default',
useFixedToolbarKit = false useFixedToolbarKit = false
}: { }: {
value: Value; value: Value;
@ -27,13 +26,11 @@ export const useReportEditor = ({
return [ return [
...EditorKit, ...EditorKit,
GlobalVariablePlugin.configurePlugin(GlobalVariablePlugin, { GlobalVariablePlugin.configure({
options: { options: { mode }
mode
}
}) })
]; ].filter((p) => !filteredKeys.includes(p.key));
}, []); }, [useFixedToolbarKit, mode]);
return usePlateEditor({ return usePlateEditor({
plugins, plugins,

View File

@ -2,7 +2,7 @@
import { useGetReport, useUpdateReport } from '@/api/buster_rest/reports'; import { useGetReport, useUpdateReport } from '@/api/buster_rest/reports';
import { cn } from '@/lib/utils'; import { cn } from '@/lib/utils';
import React, { useEffect } from 'react'; import React from 'react';
import { ReportPageHeader } from './ReportPageHeader'; import { ReportPageHeader } from './ReportPageHeader';
import { useMemoizedFn } from '@/hooks/useMemoizedFn'; import { useMemoizedFn } from '@/hooks/useMemoizedFn';
import { useDebounceFn } from '@/hooks/useDebounce'; import { useDebounceFn } from '@/hooks/useDebounce';

View File

@ -4,6 +4,7 @@ import { useMemoizedFn } from '@/hooks/useMemoizedFn';
import { useRef, useState } from 'react'; import { useRef, useState } from 'react';
import { ReportPageController } from './ReportPageController'; import { ReportPageController } from './ReportPageController';
import { printHTMLPage } from '@/lib/print'; import { printHTMLPage } from '@/lib/print';
import { timeout } from '@/lib';
const ExportContainerComponent: React.FC<{ const ExportContainerComponent: React.FC<{
reportId: string; reportId: string;
@ -18,13 +19,15 @@ const ExportContainerComponent: React.FC<{
ref={ref} ref={ref}
style={{ style={{
width: '820px', width: '820px',
minWidth: '820px',
maxWidth: '820px',
height: '100%', height: '100%',
position: 'fixed', position: 'fixed',
top: 0, top: 0,
left: -1, left: 0,
right: 0, right: 0,
bottom: 0, bottom: 0,
zIndex: 100 zIndex: -1
}}> }}>
<ReportPageController <ReportPageController
reportId={reportId} reportId={reportId}
@ -36,7 +39,7 @@ const ExportContainerComponent: React.FC<{
if (immiateChild) { if (immiateChild) {
await buildHtmlMethod(immiateChild, reportName || ''); await buildHtmlMethod(immiateChild, reportName || '');
} }
}, 100); }, 150);
}} }}
/> />
</div> </div>
@ -63,10 +66,11 @@ export const useReportPageExport = ({
const buildHtmlMethod = useMemoizedFn(async (node: HTMLElement, title: string) => { const buildHtmlMethod = useMemoizedFn(async (node: HTMLElement, title: string) => {
try { try {
await timeout(150); //wait for chart nodes to be rendered
const result = await buildExportHtml({ root: node, title }); const result = await buildExportHtml({ root: node, title });
printHTMLPage({ html: result, filename: title, closeOnPrint: false }); printHTMLPage({ html: result, filename: title, closeOnPrint: false });
} finally { } finally {
setIsExportingReport(false); // setIsExportingReport(false);
} }
}); });
@ -156,6 +160,13 @@ const buildExportHtml = async (options?: {
clone.removeAttribute('spellcheck'); clone.removeAttribute('spellcheck');
} }
// Ensure the cloned root has no padding and full width
const existingStyle = clonedRoot.getAttribute('style') || '';
clonedRoot.setAttribute(
'style',
`${existingStyle}; width: 100%; padding: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; overflow: visible;`.trim()
);
// Wrap content with a fixed width, centered container for consistency // Wrap content with a fixed width, centered container for consistency
const wrapper = document.createElement('div'); const wrapper = document.createElement('div');
wrapper.setAttribute( wrapper.setAttribute(