From 9094637f4271d256a62dbdf84c9f1d6feee1c6d7 Mon Sep 17 00:00:00 2001 From: Charlie Zhang Date: Sat, 16 Nov 2024 10:16:01 -0500 Subject: [PATCH] Fix Bugs: 1. Adjust Tooltip positions and Login URL Tooltips; 2. Allow overlapping start/end dates; 3. Improve fileStream workflows --- src/renderer/src/components/Tooltip.jsx | 9 ++-- src/renderer/src/pages/Login.jsx | 12 +++-- src/renderer/src/pages/MainPage/index.jsx | 59 +++++++++++++---------- 3 files changed, 45 insertions(+), 35 deletions(-) diff --git a/src/renderer/src/components/Tooltip.jsx b/src/renderer/src/components/Tooltip.jsx index 0180ffa..2c5ca2a 100644 --- a/src/renderer/src/components/Tooltip.jsx +++ b/src/renderer/src/components/Tooltip.jsx @@ -8,13 +8,12 @@ const Tooltip = ({ children }) => { useEffect(() => { if (tooltipRef.current && show) { - const { offsetTop, offsetHeight } = tooltipRef.current - const newTooltipPosition = { - bottom: `calc(100% + ${offsetHeight / 2}px)`, // Adjust this calculation as needed + const { offsetHeight } = tooltipRef.current + setTooltipPosition({ + top: `-${offsetHeight + 8}px`, left: '50%', transform: 'translateX(-50%)' - } - setTooltipPosition(newTooltipPosition) + }) } }, [show]) diff --git a/src/renderer/src/pages/Login.jsx b/src/renderer/src/pages/Login.jsx index 1cd1027..9985696 100644 --- a/src/renderer/src/pages/Login.jsx +++ b/src/renderer/src/pages/Login.jsx @@ -20,11 +20,13 @@ const Login = () => {
{ } const writeChunkToFile = (text, fileStream, headerState) => { - const indexOfFirstNewline = text.indexOf('\n') + const rows = text.split('\n').filter(Boolean) + + if (rows.length === 0) return if (!headerState.written) { - // Add 'downloaded_date' column to the header - const header = text.slice(0, indexOfFirstNewline) + ',downloaded_date' + // Write header only for the first chunk + const header = rows[0] + ',downloaded_date' fileStream.write(header + '\n') headerState.written = true + rows.shift() + } else { + const firstRow = rows[0] + if (firstRow.toLowerCase().includes('period') || firstRow.toLowerCase().includes('orgunit')) { + rows.shift() + } } - // Append currentDate to each row - const dataRows = text - .slice(indexOfFirstNewline + 1) - .split('\n') - .filter(Boolean) // Ensure no empty rows - const dataWithDate = dataRows.map((row) => row + `,${currentDate}`).join('\n') - - fileStream.write(dataWithDate + '\n') + if (rows.length > 0) { + const dataWithDate = rows.map((row) => row + `,${currentDate}`).join('\n') + fileStream.write(dataWithDate + '\n') + } } const saveQueryToDatabase = async (downloadParams) => { @@ -151,30 +155,35 @@ const MainPage = ({ queryDb }) => { const handleDownloadError = (error, fileStream) => { const errorMessage = error.message || error dispatch(triggerNotification({ message: errorMessage, type: 'error' })) - fileStream.end() + if (fileStream) { + fileStream.end() + } } const handleStreamDownload = async () => { - const saveFilePath = await getSaveFilePath() - if (!saveFilePath) return + let fileStream = null + try { + const saveFilePath = await getSaveFilePath() + if (!saveFilePath) return - const fileStream = window.fileSystem.createWriteStream(saveFilePath) - const downloadParams = getDownloadParameters() - const chunks = createDataChunks( - downloadParams.elementIds, - downloadParams.periods, - downloadParams.ou - ) + fileStream = window.fileSystem.createWriteStream(saveFilePath) + const downloadParams = getDownloadParameters() + const chunks = createDataChunks( + downloadParams.elementIds, + downloadParams.periods, + downloadParams.ou + ) - try { dispatch(clearLogs()) dispatch(triggerLoading(true)) - await processChunks(chunks, fileStream, downloadParams) + // Initialize header state + const headerState = { written: false } + + await processChunks(chunks, fileStream, downloadParams, headerState) fileStream.end() dispatch(triggerNotification({ message: 'Download completed successfully', type: 'success' })) - await saveQueryToDatabase(downloadParams) clearCacheIfPossible() } catch (error) { @@ -187,7 +196,7 @@ const MainPage = ({ queryDb }) => { const isDownloadDisabled = !startDate || !endDate || - new Date(startDate) >= new Date(endDate) || + new Date(startDate) > new Date(endDate) || addedElements.length === 0 || selectedOrgUnitLevels.length === 0