From 90776b0c068f65b5239ed12d010c13af5a1484ed Mon Sep 17 00:00:00 2001 From: csawatzky Date: Thu, 17 Jul 2025 09:19:01 -0600 Subject: [PATCH] changover to use the components settings and not the prefs --- package-lock.json | 4 +-- package.json | 2 +- src/component/ComponentCard.tsx | 2 +- src/component/ComponentChart.tsx | 15 ++++---- src/component/ComponentSettings.tsx | 54 ++++++++++------------------- src/pages/DeviceComponent.tsx | 4 +-- 6 files changed, 32 insertions(+), 49 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1d88f79..a4e6440 100644 --- a/package-lock.json +++ b/package-lock.json @@ -42,7 +42,7 @@ "mui-tel-input": "^7.0.0", "notistack": "^3.0.1", "openweathermap-ts": "^1.2.10", - "protobuf-ts": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#staging", + "protobuf-ts": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#node_exclusion_update", "query-string": "^9.2.1", "react": "^18.3.1", "react-beautiful-dnd": "^13.1.1", @@ -10889,7 +10889,7 @@ }, "node_modules/protobuf-ts": { "version": "1.0.0", - "resolved": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#4523ffef42032eb4a923bd50d4cfcccbb1397dbd", + "resolved": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#c027bd51ae890e5b6dc6b9468e3eb5e3cd207828", "dependencies": { "protobufjs": "^6.8.8" } diff --git a/package.json b/package.json index af322fc..afa0dea 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "mui-tel-input": "^7.0.0", "notistack": "^3.0.1", "openweathermap-ts": "^1.2.10", - "protobuf-ts": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#staging", + "protobuf-ts": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#node_exclusion_update", "query-string": "^9.2.1", "react": "^18.3.1", "react-beautiful-dnd": "^13.1.1", diff --git a/src/component/ComponentCard.tsx b/src/component/ComponentCard.tsx index a2231a6..bf83696 100644 --- a/src/component/ComponentCard.tsx +++ b/src/component/ComponentCard.tsx @@ -285,7 +285,7 @@ export default function ComponentCard(props: Props) { // ) : ( diff --git a/src/component/ComponentChart.tsx b/src/component/ComponentChart.tsx index ccb3f1f..fa69576 100644 --- a/src/component/ComponentChart.tsx +++ b/src/component/ComponentChart.tsx @@ -148,7 +148,7 @@ export default function ComponentChart(props: Props) { //use the excluded nodes to set the default for the graph filters useEffect(() => { - let excludedNodes = deviceComponentPreferences?.excludedNodes; + let excludedNodes = component.settings.excludedNodes; if (excludedNodes === undefined || excludedNodes.length === 0) return; let updatedFilters = cloneDeep(graphFilters); if (excludedNodes && component.lastMeasurement[0]) { @@ -165,7 +165,7 @@ export default function ComponentChart(props: Props) { updatedFilters.selectedNodes = includedNodes; } setGraphFilters(updatedFilters); - }, [deviceComponentPreferences, component]); //eslint-disable-line react-hooks/exhaustive-deps + }, [component]); //eslint-disable-line react-hooks/exhaustive-deps const updateDateRange = (newStartDate: any, newEndDate: any, live: boolean) => { setStartDate(newStartDate); @@ -211,10 +211,11 @@ export default function ComponentChart(props: Props) { }; const cableControls = () => { - const { component, samples, deviceComponentPreferences } = props; - const excludedNodes = deviceComponentPreferences?.excludedNodes ?? []; + const { component, samples } = props; const selectedNodes = graphFilters.selectedNodes ? graphFilters.selectedNodes : ["all"]; const lastMeasurement = component.status.lastMeasurement; + const excludedNodes = component.settings.excludedNodes ?? []; + let numNodes = 0; if (samples) { numNodes = GetNumNodes( @@ -322,7 +323,7 @@ export default function ComponentChart(props: Props) { checked={selectedNodes.includes((i - 1).toString()) ? true : false} onChange={handleGrainCableControlsChange((i - 1).toString())} value={(i - 1).toString()} - disabled={excludedNodes.includes(i - 1)} + //disabled={excludedNodes.includes(i - 1)} /> } label={{nodeLabel}} @@ -724,7 +725,7 @@ export default function ComponentChart(props: Props) { )} @@ -764,7 +765,7 @@ export default function ComponentChart(props: Props) { reading={convertedLastMeasurement} largeText boldMeasurements - excludedNodes={deviceComponentPreferences?.excludedNodes} + excludedNodes={component.settings.excludedNodes} /> )} diff --git a/src/component/ComponentSettings.tsx b/src/component/ComponentSettings.tsx index 54653a2..c05cdae 100644 --- a/src/component/ComponentSettings.tsx +++ b/src/component/ComponentSettings.tsx @@ -180,11 +180,11 @@ export default function ComponentSettings(props: Props) { setTabVal(newValue); }; - useEffect(() => { - if (deviceComponentPrefs) { - setExcludedNodes(deviceComponentPrefs.excludedNodes); - } - }, [deviceComponentPrefs]); + // useEffect(() => { + // if (deviceComponentPrefs) { + // setExcludedNodes(deviceComponentPrefs.excludedNodes); + // } + // }, [deviceComponentPrefs]); const init = useCallback(() => { let component = props.component; @@ -207,6 +207,7 @@ export default function ComponentSettings(props: Props) { ) ); setFormComponent(initComponent); + setExcludedNodes(initComponent.settings.excludedNodes) }, [props.component, componentTypeOptions]); useEffect(() => { @@ -238,7 +239,6 @@ export default function ComponentSettings(props: Props) { componentType: quack.ComponentType ): number[] => { let positions = availablePositions.get(addressType); - console.log(positions) if (!positions) return []; switch (addressType) { case quack.AddressType.ADDRESS_TYPE_I2C: @@ -320,20 +320,21 @@ export default function ComponentSettings(props: Props) { const updateComponent = () => { const component = formComponent; + component.settings.excludedNodes = excludedNodes componentAPI .update(device.id(), component.settings, getContextKeys(), getContextTypes(), as) .then((_response: any) => { success(component.name() + " was successfully updated!"); - let updatedPrefs = pond.DeviceComponentPreferences.create(); - updatedPrefs.excludedNodes = excludedNodes; - deviceAPI - .updateComponentPreferences(device.id(), component.key(), updatedPrefs, undefined, undefined, as) - .then(_resp => { - console.log("Preferences updated"); - }) - .catch(_err => { - console.log("Preferences failed to update"); - }); + // let updatedPrefs = pond.DeviceComponentPreferences.create(); + // updatedPrefs.excludedNodes = excludedNodes; + // deviceAPI + // .updateComponentPreferences(device.id(), component.key(), updatedPrefs, undefined, undefined, as) + // .then(_resp => { + // console.log("Preferences updated"); + // }) + // .catch(_err => { + // console.log("Preferences failed to update"); + // }); refresh(); }) .catch((_err: any) => { @@ -413,7 +414,6 @@ export default function ComponentSettings(props: Props) { for (let i = 0; i < addressTypes.length; i++) { let addressType = addressTypes[i]; let availablePositions = getAvailablePositions(addressType, type); - console.log(availablePositions) availableMenuItemPositions.push( @@ -976,24 +976,6 @@ export default function ComponentSettings(props: Props) { }}> Clear Excluded Nodes - {/* button for testing the pref update */} - {/* {prevComponent && ( - - )} */} ); }; @@ -1019,7 +1001,7 @@ export default function ComponentSettings(props: Props) { onChange={handleChange}> - + )} diff --git a/src/pages/DeviceComponent.tsx b/src/pages/DeviceComponent.tsx index c04a1b2..9b83000 100644 --- a/src/pages/DeviceComponent.tsx +++ b/src/pages/DeviceComponent.tsx @@ -487,7 +487,7 @@ export default function DeviceComponent() { component={component} reading={row} tableCell={true} - excludedNodes={deviceComponentPrefs?.excludedNodes} + excludedNodes={component.settings.excludedNodes} /> ) } @@ -528,7 +528,7 @@ export default function DeviceComponent() { // component={component} // reading={row} // tableCell={true} - // excludedNodes={deviceComponentPrefs?.excludedNodes} + // excludedNodes={component.settings.excludedNodes} // /> // ) // }