1
|
|
|
import { createSelector } from "reselect"; |
2
|
|
|
import { RootState } from "../store"; |
3
|
|
|
import { Classification } from "../../models/types"; |
4
|
|
|
|
5
|
|
|
// I still have no idea |
6
|
|
|
const getClassificationState = (state: RootState): { [key: string]: Classification } => |
7
|
|
|
state.classification.byId; |
8
|
|
|
|
9
|
|
|
// Get the list of classifications already stored in the state (via the function in classificationactions) |
10
|
|
|
export const getClassifications = createSelector( |
11
|
|
|
getClassificationState, |
12
|
|
|
(ClassificationState): Classification[] => Object.values(ClassificationState), |
13
|
|
|
); |
14
|
|
|
|
15
|
|
|
export const classificationsExtractKeyValueJsonArray = function(classifications : Classification[]) : {value : number, label: string}[] { |
16
|
|
|
let classificationsArr : {value : number, label: string}[] = []; |
17
|
|
|
classifications.forEach(function(classification) { |
18
|
|
|
classificationsArr.push({value : classification.id, label : classification.key |
19
|
|
|
}) |
20
|
|
|
}) |
21
|
|
|
return classificationsArr |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
export const classificationsExtractKeyValueJson = function(classifications) : JSON { |
25
|
|
|
let classificationsJson : any = {} |
26
|
|
|
let output : JSON; |
27
|
|
|
|
28
|
|
|
classifications.forEach(function (classification) { |
29
|
|
|
classificationsJson[classification.key] = classification.id |
30
|
|
|
}) |
31
|
|
|
|
32
|
|
|
output = <JSON>classificationsJson |
33
|
|
|
return output |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
export const getClassificationKey = function(classifications : Classification[], classification: number | string): string { |
37
|
|
|
let lClassification : Classification = classifications.filter(c => c.id == classification)[0] |
38
|
|
|
return lClassification ? lClassification.key : "" |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
// Get a classification from the redux state by passing in an ID |
42
|
|
|
export const getClassificationById = ( |
43
|
|
|
state: RootState, |
44
|
|
|
id: number, |
45
|
|
|
): Classification => |
46
|
|
|
getClassificationState(state)[id] |
47
|
|
|
|
48
|
|
|
export const classificationsIsLoading = (state: RootState): boolean => |
49
|
|
|
state.classification.loading; |
50
|
|
|
|