Skip to content

Commit b8beb0e

Browse files
committed
reworked RecordModuleCommand function and started runningprotocolcommand
1 parent 755839b commit b8beb0e

File tree

8 files changed

+204
-133
lines changed

8 files changed

+204
-133
lines changed

app/src/organisms/ModuleCard/HeaterShakerSlideout.tsx

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ export const HeaterShakerSlideout = (
4141
const { createLiveCommand } = useCreateLiveCommandMutation()
4242
const moduleName = getModuleDisplayName(module.moduleModel)
4343
const modulePart = t('temperature')
44-
const {
45-
reportModuleCommandCompleted,
46-
reportModuleCommandError} = useModuleCommandAnalytics()
44+
const { reportModuleCommand} = useModuleCommandAnalytics()
4745
const serialNumber = module.serialNumber
4846

4947
const sendSetTemperatureCommand: MouseEventHandler<HTMLInputElement> = e => {
@@ -60,17 +58,33 @@ export const HeaterShakerSlideout = (
6058
}
6159
createLiveCommand({
6260
command: setTempCommand,
63-
}).then((result)=> {reportModuleCommandCompleted('heaterShaker', 'set-heatershaker-temperature', {status: 'succeeded', data: result}, serialNumber, hsValue)}).catch((e: Error) => {
64-
reportModuleCommandError('heatershaker', 'set-heatershaker-temperature', serialNumber, e.message, hsValue)
65-
console.error(
66-
`error setting module status with command type ${setTempCommand.commandType}: ${e.message}`
67-
)
61+
}).then((result)=> {
62+
reportModuleCommand({
63+
moduleType: module.moduleModel,
64+
action:'set-heatershaker-temperature',
65+
result: {status: 'succeeded', data: result},
66+
serialNumber: serialNumber ?? module.serialNumber,
67+
temperature: hsValue,
68+
});
6869
})
69-
}
70+
.catch((e: Error) => {
71+
reportModuleCommand({
72+
moduleType: module.moduleModel,
73+
action: 'set-heatershaker-temperature',
74+
errorDetails: e.message,
75+
serialNumber: serialNumber ?? module.serialNumber,
76+
temperature: hsValue,
77+
});
78+
79+
console.error(
80+
`error setting module status with command type ${setTempCommand.commandType}: ${e.message}`
81+
);
82+
});
83+
7084
setHsValue(null)
7185
onCloseClick()
7286
}
73-
87+
}
7488
const errorMessage =
7589
hsValue != null && (hsValue < HS_TEMP_MIN || hsValue > HS_TEMP_MAX)
7690
? t('input_out_of_range')

app/src/organisms/ModuleCard/TemperatureModuleSlideout.tsx

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ export const TemperatureModuleSlideout = (
4141
const name = getModuleDisplayName(module.moduleModel)
4242
const [temperatureValue, setTemperatureValue] = useState<number | null>(null)
4343
const handleSubmitTemperature = (): void => {
44-
const {
45-
reportModuleCommandCompleted,
46-
reportModuleCommandError} = useModuleCommandAnalytics()
44+
const { reportModuleCommand } = useModuleCommandAnalytics();
4745
const serialNumber = module.serialNumber
4846

4947
if (temperatureValue != null) {
@@ -56,18 +54,33 @@ export const TemperatureModuleSlideout = (
5654
}
5755
createLiveCommand({
5856
command: saveTempCommand,
59-
}).then(result=>reportModuleCommandCompleted('temperatureModule', 'set-temperature-module-temperature', {status:'succeeded', data: result}, serialNumber, temperatureValue)
60-
).catch((e: Error) => {
61-
reportModuleCommandError('temperatureModule', 'set-temperature-module-temperature', e.message, serialNumber, temperatureValue)
62-
console.error(
63-
`error setting module status with command type ${saveTempCommand.commandType}: ${e.message}`
64-
)
65-
})
66-
}
57+
})
58+
.then((result) => {
59+
reportModuleCommand({
60+
moduleType: module.moduleModel,
61+
action: 'set-temperature-module-temperature',
62+
result: {status: 'succeeded', data: result},
63+
serialNumber: serialNumber ?? module.serialNumber,
64+
temperature: temperatureValue
65+
});
66+
})
67+
.catch((e: Error) => {
68+
reportModuleCommand({
69+
moduleType: module.moduleModel,
70+
action: 'set-temperature-module-temperature',
71+
errorDetails: e.message,
72+
serialNumber: serialNumber ?? module.serialNumber,
73+
temperature: temperatureValue
74+
});
75+
76+
console.error(
77+
`error setting module status with command type ${saveTempCommand.commandType}: ${e.message}`
78+
);
79+
});
6780
setTemperatureValue(null)
6881
onCloseClick()
69-
}
70-
82+
}
83+
}
7184
const valueOutOfRange =
7285
temperatureValue != null &&
7386
(temperatureValue < TEMP_MIN || temperatureValue > TEMP_MAX)

app/src/organisms/ModuleCard/ThermocyclerModuleSlideout.tsx

Lines changed: 31 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121

2222
import { Slideout } from '/app/atoms/Slideout'
2323
import { SubmitPrimaryButton } from '/app/atoms/buttons'
24-
2524
import type {
2625
TCSetTargetBlockTemperatureCreateCommand,
2726
TCSetTargetLidTemperatureCreateCommand,
@@ -46,10 +45,9 @@ export const ThermocyclerModuleSlideout = (
4645
const moduleName = getModuleDisplayName(module.moduleModel)
4746
const modulePart = isSecondaryTemp ? 'Lid' : 'Block'
4847
const tempRanges = getTCTempRange(isSecondaryTemp)
49-
const {
50-
reportModuleCommandCompleted,
51-
reportModuleCommandError} = useModuleCommandAnalytics()
5248
const serialNumber = module.serialNumber
49+
const { reportModuleCommand } = useModuleCommandAnalytics();
50+
5351
let errorMessage
5452
if (isSecondaryTemp) {
5553
errorMessage =
@@ -85,61 +83,44 @@ export const ThermocyclerModuleSlideout = (
8583
command: isSecondaryTemp ? saveLidCommand : saveBlockCommand,
8684
})
8785
.then((result) => {
88-
if (modulePart === 'Lid') {
89-
reportModuleCommandCompleted(
90-
{moduleType: module.moduleModel,
91-
action: 'set-thermocycler-lid-temperature',
92-
result: { status: 'succeeded', data: result },
93-
serialNumber: serialNumber,
94-
temperature: tempValue}
95-
);
96-
} else if (modulePart === 'Block') {
97-
reportModuleCommandCompleted(
98-
{moduleType: module.moduleModel,
99-
action:'set-thermocycler-block-temperature',
100-
result: { status: 'succeeded', data: result },
101-
serialNumber: serialNumber,
102-
temperature: tempValue}
103-
);
104-
}
105-
})
106-
.catch((e: Error) => {
107-
if (modulePart === 'Lid') {
108-
reportModuleCommandError(
109-
{moduleType: module.moduleModel,
110-
action: 'set-thermocycler-lid-temperature',
111-
errorDetails: e.message,
112-
serialNumber: serialNumber,
113-
temperature: tempValue}
114-
);
115-
} else if (modulePart === 'Block') {
116-
reportModuleCommandError(
117-
{module.moduleModel,
118-
'set-thermocycler-block-temperature',
119-
e.message,
120-
serialNumber,
121-
tempValue}
122-
);
123-
}
86+
reportModuleCommand({
87+
moduleType: module.moduleModel,
88+
action: modulePart === 'Lid'
89+
? 'set-thermocycler-lid-temperature'
90+
: 'set-thermocycler-block-temperature',
91+
result: { status: 'succeeded', data: result },
92+
serialNumber: serialNumber ?? module.serialNumber, // Fallback applied
93+
temperature: tempValue,
94+
});
95+
})
96+
.catch((e: Error) => {
97+
reportModuleCommand({
98+
moduleType: module.moduleModel,
99+
action: modulePart === 'Lid'
100+
? 'set-thermocycler-lid-temperature'
101+
: 'set-thermocycler-block-temperature',
102+
errorDetails: e.message, // Indicates an error
103+
serialNumber: serialNumber ?? module.serialNumber, // Fallback applied
104+
temperature: tempValue,
105+
});
106+
107+
console.error(
108+
`Error setting module status with command type ${
109+
isSecondaryTemp ? saveLidCommand.commandType : saveBlockCommand.commandType
110+
}: ${e.message}`
111+
);
112+
});
124113

125-
console.error(
126-
`error setting module status with command type ${
127-
isSecondaryTemp ? saveLidCommand.commandType : saveBlockCommand.commandType
128-
}: ${e.message}`
129-
);
130-
});
131-
}
132-
};
133114
setTempValue(null)
134115
onCloseClick()
135116
}
136-
117+
}
137118
const handleCloseSlideout = (): void => {
138119
setTempValue(null)
139120
onCloseClick()
140121
}
141122

142-
return (
123+
return (
143124
<Slideout
144125
title={t('tc_set_temperature', { part: modulePart, name: moduleName })}
145126
onCloseClick={handleCloseSlideout}

app/src/organisms/ModuleCard/hooks.tsx

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,33 @@ export function useLatchControls(module: AttachedModule): LatchControls {
6565
moduleId: module.id,
6666
},
6767
}
68-
const {reportModuleCommandCompleted, reportModuleCommandError} = useModuleCommandAnalytics()
68+
const {reportModuleCommand} = useModuleCommandAnalytics()
6969
const serialNumber = module.serialNumber
7070
const toggleLatch = (): void => {
7171
createLiveCommand({
7272
command: latchCommand,
73-
}).then(result=>reportModuleCommandCompleted(module.moduleModel, 'toggle-hs-latch', {status: "succeeded", data: result},serialNumber, null)).catch((e: Error) => {
74-
reportModuleCommandError(module.moduleModel, 'toggle-hs-latch', serialNumber, e.message, null)
73+
}).then((result)=> {
74+
reportModuleCommand({
75+
moduleType: module.moduleModel,
76+
action: 'toggle-hs-latch',
77+
result: {status: "succeeded", data: result},
78+
serialNumber: serialNumber ?? module.serialNumber,
79+
temperature: null,
80+
});
81+
})
82+
.catch((e: Error) => {
83+
reportModuleCommand({
84+
moduleType: module.moduleModel,
85+
action: 'toggle-hs-latch',
86+
errorDetails: e.message,
87+
serialNumber: serialNumber ?? module.serialNumber,
88+
temperature: null,
89+
});
7590
console.error(
7691
`error setting module status with command type ${latchCommand.commandType}: ${e.message}`
77-
)
78-
})
92+
);
93+
});
7994
}
80-
8195
return { toggleLatch, isLatchClosed }
8296
}
8397
export type MenuItemsByModuleType = {
@@ -210,19 +224,32 @@ export function useModuleOverflowMenu(
210224
moduleId: module.id,
211225
},
212226
}
213-
const {reportModuleCommandCompleted, reportModuleCommandError} = useModuleCommandAnalytics()
227+
const {reportModuleCommand} = useModuleCommandAnalytics()
214228
const serialNumber = module.serialNumber
215229
createLiveCommand({
216230
command: deactivateCommand,
217-
}).then(result=>reportModuleCommandCompleted(module.moduleModel, 'deactivate', {status: 'succeeded', data: result}, serialNumber, null)
218-
).catch((e: Error) => {
219-
reportModuleCommandError(module.moduleModel, 'deactivate', e.message, serialNumber,null)
231+
}).then((result)=>{
232+
reportModuleCommand({
233+
moduleType: module.moduleType,
234+
action: 'deactivate',
235+
result: {status: 'succeeded', data: result},
236+
serialNumber: serialNumber ?? module.serialNumber,
237+
temperature: null
238+
});
239+
})
240+
.catch((e: Error) => {
241+
reportModuleCommand({
242+
moduleType: module.moduleModel,
243+
action: 'deactivate',
244+
errorDetails: e.message,
245+
serialNumber: serialNumber ?? module.serialNumber,
246+
temperature: null
247+
});
220248
console.error(
221249
`error setting module status with command type ${deactivateCommand.commandType}: ${e.message}`
222-
)
223-
})
250+
);
251+
});
224252
}
225-
226253
const lidCommand: TCOpenLidCreateCommand | TCCloseLidCreateCommand = {
227254
commandType:
228255
module.moduleType === THERMOCYCLER_MODULE_TYPE &&
@@ -233,13 +260,28 @@ export function useModuleOverflowMenu(
233260
moduleId: module.id,
234261
},
235262
}
236-
const {reportModuleCommandCompleted, reportModuleCommandError} = useModuleCommandAnalytics()
263+
const {reportModuleCommand} = useModuleCommandAnalytics()
237264
const serialNumber = module.serialNumber
238265
const controlTCLid = (): void => {
239266
createLiveCommand({
240267
command: lidCommand,
241-
}).then(result=> reportModuleCommandCompleted(module.moduleModel, 'toggle-tc-lid', {status: "succeeded", data:result}, serialNumber, null)).catch((e: Error) => {
242-
reportModuleCommandError(module.moduleModel, 'toggle-tc-lid', serialNumber, e.message, null)
268+
}).then((result)=> {
269+
reportModuleCommand({
270+
moduleType: module.moduleModel,
271+
action: 'toggle-tc-lid',
272+
result: {status: 'suceeded', data: result},
273+
serialNumber: serialNumber ?? module.serialNumber,
274+
temperature: null
275+
});
276+
})
277+
.catch((e: Error) => {
278+
reportModuleCommand({
279+
moduleType: module.moduleModel,
280+
action: 'toggle-tc-lid',
281+
errorDetails: e.message,
282+
serialNumber: serialNumber ?? module.serialNumber,
283+
temperature: null,
284+
});
243285
console.error(
244286
`error setting thermocycler module status with command type ${lidCommand.commandType}: ${e.message}`
245287
)

app/src/organisms/ODD/ProtocolSetup/ProtocolSetupLabware/index.tsx

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -313,19 +313,23 @@ function LabwareLatch({
313313
params: { moduleId: matchedHeaterShaker.id },
314314

315315
}
316-
316+
317317
const toggleLatch = (): void => {
318318
// Record latch toggle to analytics
319-
const {
320-
reportModuleCommandCompleted,
321-
reportModuleCommandError} = useModuleCommandAnalytics()
319+
const {reportModuleCommand} = useModuleCommandAnalytics()
322320
const serialNumber = matchedHeaterShaker.serialNumber
323321
createLiveCommand({
324322
command: latchCommand,
325323
waitUntilComplete: true,
326324
})
327-
.then(result => {
328-
reportModuleCommandCompleted('heatershaker', 'toggle-hs-latch', {status:'succeeded', data: result}, serialNumber, null)
325+
.then((result) => {
326+
reportModuleCommand({
327+
moduleType: matchedHeaterShaker.moduleModel,
328+
action:'toggle-hs-latch',
329+
result:{status:'succeeded', data: result},
330+
serialNumber: serialNumber ?? matchedHeaterShaker.serialNumber,
331+
temperature: null
332+
});
329333
setIsRefetchingModules(true)
330334
refetchModules()
331335
.then(() => {
@@ -339,7 +343,12 @@ function LabwareLatch({
339343
})
340344
})
341345
.catch((e: Error) => {
342-
reportModuleCommandError('heatershaker', 'toggle-hs-latch', e.message, serialNumber, null)
346+
reportModuleCommand({
347+
moduleType: matchedHeaterShaker.moduleType,
348+
action: 'toggle-hs-latch',
349+
errorDetails: e.message,
350+
serialNumber: serialNumber ?? matchedHeaterShaker.serialNumber,
351+
temperature: null});
343352
console.error(
344353
`error setting module status with command type ${latchCommand.commandType}: ${e.message}`
345354
)

0 commit comments

Comments
 (0)