Skip to content

Commit

Permalink
reworked RecordModuleCommand function and started runningprotocolcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
rclarke0 committed Mar 4, 2025
1 parent 755839b commit b8beb0e
Showing 8 changed files with 204 additions and 133 deletions.
34 changes: 24 additions & 10 deletions app/src/organisms/ModuleCard/HeaterShakerSlideout.tsx
Original file line number Diff line number Diff line change
@@ -41,9 +41,7 @@ export const HeaterShakerSlideout = (
const { createLiveCommand } = useCreateLiveCommandMutation()
const moduleName = getModuleDisplayName(module.moduleModel)
const modulePart = t('temperature')
const {
reportModuleCommandCompleted,
reportModuleCommandError} = useModuleCommandAnalytics()
const { reportModuleCommand} = useModuleCommandAnalytics()
const serialNumber = module.serialNumber

const sendSetTemperatureCommand: MouseEventHandler<HTMLInputElement> = e => {
@@ -60,17 +58,33 @@ export const HeaterShakerSlideout = (
}
createLiveCommand({
command: setTempCommand,
}).then((result)=> {reportModuleCommandCompleted('heaterShaker', 'set-heatershaker-temperature', {status: 'succeeded', data: result}, serialNumber, hsValue)}).catch((e: Error) => {
reportModuleCommandError('heatershaker', 'set-heatershaker-temperature', serialNumber, e.message, hsValue)
console.error(
`error setting module status with command type ${setTempCommand.commandType}: ${e.message}`
)
}).then((result)=> {
reportModuleCommand({
moduleType: module.moduleModel,
action:'set-heatershaker-temperature',
result: {status: 'succeeded', data: result},
serialNumber: serialNumber ?? module.serialNumber,
temperature: hsValue,
});
})
}
.catch((e: Error) => {
reportModuleCommand({
moduleType: module.moduleModel,
action: 'set-heatershaker-temperature',
errorDetails: e.message,
serialNumber: serialNumber ?? module.serialNumber,
temperature: hsValue,
});

console.error(
`error setting module status with command type ${setTempCommand.commandType}: ${e.message}`
);
});

setHsValue(null)
onCloseClick()
}

}
const errorMessage =
hsValue != null && (hsValue < HS_TEMP_MIN || hsValue > HS_TEMP_MAX)
? t('input_out_of_range')
39 changes: 26 additions & 13 deletions app/src/organisms/ModuleCard/TemperatureModuleSlideout.tsx
Original file line number Diff line number Diff line change
@@ -41,9 +41,7 @@ export const TemperatureModuleSlideout = (
const name = getModuleDisplayName(module.moduleModel)
const [temperatureValue, setTemperatureValue] = useState<number | null>(null)
const handleSubmitTemperature = (): void => {
const {
reportModuleCommandCompleted,
reportModuleCommandError} = useModuleCommandAnalytics()
const { reportModuleCommand } = useModuleCommandAnalytics();

Check failure on line 44 in app/src/organisms/ModuleCard/TemperatureModuleSlideout.tsx

GitHub Actions / js checks

React Hook "useModuleCommandAnalytics" is called in function "handleSubmitTemperature" that is neither a React function component nor a custom React Hook function. React component names must start with an uppercase letter. React Hook names must start with the word "use"
const serialNumber = module.serialNumber

if (temperatureValue != null) {
@@ -56,18 +54,33 @@ export const TemperatureModuleSlideout = (
}
createLiveCommand({
command: saveTempCommand,
}).then(result=>reportModuleCommandCompleted('temperatureModule', 'set-temperature-module-temperature', {status:'succeeded', data: result}, serialNumber, temperatureValue)
).catch((e: Error) => {
reportModuleCommandError('temperatureModule', 'set-temperature-module-temperature', e.message, serialNumber, temperatureValue)
console.error(
`error setting module status with command type ${saveTempCommand.commandType}: ${e.message}`
)
})
}
})
.then((result) => {
reportModuleCommand({
moduleType: module.moduleModel,
action: 'set-temperature-module-temperature',
result: {status: 'succeeded', data: result},
serialNumber: serialNumber ?? module.serialNumber,
temperature: temperatureValue
});
})
.catch((e: Error) => {
reportModuleCommand({
moduleType: module.moduleModel,
action: 'set-temperature-module-temperature',
errorDetails: e.message,
serialNumber: serialNumber ?? module.serialNumber,
temperature: temperatureValue
});

console.error(
`error setting module status with command type ${saveTempCommand.commandType}: ${e.message}`
);
});
setTemperatureValue(null)
onCloseClick()
}

}
}
const valueOutOfRange =
temperatureValue != null &&
(temperatureValue < TEMP_MIN || temperatureValue > TEMP_MAX)
81 changes: 31 additions & 50 deletions app/src/organisms/ModuleCard/ThermocyclerModuleSlideout.tsx
Original file line number Diff line number Diff line change
@@ -21,7 +21,6 @@ import {

import { Slideout } from '/app/atoms/Slideout'
import { SubmitPrimaryButton } from '/app/atoms/buttons'

import type {
TCSetTargetBlockTemperatureCreateCommand,
TCSetTargetLidTemperatureCreateCommand,
@@ -46,10 +45,9 @@ export const ThermocyclerModuleSlideout = (
const moduleName = getModuleDisplayName(module.moduleModel)
const modulePart = isSecondaryTemp ? 'Lid' : 'Block'
const tempRanges = getTCTempRange(isSecondaryTemp)
const {
reportModuleCommandCompleted,
reportModuleCommandError} = useModuleCommandAnalytics()
const serialNumber = module.serialNumber
const { reportModuleCommand } = useModuleCommandAnalytics();

let errorMessage
if (isSecondaryTemp) {
errorMessage =
@@ -85,61 +83,44 @@ export const ThermocyclerModuleSlideout = (
command: isSecondaryTemp ? saveLidCommand : saveBlockCommand,
})
.then((result) => {
if (modulePart === 'Lid') {
reportModuleCommandCompleted(
{moduleType: module.moduleModel,
action: 'set-thermocycler-lid-temperature',
result: { status: 'succeeded', data: result },
serialNumber: serialNumber,
temperature: tempValue}
);
} else if (modulePart === 'Block') {
reportModuleCommandCompleted(
{moduleType: module.moduleModel,
action:'set-thermocycler-block-temperature',
result: { status: 'succeeded', data: result },
serialNumber: serialNumber,
temperature: tempValue}
);
}
})
.catch((e: Error) => {
if (modulePart === 'Lid') {
reportModuleCommandError(
{moduleType: module.moduleModel,
action: 'set-thermocycler-lid-temperature',
errorDetails: e.message,
serialNumber: serialNumber,
temperature: tempValue}
);
} else if (modulePart === 'Block') {
reportModuleCommandError(
{module.moduleModel,
'set-thermocycler-block-temperature',
e.message,
serialNumber,
tempValue}
);
}
reportModuleCommand({
moduleType: module.moduleModel,
action: modulePart === 'Lid'
? 'set-thermocycler-lid-temperature'
: 'set-thermocycler-block-temperature',
result: { status: 'succeeded', data: result },
serialNumber: serialNumber ?? module.serialNumber, // Fallback applied
temperature: tempValue,
});
})
.catch((e: Error) => {
reportModuleCommand({
moduleType: module.moduleModel,
action: modulePart === 'Lid'
? 'set-thermocycler-lid-temperature'
: 'set-thermocycler-block-temperature',
errorDetails: e.message, // Indicates an error
serialNumber: serialNumber ?? module.serialNumber, // Fallback applied
temperature: tempValue,
});

console.error(
`Error setting module status with command type ${
isSecondaryTemp ? saveLidCommand.commandType : saveBlockCommand.commandType
}: ${e.message}`
);
});

console.error(
`error setting module status with command type ${
isSecondaryTemp ? saveLidCommand.commandType : saveBlockCommand.commandType
}: ${e.message}`
);
});
}
};
setTempValue(null)
onCloseClick()
}

}
const handleCloseSlideout = (): void => {
setTempValue(null)
onCloseClick()
}

return (
return (
<Slideout
title={t('tc_set_temperature', { part: modulePart, name: moduleName })}
onCloseClick={handleCloseSlideout}
74 changes: 58 additions & 16 deletions app/src/organisms/ModuleCard/hooks.tsx
Original file line number Diff line number Diff line change
@@ -65,19 +65,33 @@ export function useLatchControls(module: AttachedModule): LatchControls {
moduleId: module.id,
},
}
const {reportModuleCommandCompleted, reportModuleCommandError} = useModuleCommandAnalytics()
const {reportModuleCommand} = useModuleCommandAnalytics()
const serialNumber = module.serialNumber
const toggleLatch = (): void => {
createLiveCommand({
command: latchCommand,
}).then(result=>reportModuleCommandCompleted(module.moduleModel, 'toggle-hs-latch', {status: "succeeded", data: result},serialNumber, null)).catch((e: Error) => {
reportModuleCommandError(module.moduleModel, 'toggle-hs-latch', serialNumber, e.message, null)
}).then((result)=> {
reportModuleCommand({
moduleType: module.moduleModel,
action: 'toggle-hs-latch',
result: {status: "succeeded", data: result},
serialNumber: serialNumber ?? module.serialNumber,
temperature: null,
});
})
.catch((e: Error) => {
reportModuleCommand({
moduleType: module.moduleModel,
action: 'toggle-hs-latch',
errorDetails: e.message,
serialNumber: serialNumber ?? module.serialNumber,
temperature: null,
});
console.error(
`error setting module status with command type ${latchCommand.commandType}: ${e.message}`
)
})
);
});
}

return { toggleLatch, isLatchClosed }
}
export type MenuItemsByModuleType = {
@@ -210,19 +224,32 @@ export function useModuleOverflowMenu(
moduleId: module.id,
},
}
const {reportModuleCommandCompleted, reportModuleCommandError} = useModuleCommandAnalytics()
const {reportModuleCommand} = useModuleCommandAnalytics()

Check failure on line 227 in app/src/organisms/ModuleCard/hooks.tsx

GitHub Actions / js checks

React Hook "useModuleCommandAnalytics" is called in function "handleDeactivationCommand" that is neither a React function component nor a custom React Hook function. React component names must start with an uppercase letter. React Hook names must start with the word "use"
const serialNumber = module.serialNumber
createLiveCommand({
command: deactivateCommand,
}).then(result=>reportModuleCommandCompleted(module.moduleModel, 'deactivate', {status: 'succeeded', data: result}, serialNumber, null)
).catch((e: Error) => {
reportModuleCommandError(module.moduleModel, 'deactivate', e.message, serialNumber,null)
}).then((result)=>{
reportModuleCommand({
moduleType: module.moduleType,
action: 'deactivate',
result: {status: 'succeeded', data: result},
serialNumber: serialNumber ?? module.serialNumber,
temperature: null
});
})
.catch((e: Error) => {
reportModuleCommand({
moduleType: module.moduleModel,
action: 'deactivate',
errorDetails: e.message,
serialNumber: serialNumber ?? module.serialNumber,
temperature: null
});
console.error(
`error setting module status with command type ${deactivateCommand.commandType}: ${e.message}`
)
})
);
});
}

const lidCommand: TCOpenLidCreateCommand | TCCloseLidCreateCommand = {
commandType:
module.moduleType === THERMOCYCLER_MODULE_TYPE &&
@@ -233,13 +260,28 @@ export function useModuleOverflowMenu(
moduleId: module.id,
},
}
const {reportModuleCommandCompleted, reportModuleCommandError} = useModuleCommandAnalytics()
const {reportModuleCommand} = useModuleCommandAnalytics()
const serialNumber = module.serialNumber
const controlTCLid = (): void => {
createLiveCommand({
command: lidCommand,
}).then(result=> reportModuleCommandCompleted(module.moduleModel, 'toggle-tc-lid', {status: "succeeded", data:result}, serialNumber, null)).catch((e: Error) => {
reportModuleCommandError(module.moduleModel, 'toggle-tc-lid', serialNumber, e.message, null)
}).then((result)=> {
reportModuleCommand({
moduleType: module.moduleModel,
action: 'toggle-tc-lid',
result: {status: 'suceeded', data: result},
serialNumber: serialNumber ?? module.serialNumber,
temperature: null
});
})
.catch((e: Error) => {
reportModuleCommand({
moduleType: module.moduleModel,
action: 'toggle-tc-lid',
errorDetails: e.message,
serialNumber: serialNumber ?? module.serialNumber,
temperature: null,
});
console.error(
`error setting thermocycler module status with command type ${lidCommand.commandType}: ${e.message}`
)
23 changes: 16 additions & 7 deletions app/src/organisms/ODD/ProtocolSetup/ProtocolSetupLabware/index.tsx
Original file line number Diff line number Diff line change
@@ -313,19 +313,23 @@ function LabwareLatch({
params: { moduleId: matchedHeaterShaker.id },

}

const toggleLatch = (): void => {
// Record latch toggle to analytics
const {
reportModuleCommandCompleted,
reportModuleCommandError} = useModuleCommandAnalytics()
const {reportModuleCommand} = useModuleCommandAnalytics()

Check failure on line 319 in app/src/organisms/ODD/ProtocolSetup/ProtocolSetupLabware/index.tsx

GitHub Actions / js checks

React Hook "useModuleCommandAnalytics" is called in function "toggleLatch" that is neither a React function component nor a custom React Hook function. React component names must start with an uppercase letter. React Hook names must start with the word "use"
const serialNumber = matchedHeaterShaker.serialNumber
createLiveCommand({
command: latchCommand,
waitUntilComplete: true,
})
.then(result => {
reportModuleCommandCompleted('heatershaker', 'toggle-hs-latch', {status:'succeeded', data: result}, serialNumber, null)
.then((result) => {
reportModuleCommand({
moduleType: matchedHeaterShaker.moduleModel,
action:'toggle-hs-latch',
result:{status:'succeeded', data: result},
serialNumber: serialNumber ?? matchedHeaterShaker.serialNumber,
temperature: null
});
setIsRefetchingModules(true)
refetchModules()
.then(() => {
@@ -339,7 +343,12 @@ function LabwareLatch({
})
})
.catch((e: Error) => {
reportModuleCommandError('heatershaker', 'toggle-hs-latch', e.message, serialNumber, null)
reportModuleCommand({
moduleType: matchedHeaterShaker.moduleType,
action: 'toggle-hs-latch',
errorDetails: e.message,
serialNumber: serialNumber ?? matchedHeaterShaker.serialNumber,
temperature: null});
console.error(
`error setting module status with command type ${latchCommand.commandType}: ${e.message}`
)
Loading
Oops, something went wrong.

0 comments on commit b8beb0e

Please sign in to comment.