From 4a9fa7222d4ccd4c6e36d8395da6f668676bcda3 Mon Sep 17 00:00:00 2001 From: sambokar Date: Tue, 22 Oct 2024 12:41:15 -0400 Subject: [PATCH] commenting out unnecessary part of file upload process due to massive delays being imposed, leading to webpage crashing. Will be restored later --- .../datagrids/measurementscommons.tsx | 19 +++- .../uploadsystem/segments/uploadfireazure.tsx | 5 +- .../uploadsystem/segments/uploadfiresql.tsx | 97 +++++++++---------- frontend/config/datagridhelpers.ts | 1 + 4 files changed, 69 insertions(+), 53 deletions(-) diff --git a/frontend/components/datagrids/measurementscommons.tsx b/frontend/components/datagrids/measurementscommons.tsx index f4761347..f51e3650 100644 --- a/frontend/components/datagrids/measurementscommons.tsx +++ b/frontend/components/datagrids/measurementscommons.tsx @@ -71,7 +71,16 @@ function debounce void>(fn: T, delay: number): T { type EditToolbarProps = EditToolbarCustomProps & GridToolbarProps & ToolbarPropsOverrides; -const EditToolbar = ({ handleAddNewRow, handleRefresh, handleExportAll, handleExportErrors, handleExportCSV, locked, filterModel }: EditToolbarProps) => { +const EditToolbar = ({ + handleAddNewRow, + handleRefresh, + handleExportAll, + handleExportErrors, + handleExportCSV, + handleRunValidations, + locked, + filterModel +}: EditToolbarProps) => { const handleExportClick = async () => { if (!handleExportAll) return; const fullData = await handleExportAll(filterModel); @@ -120,6 +129,9 @@ const EditToolbar = ({ handleAddNewRow, handleRefresh, handleExportAll, handleEx + {/**/} ); }; @@ -559,7 +571,10 @@ export default function MeasurementsCommons(props: Readonly { setRefresh(true); - await fetchPaginatedData(paginationModel.page); + await fetch(`/api/refreshviews/measurementssummary/${currentSite?.schemaName}`, { method: 'POST' }); + setTimeout(async () => { + await fetchPaginatedData(paginationModel.page); + }, 2000); setRefresh(false); }, [fetchPaginatedData, paginationModel.page, refresh]); diff --git a/frontend/components/uploadsystem/segments/uploadfireazure.tsx b/frontend/components/uploadsystem/segments/uploadfireazure.tsx index 17ff71e4..d5595c7d 100644 --- a/frontend/components/uploadsystem/segments/uploadfireazure.tsx +++ b/frontend/components/uploadsystem/segments/uploadfireazure.tsx @@ -52,8 +52,9 @@ const UploadFireAzure: React.FC = ({ const formData = new FormData(); formData.append(file.name, file); if (uploadForm === 'measurements') { - const fileRowErrors = mapCMErrorsToFileRowErrors(file.name); - formData.append('fileRowErrors', JSON.stringify(fileRowErrors)); // Append validation errors to formData + // this is causing massive slowdown. removing for now + // const fileRowErrors = mapCMErrorsToFileRowErrors(file.name); + // formData.append('fileRowErrors', JSON.stringify(fileRowErrors)); // Append validation errors to formData } const response = await fetch( `/api/filehandlers/storageload?fileName=${file.name}&plot=${currentPlot?.plotName?.trim().toLowerCase()}&census=${currentCensus?.dateRanges[0].censusID ? currentCensus?.dateRanges[0].censusID.toString().trim() : 0}&user=${user}&formType=${uploadForm}`, diff --git a/frontend/components/uploadsystem/segments/uploadfiresql.tsx b/frontend/components/uploadsystem/segments/uploadfiresql.tsx index d928d23e..ad83a6e0 100644 --- a/frontend/components/uploadsystem/segments/uploadfiresql.tsx +++ b/frontend/components/uploadsystem/segments/uploadfiresql.tsx @@ -4,7 +4,6 @@ import { Box, Typography } from '@mui/material'; import { ReviewStates, UploadFireProps } from '@/config/macros/uploadsystemmacros'; import { FileCollectionRowSet, FileRow, FormType } from '@/config/macros/formdetails'; import { Stack } from '@mui/joy'; -import { DetailedCMIDRow } from '@/components/uploadsystem/uploadparent'; import { LinearProgressWithLabel } from '@/components/client/clientmacros'; import { useOrgCensusContext, usePlotContext, useQuadratContext } from '@/app/contexts/userselectionprovider'; import { useSession } from 'next-auth/react'; @@ -56,54 +55,54 @@ const UploadFireSQL: React.FC = ({ setCompletedOperations(prevCompleted => prevCompleted + 1); - const result = await response.json(); - - if (result.idToRows) { - setCurrentlyRunning(`Fetching CMID details for file "${fileName}"...`); - if (uploadForm === 'measurements') { - Promise.all( - result.idToRows.map(({ coreMeasurementID }: IDToRow) => - fetch(`/api/details/cmid?schema=${schema}&cmid=${coreMeasurementID}`).then(response => response.json()) - ) - ) - .then(details => { - const newRowToCMID: DetailedCMIDRow[] = result.idToRows.map(({ coreMeasurementID, fileRow }: IDToRow, index: number) => { - const detailArray = details[index]; - if (Array.isArray(detailArray) && detailArray.length > 0) { - const detail = detailArray[0]; - if ('plotName' in detail && 'quadratName' in detail && 'plotCensusNumber' in detail && 'speciesName' in detail) { - return { - coreMeasurementID, - fileName, - row: fileRow, - plotName: detail.plotName, - quadratName: detail.quadratName, - plotCensusNumber: detail.plotCensusNumber, - speciesName: detail.speciesName - }; - } else { - throw new Error('Detail object missing required properties'); - } - } else { - throw new Error('Invalid detail array structure'); - } - }); - setAllRowToCMID(prevState => [...prevState, ...newRowToCMID]); - }) - .catch(error => { - console.error('Error fetching CMID details:', error); - setUploadError(error); - setReviewState(ReviewStates.ERRORS); - }); - } else { - const newRowToCMID: DetailedCMIDRow[] = result.idToRows.map(({ coreMeasurementID, fileRow }: IDToRow) => ({ - coreMeasurementID, - fileName, - row: fileRow - })); - setAllRowToCMID(prevState => [...prevState, ...newRowToCMID]); - } - } + // const result = await response.json(); + // + // if (result.idToRows) { + // setCurrentlyRunning(`Fetching CMID details for file "${fileName}"...`); + // if (uploadForm === 'measurements') { + // Promise.all( + // result.idToRows.map(({ coreMeasurementID }: IDToRow) => + // fetch(`/api/details/cmid?schema=${schema}&cmid=${coreMeasurementID}`).then(response => response.json()) + // ) + // ) + // .then(details => { + // const newRowToCMID: DetailedCMIDRow[] = result.idToRows.map(({ coreMeasurementID, fileRow }: IDToRow, index: number) => { + // const detailArray = details[index]; + // if (Array.isArray(detailArray) && detailArray.length > 0) { + // const detail = detailArray[0]; + // if ('plotName' in detail && 'quadratName' in detail && 'plotCensusNumber' in detail && 'speciesName' in detail) { + // return { + // coreMeasurementID, + // fileName, + // row: fileRow, + // plotName: detail.plotName, + // quadratName: detail.quadratName, + // plotCensusNumber: detail.plotCensusNumber, + // speciesName: detail.speciesName + // }; + // } else { + // throw new Error('Detail object missing required properties'); + // } + // } else { + // throw new Error('Invalid detail array structure'); + // } + // }); + // setAllRowToCMID(prevState => [...prevState, ...newRowToCMID]); + // }) + // .catch(error => { + // console.error('Error fetching CMID details:', error); + // setUploadError(error); + // setReviewState(ReviewStates.ERRORS); + // }); + // } else { + // const newRowToCMID: DetailedCMIDRow[] = result.idToRows.map(({ coreMeasurementID, fileRow }: IDToRow) => ({ + // coreMeasurementID, + // fileName, + // row: fileRow + // })); + // setAllRowToCMID(prevState => [...prevState, ...newRowToCMID]); + // } + // } return response.ok ? 'SQL load successful' : 'SQL load failed'; } catch (error) { diff --git a/frontend/config/datagridhelpers.ts b/frontend/config/datagridhelpers.ts index 3b7f2434..efb374c3 100644 --- a/frontend/config/datagridhelpers.ts +++ b/frontend/config/datagridhelpers.ts @@ -171,6 +171,7 @@ export interface EditToolbarCustomProps { handleRefresh?: () => Promise; handleExportAll?: (filterModel?: GridFilterModel) => Promise; handleExportCSV?: () => Promise; + handleRunValidations?: () => Promise; filterModel?: GridFilterModel; locked?: boolean; }