Skip to content

Commit

Permalink
fix fetch for dataheader and missouri/search effort data entries
Browse files Browse the repository at this point in the history
  • Loading branch information
jguevarra committed May 16, 2024
1 parent 3ca3856 commit a29ff5b
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 81 deletions.
9 changes: 6 additions & 3 deletions src/app-bundles/sites-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default {
store.doDomainBendRnFetch();
},

doSitesFetch: (data) => ({ dispatch, store, apiGet }) => {
doSitesFetch: (siteId) => ({ dispatch, store, apiGet }) => {
dispatch({ type: 'SITES_FETCH_START' });
const params = store.selectSitesParams();
const pageSize = store.selectSitesPageSize();
Expand All @@ -69,10 +69,13 @@ export default {
});

const queryById = queryFromObject({
...data,
...params,
...siteId,
size: pageSize,
page: pageNumber,
});

const url = `/psapi/siteDataEntry${data ? queryById : query}`;
const url = `/psapi/siteDataEntry${siteId ? queryById : query}`;

apiGet(url, (err, body) => {
if (!err) {
Expand Down
124 changes: 57 additions & 67 deletions src/app-pages/data-entry/datasheets/components/dataHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,76 +8,66 @@ import { Row } from 'app-pages/data-entry/edit-data-sheet/forms/_shared/helper';
import '../../dataentry.scss';

const DataHeader = connect(
'doFetchHeaderData',
'selectHeaderData',
({
doFetchHeaderData,
headerData,
id,
office,
year,
project
}) => {
useEffect(() => {
doFetchHeaderData(id, office, year, project);
}, [id, office, year, project]);

return (
<Card className='mb-3'>
<Card.Body>
<Row>
<div className='col-md-12 col-xs-4'>
<Row className='border-bottom'>
<div className='col-sm-2'>
<b className='mr-2'>Site ID:</b>
{id || '--'}
</div>
<div className='col-sm-2'>
<b className='mr-2'>Year:</b>
{headerData?.[0]?.year || '--'}
</div>
<div className='col-sm-2'>
<b className='mr-2'>Field Office:</b>
{headerData?.[0]?.fieldoffice || '--'}
</div>
<div className='col-sm-2'>
<b className='mr-2'>Project:</b>
{headerData?.[0]?.project || '--'}
</div>
<div className='col-sm-2'>
<b className='mr-2'>Segment:</b>
{headerData?.[0]?.segment || '--'}
</div>
<div className='col-sm-2'>
<b className='mr-2'>Season:</b>
{headerData?.[0]?.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 || '--'}
</div>
<div className='col-sm-2'>
<b className='mr-2'>Sample Unit:</b>
{headerData?.[0]?.bend || '--'}
</div>
<div className='col-sm-2'>
<b className='mr-2'>R/N:</b>
{headerData?.[0]?.bendrn || '--'}
</div>
<div className='col-sm-2'>
<b className='mr-2'>Bend River Mile:</b>
{headerData?.[0]?.bendrivermile || '--'}
</div>
</Row>
</div>
</Row>
</Card.Body>
</Card>
);
});
}) => (
<Card className='mb-3'>
<Card.Body>
<Row>
<div className='col-md-12 col-xs-4'>
<Row className='border-bottom'>
<div className='col-sm-2'>
<b className='mr-2'>Site ID:</b>
{id || '--'}
</div>
<div className='col-sm-2'>
<b className='mr-2'>Year:</b>
{headerData?.[0]?.year || '--'}
</div>
<div className='col-sm-2'>
<b className='mr-2'>Field Office:</b>
{headerData?.[0]?.fieldoffice || '--'}
</div>
<div className='col-sm-2'>
<b className='mr-2'>Project:</b>
{headerData?.[0]?.project || '--'}
</div>
<div className='col-sm-2'>
<b className='mr-2'>Segment:</b>
{headerData?.[0]?.segment || '--'}
</div>
<div className='col-sm-2'>
<b className='mr-2'>Season:</b>
{headerData?.[0]?.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 || '--'}
</div>
<div className='col-sm-2'>
<b className='mr-2'>Sample Unit:</b>
{headerData?.[0]?.bend || '--'}
</div>
<div className='col-sm-2'>
<b className='mr-2'>R/N:</b>
{headerData?.[0]?.bendrn || '--'}
</div>
<div className='col-sm-2'>
<b className='mr-2'>Bend River Mile:</b>
{headerData?.[0]?.bendrivermile || '--'}
</div>
</Row>
</div>
</Row>
</Card.Body>
</Card>
)
);

export default DataHeader;
8 changes: 6 additions & 2 deletions src/app-pages/data-entry/datasheets/pages/site-datasheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ const SiteDatasheet = connect(
searchEffortSitesDatasheetTotalResults,
}) => {
const [currentTab, setCurrentTab] = useState(0);
const { siteId, fieldoffice, year, projectId } = sitesData[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;

useEffect(() => {
const params = { siteId: siteId };
Expand All @@ -41,7 +45,7 @@ const SiteDatasheet = connect(
</div>
</div>
{/* Top Level Info */}
<DataHeader id={siteId} office={fieldoffice} year={year} project={projectId} />
<DataHeader id={siteId} />
{/* Tab Container */}
<Card>
<Card.Header text='Datasheet Workflows' />
Expand Down
26 changes: 17 additions & 9 deletions src/common/gridCellRenderers/siteIdCellRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,32 @@ 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,
edit,
data,
value,
}) => (
<Button
size='small'
variant='link'
className='p-0 mb-1'
text={value}
handleClick={() => edit ? doModalOpen(SitesFormModal, { edit: true, id: value }) : doSitesFetch({siteId: data.siteId}, doUpdateUrl('/sites-list/datasheet'))}
/>
));
}) => {
const handleCallback = () => {
doFetchHeaderData(data?.siteId, data?.fieldoffice, data?.year, data?.projectId);
doUpdateUrl('/sites-list/datasheet');
};

return(
<Button
size='small'
variant='link'
className='p-0 mb-1'
text={value}
handleClick={() => edit ? doModalOpen(SitesFormModal, { edit: true, id: value }) : doSitesFetch({siteId: data?.siteId}, handleCallback())}
/>
);});

export default SiteIdCellRenderer;

0 comments on commit a29ff5b

Please sign in to comment.