Passed
Push — dependabot/npm_and_yarn/dev/st... ( 790070...2dbd00 )
by
unknown
17:44 queued 12:22
created

resources/assets/js/store/HrAdvisor/hrAdvisorSelector.ts   A

Complexity

Total Complexity 1
Complexity/F 0

Size

Lines of Code 38
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 36
c 0
b 0
f 0
dl 0
loc 38
rs 10
mnd 1
bc 1
fnc 0
bpm 0
cpm 0
noi 0
1
import { RootState } from "../store";
2
import { EntityState, UiState } from "./hrAdvisorReducer";
3
import { HrAdvisor } from "../../models/types";
4
import { hasKey, identity } from "../../helpers/queries";
5
6
const entities = (state: RootState): EntityState => state.hrAdvisor.entities;
7
const ui = (state: RootState): UiState => state.hrAdvisor.ui;
8
9
export const getHrAdvisor = (
10
  state: RootState,
11
  { hrAdvisorId }: { hrAdvisorId: number },
12
): HrAdvisor | null => {
13
  const advisors = entities(state).hrAdvisors.byId;
14
  return hasKey(advisors, hrAdvisorId) ? advisors[hrAdvisorId] : null;
15
};
16
17
const anyJobClaimIsUpdatingForUser = (
18
  state: RootState,
19
  { hrAdvisorId }: { hrAdvisorId: number },
20
): boolean =>
21
  hasKey(ui(state).jobClaimUpdating, hrAdvisorId) &&
22
  Object.values(ui(state).jobClaimUpdating[hrAdvisorId]).some(identity);
23
24
export const getHrAdvisorIsUpdating = (
25
  state: RootState,
26
  { hrAdvisorId }: { hrAdvisorId: number },
27
): boolean =>
28
  ui(state).hrAdvisorUpdating[hrAdvisorId] === true ||
29
  anyJobClaimIsUpdatingForUser(state, { hrAdvisorId });
30
31
export const getJobClaimIsUpdating = (
32
  state: RootState,
33
  { hrAdvisorId, jobId }: { hrAdvisorId: number; jobId: number },
34
): boolean =>
35
  hasKey(ui(state).jobClaimUpdating, hrAdvisorId) &&
36
  hasKey(ui(state).jobClaimUpdating[hrAdvisorId], jobId) &&
37
  ui(state).jobClaimUpdating[hrAdvisorId][jobId];
38