From b4f12315d225d44cb32653310ab265897018699c Mon Sep 17 00:00:00 2001 From: crazywoola <427733928@qq.com> Date: Thu, 22 May 2025 16:19:37 +0800 Subject: [PATCH] fix: lint --- web/app/components/base/markdown.tsx | 128 +++++++++++++-------------- 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/web/app/components/base/markdown.tsx b/web/app/components/base/markdown.tsx index 69c19c0d3b..b28bf2bc8f 100644 --- a/web/app/components/base/markdown.tsx +++ b/web/app/components/base/markdown.tsx @@ -141,9 +141,8 @@ const CodeBlock: any = memo(({ inline, className, children = '', ...props }: any const handleResize = () => { // This gets the echarts instance from the component const instance = echartsRef.current?.getEchartsInstance?.() - if (instance) { + if (instance) instance.resize() - } } window.addEventListener('resize', handleResize) @@ -179,85 +178,87 @@ const CodeBlock: any = memo(({ inline, className, children = '', ...props }: any // Detect if this is historical data (already complete) // Historical data typically comes as a complete code block with complete JSON - const isCompleteJson = - (trimmedContent.startsWith('{') && trimmedContent.endsWith('}') && - trimmedContent.split('{').length === trimmedContent.split('}').length) || - (trimmedContent.startsWith('[') && trimmedContent.endsWith(']') && - trimmedContent.split('[').length === trimmedContent.split(']').length); + const isCompleteJson + = (trimmedContent.startsWith('{') && trimmedContent.endsWith('}') + && trimmedContent.split('{').length === trimmedContent.split('}').length) + || (trimmedContent.startsWith('[') && trimmedContent.endsWith(']') + && trimmedContent.split('[').length === trimmedContent.split(']').length) // If the JSON structure looks complete, try to parse it right away if (isCompleteJson && !processedRef.current) { try { - const parsed = JSON.parse(trimmedContent); + const parsed = JSON.parse(trimmedContent) if (typeof parsed === 'object' && parsed !== null) { - setFinalChartOption(parsed); - setChartState('success'); - processedRef.current = true; - return; + setFinalChartOption(parsed) + setChartState('success') + processedRef.current = true + return } - } catch { + } + catch { try { // eslint-disable-next-line no-new-func, sonarjs/code-eval - const result = new Function(`return ${trimmedContent}`)(); + const result = new Function(`return ${trimmedContent}`)() if (typeof result === 'object' && result !== null) { - setFinalChartOption(result); - setChartState('success'); - processedRef.current = true; - return; + setFinalChartOption(result) + setChartState('success') + processedRef.current = true + return } - } catch { + } + catch { // If we have a complete JSON structure but it doesn't parse, // it's likely an error rather than incomplete data - setChartState('error'); - processedRef.current = true; - return; + setChartState('error') + processedRef.current = true + return } } } // If we get here, either the JSON isn't complete yet, or we failed to parse it // Check more conditions for streaming data - const isIncomplete = - trimmedContent.length < 5 || - (trimmedContent.startsWith('{') && - (!trimmedContent.endsWith('}') || - trimmedContent.split('{').length !== trimmedContent.split('}').length)) || - (trimmedContent.startsWith('[') && - (!trimmedContent.endsWith(']') || - trimmedContent.split('[').length !== trimmedContent.split('}').length)) || - (trimmedContent.split('"').length % 2 !== 1) || - (trimmedContent.includes('{"') && !trimmedContent.includes('"}')); + const isIncomplete + = trimmedContent.length < 5 + || (trimmedContent.startsWith('{') + && (!trimmedContent.endsWith('}') + || trimmedContent.split('{').length !== trimmedContent.split('}').length)) + || (trimmedContent.startsWith('[') + && (!trimmedContent.endsWith(']') + || trimmedContent.split('[').length !== trimmedContent.split('}').length)) + || (trimmedContent.split('"').length % 2 !== 1) + || (trimmedContent.includes('{"') && !trimmedContent.includes('"}')) // Only try to parse streaming data if it looks complete and hasn't been processed if (!isIncomplete && !processedRef.current) { - let isValidOption = false; + let isValidOption = false try { - const parsed = JSON.parse(trimmedContent); + const parsed = JSON.parse(trimmedContent) if (typeof parsed === 'object' && parsed !== null) { - setFinalChartOption(parsed); - isValidOption = true; + setFinalChartOption(parsed) + isValidOption = true } - } catch(e) { + } + catch { try { // eslint-disable-next-line no-new-func, sonarjs/code-eval - const result = new Function(`return ${trimmedContent}`)(); + const result = new Function(`return ${trimmedContent}`)() if (typeof result === 'object' && result !== null) { - setFinalChartOption(result); - isValidOption = true; + setFinalChartOption(result) + isValidOption = true } - } catch(e2) { + } + catch { // Both parsing methods failed, but content looks complete - if (!isIncomplete) { - setChartState('error'); - processedRef.current = true; - } + setChartState('error') + processedRef.current = true } } if (isValidOption) { - setChartState('success'); - processedRef.current = true; + setChartState('success') + processedRef.current = true } } }, [language, children]) @@ -283,7 +284,7 @@ const CodeBlock: any = memo(({ inline, className, children = '', ...props }: any borderBottomLeftRadius: '10px', borderBottomRightRadius: '10px', backgroundColor: isDarkMode ? 'var(--color-components-input-bg-normal)' : 'transparent', - color: 'var(--color-text-secondary)' + color: 'var(--color-text-secondary)', }}>
{/* Rotating spinner that works in both light and dark modes */} - + - - + +
{ + finished: () => { const instance = echartsRef.current?.getEchartsInstance?.() - if (instance) { + if (instance) instance.resize() - } - } + }, }} /> @@ -356,9 +356,9 @@ const CodeBlock: any = memo(({ inline, className, children = '', ...props }: any // Error state: show error message const errorOption = { title: { - text: "ECharts error - Wrong option." - } - }; + text: 'ECharts error - Wrong option.', + }, + } return (