Passed
Push — feature/applicant-profile-skil... ( 1e801a...8cc5f5 )
by Tristan
04:52
created

resources/assets/js/store/Manager/managerSelector.ts   A

Complexity

Total Complexity 2
Complexity/F 0

Size

Lines of Code 35
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 31
dl 0
loc 35
rs 10
c 0
b 0
f 0
mnd 2
bc 2
fnc 0
bpm 0
cpm 0
noi 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