Passed
Push — feature/azure-webapp-pipeline-... ( f7c88d...cc7783 )
by Grant
05:46 queued 13s
created

resources/assets/js/store/Classification/classificationReducer.ts   A

Complexity

Total Complexity 1
Complexity/F 0

Size

Lines of Code 39
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 32
c 0
b 0
f 0
dl 0
loc 39
rs 10
mnd 1
bc 1
fnc 0
bpm 0
cpm 0
noi 0
1
import { Classification } from "../../models/types";
2
import {
3
  ClassificationAction,
4
  GET_CLASSIFICATIONS_STARTED,
5
  GET_CLASSIFICATIONS_SUCCEEDED,
6
  GET_CLASSIFICATIONS_FAILED,
7
} from "./classificationActions";
8
import { mapToObject, getId } from "../../helpers/queries";
9
10
export interface ClassificationState {
11
  byId: {
12
    [id: number]: Classification;
13
  };
14
  loading: boolean;
15
}
16
17
export const initClassificationState = (): ClassificationState => ({
18
  byId: [],
19
  loading: false,
20
});
21
22
const classificationReducer = (
23
  state = initClassificationState(),
24
  action: ClassificationAction,
25
): ClassificationState => {
26
  switch (action.type) {
27
    case GET_CLASSIFICATIONS_STARTED:
28
      return { ...state, loading: true };
29
    case GET_CLASSIFICATIONS_SUCCEEDED:
30
      return { byId: mapToObject(action.payload, getId), loading: false };
31
    case GET_CLASSIFICATIONS_FAILED:
32
      return { ...state, loading: false };
33
    default:
34
      return state;
35
  }
36
};
37
38
export default classificationReducer;
39