Newer
Older
import { createEntityAdapter, EntityAdapter, EntityState, Update } from '@ngrx/entity';
import * as actions from './search-multiple.action';
import { DataByDataset, DatasetCount } from './model';
export interface State extends EntityState<DataByDataset> {
currentStep: string;
positionStepChecked: boolean;
datasetsStepChecked: boolean;
resultStepChecked: boolean;
selectedDatasets: string[];
datasetsCountIsLoading: boolean;
datasetsCountIsLoaded: boolean;
datasetsCount: DatasetCount[];
selectedData: { dname: string, data: (string | number)[] }[];
export function selectDataByDatasetId(d: DataByDataset): string {
return d.datasetName;
export const adapter: EntityAdapter<DataByDataset> = createEntityAdapter<DataByDataset>({
selectId: selectDataByDatasetId
});
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
export const initialState: State = adapter.getInitialState({
pristine: true,
currentStep: null,
positionStepChecked: false,
datasetsStepChecked: false,
resultStepChecked: false,
selectedDatasets: [],
datasetsCountIsLoading: false,
datasetsCountIsLoaded: false,
datasetsCount: [],
selectedData: []
});
export function reducer(state: State = initialState, action: actions.Actions): State {
switch (action.type) {
case actions.INIT_SELECTED_DATASETS:
return {
...state,
selectedDatasets: action.payload
};
case actions.CHANGE_STEP:
return {
...state,
currentStep: action.payload
};
case actions.POSITION_CHECKED:
return {
...state,
pristine: false,
positionStepChecked: true
};
case actions.DATASETS_CHECKED:
return {
...state,
datasetsStepChecked: true
};
return {
...state,
case actions.UPDATE_SELECTED_DATASETS:
return {
...state,
case actions.RETRIEVE_DATASETS_COUNT:
return {
...state,
case actions.RETRIEVE_DATASETS_COUNT_SUCCESS:
return {
...state,
datasetsCountIsLoading: false,
datasetsCountIsLoaded: true,
datasetsCount: action.payload
case actions.RETRIEVE_DATASETS_COUNT_FAIL:
return {
...state,
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
};
case actions.RETRIEVE_DATA:
return adapter.upsertOne({
datasetName: action.payload.dname,
isLoading: true,
isLoaded: false,
data: []
}, state);
case actions.RETRIEVE_DATA_SUCCESS:
return adapter.updateOne({
id: action.payload.datasetName,
changes: {
isLoading: false,
isLoaded: true,
data: action.payload.data
}
} as Update<DataByDataset>, state);
case actions.RETRIEVE_DATA_FAIL:
return adapter.updateOne({
id: action.payload,
changes: {
isLoading: false
}
} as Update<DataByDataset>, state);
case actions.UPDATE_SELECTED_DATA:
return {
...state,
selectedData: action.payload
};
case actions.DESTROY_RESULTS:
return adapter.removeAll({
...state,
datasetsCountIsLoaded: false,
datasetsCount: [],
selectedData: []
});
case actions.RESET_SEARCH:
return { ...initialState };
default:
return state;
}
}
export const {
selectAll,
selectEntities,
selectIds,
selectTotal
} = adapter.getSelectors();
export const getCurrentStep = (state: State) => state.currentStep;
export const getPositionStepChecked = (state: State) => state.positionStepChecked;
export const getDatasetsStepChecked = (state: State) => state.datasetsStepChecked;
export const getResultStepChecked = (state: State) => state.resultStepChecked;
export const getSelectedDatasets = (state: State) => state.selectedDatasets;
export const getDatasetsCountIsLoading = (state: State) => state.datasetsCountIsLoading;
export const getDatasetsCountIsLoaded = (state: State) => state.datasetsCountIsLoaded;
export const getDatasetsCount = (state: State) => state.datasetsCount;
export const getSelectedData = (state: State) => state.selectedData;