From a9b0a389fff54674b5384a681b0b27eefd64e89d Mon Sep 17 00:00:00 2001 From: Jazlene Rae Guevarra <43012576+jguevarra@users.noreply.github.com> Date: Tue, 25 Jun 2024 20:57:25 -0400 Subject: [PATCH] bugfixes for supplemental tab fields (#114) --- src/app-bundles/base-data-bundle.js | 4 ++ .../datasheets/tables/fishDsTable.js | 2 +- .../datasheets/tables/suppDsTable.js | 19 +++++-- .../forms/missouriRiverForm.js | 7 +++ .../gridCellRenderers/suppLinkCellRenderer.js | 52 +++++++++---------- 5 files changed, 52 insertions(+), 32 deletions(-) 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 ( <>
diff --git a/src/common/gridCellRenderers/suppLinkCellRenderer.js b/src/common/gridCellRenderers/suppLinkCellRenderer.js index 49fbaaf..a1caf0e 100644 --- a/src/common/gridCellRenderers/suppLinkCellRenderer.js +++ b/src/common/gridCellRenderers/suppLinkCellRenderer.js @@ -5,9 +5,11 @@ import Button from 'app-components/button'; import Icon from 'app-components/icon'; const SuppLinkCellRenderer = connect( + 'doUpdateBaseData', 'doUpdateCurrentTab', 'selectDataEntrySupplemental', ({ + doUpdateBaseData, doUpdateCurrentTab, dataEntrySupplemental, data, @@ -15,7 +17,7 @@ const SuppLinkCellRenderer = connect( 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) => { @@ -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; @@ -39,32 +53,16 @@ const SuppLinkCellRenderer = connect( }; return ( - <> - {hasSuppData ? ( -