Skip to content

Commit

Permalink
bugfixes for supplemental tab fields (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
jguevarra authored Jun 26, 2024
1 parent cbcf3e2 commit a9b0a38
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 32 deletions.
4 changes: 4 additions & 0 deletions src/app-bundles/base-data-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ const baseDataBundle = {
},

selectBaseData: state => state.baseData.data,

doUpdateBaseData: (name, value) => ({ dispatch }) => {
dispatch({ type: 'UPDATE_BASE_DATA', payload: { [name]: value } });
},
};

export default baseDataBundle;
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 @@ -46,7 +46,7 @@ const FishDsTable = connect(
}) => {
const gridRef = useRef();
const [ isEditingRow, setIsEditingRow ] = useState(false);
const lastRow = dataEntryFishData.items[dataEntryFishData.totalCount - 1];
const lastRow = dataEntryFishData?.items?.[dataEntryFishData?.totalCount - 1];
const initialState = {
mrId: dataEntryLastParams.mrId
};
Expand Down
19 changes: 15 additions & 4 deletions src/app-pages/data-entry/datasheets/tables/suppDsTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,39 @@ const SuppDsTable = connect(
'selectDataEntrySupplemental',
'selectDataEntryLastParams',
'selectUserRole',
'selectBaseData',
({
doModalOpen,
doSaveSupplementalDataEntry,
doUpdateSupplementalDataEntry,
dataEntrySupplemental,
dataEntryLastParams,
userRole,
baseData,
isAddRow,
rowId,
setIsAddRow,
setRowId,
}) => {
const gridRef = useRef();
const [ isEditingRow, setIsEditingRow ] = useState(false);
const { items } = dataEntrySupplemental;

const defaultValues = {
fid: baseData?.fid,
ffid: baseData?.ffid,
condition: baseData?.condition,
netrivermile: baseData?.netrivermile,
length: baseData?.length,
weight: baseData?.weight,
species: baseData?.species
};

const initialState = {
mrId: dataEntryLastParams.mrId
};

const addRow = useCallback((fid) => {
gridRef.current.api.applyTransaction({ add: [{ fid: fid }] });
const addRow = useCallback(() => {
gridRef.current.api.applyTransaction({ add: [defaultValues] });
}, []);

const refreshSuppLinkButtons = () => {
Expand All @@ -62,7 +73,7 @@ const SuppDsTable = connect(

useEffect(() => {
if (isAddRow) {
addRow(rowId);
addRow();
}
}, [isAddRow]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const reducer = (state, action) => {
};

const MissouriRiverForm = connect(
'doUpdateBaseData',
'doMoRiverDatasheetLoadData',
'doSaveMoRiverDataEntry',
'doUpdateMoRiverDataEntry',
Expand All @@ -55,6 +56,7 @@ const MissouriRiverForm = connect(
'selectUserRole',
'selectRouteParams',
({
doUpdateBaseData,
doMoRiverDatasheetLoadData,
doSaveMoRiverDataEntry,
doUpdateMoRiverDataEntry,
Expand Down Expand Up @@ -226,6 +228,11 @@ const MissouriRiverForm = connect(
}
}, [isCreate, dataEntryData.mrId, userRole.id]);

useEffect(() => {
// netrivermile in baseData
doUpdateBaseData('netrivermile', state['netrivermile']);
}, [state['netrivermile']]);

return (
<>
<div className='row'>
Expand Down
52 changes: 25 additions & 27 deletions src/common/gridCellRenderers/suppLinkCellRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ import Button from 'app-components/button';
import Icon from 'app-components/icon';

const SuppLinkCellRenderer = connect(
'doUpdateBaseData',
'doUpdateCurrentTab',
'selectDataEntrySupplemental',
({
doUpdateBaseData,
doUpdateCurrentTab,
dataEntrySupplemental,
data,
setIsAddRow,
setRowId,
}) => {
const fId = data.fid;
const hasSuppData = !!dataEntrySupplemental.items.filter(data => data.fid === fId).length;
const hasSuppData = !!dataEntrySupplemental?.items?.filter(data => data.fid === fId)?.length;
const isNewRow = Object.keys(data).length === 0;

const handleAddRow = (add) => {
Expand All @@ -26,6 +28,18 @@ const SuppLinkCellRenderer = connect(
}
};

const handleClick = (e) => {
// Store condition, length, weight, species in baseData
doUpdateBaseData('condition', data?.condition);
doUpdateBaseData('length', data?.length);
doUpdateBaseData('weight', data?.weight);
doUpdateBaseData('species', data?.species);
doUpdateBaseData('fid', data?.fid);
doUpdateBaseData('ffid', data?.ffid);
// Add row in Supplemental tab
handleAddRow(true);
};

const isButtonDisabled = () => {
if (isNewRow || !data.fid) {
return true;
Expand All @@ -39,32 +53,16 @@ const SuppLinkCellRenderer = connect(
};

return (
<>
{hasSuppData ? (
<Button
isOutline
size='small'
variant='info'
title='Associated Supplemental Data Entries'
text={'View Data'}
icon={<Icon icon='dots-horizontal' />}
handleClick={() => handleAddRow(false)}
isDisabled={isButtonDisabled()}
/>
) : (
<Button
isOutline
size='small'
variant='success'
title='Associated Supplemental Data Entries'
text={'Add Data'}
icon={<Icon icon='plus' />}
handleClick={() => handleAddRow(true)}
isDisabled={isButtonDisabled()}
/>
)}

</>
<Button
isOutline
size='small'
variant={hasSuppData ? 'info' : 'success'}
title='Associated Supplemental Data Entries'
text={hasSuppData ? 'View Data' : 'Add Data'}
icon={<Icon icon={hasSuppData ? 'dots-horizontal' : 'plus'} />}
handleClick={handleClick}
isDisabled={isButtonDisabled()}
/>
);
});

Expand Down

0 comments on commit a9b0a38

Please sign in to comment.