Skip to content

Commit

Permalink
commenting out unnecessary part of file upload process due to massive…
Browse files Browse the repository at this point in the history
… delays being imposed, leading to webpage crashing. Will be restored later
  • Loading branch information
siddheshraze committed Oct 22, 2024
1 parent 0b38f66 commit 4a9fa72
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 53 deletions.
19 changes: 17 additions & 2 deletions frontend/components/datagrids/measurementscommons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,16 @@ function debounce<T extends (...args: any[]) => 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);
Expand Down Expand Up @@ -120,6 +129,9 @@ const EditToolbar = ({ handleAddNewRow, handleRefresh, handleExportAll, handleEx
<Button color={'primary'} startIcon={<FileDownloadTwoTone />} onClick={handleExportCSV}>
Export Form CSV
</Button>
{/*<Button color={'primary'} startIcon={<Quiz />} onClick={handleRunValidations}>*/}
{/* Run Validations*/}
{/*</Button>*/}
</GridToolbarContainer>
);
};
Expand Down Expand Up @@ -559,7 +571,10 @@ export default function MeasurementsCommons(props: Readonly<MeasurementsCommonsP

const handleRefresh = useCallback(async () => {
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]);

Expand Down
5 changes: 3 additions & 2 deletions frontend/components/uploadsystem/segments/uploadfireazure.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ const UploadFireAzure: React.FC<UploadFireAzureProps> = ({
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}`,
Expand Down
97 changes: 48 additions & 49 deletions frontend/components/uploadsystem/segments/uploadfiresql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -56,54 +55,54 @@ const UploadFireSQL: React.FC<UploadFireProps> = ({

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) {
Expand Down
1 change: 1 addition & 0 deletions frontend/config/datagridhelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export interface EditToolbarCustomProps {
handleRefresh?: () => Promise<void>;
handleExportAll?: (filterModel?: GridFilterModel) => Promise<void>;
handleExportCSV?: () => Promise<void>;
handleRunValidations?: () => Promise<void>;
filterModel?: GridFilterModel;
locked?: boolean;
}
Expand Down

0 comments on commit 4a9fa72

Please sign in to comment.