Add activeModelSelector

Active Model details are used in multiple places. So makes sense to have a selector for it.
This commit is contained in:
blessedcoolant 2023-02-07 18:25:12 +13:00
parent d5810f6270
commit a7dd7b4298

View File

@ -1,6 +1,31 @@
import { createSelector } from '@reduxjs/toolkit';
import { RootState } from 'app/store'; import { RootState } from 'app/store';
import { SystemState } from './systemSlice'; import { SystemState } from './systemSlice';
import _ from 'lodash';
export const systemSelector = (state: RootState): SystemState => state.system; export const systemSelector = (state: RootState): SystemState => state.system;
export const toastQueueSelector = (state: RootState) => state.system.toastQueue; export const toastQueueSelector = (state: RootState) => state.system.toastQueue;
export const activeModelSelector = createSelector(
systemSelector,
(system) => {
const { model_list } = system;
const activeModel = _.reduce(
model_list,
(acc, model, key) => {
if (model.status === 'active') {
acc = key;
}
return acc;
},
''
);
return { ...model_list[activeModel], name: activeModel };
},
{
memoizeOptions: {
resultEqualityCheck: _.isEqual,
},
}
);