From eb76dc185a1a177fc43541e457d723e47cd2c57f Mon Sep 17 00:00:00 2001 From: Kevin Jackson <30411845+KevinJJackson@users.noreply.github.com> Date: Wed, 20 Nov 2024 19:34:20 -0500 Subject: [PATCH] enhancement/multiple-instrument (#245) --- package-lock.json | 158 +++++++++++- package.json | 3 +- src/app-bundles/explore-data-bundle.js | 32 +-- src/app-bundles/inclinometer-measurements.js | 69 ----- src/app-bundles/index.js | 4 - .../instrument-constants-bundle.js | 15 -- src/app-bundles/time-series-bundle.js | 1 - src/app-components/domain-select.jsx | 82 +++--- src/app-components/helper-tooltip.jsx | 3 +- .../instrument/constants/constant-form.jsx | 38 ++- .../instrument/constants/constants.jsx | 24 +- .../instrument/sensors/sensorDetails.jsx | 74 ++++++ src/app-pages/instrument/sensors/sensors.jsx | 6 + src/app-pages/instrument/settings.jsx | 14 +- .../instrument/timeseries/timeseries-form.jsx | 28 +- .../instrument/timeseries/timeseries.jsx | 69 +---- .../project/batch-plotting/helper.js | 1 + .../data-loggers/modals/dataLoggerModal.jsx | 17 +- .../deleteDataLoggerMappingRowModal.jsx | 19 +- .../components/modals/newAlertConfigModal.jsx | 1 - src/app-pages/project/uploader/Uploader.jsx | 5 +- src/app-pages/project/uploader/helper.js | 148 +++++++++-- .../project/uploader/mappingDetails.jsx | 138 ++++++---- .../uploader/modals/_configurationOption.jsx | 2 +- .../project/uploader/modals/_formGen.jsx | 99 ++++++- .../uploader/modals/_generalColumnFields.jsx | 242 ++++++++++++------ .../uploader/modals/newConfiguration.jsx | 210 +++++++++++---- .../project/uploader/modals/uploadFile.jsx | 32 +-- src/app-services/collections/domains.ts | 12 +- src/common/forms/instrument-form.jsx | 3 +- 30 files changed, 1050 insertions(+), 499 deletions(-) delete mode 100644 src/app-bundles/inclinometer-measurements.js delete mode 100644 src/app-bundles/instrument-constants-bundle.js diff --git a/package-lock.json b/package-lock.json index ffa7b0ca..3a589a3c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -59,7 +59,8 @@ "stream-browserify": "^3.0.0", "url": "^0.11.1", "util": "^0.12.5", - "xhr": "^2.6.0" + "xhr": "^2.6.0", + "xlsx": "^0.18.5" }, "devDependencies": { "@babel/eslint-parser": "^7.22.9", @@ -2188,6 +2189,14 @@ "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" } }, + "node_modules/adler-32": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/adler-32/-/adler-32-1.3.1.tgz", + "integrity": "sha512-ynZ4w/nUUv5rrsR8UUGoe1VC9hZj6V5hU9Qw1HlMDJGEJw5S7TfTErWTjMys6M7vr0YWcPqs3qAr4ss0nDfP+A==", + "engines": { + "node": ">=0.8" + } + }, "node_modules/ajv": { "version": "6.12.6", "dev": true, @@ -2619,6 +2628,18 @@ "element-size": "^1.1.1" } }, + "node_modules/cfb": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/cfb/-/cfb-1.2.2.tgz", + "integrity": "sha512-KfdUZsSOw19/ObEWasvBP/Ac4reZvAGauZhs6S/gqNhXhI7cKwvlH7ulj+dOEYnca4bm4SGo8C1bTAQvnTjgQA==", + "dependencies": { + "adler-32": "~1.3.0", + "crc-32": "~1.2.0" + }, + "engines": { + "node": ">=0.8" + } + }, "node_modules/chalk": { "version": "4.1.2", "license": "MIT", @@ -2699,6 +2720,14 @@ "node": ">=6" } }, + "node_modules/codepage": { + "version": "1.15.0", + "resolved": "https://registry.npmjs.org/codepage/-/codepage-1.15.0.tgz", + "integrity": "sha512-3g6NUTPd/YtuuGrhMnOMRjFc+LJw/bnMp3+0r/Wcz3IXUuCosKRJvMphm5+Q+bvTVGcJJuRvVLuYba+WojaFaA==", + "engines": { + "node": ">=0.8" + } + }, "node_modules/color-alpha": { "version": "1.0.4", "license": "MIT", @@ -2820,6 +2849,17 @@ "version": "1.1.0", "license": "MIT" }, + "node_modules/crc-32": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/crc-32/-/crc-32-1.2.2.tgz", + "integrity": "sha512-ROmzCKrTnOwybPcJApAA6WBWij23HVfGVNKqqrZpuyZOHqK2CwHSvpGuyt/UNNvaIjEd8X5IFGp4Mh+Ie1IHJQ==", + "bin": { + "crc32": "bin/crc32.njs" + }, + "engines": { + "node": ">=0.8" + } + }, "node_modules/cross-env": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-7.0.3.tgz", @@ -4263,6 +4303,14 @@ "is-callable": "^1.1.3" } }, + "node_modules/frac": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/frac/-/frac-1.1.2.tgz", + "integrity": "sha512-w/XBfkibaTl3YDqASwfDUqkna4Z2p9cFSr1aHDt0WoMTECnRfBOv2WArlZILlqgWlmdIlALXGpM2AOhEk5W3IA==", + "engines": { + "node": ">=0.8" + } + }, "node_modules/from2": { "version": "2.3.0", "license": "MIT", @@ -7598,6 +7646,17 @@ "version": "1.4.8", "license": "MIT" }, + "node_modules/ssf": { + "version": "0.11.2", + "resolved": "https://registry.npmjs.org/ssf/-/ssf-0.11.2.tgz", + "integrity": "sha512-+idbmIXoYET47hH+d7dfm2epdOMUDjqcB4648sTZ+t2JwoyBFL/insLfB/racrDmsKB3diwsDA696pZMieAC5g==", + "dependencies": { + "frac": "~1.1.2" + }, + "engines": { + "node": ">=0.8" + } + }, "node_modules/stack-generator": { "version": "2.0.10", "resolved": "https://registry.npmjs.org/stack-generator/-/stack-generator-2.0.10.tgz", @@ -8981,6 +9040,22 @@ "version": "1.3.2", "license": "MIT" }, + "node_modules/wmf": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wmf/-/wmf-1.0.2.tgz", + "integrity": "sha512-/p9K7bEh0Dj6WbXg4JG0xvLQmIadrner1bi45VMJTfnbVHsc7yIajZyoSoK60/dtVBs12Fm6WkUI5/3WAVsNMw==", + "engines": { + "node": ">=0.8" + } + }, + "node_modules/word": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/word/-/word-0.3.0.tgz", + "integrity": "sha512-OELeY0Q61OXpdUfTp+oweA/vtLVg5VDOXh+3he3PNzLGG/y0oylSOC1xRVj0+l4vQ3tj/bB1HVHv1ocXkQceFA==", + "engines": { + "node": ">=0.8" + } + }, "node_modules/word-wrap": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.4.tgz", @@ -9026,6 +9101,26 @@ "xtend": "^4.0.0" } }, + "node_modules/xlsx": { + "version": "0.18.5", + "resolved": "https://registry.npmjs.org/xlsx/-/xlsx-0.18.5.tgz", + "integrity": "sha512-dmg3LCjBPHZnQp5/F/+nnTa+miPJxUXB6vtk42YjBBKayDNagxGEeIdWApkYPOf3Z3pm3k62Knjzp7lMeTEtFQ==", + "dependencies": { + "adler-32": "~1.3.0", + "cfb": "~1.2.1", + "codepage": "~1.15.0", + "crc-32": "~1.2.1", + "ssf": "~0.11.2", + "wmf": "~1.0.1", + "word": "~0.3.0" + }, + "bin": { + "xlsx": "bin/xlsx.njs" + }, + "engines": { + "node": ">=0.8" + } + }, "node_modules/xml-utils": { "version": "1.7.0", "resolved": "https://registry.npmjs.org/xml-utils/-/xml-utils-1.7.0.tgz", @@ -10569,6 +10664,11 @@ "dev": true, "requires": {} }, + "adler-32": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/adler-32/-/adler-32-1.3.1.tgz", + "integrity": "sha512-ynZ4w/nUUv5rrsR8UUGoe1VC9hZj6V5hU9Qw1HlMDJGEJw5S7TfTErWTjMys6M7vr0YWcPqs3qAr4ss0nDfP+A==" + }, "ajv": { "version": "6.12.6", "dev": true, @@ -10816,6 +10916,15 @@ "element-size": "^1.1.1" } }, + "cfb": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/cfb/-/cfb-1.2.2.tgz", + "integrity": "sha512-KfdUZsSOw19/ObEWasvBP/Ac4reZvAGauZhs6S/gqNhXhI7cKwvlH7ulj+dOEYnca4bm4SGo8C1bTAQvnTjgQA==", + "requires": { + "adler-32": "~1.3.0", + "crc-32": "~1.2.0" + } + }, "chalk": { "version": "4.1.2", "requires": { @@ -10867,6 +10976,11 @@ "clsx": { "version": "1.2.1" }, + "codepage": { + "version": "1.15.0", + "resolved": "https://registry.npmjs.org/codepage/-/codepage-1.15.0.tgz", + "integrity": "sha512-3g6NUTPd/YtuuGrhMnOMRjFc+LJw/bnMp3+0r/Wcz3IXUuCosKRJvMphm5+Q+bvTVGcJJuRvVLuYba+WojaFaA==" + }, "color-alpha": { "version": "1.0.4", "requires": { @@ -10966,6 +11080,11 @@ "country-regex": { "version": "1.1.0" }, + "crc-32": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/crc-32/-/crc-32-1.2.2.tgz", + "integrity": "sha512-ROmzCKrTnOwybPcJApAA6WBWij23HVfGVNKqqrZpuyZOHqK2CwHSvpGuyt/UNNvaIjEd8X5IFGp4Mh+Ie1IHJQ==" + }, "cross-env": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-7.0.3.tgz", @@ -12004,6 +12123,11 @@ "is-callable": "^1.1.3" } }, + "frac": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/frac/-/frac-1.1.2.tgz", + "integrity": "sha512-w/XBfkibaTl3YDqASwfDUqkna4Z2p9cFSr1aHDt0WoMTECnRfBOv2WArlZILlqgWlmdIlALXGpM2AOhEk5W3IA==" + }, "from2": { "version": "2.3.0", "requires": { @@ -14200,6 +14324,14 @@ "sourcemap-codec": { "version": "1.4.8" }, + "ssf": { + "version": "0.11.2", + "resolved": "https://registry.npmjs.org/ssf/-/ssf-0.11.2.tgz", + "integrity": "sha512-+idbmIXoYET47hH+d7dfm2epdOMUDjqcB4648sTZ+t2JwoyBFL/insLfB/racrDmsKB3diwsDA696pZMieAC5g==", + "requires": { + "frac": "~1.1.2" + } + }, "stack-generator": { "version": "2.0.10", "resolved": "https://registry.npmjs.org/stack-generator/-/stack-generator-2.0.10.tgz", @@ -15099,6 +15231,16 @@ "wkt-parser": { "version": "1.3.2" }, + "wmf": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wmf/-/wmf-1.0.2.tgz", + "integrity": "sha512-/p9K7bEh0Dj6WbXg4JG0xvLQmIadrner1bi45VMJTfnbVHsc7yIajZyoSoK60/dtVBs12Fm6WkUI5/3WAVsNMw==" + }, + "word": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/word/-/word-0.3.0.tgz", + "integrity": "sha512-OELeY0Q61OXpdUfTp+oweA/vtLVg5VDOXh+3he3PNzLGG/y0oylSOC1xRVj0+l4vQ3tj/bB1HVHv1ocXkQceFA==" + }, "word-wrap": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.4.tgz", @@ -15131,6 +15273,20 @@ "xtend": "^4.0.0" } }, + "xlsx": { + "version": "0.18.5", + "resolved": "https://registry.npmjs.org/xlsx/-/xlsx-0.18.5.tgz", + "integrity": "sha512-dmg3LCjBPHZnQp5/F/+nnTa+miPJxUXB6vtk42YjBBKayDNagxGEeIdWApkYPOf3Z3pm3k62Knjzp7lMeTEtFQ==", + "requires": { + "adler-32": "~1.3.0", + "cfb": "~1.2.1", + "codepage": "~1.15.0", + "crc-32": "~1.2.1", + "ssf": "~0.11.2", + "wmf": "~1.0.1", + "word": "~0.3.0" + } + }, "xml-utils": { "version": "1.7.0", "resolved": "https://registry.npmjs.org/xml-utils/-/xml-utils-1.7.0.tgz", diff --git a/package.json b/package.json index d080625a..99d26fe7 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,8 @@ "stream-browserify": "^3.0.0", "url": "^0.11.1", "util": "^0.12.5", - "xhr": "^2.6.0" + "xhr": "^2.6.0", + "xlsx": "^0.18.5" }, "devDependencies": { "@babel/eslint-parser": "^7.22.9", diff --git a/src/app-bundles/explore-data-bundle.js b/src/app-bundles/explore-data-bundle.js index b4c49d29..43444093 100644 --- a/src/app-bundles/explore-data-bundle.js +++ b/src/app-bundles/explore-data-bundle.js @@ -84,22 +84,22 @@ const exploreDataBundle = { }); }); - await fetch(`${apiRoot}/inclinometer_explorer?before=${before}&after=${after}`, { - method: 'POST', - mode: 'cors', - headers: { - 'Content-Type': 'application/json', - 'Authorization': 'Bearer ' + getToken(), - }, - body: JSON.stringify(instrumentIds), - }) - .then((response) => response.json()) - .then((data) => { - dispatch({ - type: 'INCLINOMETER_DATA_LOAD', - payload: data, - }); - }); + // await fetch(`${apiRoot}/inclinometer_explorer?before=${before}&after=${after}`, { + // method: 'POST', + // mode: 'cors', + // headers: { + // 'Content-Type': 'application/json', + // 'Authorization': 'Bearer ' + getToken(), + // }, + // body: JSON.stringify(instrumentIds), + // }) + // .then((response) => response.json()) + // .then((data) => { + // dispatch({ + // type: 'INCLINOMETER_DATA_LOAD', + // payload: data, + // }); + // }); dispatch({ type: 'EXPLORE_DATA_LOADING', payload: false }); }, diff --git a/src/app-bundles/inclinometer-measurements.js b/src/app-bundles/inclinometer-measurements.js deleted file mode 100644 index 9dbf3fe3..00000000 --- a/src/app-bundles/inclinometer-measurements.js +++ /dev/null @@ -1,69 +0,0 @@ -import createRestBundle from './create-rest-bundle'; - -export default createRestBundle({ - name: 'inclinometerMeasurements', - uid: 'timeseries_id', - staleAfter: 10000, - persist: false, - routeParam: '', - - // TODO: default before and after time periods should be implemented on the backend. - getTemplate: '/timeseries/:timeseriesId/inclinometer_measurements?before=2025-01-01T00:00:00.00Z&after=1900-01-01T00:00:00.00Z', - putTemplate: '', - postTemplate: '/timeseries/:timeseriesId/inclinometer_measurements', - deleteTemplate: '/timeseries/:timeseriesId/inclinometer_measurements?time={:item.date}', - fetchActions: [], - forceFetchActions: [ - 'INSTRUMENTTIMESERIES_SET_ACTIVE_ID', - 'INSTRUMENTTIMESERIES_FETCH_FINISHED', - 'TIMESERIESMEASUREMENTS_SAVE_FINISHED', - ], - urlParamSelectors: [ - 'selectInstrumentTimeseriesActiveIdParam', - ], - mergeItems: true, - prefetch: (store) => { - const hash = store.selectHashStripQuery(); - const pathname = store.selectRelativePathname(); - - const whitelist = []; - const pathnameWhitelist = ['/instruments/', '/groups/', '/collection-groups/']; - - return whitelist.includes(hash) || pathnameWhitelist.some(elem => pathname.includes(elem)); - }, - addons: { - doFetchInclinometerMeasurementsByTimeseriesId: (timeseriesId) => ({ dispatch, apiGet }) => { - const uri = `/timeseries/${timeseriesId}/inclinometer_measurements?before=2025-01-01T00:00:00.00Z&after=1900-01-01T00:00:00.00Z`; - - apiGet(uri, (err, body) => { - if (err) { - // eslint-disable-next-line no-console - console.log('error: ', err); - } else { - dispatch({ - type: 'SET_CURRENT_INCLINOMETER_MEASUREMENTS', - payload: { - timeseriesId, - measurements: body, - }, - }); - } - }); - }, - - selectCurrentInclinometerMeasurements: state => state.inclinometerMeasurements.currentMeasurements, - }, - reduceFurther: (state, { type, payload }) => { - if (type === 'SET_CURRENT_INCLINOMETER_MEASUREMENTS') { - return { - ...state, - 'currentMeasurements': { - ...state['currentMeasurements'], - [payload.timeseriesId]: payload.measurements, - }, - }; - } else { - return state; - } - }, -}); diff --git a/src/app-bundles/index.js b/src/app-bundles/index.js index 5fa934b2..306d1e40 100644 --- a/src/app-bundles/index.js +++ b/src/app-bundles/index.js @@ -29,12 +29,10 @@ import exploreDataBundle from './explore-data-bundle'; import exploreMapBundle from './explore-map-bundle'; import exploreMapInteractionBundle from './explore-map-interaction-bundle'; import homeDataBundle from './home-data-bundle'; -import inclinometerMeasurements from './inclinometer-measurements'; import instrumentAlertConfigsBundle from './instrument-alert-configs-bundle'; import instrumentAlertsBundle from './instrument-alerts-bundle'; import instrumentAssignmentBundle from './instrument-assignment-bundle'; import instrumentBundle from './instrument-bundle'; -import instrumentConstantsBundle from './instrument-constants-bundle'; import instrumentDrawBundle from './instrument-draw-bundle'; import instrumentFormulasBundle from './instrument-formulas-bundle'; import instrumentGroupBundle from './instrument-group-bundle'; @@ -124,12 +122,10 @@ export default composeBundles( exploreMapBundle, exploreMapInteractionBundle, homeDataBundle, - inclinometerMeasurements, instrumentAlertConfigsBundle, instrumentAlertsBundle, instrumentAssignmentBundle, instrumentBundle, - instrumentConstantsBundle, instrumentDrawBundle, instrumentFormulasBundle, instrumentGroupBundle, diff --git a/src/app-bundles/instrument-constants-bundle.js b/src/app-bundles/instrument-constants-bundle.js deleted file mode 100644 index 8f59b6df..00000000 --- a/src/app-bundles/instrument-constants-bundle.js +++ /dev/null @@ -1,15 +0,0 @@ -import createRestBundle from './create-rest-bundle'; - -export default createRestBundle({ - name: 'instrumentConstants', - uid: 'id', - staleAfter: 10000, - persist: false, - routeParam: 'id', - getTemplate: '/:', // "/:" disables any accidental trigger of a fetch - putTemplate: '/projects/:projectId/instruments/:instrumentId/constants/{:item.id}', - postTemplate: '/projects/:projectId/instruments/:instrumentId/constants', - deleteTemplate: '/projects/:projectId/instruments/:instrumentId/constants/{:item.id}', - fetchActions: [], - urlParamSelectors: ['selectProjectsIdByRoute', 'selectInstrumentsIdByRoute'], -}); diff --git a/src/app-bundles/time-series-bundle.js b/src/app-bundles/time-series-bundle.js index fb4066d6..1e7f8c8c 100644 --- a/src/app-bundles/time-series-bundle.js +++ b/src/app-bundles/time-series-bundle.js @@ -17,7 +17,6 @@ export default createRestBundle({ forceFetchActions: [ 'INSTRUMENTS_FETCH_FINISHED', 'INSTRUMENTGROUPS_FETCH_FINISHED', - 'INSTRUMENTCONSTANTS_SAVE_FINISHED', 'INSTRUMENTTIMESERIES_SAVE_FINISHED', 'CREATED_NEW_TIMESERIES_FOR_FIELD_NAMES', ], diff --git a/src/app-components/domain-select.jsx b/src/app-components/domain-select.jsx index 5e858c74..cec8690b 100644 --- a/src/app-components/domain-select.jsx +++ b/src/app-components/domain-select.jsx @@ -1,52 +1,50 @@ import React from 'react'; -import { connect } from 'redux-bundler-react'; import { Autocomplete, TextField } from '@mui/material'; +import { useGetDomainsByGroup } from '../app-services/collections/domains.ts'; + const isAlertThresholdReady = String(import.meta.env.VITE_ALERT_THRESHOLDS) === 'true'; -const flaggedDomains = (domains = [], domain = '') => { - if (!domains?.length) return []; +const flaggedDomains = (domains = {}, domain = '') => { + if (!Object.keys(domains)?.length) return []; if (domain === 'alert_type' && !isAlertThresholdReady) { - const filtered = domains.filter(el => !['Rate of Change', 'Threshold'].includes(el.value)); + const filtered = domains[domain].filter(el => !['Rate of Change', 'Threshold'].includes(el.value)); return filtered; - } else return domains; -} + } else return domains[domain]; +}; + +const DomainSelect = ({ + defaultValue, + useLabelAsDefault = false, + onChange, + domain, + label = '', + ...customProps +}) => { + const { data: domainsByGroup, isLoading } = useGetDomainsByGroup(); + const options = flaggedDomains(domainsByGroup, domain)?.map(item => ( + { value: item.id, label: item.value } + )) || []; -export default connect( - 'selectDomainsItemsByGroup', - ({ - domainsItemsByGroup, - defaultValue, - useLabelAsDefault = false, - onChange, - domain, - label = '', - ...customProps - }) => { - const options = flaggedDomains(domainsItemsByGroup[domain], domain)?.map(item => ( - { value: item.id, label: item.value } - )) || []; + return ( +