Skip to content

Commit

Permalink
Merge branch 'development' into forestgeo-app-development
Browse files Browse the repository at this point in the history
  • Loading branch information
siddheshraze committed Oct 21, 2024
2 parents 5bf7df9 + 491ff63 commit 780ad20
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export async function GET(
case 'personnel':
paginatedQuery = `
SELECT SQL_CALC_FOUND_ROWS p.*
FROM ${schema}.${params.dataType} q
FROM ${schema}.${params.dataType} p
JOIN ${schema}.census c ON p.CensusID = c.CensusID
WHERE c.PlotID = ?
AND c.PlotCensusNumber = ? LIMIT ?, ?;`;
Expand Down
84 changes: 35 additions & 49 deletions frontend/components/client/formcolumns.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import { GridColDef, GridRenderEditCellParams, useGridApiContext, useGridApiRef } from '@mui/x-data-grid';
import { GridColDef, GridRenderEditCellParams, useGridApiContext } from '@mui/x-data-grid';
import { areaSelectionOptions, unitSelectionOptions } from '@/config/macros';
import { formatHeader } from '@/components/client/datagridcolumns';
import moment from 'moment/moment';
Expand All @@ -12,25 +12,44 @@ import { AttributeStatusOptions } from '@/config/sqlrdsdefinitions/core';
import { styled } from '@mui/joy/styles';
import { CheckCircleOutlined } from '@mui/icons-material';

const renderDatePicker = (params: GridRenderEditCellParams) => {
export const renderDatePicker = (params: GridRenderEditCellParams) => {
const convertedValue = params.row.date ? moment(params.row.date, 'YYYY-MM-DD') : null;
if (!convertedValue) return <></>;

return (
<Box sx={{ display: 'flex', flexDirection: 'row', gap: '0.5em', alignItems: 'center' }}>
<DatePicker label={'Recorded Date'} value={convertedValue} disabled />
<Box
sx={{
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
width: '100%',
height: '100%',
padding: '0'
}}
>
<Input
size={'lg'}
value={convertedValue.format('MM-DD-YYYY')}
disabled
sx={{
textAlign: 'center',
width: '100%',
overflow: 'hidden'
}}
/>
</Box>
);
};

const renderEditDatePicker = (params: GridRenderEditCellParams) => {
const apiRef = useGridApiRef();
export const renderEditDatePicker = (params: GridRenderEditCellParams) => {
const apiRef = useGridApiContext();
const { id, row } = params;

return (
<Box sx={{ display: 'flex', flexDirection: 'row', gap: '0.5em', alignItems: 'center' }}>
<Box sx={{ display: 'flex', flexDirection: 'row', gap: '0.5em', alignItems: 'center', marginY: 1 }}>
<DatePicker
label={'Recorded Date'}
slotProps={{ textField: { size: 'small' } }}
value={moment(row.date, 'YYYY-MM-DD')}
onChange={newValue => {
apiRef.current.setEditCellValue({ id, field: 'date', value: newValue ? newValue.format('YYYY-MM-DD') : null });
Expand Down Expand Up @@ -344,23 +363,20 @@ export const AttributesFormGridColumns: GridColDef[] = [
field: 'code',
headerName: 'Code',
headerClassName: 'header',
minWidth: 250,
flex: 1,
editable: true
},
{
field: 'description',
headerName: 'Description',
headerClassName: 'header',
minWidth: 250,
flex: 1,
editable: true
},
{
field: 'status',
headerName: 'Status',
headerClassName: 'header',
minWidth: 250,
flex: 1,
editable: true
// This is temporarily being suspended -- it's a nice to have, not a need to have
Expand All @@ -382,7 +398,6 @@ export const PersonnelFormGridColumns: GridColDef[] = [
field: 'firstname',
headerName: 'First Name',
headerClassName: 'header',
minWidth: 250,
flex: 1,
align: 'left',
editable: true
Expand All @@ -391,7 +406,6 @@ export const PersonnelFormGridColumns: GridColDef[] = [
field: 'lastname',
headerName: 'Last Name',
headerClassName: 'header',
minWidth: 250,
flex: 1,
align: 'left',
editable: true
Expand All @@ -400,7 +414,6 @@ export const PersonnelFormGridColumns: GridColDef[] = [
field: 'role',
headerName: 'Role',
headerClassName: 'header',
minWidth: 250,
flex: 1,
align: 'left',
editable: true
Expand All @@ -409,7 +422,6 @@ export const PersonnelFormGridColumns: GridColDef[] = [
field: 'roledescription',
headerName: 'Role Description',
headerClassName: 'header',
minWidth: 250,
flex: 1,
align: 'left',
editable: true
Expand All @@ -430,7 +442,6 @@ export const SpeciesFormGridColumns: GridColDef[] = [
field: 'spcode',
headerName: 'Species Code',
headerClassName: 'header',
minWidth: 250,
flex: 1,
align: 'left',
editable: true
Expand All @@ -439,7 +450,6 @@ export const SpeciesFormGridColumns: GridColDef[] = [
field: 'family',
headerName: 'Family',
headerClassName: 'header',
minWidth: 250,
flex: 1,
align: 'left',
editable: true
Expand All @@ -448,7 +458,6 @@ export const SpeciesFormGridColumns: GridColDef[] = [
field: 'genus',
headerName: 'Genus',
headerClassName: 'header',
minWidth: 250,
flex: 1,
align: 'left',
editable: true
Expand All @@ -457,7 +466,6 @@ export const SpeciesFormGridColumns: GridColDef[] = [
field: 'species',
headerName: 'Species',
headerClassName: 'header',
minWidth: 250,
flex: 1,
align: 'left',
editable: true
Expand All @@ -466,7 +474,6 @@ export const SpeciesFormGridColumns: GridColDef[] = [
field: 'subspecies',
headerName: 'Subspecies',
headerClassName: 'header',
minWidth: 250,
flex: 1,
align: 'left',
editable: true
Expand All @@ -475,7 +482,6 @@ export const SpeciesFormGridColumns: GridColDef[] = [
field: 'idlevel',
headerName: 'ID Level',
headerClassName: 'header',
minWidth: 250,
flex: 1,
align: 'left',
editable: true
Expand All @@ -484,7 +490,6 @@ export const SpeciesFormGridColumns: GridColDef[] = [
field: 'authority',
headerName: 'Authority',
headerClassName: 'header',
minWidth: 250,
flex: 1,
align: 'left',
editable: true
Expand All @@ -493,7 +498,6 @@ export const SpeciesFormGridColumns: GridColDef[] = [
field: 'subspeciesauthority',
headerName: 'Subspecies Authority',
headerClassName: 'header',
minWidth: 250,
flex: 1,
align: 'left',
editable: true
Expand Down Expand Up @@ -681,10 +685,10 @@ export const MeasurementsFormGridColumns: GridColDef[] = [
},
{
field: 'coordinateunit',
headerName: 'Coordinate Units',
headerName: '<= Units',
headerClassName: 'header',
renderHeader: () => formatHeader('Coordinate', 'Units'),
flex: 1.5,
// renderHeader: () => formatHeader('Coordinate', 'Units'),
flex: 0.5,
align: 'center',
editable: true,
renderEditCell: params => <EditUnitsCell {...params} fieldName={'coordinateunit'} isArea={false} />
Expand All @@ -700,10 +704,10 @@ export const MeasurementsFormGridColumns: GridColDef[] = [
},
{
field: 'dbhunit',
headerName: 'DBH Units',
headerName: '<= Units',
headerClassName: 'header',
renderHeader: () => formatHeader('DBH', 'Units'),
flex: 1.5,
// renderHeader: () => formatHeader('DBH', 'Units'),
flex: 0.5,
align: 'center',
editable: true,
renderEditCell: params => <EditUnitsCell {...params} fieldName={'dbhunit'} isArea={false} />
Expand All @@ -719,30 +723,12 @@ export const MeasurementsFormGridColumns: GridColDef[] = [
},
{
field: 'homunit',
headerName: 'HOM Units',
headerName: '<= Units',
headerClassName: 'header',
renderHeader: () => formatHeader('HOM', 'Units'),
flex: 1.5,
// renderHeader: () => formatHeader('HOM', 'Units'),
flex: 0.5,
align: 'center',
editable: true,
renderEditCell: params => <EditUnitsCell {...params} fieldName={'homunit'} isArea={false} />
},
{
field: 'date',
headerName: 'Date',
headerClassName: 'header',
flex: 1,
align: 'center',
editable: true,
renderCell: renderDatePicker,
renderEditCell: renderEditDatePicker
},
{
field: 'codes',
headerName: 'Codes',
headerClassName: 'header',
flex: 1,
align: 'center',
editable: true
}
];
21 changes: 18 additions & 3 deletions frontend/components/datagrids/applications/msvdatagrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import { useOrgCensusContext, usePlotContext, useSiteContext } from '@/app/contexts/userselectionprovider';
import React, { useEffect, useState } from 'react';
import { GridRowModes, GridRowModesModel, GridRowsProp } from '@mui/x-data-grid';
import { Alert, AlertProps } from '@mui/material';
import { randomId } from '@mui/x-data-grid-generator';
import { Box, Button, Snackbar, Stack, Typography } from '@mui/joy';
import UploadParentModal from '@/components/uploadsystemhelpers/uploadparentmodal';
Expand All @@ -13,6 +12,7 @@ import { FormType } from '@/config/macros/formdetails';
import { MeasurementsSummaryRDS } from '@/config/sqlrdsdefinitions/views';
import MultilineModal from '@/components/datagrids/applications/multiline/multilinemodal';
import { useLoading } from '@/app/contexts/loadingprovider';
import { Alert, AlertProps, AlertTitle, Collapse } from '@mui/material';

const initialMeasurementsSummaryViewRDSRow: MeasurementsSummaryRDS = {
id: 0,
Expand Down Expand Up @@ -50,6 +50,7 @@ export default function MeasurementsSummaryViewDataGrid() {
const [isManualEntryFormOpen, setIsManualEntryFormOpen] = useState(false);
const [triggerGlobalError, setTriggerGlobalError] = useState(false);
const [globalError, setGlobalError] = useState<string | null>(null);
const [openAlert, setOpenAlert] = useState(false);

const [rows, setRows] = React.useState([initialMeasurementsSummaryViewRDSRow] as GridRowsProp);
const [rowCount, setRowCount] = useState(0);
Expand Down Expand Up @@ -156,15 +157,15 @@ export default function MeasurementsSummaryViewDataGrid() {
isUploadModalOpen={isUploadModalOpen}
handleCloseUploadModal={() => {
setIsUploadModalOpen(false);
setRefresh(true);
setOpenAlert(true);
}}
formType={FormType.measurements}
/>
<MultilineModal
isManualEntryFormOpen={isManualEntryFormOpen}
handleCloseManualEntryForm={() => {
setIsManualEntryFormOpen(false);
setRefresh(true);
setOpenAlert(true);
}}
formType={'measurements'}
/>
Expand All @@ -190,6 +191,20 @@ export default function MeasurementsSummaryViewDataGrid() {
setShouldAddRowAfterFetch={setShouldAddRowAfterFetch}
addNewRowToGrid={addNewRowToGrid}
/>
<Collapse in={openAlert} sx={{ width: '100%' }}>
<Snackbar
anchorOrigin={{ vertical: 'top', horizontal: 'center' }}
open={openAlert}
autoHideDuration={6000}
onClose={() => setOpenAlert(false)}
sx={{ display: 'flex', flex: 1, alignSelf: 'center', justifySelf: 'center', alignItems: 'center', justifyContent: 'center' }}
>
<Alert variant={'outlined'} onClose={() => setOpenAlert(false)} severity="warning">
<AlertTitle>Changes detected!</AlertTitle>
Please press the refresh button to update the grid.
</Alert>
</Snackbar>
</Collapse>
</>
);
}
24 changes: 20 additions & 4 deletions frontend/components/datagrids/isolatedmultilinedatagridcommons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { getColumnVisibilityModel } from '@/config/datagridhelpers';
import { useOrgCensusContext, usePlotContext, useSiteContext } from '@/app/contexts/userselectionprovider';
import { FileRow, FileRowSet } from '@/config/macros/formdetails';
import { AttributeStatusOptions } from '@/config/sqlrdsdefinitions/core';
import { renderDatePicker, renderEditDatePicker } from '@/components/client/formcolumns';

export interface IsolatedDataGridCommonProps {
gridType: string;
Expand Down Expand Up @@ -85,7 +86,24 @@ export default function IsolatedMultilineDataGridCommons(props: Readonly<Isolate
];
}
},
...gridColumns
...gridColumns,
{
field: 'date',
headerName: 'Date',
headerClassName: 'header',
flex: 1,
editable: true,
renderCell: renderDatePicker,
renderEditCell: renderEditDatePicker
},
{
field: 'codes',
headerName: 'Codes',
headerClassName: 'header',
flex: 1,
align: 'center',
editable: true
}
],
[gridColumns, unsavedChangesRef, apiRef, setRows]
);
Expand Down Expand Up @@ -119,7 +137,6 @@ export default function IsolatedMultilineDataGridCommons(props: Readonly<Isolate
try {
setIsSaving(true);

// After saving, process both edited and deleted rows
const rowsToDelete = Object.values(unsavedChangesRef.current.unsavedRows).filter(row => row._action === 'delete');
const rowsToSave = Object.values(unsavedChangesRef.current.unsavedRows).filter(row => row._action !== 'delete');

Expand All @@ -134,7 +151,6 @@ export default function IsolatedMultilineDataGridCommons(props: Readonly<Isolate
});
});

// Clear unsaved changes
unsavedChangesRef.current.unsavedRows = {};
unsavedChangesRef.current.rowsBeforeChange = {};

Expand Down Expand Up @@ -294,7 +310,7 @@ export default function IsolatedMultilineDataGridCommons(props: Readonly<Isolate
}}
loading={isSaving}
getRowClassName={getRowClassName}
autoHeight
getRowHeight={() => 'auto'}
/>
</Box>
<Button sx={{ marginTop: 8 }} onClick={submitChanges} color={'primary'} size={'lg'}>
Expand Down
Loading

0 comments on commit 780ad20

Please sign in to comment.