Skip to content

Commit

Permalink
PlotRDS type was updated to remove usesSubquadrats, but summary page …
Browse files Browse the repository at this point in the history
…was not updated to correctly work with this change, now repaired.
  • Loading branch information
siddheshraze committed Jul 5, 2024
1 parent 525e93d commit c08b6a3
Showing 1 changed file with 9 additions and 37 deletions.
46 changes: 9 additions & 37 deletions frontend/app/(hub)/measurementshub/summary/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import React, { useEffect, useState } from "react";
import { GridRowModes, GridRowModesModel, GridRowsProp } from "@mui/x-data-grid";
import { Alert, AlertProps, LinearProgress, Tooltip, TooltipProps, styled, tooltipClasses } from "@mui/material";
import { gridColumnsArrayMSVRDS, initialMeasurementsSummaryViewRDSRow } from '@/config/sqlrdsdefinitions/views/measurementssummaryviewrds';
import { Box, ListItemContent, ListItem, List, Modal, ModalDialog, Typography, Button, DialogTitle, DialogContent, DialogActions, Snackbar, Stack,} from "@mui/joy";
import { Box, ListItemContent, ListItem, List, Modal, ModalDialog, Typography, Button, DialogTitle, DialogContent, DialogActions, Snackbar, Stack, } from "@mui/joy";
import Select, { SelectOption } from "@mui/joy/Select";
import { useSession } from "next-auth/react";
import { useOrgCensusContext, usePlotContext, useQuadratDispatch, useSiteContext} from "@/app/contexts/userselectionprovider";
import { useOrgCensusContext, usePlotContext, useQuadratDispatch, useSiteContext } from "@/app/contexts/userselectionprovider";
import { randomId } from "@mui/x-data-grid-generator";
import UploadParentModal from "@/components/uploadsystemhelpers/uploadparentmodal";
import { useQuadratListContext } from "@/app/contexts/listselectionprovider";
Expand Down Expand Up @@ -65,7 +65,6 @@ export default function SummaryPage() {
});
const [isNewRowAdded, setIsNewRowAdded] = useState<boolean>(false);
const [shouldAddRowAfterFetch, setShouldAddRowAfterFetch] = useState(false);
const [useSubquadrats, setUseSubquadrats] = useState(currentPlot?.usesSubquadrats ?? false);

useEffect(() => {
const verifyPreconditions = async () => {
Expand Down Expand Up @@ -220,7 +219,7 @@ export default function SummaryPage() {
<Stack direction="column" spacing={2} marginBottom={2}>
<Typography level="title-sm">Select Quadrat:</Typography>
<Select
disabled={!validity['quadrats'] || !currentPlot?.usesSubquadrats}
disabled={!validity['quadrats']}
placeholder="Select a Quadrat"
name="None"
required
Expand All @@ -245,7 +244,7 @@ export default function SummaryPage() {
onClick={handleConfirmQuadrat}
size="sm"
color="primary"
disabled={!currentPlot?.usesSubquadrats}
disabled={!validity['quadrats']}
>Confirm</Button>
{!validity['quadrats'] && (
<Alert severity="warning" sx={{ mt: 2 }}>
Expand All @@ -255,25 +254,6 @@ export default function SummaryPage() {
</Stack>
);

useEffect(() => {
const updateUseSubquadrats = async () => {
const updatedPlot = {
...currentPlot,
usesSubquadrats: useSubquadrats,
};
const response = await fetch(`/api/fixeddata/plots?schema=${currentSite?.schemaName ?? ''}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(updatedPlot)
});
if (!response.ok) setGlobalError('Toggling subquadrats usage failed!');
};

if (currentPlot?.usesSubquadrats !== useSubquadrats) {
updateUseSubquadrats().catch(console.error);
}
}, [currentPlot, useSubquadrats]);

return (
<>
{globalError && (
Expand All @@ -290,19 +270,11 @@ export default function SummaryPage() {
<Stack direction="column">
<Box sx={{ display: 'flex', flexDirection: 'column', flexGrow: 1 }}>
<Box sx={{ flex: 1, display: 'flex', justifyContent: 'left', flexDirection: 'column', marginTop: 2 }}>
{currentPlot?.usesSubquadrats ? (
<Box sx={{ display: 'flex', flexDirection: 'row' }}>
<Typography level={"title-md"} sx={{ color: "#ffa726" }}>Note: This plot has been set to accept
subquadrats. <br />
Please ensure you select a quadrat before proceeding.</Typography>
<QuadratSelectionMenu />
</Box>
) : (
<Typography level={"title-md"} sx={{ color: "#ffa726" }}>Note: This plot does not accept
subquadrats. <br />
Please ensure that you use quadrat names when submitting new measurements instead of subquadrat
names</Typography>
)}
<Typography level={"title-md"} sx={{ color: "#ffa726" }}>Note: This plot does not accept
subquadrats. <br />
Please ensure that you use quadrat names when submitting new measurements instead of subquadrat
names
</Typography>
{session?.user.userStatus !== 'fieldcrew' ? (
<Stack direction="column">
{/* <Typography level={"title-lg"} sx={{color: "#ffa726"}}>Note: ADMINISTRATOR VIEW</Typography>
Expand Down

0 comments on commit c08b6a3

Please sign in to comment.