- {modules.map((moduleType, i) => {
- const label = t(`module_display_names.${moduleType}`)
- const defaultModel = DEFAULT_MODEL_FOR_MODULE_TYPE[moduleType]
- const selectedModel = values[moduleType].model
+
+ {OT2_SUPPORTED_MODULE_MODELS.map(moduleModel => {
+ const moduleType = getModuleType(moduleModel)
+ const moduleOnDeck = moduleModelsOnDeck.includes(moduleModel)
return (
-
-
(
- ) => {
- const type: ModuleType = e.target.value as ModuleType
- field.onChange(e)
- await trigger(`modulesByType.${type}.onDeck`)
- }}
- tabIndex={i}
- />
- )}
- />
-
-
- (
-
- {values[moduleType].onDeck && (
-
-
-
- )}
-
- )}
- />
-
+ }
+ text={getModuleDisplayName(moduleModel)}
+ disabled={moduleTypesOnDeck.includes(moduleType) && !moduleOnDeck}
+ onClick={() => {
+ if (moduleOnDeck) {
+ const updatedModulesByModel =
+ modules != null
+ ? Object.fromEntries(
+ Object.entries(modules).filter(
+ ([key, value]) => value.model !== moduleModel
+ )
+ )
+ : {}
+ setValue('modules', updatedModulesByModel)
+ } else {
+ setValue('modules', {
+ ...modules,
+ [uuid()]: {
+ model: moduleModel,
+ type: moduleType,
+ slot: DEFAULT_SLOT_MAP[moduleType] ?? '',
+ },
+ })
+ }
+ }}
+ showCheckbox
+ />
)
})}
-
+