@@ -67,39 +67,50 @@ export const MapsSection: React.FC<MapsSectionProps> = ({ obj }) => {
67
67
68
68
const availableSources = sourceStorages ?. filter ( ( n ) => ! isStorageMapped ( n ?. id ) ) ;
69
69
70
- const getInventoryStorageName = ( id : string ) => sourceStorages . find ( ( s ) => s . id === id ) ?. name ;
70
+ const getInventoryStorageName = ( id : string ) => sourceStorages ? .find ( ( s ) => s . id === id ) ?. name ;
71
71
72
72
const onAdd = ( ) =>
73
73
availableSources . length > 0 &&
74
74
dispatch ( {
75
75
type : 'SET_MAP' ,
76
76
payload : [
77
77
...( state . StorageMap ?. spec ?. map || [ ] ) ,
78
- {
79
- source : availableSources [ 0 ] ,
80
- destination : { storageClass : destinationStorages ?. [ 0 ] . name } ,
81
- } ,
78
+ sourceProvider ?. spec ?. type === 'openshift'
79
+ ? {
80
+ source : { name : availableSources ?. [ 0 ] ?. name } ,
81
+ destination : { storageClass : destinationStorages ?. [ 0 ] . name } ,
82
+ }
83
+ : {
84
+ source : { id : availableSources ?. [ 0 ] ?. id } ,
85
+ destination : { storageClass : destinationStorages ?. [ 0 ] . name } ,
86
+ } ,
82
87
] ,
83
88
} ) ;
84
89
85
90
const onReplace = ( { current, next } ) => {
86
91
const currentDestinationStorage = destinationStorages . find (
87
92
( n ) => n . name == current . destination ,
88
93
) ;
89
- const currentSourceStorage = sourceStorages . find ( ( n ) => n ?. name === current . source ) ;
94
+ const currentSourceStorage = sourceStorages ? .find ( ( n ) => n ?. name === current . source ) ;
90
95
91
96
const nextDestinationStorage = destinationStorages . find ( ( n ) => n . name == next . destination ) ;
92
- const nextSourceStorage = sourceStorages . find ( ( n ) => n ?. name === next . source ) ;
97
+ const nextSourceStorage = sourceStorages ? .find ( ( n ) => n ?. name === next . source ) ;
93
98
94
99
// sanity check, names may not be valid
95
100
if ( ! nextSourceStorage || ! nextDestinationStorage ) {
96
101
return ;
97
102
}
98
103
99
- const nextMap : V1beta1StorageMapSpecMap = {
100
- source : { id : nextSourceStorage . id } ,
101
- destination : { storageClass : nextDestinationStorage . name } ,
102
- } ;
104
+ const nextMap : V1beta1StorageMapSpecMap =
105
+ sourceProvider ?. spec ?. type === 'openshift'
106
+ ? {
107
+ source : { name : nextSourceStorage . name } ,
108
+ destination : { storageClass : nextDestinationStorage . name } ,
109
+ }
110
+ : {
111
+ source : { id : nextSourceStorage . id } ,
112
+ destination : { storageClass : nextDestinationStorage . name } ,
113
+ } ;
103
114
104
115
const payload = state ?. StorageMap ?. spec ?. map ?. map ( ( map ) => {
105
116
return map ?. source ?. id === currentSourceStorage ?. id &&
@@ -116,7 +127,7 @@ export const MapsSection: React.FC<MapsSectionProps> = ({ obj }) => {
116
127
117
128
const onDelete = ( current : Mapping ) => {
118
129
const references = storageNameToIDReference ( state ?. StorageMap ?. status ?. references || [ ] ) ;
119
- const currentSourceStorage = sourceStorages . find ( ( n ) => n . name === current . source ) ;
130
+ const currentSourceStorage = sourceStorages ? .find ( ( n ) => n . name === current . source ) ;
120
131
121
132
dispatch ( {
122
133
type : 'SET_MAP' ,
@@ -125,6 +136,7 @@ export const MapsSection: React.FC<MapsSectionProps> = ({ obj }) => {
125
136
( map ) =>
126
137
! (
127
138
( map ?. source ?. id === currentSourceStorage ?. id ||
139
+ map ?. source ?. name === current . source ||
128
140
map ?. source ?. id === references [ current . source ] ) &&
129
141
map . destination ?. storageClass === current . destination
130
142
) ,
0 commit comments