@@ -18,6 +18,7 @@ import {
18
18
import { ClearPaginationOfType , ResetPaginationOfType } from '../../../../../store/src/actions/pagination.actions' ;
19
19
import { AppState } from '../../../../../store/src/app-state' ;
20
20
import { entityCatalog } from '../../../../../store/src/entity-catalog/entity-catalog' ;
21
+ import { EntitySchema } from '../../../../../store/src/helpers/entity-schema' ;
21
22
import { isJetstreamError } from '../../../../../store/src/jetstream' ;
22
23
import { ApiRequestTypes } from '../../../../../store/src/reducers/api-request-reducer/request-helpers' ;
23
24
import { endpointOfTypeSelector } from '../../../../../store/src/selectors/endpoint.selectors' ;
@@ -31,13 +32,7 @@ import {
31
32
WrapperRequestActionSuccess ,
32
33
} from '../../../../../store/src/types/request.types' ;
33
34
import { helmEntityCatalog } from '../helm-entity-catalog' ;
34
- import {
35
- getHelmVersionId ,
36
- getMonocularChartId ,
37
- HELM_ENDPOINT_TYPE ,
38
- HELM_HUB_ENDPOINT_TYPE ,
39
- HELM_REPO_ENDPOINT_TYPE ,
40
- } from '../helm-entity-factory' ;
35
+ import { HELM_ENDPOINT_TYPE , HELM_HUB_ENDPOINT_TYPE , HELM_REPO_ENDPOINT_TYPE } from '../helm-entity-factory' ;
41
36
import { Chart } from '../monocular/shared/models/chart' ;
42
37
import { stratosMonocularEndpointGuid } from '../monocular/stratos-monocular.helper' ;
43
38
import {
@@ -58,15 +53,19 @@ type MonocularChartsResponse = {
58
53
data : Chart [ ] ;
59
54
} ;
60
55
61
- const mapMonocularChartResponse = ( entityKey : string , response : MonocularChartsResponse ) : NormalizedResponse => {
56
+ const mapMonocularChartResponse = (
57
+ entityKey : string ,
58
+ response : MonocularChartsResponse ,
59
+ schema : EntitySchema
60
+ ) : NormalizedResponse => {
62
61
const base : NormalizedResponse = {
63
62
entities : { [ entityKey ] : { } } ,
64
63
result : [ ]
65
64
} ;
66
65
67
66
const items = response . data as Array < any > ;
68
67
const processedData : NormalizedResponse = items . reduce ( ( res , data ) => {
69
- const id = getMonocularChartId ( data ) ;
68
+ const id = schema . getId ( data ) ;
70
69
res . entities [ entityKey ] [ id ] = data ;
71
70
// Promote the name to the top-level object for simplicity
72
71
data . name = data . attributes . name ;
@@ -76,12 +75,16 @@ const mapMonocularChartResponse = (entityKey: string, response: MonocularChartsR
76
75
return processedData ;
77
76
} ;
78
77
79
- const mergeMonocularChartResponses = ( entityKey : string , responses : MonocularChartsResponse [ ] ) : NormalizedResponse => {
78
+ const mergeMonocularChartResponses = (
79
+ entityKey : string ,
80
+ responses : MonocularChartsResponse [ ] ,
81
+ schema : EntitySchema
82
+ ) : NormalizedResponse => {
80
83
const combined = responses . reduce ( ( res , response ) => {
81
84
res . data = res . data . concat ( response . data ) ;
82
85
return res ;
83
86
} , { data : [ ] } ) ;
84
- return mapMonocularChartResponse ( entityKey , combined ) ;
87
+ return mapMonocularChartResponse ( entityKey , combined , schema ) ;
85
88
} ;
86
89
87
90
const addMonocularId = ( endpointId : string , response : MonocularChartsResponse ) : MonocularChartsResponse => {
@@ -155,7 +158,7 @@ export class HelmEffects {
155
158
this . createHelmRepoRequest ( helmEndpoints ) ,
156
159
this . createHelmHubRequest ( helmHubEndpoint )
157
160
] ) . pipe (
158
- map ( res => mergeMonocularChartResponses ( entityKey , res ) ) ,
161
+ map ( res => mergeMonocularChartResponses ( entityKey , res , action . entity [ 0 ] ) ) ,
159
162
mergeMap ( ( response : NormalizedResponse ) => [ new WrapperRequestActionSuccess ( response , action ) ] ) ,
160
163
catchError ( error => {
161
164
const { status, message } = HelmEffects . createHelmError ( error ) ;
@@ -199,7 +202,7 @@ export class HelmEffects {
199
202
endpointId : endpoint ,
200
203
...endpointData
201
204
} ;
202
- processedData . entities [ entityKey ] [ getHelmVersionId ( version ) ] = version ;
205
+ processedData . entities [ entityKey ] [ action . entity [ 0 ] . getId ( version ) ] = version ;
203
206
processedData . result . push ( endpoint ) ;
204
207
} ) ;
205
208
return processedData ;
@@ -221,7 +224,7 @@ export class HelmEffects {
221
224
222
225
const items = response . data as Array < any > ;
223
226
const processedData = items . reduce ( ( res , data ) => {
224
- const id = getMonocularChartId ( data ) ;
227
+ const id = action . entity [ 0 ] . getId ( data ) ;
225
228
res . entities [ entityKey ] [ id ] = data ;
226
229
// Promote the name to the top-level object for simplicity
227
230
data . name = data . attributes . name ;
0 commit comments