Skip to content

Commit

Permalink
bugfixes/multiple-equivalency (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinJJackson authored Dec 18, 2023
1 parent 3c6d593 commit 66c0a57
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
14 changes: 8 additions & 6 deletions src/app-bundles/data-logger-equivalency-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 });
}
});
},
Expand Down Expand Up @@ -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!');
}
});
Expand Down Expand Up @@ -143,15 +145,15 @@ 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) {
// eslint-disable-next-line no-console
console.log('todo', err);
} else {
if (refreshData) {
store.doFetchDataLoggerEquivalency({ dataLoggerId });
store.doFetchDataLoggerEquivalency({ dataLoggerId, tableId });
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 })}
/>
</Modal.ModalContent>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 });
}}
/>
<Button
Expand Down

0 comments on commit 66c0a57

Please sign in to comment.