diff --git a/app/frontend/src/javascript/components/machines/machine-categories-list.tsx b/app/frontend/src/javascript/components/machines/machine-categories-list.tsx index 9ca66f20a..f85cc10c0 100644 --- a/app/frontend/src/javascript/components/machines/machine-categories-list.tsx +++ b/app/frontend/src/javascript/components/machines/machine-categories-list.tsx @@ -40,11 +40,11 @@ export const MachineCategoriesList: React.FC = ({ on // retrieve the full list of machine categories on component mount useEffect(() => { MachineCategoryAPI.index() - .then(data => setMachineCategories(data)) - .catch(e => onError(e)); - MachineAPI.index() - .then(data => setMachines(data)) - .catch(e => onError(e)); + .then(setMachineCategories) + .catch(onError); + MachineAPI.index({ category: 'none' }) + .then(setMachines) + .catch(onError); }, []); /** @@ -59,6 +59,7 @@ export const MachineCategoriesList: React.FC = ({ on */ const onSaveTypeSuccess = (message: string): void => { setModalIsOpen(false); + MachineAPI.index({ category: 'none' }).then(setMachines).catch(onError); MachineCategoryAPI.index().then(data => { setMachineCategories(data); onSuccess(message); diff --git a/app/frontend/src/javascript/models/machine.ts b/app/frontend/src/javascript/models/machine.ts index afd74b430..c9469adf2 100644 --- a/app/frontend/src/javascript/models/machine.ts +++ b/app/frontend/src/javascript/models/machine.ts @@ -5,7 +5,7 @@ import { AdvancedAccounting } from './advanced-accounting'; export interface MachineIndexFilter extends ApiFilter { disabled?: boolean, - category?: number + category?: number | 'none' } export interface Machine { diff --git a/app/services/machine_service.rb b/app/services/machine_service.rb index 11b041ff7..9e4088e3a 100644 --- a/app/services/machine_service.rb +++ b/app/services/machine_service.rb @@ -34,6 +34,8 @@ class MachineService def filter_by_category(machines, filters) return machines if filters[:category].blank? + return machines.where(machine_category_id: nil) if filters[:category] == 'none' + machines.where(machine_category_id: filters[:category]) end end