Skip to content

Commit

Permalink
1. minor enhancements to the measurements-oriented datagrid to displa…
Browse files Browse the repository at this point in the history
…y viewfulltable.

2. global formatting and adjustments
  • Loading branch information
siddheshraze committed Aug 6, 2024
1 parent ff819f8 commit 320ac7c
Showing 1 changed file with 99 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// viewfulltable view datagrid
'use client';

import { initialViewFullTableViewRDS } from '@/config/sqlrdsdefinitions/views/viewfulltableviewrds';
import { Box, Typography } from '@mui/joy';
import { AlertProps } from '@mui/material';
import { GridRowsProp } from '@mui/x-data-grid';
import { randomId } from '@mui/x-data-grid-generator';
import { useSession } from 'next-auth/react';
import { useState } from 'react';
import { ViewFullTableGridColumns } from '@/components/client/datagridcolumns';
import MeasurementSummaryGrid from '@/components/datagrids/msvdatagrid';

export default function ViewFullTableDataGrid() {
const [rows, setRows] = useState<GridRowsProp>([initialViewFullTableViewRDS] as GridRowsProp);
const [rowCount, setRowCount] = useState(0);
const [rowModesModel, setRowModesModel] = useState({});
const [snackbar, setSnackbar] = useState<Pick<AlertProps, 'children' | 'severity'> | null>(null);
const [refresh, setRefresh] = useState(false);
const [paginationModel, setPaginationModel] = useState({
page: 0,
pageSize: 10
});
const [isNewRowAdded, setIsNewRowAdded] = useState(false);
const [shouldAddRowAfterFetch, setShouldAddRowAfterFetch] = useState(false);
const { data: session } = useSession();

const addNewRowToGrid = () => {
const id = randomId();
const newRow = {
...initialViewFullTableViewRDS,
id,
isNew: true
};

setRows(oldRows => [...(oldRows ?? []), newRow]);
setRowModesModel(oldModel => ({
...oldModel,
[id]: { mode: 'edit', fieldToFocus: 'speciesCode' }
}));
console.log('viewfulltableview addnewrowtogrid triggered');
};

return (
<>
<Box
sx={{
display: 'flex',
alignItems: 'center',
mb: 3,
width: '100%',
flexDirection: 'column'
}}
>
<Box
sx={{
width: '100%',
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
backgroundColor: 'warning.main',
borderRadius: '4px',
p: 2
}}
>
<Box sx={{ flexGrow: 1 }}>
{session?.user.userStatus !== 'fieldcrew' && (
<Typography level="title-lg" sx={{ color: '#ffa726' }}>
Note: ADMINISTRATOR VIEW
</Typography>
)}
</Box>
</Box>

<MeasurementSummaryGrid
gridType="viewfulltable"
gridColumns={ViewFullTableGridColumns}
rows={rows}
setRows={setRows}
rowCount={rowCount}
setRowCount={setRowCount}
rowModesModel={rowModesModel}
setRowModesModel={setRowModesModel}
snackbar={snackbar}
setSnackbar={setSnackbar}
refresh={refresh}
setRefresh={setRefresh}
paginationModel={paginationModel}
setPaginationModel={setPaginationModel}
isNewRowAdded={isNewRowAdded}
setIsNewRowAdded={setIsNewRowAdded}
shouldAddRowAfterFetch={shouldAddRowAfterFetch}
setShouldAddRowAfterFetch={setShouldAddRowAfterFetch}
addNewRowToGrid={addNewRowToGrid}
/>
</Box>
</>
);
}

0 comments on commit 320ac7c

Please sign in to comment.