1
1
import { t } from '@lingui/macro' ;
2
- import { Button , Modal , Radio } from '@patternfly/react-core' ;
2
+ import {
3
+ Button ,
4
+ Flex ,
5
+ FlexItem ,
6
+ Label ,
7
+ Modal ,
8
+ Radio ,
9
+ } from '@patternfly/react-core' ;
3
10
import { FolderOpenIcon , SpinnerIcon } from '@patternfly/react-icons' ;
4
11
import axios from 'axios' ;
5
12
import cx from 'classnames' ;
@@ -14,9 +21,11 @@ import {
14
21
import {
15
22
AlertList ,
16
23
AlertType ,
24
+ LabelGroup ,
17
25
MultipleRepoSelector ,
18
26
closeAlertMixin ,
19
27
} from 'src/components' ;
28
+ import { AppContext } from 'src/loaders/app-context' ;
20
29
import { repositoryBasePath } from 'src/utilities' ;
21
30
import './import-modal.scss' ;
22
31
@@ -44,9 +53,12 @@ interface IState {
44
53
alerts : AlertType [ ] ;
45
54
selectedRepos : AnsibleRepositoryType [ ] ; // 0 or 1 repos
46
55
onlyStaging : boolean ;
56
+ hideSelector : boolean ;
47
57
}
48
58
49
59
export class ImportModal extends React . Component < IProps , IState > {
60
+ static contextType = AppContext ;
61
+
50
62
acceptedFileTypes = [ 'application/x-gzip' , 'application/gzip' ] ;
51
63
cancelToken : ReturnType < typeof CollectionAPI . getCancelToken > ;
52
64
COLLECTION_NAME_REGEX = / [ 0 - 9 a - z _ ] + - [ 0 - 9 a - z _ ] + - [ 0 - 9 A - Z a - z . + - ] + / ;
@@ -64,18 +76,19 @@ export class ImportModal extends React.Component<IProps, IState> {
64
76
alerts : [ ] ,
65
77
selectedRepos : [ ] ,
66
78
onlyStaging : true ,
79
+ hideSelector : false ,
67
80
} ;
68
81
}
69
82
70
83
componentDidMount ( ) {
71
84
this . loadAllRepos ( ) ;
72
85
}
73
86
74
- private async loadAllRepos ( ) {
87
+ private loadAllRepos ( ) {
75
88
const { onlyStaging } = this . state ;
76
89
77
- const staging = onlyStaging
78
- ? await AnsibleRepositoryAPI . list ( {
90
+ const stagingByName = onlyStaging
91
+ ? AnsibleRepositoryAPI . list ( {
79
92
name : 'staging' ,
80
93
page_size : 1 ,
81
94
pulp_label_select : 'pipeline=staging' ,
@@ -84,18 +97,32 @@ export class ImportModal extends React.Component<IProps, IState> {
84
97
. catch ( ( ) => null )
85
98
: null ;
86
99
87
- return AnsibleRepositoryAPI . list ( {
100
+ const byPipeline = AnsibleRepositoryAPI . list ( {
88
101
pulp_label_select : onlyStaging ? 'pipeline=staging' : '!pipeline' ,
89
102
page_size : 1 ,
90
- } )
91
- . then ( ( { data : { count, results } } ) =>
92
- this . setState ( {
93
- selectedRepos : onlyStaging
103
+ } ) ;
104
+
105
+ return Promise . all ( [ byPipeline , stagingByName ] )
106
+ . then (
107
+ ( [
108
+ {
109
+ data : { count, results } ,
110
+ } ,
111
+ staging ,
112
+ ] ) => {
113
+ // only staging: preselect "staging", or first repo if not found
114
+ // all repos: preselect first repo only if there are no other choices
115
+ const selectedRepos = onlyStaging
94
116
? [ staging || results [ 0 ] ] . filter ( Boolean )
95
117
: count === 1
96
118
? [ results [ 0 ] ]
97
- : [ ] ,
98
- } ) ,
119
+ : [ ] ;
120
+
121
+ this . setState ( {
122
+ selectedRepos,
123
+ hideSelector : selectedRepos . length && count < 2 ,
124
+ } ) ;
125
+ } ,
99
126
)
100
127
. catch ( ( error ) =>
101
128
this . addAlert ( t `Error loading repositories.` , 'danger' , error ?. message ) ,
@@ -125,15 +152,18 @@ export class ImportModal extends React.Component<IProps, IState> {
125
152
}
126
153
127
154
render ( ) {
128
- const { isOpen , collection } = this . props ;
155
+ const { collection , namespace , isOpen } = this . props ;
129
156
const {
130
- errors,
131
157
errorVariant,
158
+ errors,
132
159
file,
160
+ hideSelector,
133
161
onlyStaging,
162
+ selectedRepos,
134
163
uploadProgress,
135
164
uploadStatus,
136
165
} = this . state ;
166
+ const { featureFlags } = this . context ;
137
167
138
168
const skipError = ( ) => {
139
169
if ( errorVariant === 'skippable' ) {
@@ -145,7 +175,9 @@ export class ImportModal extends React.Component<IProps, IState> {
145
175
< Modal
146
176
variant = { 'large' }
147
177
title = {
148
- collection ? t `New version of ${ collection . name } ` : t `New collection`
178
+ collection
179
+ ? t `New version of ${ namespace } .${ collection . name } `
180
+ : t `New collection`
149
181
}
150
182
isOpen = { isOpen }
151
183
onClose = { ( ) => this . handleClose ( ) }
@@ -209,37 +241,54 @@ export class ImportModal extends React.Component<IProps, IState> {
209
241
) : null }
210
242
</ div >
211
243
212
- < >
213
- < br />
214
- < Radio
215
- isChecked = { this . state . onlyStaging }
216
- name = 'radio-1'
217
- onChange = { ( val ) => {
218
- this . setState ( { onlyStaging : val } , ( ) => this . loadAllRepos ( ) ) ;
219
- } }
220
- label = { t `Staging Repos` }
221
- id = 'radio-staging'
222
- > </ Radio >
223
- < Radio
224
- isChecked = { ! this . state . onlyStaging }
225
- name = 'radio-2'
226
- onChange = { ( val ) => {
227
- this . setState ( { onlyStaging : ! val } , ( ) => this . loadAllRepos ( ) ) ;
228
- } }
229
- label = { t `All Repos` }
230
- id = 'radio-all'
231
- > </ Radio >
232
- { ! this . state . onlyStaging && (
233
- < > { t `Please note that these repositories are not filtered by permissions. Upload may fail without the right permissions.` } </ >
234
- ) }
235
-
244
+ < div style = { { lineHeight : '1em' } } > </ div >
245
+
246
+ { featureFlags . display_repositories ? (
247
+ < >
248
+ < Radio
249
+ id = 'radio-staging'
250
+ isChecked = { onlyStaging }
251
+ label = { t `Staging Repos` }
252
+ name = 'radio-staging'
253
+ onChange = { ( ) =>
254
+ this . setState ( { onlyStaging : true } , ( ) => this . loadAllRepos ( ) )
255
+ }
256
+ />
257
+ < Radio
258
+ id = 'radio-all'
259
+ isChecked = { ! onlyStaging }
260
+ label = { t `All Repos` }
261
+ name = 'radio-all'
262
+ onChange = { ( ) =>
263
+ this . setState ( { onlyStaging : false } , ( ) => this . loadAllRepos ( ) )
264
+ }
265
+ />
266
+ </ >
267
+ ) : null }
268
+
269
+ { ! onlyStaging && (
270
+ < > { t `Please note that these repositories are not filtered by permissions. Upload may fail without the right permissions.` } </ >
271
+ ) }
272
+
273
+ { hideSelector ? (
274
+ < Flex >
275
+ < FlexItem >
276
+ < b > { t `Repository` } </ b >
277
+ </ FlexItem >
278
+ < FlexItem >
279
+ < LabelGroup >
280
+ < Label > { selectedRepos [ 0 ] . name } </ Label >
281
+ </ LabelGroup >
282
+ </ FlexItem >
283
+ </ Flex >
284
+ ) : (
236
285
< MultipleRepoSelector
237
286
addAlert = { ( a ) => this . addAlertObj ( a ) }
238
287
params = { {
239
288
pulp_label_select : onlyStaging ? 'pipeline=staging' : '!pipeline' ,
240
289
} }
241
290
singleSelectionOnly = { true }
242
- selectedRepos = { this . state . selectedRepos }
291
+ selectedRepos = { selectedRepos }
243
292
setSelectedRepos = { ( selectedRepos ) =>
244
293
this . setState ( {
245
294
selectedRepos,
@@ -248,7 +297,7 @@ export class ImportModal extends React.Component<IProps, IState> {
248
297
} )
249
298
}
250
299
/>
251
- </ >
300
+ ) }
252
301
</ Modal >
253
302
) ;
254
303
}
0 commit comments