diff --git a/src/app-bundles/base-data-bundle.js b/src/app-bundles/base-data-bundle.js index 7a8bcda..0b1949f 100644 --- a/src/app-bundles/base-data-bundle.js +++ b/src/app-bundles/base-data-bundle.js @@ -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; diff --git a/src/app-pages/data-entry/datasheets/tables/fishDsTable.js b/src/app-pages/data-entry/datasheets/tables/fishDsTable.js index e3acbdf..5a84124 100644 --- a/src/app-pages/data-entry/datasheets/tables/fishDsTable.js +++ b/src/app-pages/data-entry/datasheets/tables/fishDsTable.js @@ -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 }; diff --git a/src/app-pages/data-entry/datasheets/tables/suppDsTable.js b/src/app-pages/data-entry/datasheets/tables/suppDsTable.js index e58cae7..e91bb6a 100644 --- a/src/app-pages/data-entry/datasheets/tables/suppDsTable.js +++ b/src/app-pages/data-entry/datasheets/tables/suppDsTable.js @@ -23,6 +23,7 @@ const SuppDsTable = connect( 'selectDataEntrySupplemental', 'selectDataEntryLastParams', 'selectUserRole', + 'selectBaseData', ({ doModalOpen, doSaveSupplementalDataEntry, @@ -30,8 +31,8 @@ const SuppDsTable = connect( dataEntrySupplemental, dataEntryLastParams, userRole, + baseData, isAddRow, - rowId, setIsAddRow, setRowId, }) => { @@ -39,12 +40,22 @@ const SuppDsTable = connect( 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 = () => { @@ -62,7 +73,7 @@ const SuppDsTable = connect( useEffect(() => { if (isAddRow) { - addRow(rowId); + addRow(); } }, [isAddRow]); diff --git a/src/app-pages/data-entry/edit-data-sheet/forms/missouriRiverForm.js b/src/app-pages/data-entry/edit-data-sheet/forms/missouriRiverForm.js index 42e8f25..f67f0de 100644 --- a/src/app-pages/data-entry/edit-data-sheet/forms/missouriRiverForm.js +++ b/src/app-pages/data-entry/edit-data-sheet/forms/missouriRiverForm.js @@ -31,6 +31,7 @@ const reducer = (state, action) => { }; const MissouriRiverForm = connect( + 'doUpdateBaseData', 'doMoRiverDatasheetLoadData', 'doSaveMoRiverDataEntry', 'doUpdateMoRiverDataEntry', @@ -55,6 +56,7 @@ const MissouriRiverForm = connect( 'selectUserRole', 'selectRouteParams', ({ + doUpdateBaseData, doMoRiverDatasheetLoadData, doSaveMoRiverDataEntry, doUpdateMoRiverDataEntry, @@ -226,6 +228,11 @@ const MissouriRiverForm = connect( } }, [isCreate, dataEntryData.mrId, userRole.id]); + useEffect(() => { + // netrivermile in baseData + doUpdateBaseData('netrivermile', state['netrivermile']); + }, [state['netrivermile']]); + return ( <>