Skip to content

Commit

Permalink
Data Header Logic Rewrite (#113)
Browse files Browse the repository at this point in the history
* dataheader logic rewrite

* jasmin's changes for displaying new fields
  • Loading branch information
jguevarra authored Jun 24, 2024
1 parent 44c0aeb commit b5addad
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 59 deletions.
25 changes: 25 additions & 0 deletions src/app-bundles/base-data-bundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const baseDataBundle = {
name: 'baseData',

getReducer: () => {
const initialData = {
data: [],
};

return (state = initialData, { type, payload }) => {
switch (type) {
case 'UPDATE_BASE_DATA':
return {
...state,
data: { ...state.data, ...payload },
};
default:
return state;
}
};
},

selectBaseData: state => state.baseData.data,
};

export default baseDataBundle;
21 changes: 1 addition & 20 deletions src/app-bundles/data-entry-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export default {
items: [],
totalCount: 0,
},
headerData: {},
lastParams: {},
currentTab: 0,
};
Expand Down Expand Up @@ -104,8 +103,6 @@ export default {
},
};

case 'UPDATED_HEADER_DATA':
return { ...state, headerData: payload };
case 'UPDATE_CURRENT_TAB':
return {
...state,
Expand Down Expand Up @@ -154,7 +151,6 @@ export default {
selectDataEntry: state => state.dataEntry,
selectDataEntryData: state => state.dataEntry.data.length ? state.dataEntry.data[0] : {},
selectDataEntryLastParams: state => state.dataEntry.lastParams,
selectHeaderData: state => state.dataEntry.headerData,
selectCurrentTab: state => state.dataEntry.currentTab,
selectDataEntryTotalCount: state => state.dataEntry.totalCount,

Expand All @@ -176,22 +172,6 @@ export default {
store.doDomainSampleUnitTypesFetch();
},

doFetchHeaderData: (siteId, office, year, project) => ({ dispatch, apiGet }) => {
const url = '/psapi/headerData?' + new URLSearchParams({
siteId: siteId,
office: office,
year: year,
project: project,
});

apiGet(url, (_err, body) => {
dispatch({
type: 'UPDATED_HEADER_DATA',
payload: body,
});
});
},

doMoRiverDatasheetLoadData: (id) => ({ store }) => {
// Load data
store.doFetchFishDataEntry({ mrId: id, id: store.selectUserRole().id }, null, false);
Expand Down Expand Up @@ -232,6 +212,7 @@ export default {
type: 'missouriRiver',
},
});
dispatch({ type: 'UPDATE_BASE_DATA', payload: { mrId: body?.items?.[0]?.mrId, mrFid: body?.items?.[0]?.mrFid } });

if (store.selectDataEntryTotalCount() === 0) {
if (ignoreToast) { tWarning(toastId, 'No Missouri River datasheet(s) found.'); }
Expand Down
2 changes: 2 additions & 0 deletions src/app-bundles/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import usersBundle from './users-bundle';
import sitesDatasheetBundle from './sites-datasheet-bundle';
import exportsBundle from './exports/exports-bundle';
import loadingBundle from './loading-bundle';
import baseDataBundle from './base-data-bundle';

// Mock Token User
const mockTokenApplicationAdmin =
Expand Down Expand Up @@ -63,4 +64,5 @@ export default composeBundles(
sitesDatasheetBundle,
exportsBundle,
loadingBundle,
baseDataBundle
);
7 changes: 2 additions & 5 deletions src/app-bundles/sites-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,8 @@ export default {

apiGet(url, (err, body) => {
if (!err) {
dispatch({
type: 'SITES_UPDATED_ITEMS',
payload: body,
});
dispatch({ type: 'SITES_FETCH_FINISHED' });
dispatch({ type: 'SITES_UPDATED_ITEMS', payload: body });
siteId && dispatch({ type: 'UPDATE_BASE_DATA', payload: body?.items?.[0] });
} else {
dispatch({ type: 'SITES_FETCH_ERROR', payload: err });
}
Expand Down
33 changes: 20 additions & 13 deletions src/app-pages/data-entry/datasheets/components/dataHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import { Row } from 'app-pages/data-entry/edit-data-sheet/forms/_shared/helper';
import '../../dataentry.scss';

const DataHeader = connect(
'selectHeaderData',
'selectBaseData',
'selectRouteParams',
({
headerData,
id,
baseData,
routeParams
}) => (
<Card className='mb-3'>
<Card.Body>
Expand All @@ -20,48 +21,54 @@ const DataHeader = connect(
<Row className='border-bottom'>
<div className='col-sm-2'>
<b className='mr-2'>Site ID:</b>
{id || '--'}
{baseData?.siteId || '--'}
</div>
<div className='col-sm-2'>
<b className='mr-2'>Year:</b>
{headerData?.[0]?.year || '--'}
{baseData?.year || '--'}
</div>
<div className='col-sm-2'>
<b className='mr-2'>Field Office:</b>
{headerData?.[0]?.fieldoffice || '--'}
{baseData?.fieldoffice || '--'}
</div>
<div className='col-sm-2'>
<b className='mr-2'>Project:</b>
{headerData?.[0]?.project || '--'}
{baseData?.projectId || '--'}
</div>
<div className='col-sm-2'>
<b className='mr-2'>Segment:</b>
{headerData?.[0]?.segment || '--'}
{baseData?.segmentId || '--'}
</div>
<div className='col-sm-2'>
<b className='mr-2'>Season:</b>
{headerData?.[0]?.season || '--'}
{baseData?.season || '--'}
</div>
</Row>
</div>
<div className='col-md-12 col-xs-4 mt-2'>
<Row>
<div className='col-sm-2'>
<b className='mr-2'>Sample Unit Type:</b>
{headerData?.[0]?.sampleUnitType || '--'}
{baseData?.sampleUnitType || '--'}
</div>
<div className='col-sm-2'>
<b className='mr-2'>Sample Unit:</b>
{headerData?.[0]?.bend || '--'}
{baseData?.bend || '--'}
</div>
<div className='col-sm-2'>
<b className='mr-2'>R/N:</b>
{headerData?.[0]?.bendrn || '--'}
{baseData?.bendrn || '--'}
</div>
<div className='col-sm-2'>
<b className='mr-2'>Bend River Mile:</b>
{headerData?.[0]?.bendrivermile || '--'}
{baseData?.bendRiverMile || '--'}
</div>
{(routeParams?.form === 'missouriRiver-edit' || routeParams?.form === 'missouriRiver-create') && (
<div className='col-sm-4'>
<b className='mr-2'>MR FID:</b>
{baseData?.mrFid || '--'}
</div>
)}
</Row>
</div>
</Row>
Expand Down
14 changes: 5 additions & 9 deletions src/app-pages/data-entry/datasheets/pages/site-datasheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,18 @@ import SearchDsTable from '../tables/searchDsTable';
const SiteDatasheet = connect(
'doSitesDatasheetLoadData',
'doUpdateSitesDatasheetParams',
'selectSitesData',
'selectBaseData',
'selectMoriverSitesDatasheetTotalResults',
'selectSearchEffortSitesDatasheetTotalResults',
({
doSitesDatasheetLoadData,
doUpdateSitesDatasheetParams,
sitesData,
baseData,
moriverSitesDatasheetTotalResults,
searchEffortSitesDatasheetTotalResults,
searchEffortSitesDatasheetTotalResults
}) => {
const [currentTab, setCurrentTab] = useState(0);

const siteId = sitesData?.[0]?.siteId ?? null;
const fieldoffice = sitesData?.[0]?.fieldoffice ?? null;
const year = sitesData?.[0]?.year ?? null;
const projectId = sitesData?.[0]?.projectId ?? null;
const siteId = baseData?.siteId ?? null;

useEffect(() => {
const params = { siteId: siteId };
Expand All @@ -45,7 +41,7 @@ const SiteDatasheet = connect(
</div>
</div>
{/* Top Level Info */}
<DataHeader id={siteId} />
<DataHeader />
{/* Tab Container */}
<Card>
<Card.Header text='Datasheet Workflows' />
Expand Down
2 changes: 1 addition & 1 deletion src/app-pages/data-entry/datasheets/tables/fishDsTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ const FishDsTable = connect(
isRequired: true
}}
/>
<AgGridColumn field='length' cellEditor='numberEditor' />
<AgGridColumn field='length' cellEditor='floatEditor' />
<AgGridColumn field='weight' cellEditor='floatEditor' />
<AgGridColumn field='countF' headerName='Count' cellEditor='numberEditor' />
<AgGridColumn
Expand Down
4 changes: 4 additions & 0 deletions src/app-pages/data-entry/datasheets/tables/suppDsTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ const SuppDsTable = connect(
<AgGridColumn field='checkby' headerName='Checked' cellEditor='textEditor' sortable unSortIcon />
<AgGridColumn field='approved' cellEditor='selectEditor' cellEditorParams={{ options: YNNumOptions, type: 'number' }} sortable unSortIcon />
<AgGridColumn field='speciesId' headerName='Species' cellEditor='numberEditor' sortable unSortIcon />
<AgGridColumn field='netrivermile' headerName='Net River Mile' cellEditor='numberEditor' editable={false}/>
<AgGridColumn field='length' headerName='Length' cellEditor='textEditor' editable={false} />
<AgGridColumn field='weight' headerName='Weight' cellEditor='textEditor' editable={false} />
<AgGridColumn field='condition' headerName='Condition' cellEditor='numberEditor' editable={false} />
<AgGridColumn field='recorder' cellEditor='textEditor' sortable unSortIcon />
<AgGridColumn field='tagnumber' cellEditor='textEditor' width={125} sortable unSortIcon />
<AgGridColumn field='pitrn' headerName='PIT R/N/Z' cellEditor='selectEditor' cellEditorParams={{ options: visualAssessmentOptions }} sortable unSortIcon />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const MissouriRiverForm = connect(
'doDomainsSetSite2Fetch',
'doResetMoRiverDataEntryData',
'selectDataEntryData',
'selectSitesData',
'selectBaseData',
'selectDomainsMeso',
'selectDomainsStructureFlow',
'selectDomainsStructureMod',
Expand All @@ -66,7 +66,7 @@ const MissouriRiverForm = connect(
doDomainsSetSite2Fetch,
doResetMoRiverDataEntryData,
dataEntryData,
sitesData,
baseData,
domainsMeso,
domainsStructureFlow,
domainsStructureMod,
Expand Down Expand Up @@ -95,9 +95,7 @@ const MissouriRiverForm = connect(
const [isNoTurbidity, setIsNoTurbidity] = useState(false);
const [isNoVelocity, setIsNoVelocity] = useState(false);

const siteId = edit ? state['siteId'] : sitesData[0].siteId;
const isCreate = routeParams.form.split('-')[1] === 'create';
const data = sitesData[0];
const formComplete = true;

const handleChange = e => {
Expand Down Expand Up @@ -214,7 +212,7 @@ const MissouriRiverForm = connect(
setIsNoVelocity(false);
}
} else {
handleSelect('siteId', Number(data.siteId));
handleSelect('siteId', Number(baseData?.siteId));
}
}, [edit, dataEntryData]);

Expand All @@ -236,7 +234,7 @@ const MissouriRiverForm = connect(
</div>
</div>
{/* Top Level Info */}
<DataHeader id={siteId} />
<DataHeader />
{/* Approval */}
{/* TO DO: include component props */}
<Approval />
Expand Down
4 changes: 2 additions & 2 deletions src/common/gridCellRenderers/mrIdCellRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const MrIdCellRenderer = connect(
type,
tab = 0,
}) => {
const handleChange = () => {
const handleClick = () => {
doUpdateCurrentTab(tab);
doFetchMoRiverDataEntry({ tableId: getMrId()}, () => doUpdateUrl(uri), false);
};
Expand Down Expand Up @@ -53,7 +53,7 @@ const MrIdCellRenderer = connect(
variant='link'
className='p-0 mb-1'
text={getTypeText()}
handleClick={handleChange}
handleClick={handleClick}
/>
);
});
Expand Down
3 changes: 0 additions & 3 deletions src/common/gridCellRenderers/siteIdCellRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ import Button from 'app-components/button';
import SitesFormModal from 'app-pages/data-entry/sites-list/components/modals/sitesForm';

const SiteIdCellRenderer = connect(
'doFetchHeaderData',
'doSitesFetch',
'doUpdateUrl',
'doModalOpen',
({
doFetchHeaderData,
doSitesFetch,
doUpdateUrl,
doModalOpen,
Expand All @@ -19,7 +17,6 @@ const SiteIdCellRenderer = connect(
value,
}) => {
const handleCallback = () => {
doFetchHeaderData(data?.siteId, data?.fieldoffice, data?.year, data?.projectId);
doUpdateUrl('/sites-list/datasheet');
};

Expand Down

0 comments on commit b5addad

Please sign in to comment.