diff --git a/src/app-bundles/data-logger-equivalency-bundle.js b/src/app-bundles/data-logger-equivalency-bundle.js index bdc38583..4c352f6f 100644 --- a/src/app-bundles/data-logger-equivalency-bundle.js +++ b/src/app-bundles/data-logger-equivalency-bundle.js @@ -61,7 +61,7 @@ export default { }); }, - doCreateDataLoggerEquivalency: ({ dataLoggerId, tableId, newRows = [], unusedRows = [], isDeleteChecked = false }) => ({ store, apiPost }) => { + doAutoMapDataLoggerEquivalency: ({ dataLoggerId, tableId, tableName, newRows = [], unusedRows = [], isDeleteChecked = false }) => ({ store, apiPut }) => { const uri = `/datalogger/${dataLoggerId}/tables/${tableId}/equivalency_table`; if (isDeleteChecked) { @@ -73,18 +73,20 @@ export default { const payload = { datalogger_id: dataLoggerId, + datalogger_table_id: tableId, + datalogger_table_name: tableName, rows: newRows.map(row => ({ field_name: row, display_name: row, })), }; - apiPost(uri, payload, (err, _body) => { + apiPut(uri, payload, (err, _body) => { if (err) { // eslint-disable-next-line no-console console.log('todo', err); } else { - store.doFetchDataLoggerEquivalency({ dataLoggerId }); + store.doFetchDataLoggerEquivalency({ dataLoggerId, tableId }); } }); }, @@ -114,7 +116,7 @@ export default { console.log('test err: ', JSON.stringify(err)); // tUpdateError(toastId, 'Failed'); } else { - store.doFetchDataLoggerEquivalency({ dataLoggerId }); + store.doFetchDataLoggerEquivalency({ dataLoggerId, tableId }); // tUpdateSuccess(toastId, 'Successfully updated Field Mapping!'); } }); @@ -143,7 +145,7 @@ export default { }, doDeleteDataLoggerEquivalencyRow: ({ dataLoggerId, tableId, id, refreshData = true }) => ({ store, apiDelete }) => { - const uri = `/datalogger/${dataLoggerId}/tables/${tableId}/equivalency_table/row?id=${id}`; + const uri = `/datalogger/${dataLoggerId}/tables/${tableId}/equivalency_table/row/${id}`; apiDelete(uri, (err, _body) => { if (err) { @@ -151,7 +153,7 @@ export default { console.log('todo', err); } else { if (refreshData) { - store.doFetchDataLoggerEquivalency({ dataLoggerId }); + store.doFetchDataLoggerEquivalency({ dataLoggerId, tableId }); } } }); diff --git a/src/app-pages/project/data-loggers/modals/addMappingRowsModal.jsx b/src/app-pages/project/data-loggers/modals/addMappingRowsModal.jsx index 07e93fe1..265b7a78 100644 --- a/src/app-pages/project/data-loggers/modals/addMappingRowsModal.jsx +++ b/src/app-pages/project/data-loggers/modals/addMappingRowsModal.jsx @@ -5,14 +5,15 @@ import * as Modal from '../../../../app-components/modal'; import HelperTooltip from '../../../../app-components/helper-tooltip'; const AddMappingRowsModal = connect( - 'doCreateDataLoggerEquivalency', + 'doAutoMapDataLoggerEquivalency', 'selectDataLoggerEquivalencyTable', ({ - doCreateDataLoggerEquivalency, + doAutoMapDataLoggerEquivalency, dataLoggerEquivalencyTable: equivalencyTable, fieldNames = [], dataLoggerId, tableId, + tableName, }) => { const { rows = [] } = equivalencyTable; const newFieldNames = fieldNames.map(field => field.fieldName); @@ -93,7 +94,7 @@ const AddMappingRowsModal = connect( showCancelButton saveText='Update Table' showSaveButton={!noChanges} - onSave={() => doCreateDataLoggerEquivalency({ dataLoggerId, tableId, newRows, unusedRows, isDeleteChecked })} + onSave={() => doAutoMapDataLoggerEquivalency({ dataLoggerId, tableId, tableName, newRows, unusedRows, isDeleteChecked })} /> ); diff --git a/src/app-pages/project/data-loggers/tables/incomingRawDataTable.jsx b/src/app-pages/project/data-loggers/tables/incomingRawDataTable.jsx index 07d9d0a8..70bcb7aa 100644 --- a/src/app-pages/project/data-loggers/tables/incomingRawDataTable.jsx +++ b/src/app-pages/project/data-loggers/tables/incomingRawDataTable.jsx @@ -21,7 +21,7 @@ const IncomingRawDataTable = connect( dataLogger, tableId, }) => { - const { id, model } = dataLogger; + const { id, model, tables } = dataLogger; const { preview = {} } = dataLoggerPreview; const [isOpen, setIsOpen] = useState(false); @@ -68,7 +68,7 @@ const IncomingRawDataTable = connect( // eslint-disable-next-line import/namespace const myExtractor = extractorFns[`${model}_fieldNameExtractor`]; const fieldNames = myExtractor(preview); - doModalOpen(AddMappingRowsModal, { fieldNames, dataLoggerId: id }); + doModalOpen(AddMappingRowsModal, { fieldNames, dataLoggerId: id, tableId, tableName: tables.find(el => el.id === tableId)?.table_name }); }} />