Skip to content

Commit

Permalink
partial save. resolving baseline changes for validation CRUD system a…
Browse files Browse the repository at this point in the history
…nd preparing for further development.
  • Loading branch information
siddheshraze committed Aug 15, 2024
1 parent f4bdc5c commit 3605928
Show file tree
Hide file tree
Showing 35 changed files with 14,555 additions and 14,148 deletions.
2 changes: 1 addition & 1 deletion frontend/app/(hub)/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export default function DashboardPage() {
<Typography level={'body-md'} sx={{ alignSelf: 'flex-start', width: '100%' }}>
You have access to the following sites:
</Typography>
<Stack>
<Stack spacing={0.5}>
{allowedSites?.map(site => (
<Chip key={site.schemaName} variant="soft" startDecorator={<CheckIcon />} sx={{ flexBasis: 'auto' }}>
<Typography level={'body-md'} key={site.schemaName} sx={{ marginBottom: 1, wordBreak: 'break-word', flexBasis: 'auto' }}>
Expand Down
29 changes: 20 additions & 9 deletions frontend/app/(hub)/measurementshub/validations/page.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
'use client';

import { Card, CardContent, Typography } from '@mui/joy';
import { Box, Card, CardContent, Typography } from '@mui/joy';
import React from 'react';
import ValidationProceduresDataGrid from '@/components/datagrids/applications/validationproceduresdatagrid';
import SiteSpecificValidationsDataGrid from '@/components/datagrids/applications/sitespecificvalidationsdatagrid';

export default function ValidationsPage() {
return (
<Card variant={'plain'} sx={{ width: '100%' }}>
<CardContent>
<Typography level={'title-lg'} fontWeight={'bold'}>
Review Global Validations
</Typography>
<ValidationProceduresDataGrid />
</CardContent>
</Card>
<Box sx={{ width: '100%' }}>
<Card variant={'plain'} sx={{ width: '100%' }}>
<CardContent>
<Typography level={'title-lg'} fontWeight={'bold'}>
Review Global Validations
</Typography>
<ValidationProceduresDataGrid />
</CardContent>
</Card>
<Card variant={'plain'} sx={{ width: '100%' }}>
<CardContent>
<Typography level={'title-lg'} fontWeight={'bold'}>
Review Site-Specific Validations
</Typography>
<SiteSpecificValidationsDataGrid />
</CardContent>
</Card>
</Box>
);
}
7 changes: 4 additions & 3 deletions frontend/app/api/auth/[[...nextauth]]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import NextAuth, { AzureADProfile } from 'next-auth';
import AzureADProvider from 'next-auth/providers/azure-ad';
import { getAllowedSchemas, getAllSchemas, verifyEmail } from '@/components/processors/processorhelperfunctions';
import { SitesRDS } from '@/config/sqlrdsdefinitions/tables/sitesrds';
import { UserAuthRoles } from '@/config/macros';

const handler = NextAuth({
secret: process.env.NEXTAUTH_SECRET as string,
Expand Down Expand Up @@ -30,7 +31,7 @@ const handler = NextAuth({
if (!emailVerified) {
throw new Error('User email not found.');
}
user.userStatus = userStatus; // Add userStatus property to the user object
user.userStatus = userStatus as UserAuthRoles; // Add userStatus property to the user object
user.email = userEmail;
// console.log('getting all sites: ');
const allSites = await getAllSchemas();
Expand All @@ -55,9 +56,9 @@ const handler = NextAuth({

async session({ session, token }) {
if (typeof token.userStatus === 'string') {
session.user.userStatus = token.userStatus;
session.user.userStatus = token.userStatus as UserAuthRoles;
} else {
session.user.userStatus = 'fieldcrew'; // default no admin permissions
session.user.userStatus = 'field crew' as UserAuthRoles; // default no admin permissions
}
if (token && token.allsites && Array.isArray(token.allsites)) {
session.user.allsites = token.allsites as SitesRDS[];
Expand Down
9 changes: 0 additions & 9 deletions frontend/app/api/fixeddata/[dataType]/[[...slugs]]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ export async function GET(
throw new Error('core slugs schema/page/pageSize not correctly received');
if (!plotIDParam || plotIDParam === '0' || !plotCensusNumberParam || plotCensusNumberParam === '0')
throw new Error('Core plot/census information not received');
// optional pending parameter to filter only pending rows:
const pending = request.nextUrl.searchParams.get('pending') === 'true';
const page = parseInt(pageParam);
const pageSize = parseInt(pageSizeParam);
const plotID = parseInt(plotIDParam);
Expand All @@ -36,7 +34,6 @@ export async function GET(
let conn: PoolConnection | null = null;
let updatedMeasurementsExist = false;
let censusIDs;
let mostRecentCensusID: any;
let pastCensusIDs: string | any[];

try {
Expand Down Expand Up @@ -137,26 +134,20 @@ export async function GET(
JOIN ${schema}.census c ON pdt.CensusID = c.CensusID
WHERE c.PlotID = ?
AND c.PlotCensusNumber = ?
${pending ? ` AND pdt.IsValidated IS NULL` : ''}
ORDER BY pdt.MeasurementDate LIMIT ?, ?`;
queryParams.push(plotID, plotCensusNumber, page * pageSize, pageSize);
break;
} else {
updatedMeasurementsExist = true;
censusIDs = censusResults.map((c: any) => c.CensusID);
mostRecentCensusID = censusIDs[0];
pastCensusIDs = censusIDs.slice(1);
// Query to fetch paginated measurements from measurementssummaryview
paginatedQuery = `
SELECT SQL_CALC_FOUND_ROWS pdt.*
FROM ${schema}.${params.dataType} pdt
JOIN ${schema}.stems s ON pdt.StemID = s.StemID
JOIN ${schema}.trees t ON s.TreeID = t.TreeID
JOIN ${schema}.species sp ON t.SpeciesID = sp.SpeciesID
JOIN ${schema}.census c ON sp.CensusID = c.CensusID
WHERE c.PlotID = ?
AND c.CensusID IN (${censusIDs.map(() => '?').join(', ')})
${pending ? ` AND pdt.IsValidated IS NULL` : ''}
ORDER BY pdt.MeasurementDate ASC LIMIT ?, ?`;
queryParams.push(plotID, ...censusIDs, page * pageSize, pageSize);
break;
Expand Down
127 changes: 125 additions & 2 deletions frontend/components/client/datagridcolumns.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { areaSelectionOptions, unitSelectionOptions } from '@/config/macros';
import { AttributeStatusOptions } from '@/config/sqlrdsdefinitions/tables/attributerds';
import { Box, FormHelperText, Input, Option, Select, Stack, Typography } from '@mui/joy';
import { Accordion, AccordionDetails, AccordionGroup, AccordionSummary, Box, FormHelperText, Input, Option, Select, Stack, Typography } from '@mui/joy';
import { GridColDef, GridRenderEditCellParams, useGridApiRef } from '@mui/x-data-grid';
import { useEffect, useState } from 'react';
import React, { useEffect, useState } from 'react';
import Avatar from '@mui/joy/Avatar';
import { ExpandMore } from '@mui/icons-material';
import { useSession } from 'next-auth/react';
import CodeMirror from '@uiw/react-codemirror';
import { sql } from '@codemirror/lang-sql';

const formatHeader = (word1: string, word2: string) => (
<Stack direction={'column'} sx={{ alignItems: 'center', justifyContent: 'center' }}>
Expand Down Expand Up @@ -1487,6 +1492,61 @@ export const ValidationProceduresGridColumns: GridColDef[] = [
return <Typography level={'body-md'}>{params.row.description}</Typography>;
}
},
{
field: 'definition',
headerName: 'SQL Implementation',
headerClassName: 'header',
type: 'string',
editable: true,
flex: 1,
renderCell: (params: GridRenderEditCellParams) => {
const { data: session } = useSession();
let isEditing = false;
if (typeof params.id === 'string') {
isEditing = params.rowModesModel[parseInt(params.id)]?.mode === 'edit';
}
const isAdmin = session?.user?.userStatus === 'db admin' || session?.user?.userStatus === 'global';

if (isEditing && isAdmin) {
return (
<CodeMirror
value={params.value}
height="auto"
extensions={[sql()]}
onChange={value => {
// Update the grid row with the new value from CodeMirror
params.api.updateRows([{ ...params.row, definition: value }]);
}}
/>
);
}

return (
<AccordionGroup>
<Accordion sx={{ width: '100%' }}>
<AccordionSummary
sx={{
padding: 0,
'& .MuiAccordionSummary-content': {
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap'
}
}}
>
<Avatar>
<ExpandMore />
</Avatar>
<Typography level={'body-md'}>{params.row.description}</Typography>
</AccordionSummary>
<AccordionDetails sx={{ padding: 0 }}>
<Typography level={'body-md'}>{params.row.definition}</Typography>
</AccordionDetails>
</Accordion>
</AccordionGroup>
);
}
},
{
field: 'createdAt',
headerName: 'Created At',
Expand Down Expand Up @@ -1517,3 +1577,66 @@ export const ValidationProceduresGridColumns: GridColDef[] = [
},
{ field: 'isEnabled', headerName: 'Active?', headerClassName: 'header', type: 'boolean', editable: true, flex: 0.2 }
];

export const SiteSpecificValidationsGridColumns: GridColDef[] = [
{ field: 'id', headerName: 'ID', headerClassName: 'header' },
{ field: 'validationProcedureID', headerName: '#', headerClassName: 'header' },
{
field: 'name',
headerName: 'Procedure',
headerClassName: 'header',
type: 'string',
editable: true,
flex: 1,
renderCell: (params: GridRenderEditCellParams) => {
const value = params.row.procedureName.replace(/(DBH|HOM)([A-Z])/g, '$1 $2').replace(/([a-z])([A-Z])/g, '$1 $2');
return <Typography level={'body-lg'}>{value}</Typography>;
}
},
{
field: 'description',
headerName: 'Description',
headerClassName: 'header',
type: 'string',
editable: true,
flex: 1,
renderCell: (params: GridRenderEditCellParams) => {
return <Typography level={'body-md'}>{params.row.description}</Typography>;
}
},
{
field: 'definition',
headerName: 'SQL Implementation',
headerClassName: 'header',
type: 'string',
editable: true,
flex: 1,
renderCell: (params: GridRenderEditCellParams) => {
return (
<AccordionGroup>
<Accordion sx={{ width: '100%' }}>
<AccordionSummary
sx={{
padding: 0,
'& .MuiAccordionSummary-content': {
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap'
}
}}
>
<Avatar>
<ExpandMore />
</Avatar>
<Typography level={'body-md'}>{params.row.description}</Typography>
</AccordionSummary>
<AccordionDetails sx={{ padding: 0 }}>
<Typography level={'body-md'}>{params.row.description}</Typography>
</AccordionDetails>
</Accordion>
</AccordionGroup>
);
}
},
{ field: 'isEnabled', headerName: 'Active?', headerClassName: 'header', type: 'boolean', editable: true, flex: 0.2 }
];
3 changes: 2 additions & 1 deletion frontend/components/client/githubfeedbackmodal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ const formatHeaders = (headers: any) => {
));
};

export default function GithubFeedbackModal({ open, onClose }: GithubFeedbackModalProps) {
export default function GithubFeedbackModal(props: GithubFeedbackModalProps) {
const { open, onClose } = props;
const [name, setName] = useState<string>('');
const [issueType, setIssueType] = useState<IssueType | null>(null);
const [description, setDescription] = useState('');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default function AllTaxonomiesViewDataGrid() {
}}
>
<Box sx={{ flexGrow: 1 }}>
{session?.user.userStatus !== 'fieldcrew' && (
{session?.user.userStatus !== 'field crew' && (
<Typography level={'title-lg'} sx={{ color: '#ffa726' }}>
Note: ADMINISTRATOR VIEW
</Typography>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default function AttributesDataGrid() {
}}
>
<Box sx={{ flexGrow: 1 }}>
{session?.user.userStatus !== 'fieldcrew' && (
{session?.user.userStatus !== 'field crew' && (
<Typography level={'title-lg'} sx={{ color: '#ffa726' }}>
Note: ADMINISTRATOR VIEW
</Typography>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ import MeasurementsCommons from '@/components/datagrids/measurementscommons';
import { CoreMeasurementsGridColumns } from '@/components/client/datagridcolumns';
import { initialCoreMeasurementsRDSRow } from '@/config/sqlrdsdefinitions/tables/coremeasurementsrds';

interface CoreMeasurementsDataGridProps {
filterPending?: boolean;
}

export default function CoreMeasurementsDataGrid({ filterPending }: CoreMeasurementsDataGridProps) {
export default function CoreMeasurementsDataGrid() {
const [isUploadModalOpen, setIsUploadModalOpen] = useState(false);
const [triggerGlobalError, setTriggerGlobalError] = useState(false);
const [globalError, setGlobalError] = useState<string | null>(null);
Expand Down Expand Up @@ -125,7 +121,6 @@ export default function CoreMeasurementsDataGrid({ filterPending }: CoreMeasurem
shouldAddRowAfterFetch={shouldAddRowAfterFetch}
setShouldAddRowAfterFetch={setShouldAddRowAfterFetch}
addNewRowToGrid={addNewRowToGrid}
filterPending={filterPending}
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ import UploadParentModal from '@/components/uploadsystemhelpers/uploadparentmoda
import MeasurementsCommons from '@/components/datagrids/measurementscommons';
import { measurementsSummaryViewGridColumns } from '@/components/client/datagridcolumns';

interface MSVDataGridProps {
filterPending?: boolean;
}

export default function MeasurementsSummaryViewDataGrid({ filterPending }: MSVDataGridProps) {
export default function MeasurementsSummaryViewDataGrid() {
const currentPlot = usePlotContext();
const currentCensus = useOrgCensusContext();
const [isUploadModalOpen, setIsUploadModalOpen] = useState(false);
Expand Down Expand Up @@ -132,7 +128,6 @@ export default function MeasurementsSummaryViewDataGrid({ filterPending }: MSVDa
shouldAddRowAfterFetch={shouldAddRowAfterFetch}
setShouldAddRowAfterFetch={setShouldAddRowAfterFetch}
addNewRowToGrid={addNewRowToGrid}
filterPending={filterPending}
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { useSession } from 'next-auth/react';
import { Box, Button, Stack, Typography } from '@mui/joy';
import UploadParentModal from '@/components/uploadsystemhelpers/uploadparentmodal';
import Link from 'next/link';
import { useOrgCensusContext } from '@/app/contexts/userselectionprovider';
import { PersonnelGridColumns } from '@/components/client/datagridcolumns';

export default function PersonnelDataGrid() {
Expand All @@ -27,7 +26,6 @@ export default function PersonnelDataGrid() {
const [shouldAddRowAfterFetch, setShouldAddRowAfterFetch] = useState(false);
const [isUploadModalOpen, setIsUploadModalOpen] = useState(false);
const { data: session } = useSession();
const currentCensus = useOrgCensusContext();
// Function to fetch paginated data
const addNewRowToGrid = () => {
const id = randomId();
Expand Down Expand Up @@ -64,7 +62,7 @@ export default function PersonnelDataGrid() {
}}
>
<Box sx={{ flexGrow: 1 }}>
{session?.user.userStatus !== 'fieldcrew' && (
{session?.user.userStatus !== 'field crew' && (
<Typography level={'title-lg'} sx={{ color: '#ffa726' }}>
Note: ADMINISTRATOR VIEW
</Typography>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export default function QuadratPersonnelDataGrid() {
}}
>
<Box sx={{ flexGrow: 1 }}>
{session?.user.userStatus !== 'fieldcrew' && (
{session?.user.userStatus !== 'field crew' && (
<Typography level={'title-lg'} sx={{ color: '#ffa726' }}>
Note: ADMINISTRATOR VIEW
</Typography>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default function QuadratsDataGrid() {
}}
>
<Box sx={{ flexGrow: 1 }}>
{session?.user.userStatus !== 'fieldcrew' && (
{session?.user.userStatus !== 'field crew' && (
<Typography level={'title-lg'} sx={{ color: '#ffa726' }}>
Note: ADMINISTRATOR VIEW
</Typography>
Expand Down
Loading

0 comments on commit 3605928

Please sign in to comment.