Skip to content

Commit

Permalink
Fix Bugs:
Browse files Browse the repository at this point in the history
1. Adjust Tooltip positions and Login URL Tooltips;
2. Allow overlapping start/end dates;
3. Improve fileStream workflows
  • Loading branch information
ccxzhang committed Nov 16, 2024
1 parent cf8e1e6 commit 9220683
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 35 deletions.
9 changes: 4 additions & 5 deletions src/renderer/src/components/Tooltip.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down
12 changes: 7 additions & 5 deletions src/renderer/src/pages/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ const Login = () => {
<div>
<label className="block mb-2">
DHIS2 URL
<Tooltip
text={
'Enter the DHIS2 Link without the last forward slash, e.g. https://your-dhis2.com instead of https://your-dhis2.com/.'
}
/>
<Tooltip>
<p>
Enter the DHIS2 Link without the last forward slash, e.g.,{' '}
<code> https://your-dhis2.com</code> instead of{' '}
<code> https://your-dhis2.com/</code>.
</p>
</Tooltip>
</label>
<input
type="text"
Expand Down
59 changes: 34 additions & 25 deletions src/renderer/src/pages/MainPage/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,23 +111,27 @@ const MainPage = ({ queryDb }) => {
}

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) => {
Expand All @@ -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) {
Expand All @@ -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

Expand Down

0 comments on commit 9220683

Please sign in to comment.