diff --git a/src/app/controllers/components/ControllerForms/ControllerActionFormWrapper/ControllerActionFormWrapper.tsx b/src/app/controllers/components/ControllerForms/ControllerActionFormWrapper/ControllerActionFormWrapper.tsx index e31a3c542c..7b37f18211 100644 --- a/src/app/controllers/components/ControllerForms/ControllerActionFormWrapper/ControllerActionFormWrapper.tsx +++ b/src/app/controllers/components/ControllerForms/ControllerActionFormWrapper/ControllerActionFormWrapper.tsx @@ -55,12 +55,13 @@ export const ControllerActionFormWrapper = ({ const processingControllers = useSelector( actionStatus ? statusSelectors[actionStatus] : () => [] ); + const controllerSystemIds = controllers.map(({ system_id }) => system_id); // The form expects one error, so we only show the latest error with the // assumption that all selected controllers fail in the same way. const errors = useSelector((state: RootState) => controllerSelectors.eventErrorsForControllers( state, - controllers.map(({ system_id }) => system_id), + controllerSystemIds, kebabToCamelCase(action) ) )[0]?.error; diff --git a/src/app/store/controller/selectors.ts b/src/app/store/controller/selectors.ts index 6c487ce8d1..8dc3dd9e6e 100644 --- a/src/app/store/controller/selectors.ts +++ b/src/app/store/controller/selectors.ts @@ -61,20 +61,21 @@ const processing = (state: RootState): Controller[ControllerMeta.PK][] => ) ); -export const statusSelectors: { - [x: string]: Selector; -} = {}; - // Create a selector for each controller status. -ACTIONS.forEach(({ status }) => { - statusSelectors[status] = createSelector( - [defaultSelectors.all, statuses], - (controllers: Controller[], statuses: ControllerStatuses) => - controllers.filter( - ({ system_id }) => statuses[system_id][status as keyof ControllerStatus] - ) - ); -}); +export const statusSelectors = ACTIONS.reduce( + (selectors, { status }) => { + selectors[status] = createSelector( + [defaultSelectors.all, statuses], + (controllers: Controller[], statuses: ControllerStatuses) => + controllers.filter( + ({ system_id }) => + statuses[system_id][status as keyof ControllerStatus] + ) + ); + return selectors; + }, + {} as { [x: string]: Selector } +); /** * Get the statuses for a controller.