From 5607672a4b95ccd6c11e11ae212d6afbd82baefc Mon Sep 17 00:00:00 2001 From: csawatzky Date: Mon, 30 Jun 2025 16:46:39 -0600 Subject: [PATCH] adding way of disabling the scan button the button will be disabled once it has been clicked as well as on the device page if a scan is in progress (there are pending requests) --- package-lock.json | 2 +- src/device/DeviceWizard.tsx | 6 +++++- .../autoDetect/DeviceScannedComponents.tsx | 15 +++++++++++++-- src/pages/Device.tsx | 5 ++++- src/providers/pond/deviceAPI.tsx | 17 ++++++++++++++++- 5 files changed, 39 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 52c6189..fc2ade1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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#091928b04970731f9b543fcecc313b6f4ea7d4e2", + "resolved": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#3c25c27d545a375db5705dd0450ea94d5a4a4dcb", "dependencies": { "protobufjs": "^6.8.8" } diff --git a/src/device/DeviceWizard.tsx b/src/device/DeviceWizard.tsx index 4de3cc2..7afe7a5 100644 --- a/src/device/DeviceWizard.tsx +++ b/src/device/DeviceWizard.tsx @@ -37,6 +37,7 @@ interface Props { //permissions: pond.Permission[]; components: Component[]; refreshCallback: () => void; + scanInProgress?: boolean } const useStyles = makeStyles((theme: Theme) => { @@ -69,7 +70,7 @@ const useStyles = makeStyles((theme: Theme) => { }); export default function DeviceWizard(props: Props) { - const { device, components, refreshCallback } = props; + const { device, components, refreshCallback, scanInProgress } = props; const [{as}] = useGlobalState(); const [componentDialogOpen, setComponentDialogOpen] = useState(false); const [availableOffsets, setAvailableOffsets] = useState(new Map()); @@ -86,6 +87,7 @@ export default function DeviceWizard(props: Props) { const [selectedPort, setSelectedPort] = useState(); const deviceAPI = useDeviceAPI() const { openSnack } = useSnackbar() + const [buttonClicked, setButtonClicked] = useState(false); //const [addressType, setAddressType] = useState(quack.AddressType.ADDRESS_TYPE_CONFIGURABLE_PIN_ARRAY); const wizardMenu = () => { @@ -125,7 +127,9 @@ export default function DeviceWizard(props: Props) { { + setButtonClicked(true) deviceAPI.detectI2C(device.id()) .then(resp => { openSnack("Device will scan port on next check-in") diff --git a/src/device/autoDetect/DeviceScannedComponents.tsx b/src/device/autoDetect/DeviceScannedComponents.tsx index 52a66e4..e1651de 100644 --- a/src/device/autoDetect/DeviceScannedComponents.tsx +++ b/src/device/autoDetect/DeviceScannedComponents.tsx @@ -9,7 +9,7 @@ import ComponentForm from "component/ComponentForm"; import { Component, Device } from "models"; import { DeviceAvailabilityMap, OffsetAvailabilityMap } from "pbHelpers/DeviceAvailability"; import ResponsiveDialog from "common/ResponsiveDialog"; -import { useComponentAPI, useSnackbar } from "hooks"; +import { useComponentAPI, useDeviceAPI, useSnackbar } from "hooks"; interface Props { scannedComponents: pond.ComponentAddressMap @@ -27,6 +27,7 @@ interface CompStep { export default function DeviceScannedComponents(props: Props){ const {scannedComponents, device, availablePositions, availableOffsets, refreshCallback} = props const compAPI = useComponentAPI(); + const deviceAPI = useDeviceAPI() const [scannedI2C, setScannedI2C] = useState() const [components, setComponents] = useState([]) const [steps, setSteps] = useState([]); @@ -180,6 +181,15 @@ export default function DeviceScannedComponents(props: Props){ setComponents(cloneList) } + const removeScan = (key: string) => { + deviceAPI.removeFoundComponents(device.settings.deviceId, key) + .then(resp => { + console.log("Cleared this scan") + }).catch(err => { + console.log("There was a problem clearing this scan") + }) + } + return ( @@ -187,10 +197,11 @@ export default function DeviceScannedComponents(props: Props){ {scannedI2C !== undefined && - + I2C Sensors + {scannedI2C.settings?.foundAddresses && scannedI2C.settings.foundAddresses.length > 0 ? scannedI2C?.settings?.foundAddresses.map((addr, index) => { return ( diff --git a/src/pages/Device.tsx b/src/pages/Device.tsx index 609ecc3..a06a173 100644 --- a/src/pages/Device.tsx +++ b/src/pages/Device.tsx @@ -58,6 +58,7 @@ export default function DevicePage() { const [components, setComponents] = useState>(new Map()); const [diagnosticComponents, setDiagnosticComponents] = useState([]); const [scannedAddresses, setScannedAddresses] = useState(undefined) + const [scanInProgress, setScanInProgress] = useState(false) // const [components, setComponents] = useState([]); const [addComponentManualDialogOpen, setAddComponentManualDialogOpen] = useState(false) @@ -78,7 +79,8 @@ export default function DevicePage() { deviceAPI.getPageData(deviceID, getContextKeys(), getContextTypes(), as).then(resp => { // setDevicePageData(resp.data) let device = Device.any(resp.data.device) - // console.log(resp.data.device) + // console.log(resp.data) + setScanInProgress(resp.data.pendingRequests) setDevice(device) let newPermissions: pond.Permission[] = [] resp.data.permissions.forEach(perm => { @@ -400,6 +402,7 @@ export default function DevicePage() { Promise; + removeFoundComponents: (id: number, key: string, otherTeam?: string) => Promise>; } export const DeviceAPIContext = createContext({} as IDeviceAPIContext); @@ -974,6 +975,19 @@ export default function DeviceProvider(props: PropsWithChildren) { }) } + const removeFoundComponents = (id: number, key: string, otherTeam?: string) => { + let url = "/devices/" + id + "/removeFoundComponents/" + key; + const view = otherTeam ? otherTeam : as + if(view) url = url + "?as=" + view + return new Promise>((resolve, reject) => { + del(pondURL(url)).then(resp => { + return resolve(resp) + }).catch(err => { + return reject(err) + }) + }) + } + return ( ) { updateComponentPreferences, listDeviceComponentPreferences, detectI2C, - listFoundComponents + listFoundComponents, + removeFoundComponents }}> {children}