Total Complexity | 2 |
Complexity/F | 0 |
Lines of Code | 35 |
Function Count | 0 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { createSelector } from "reselect"; |
||
2 | import { RootState } from "../store"; |
||
3 | import { Manager } from "../../models/types"; |
||
4 | import { hasKey } from "../../helpers/queries"; |
||
5 | |||
6 | const getManagersById = (state: RootState): { [id: number]: Manager } => |
||
7 | state.manager.managersById; |
||
8 | |||
9 | const getSelectedId = (state: RootState): number | null => |
||
10 | state.manager.selectedManagerId; |
||
11 | |||
12 | export const getManagers = createSelector( |
||
13 | getManagersById, |
||
14 | (managersById): Manager[] => Object.values(managersById), |
||
15 | ); |
||
16 | |||
17 | export const getManagerById = ( |
||
18 | state: RootState, |
||
19 | { managerId }: { managerId: number }, |
||
20 | ): Manager | null => { |
||
21 | const managersById = getManagersById(state); |
||
22 | return hasKey(managersById, managerId) ? managersById[managerId] : null; |
||
23 | }; |
||
24 | |||
25 | export const getSelectedManager = (state: RootState): Manager | null => { |
||
26 | const selectedId = getSelectedId(state); |
||
27 | return selectedId !== null |
||
28 | ? getManagerById(state, { managerId: selectedId }) |
||
29 | : null; |
||
30 | }; |
||
31 | |||
32 | export const getManagerIsUpdatingById = ( |
||
33 | state: RootState, |
||
34 | ): { [id: number]: boolean } => state.manager.managerUpdating; |
||
35 |