1
- import { t } from '@lingui/macro' ;
2
- import { Button , Modal , Radio } from '@patternfly/react-core' ;
1
+ import { plural , t } from '@lingui/macro' ;
2
+ import { Button , Checkbox , Modal } from '@patternfly/react-core' ;
3
3
import React , { useState } from 'react' ;
4
4
import {
5
5
AnsibleRepositoryAPI ,
@@ -8,29 +8,44 @@ import {
8
8
} from 'src/api' ;
9
9
import { AlertList , AlertType , DetailList , closeAlert } from 'src/components' ;
10
10
import { canEditAnsibleRepository } from 'src/permissions' ;
11
- import { handleHttpError , parsePulpIDFromURL , taskAlert } from 'src/utilities' ;
11
+ import {
12
+ RepositoriesUtils ,
13
+ handleHttpError ,
14
+ parsePulpIDFromURL ,
15
+ taskAlert ,
16
+ } from 'src/utilities' ;
12
17
import { Action } from './action' ;
13
18
14
19
const add = (
15
20
{ repositoryHref, repositoryName } ,
16
- { namespace , name , version , pulp_href : collectionVersionHref } ,
21
+ collections ,
17
22
{ addAlert, setState, query } ,
18
23
) => {
19
24
const pulpId = parsePulpIDFromURL ( repositoryHref ) ;
20
- return AnsibleRepositoryAPI . addContent ( pulpId , collectionVersionHref )
25
+ const collectionVersionHrefs = collections . map (
26
+ ( c ) => c . collection_version . pulp_href ,
27
+ ) ;
28
+ return AnsibleRepositoryAPI . addContent ( pulpId , collectionVersionHrefs )
21
29
. then ( ( { data } ) => {
22
- addAlert (
23
- taskAlert (
24
- data . task ,
25
- t `Started adding ${ namespace } .${ name } v${ version } to repository "${ repositoryName } ".` ,
26
- ) ,
30
+ collections . map (
31
+ ( { collection_version : { name, namespace, version } , repository } ) => {
32
+ addAlert (
33
+ taskAlert (
34
+ data . task ,
35
+ t `Started adding ${ namespace } .${ name } v${ version } from "${ repository . name } " to repository "${ repositoryName } ".` ,
36
+ ) ,
37
+ ) ;
38
+ setState ( ( ms ) => ( { ...ms , addCollectionVersionModal : null } ) ) ;
39
+ query ( { } ) ;
40
+ } ,
27
41
) ;
28
- setState ( ( ms ) => ( { ...ms , addCollectionVersionModal : null } ) ) ;
29
- query ( { } ) ;
30
42
} )
31
43
. catch (
32
44
handleHttpError (
33
- t `Failed to add ${ namespace } .${ name } v${ version } to repository "${ repositoryName } ".` ,
45
+ plural ( collections . length , {
46
+ one : `Failed to add collection to repository "${ repositoryName } ".` ,
47
+ other : `Failed to add collections to repository "${ repositoryName } ".` ,
48
+ } ) ,
34
49
( ) => setState ( ( ms ) => ( { ...ms , addCollectionVersionModal : null } ) ) ,
35
50
addAlert ,
36
51
) ,
@@ -45,7 +60,7 @@ const AddCollectionVersionModal = ({
45
60
closeAction : ( ) => void ;
46
61
} ) => {
47
62
const [ alerts , setAlerts ] = useState ( [ ] ) ;
48
- const [ selected , setSelected ] = useState ( null ) ;
63
+ const [ selected , setSelected ] = useState < CollectionVersionSearch [ ] > ( [ ] ) ;
49
64
50
65
const addAlert = ( alert : AlertType ) => {
51
66
setAlerts ( [ ...alerts , alert ] ) ;
@@ -75,22 +90,31 @@ const AddCollectionVersionModal = ({
75
90
const renderTableRow = ( item : CollectionVersionSearch , index : number ) => {
76
91
const {
77
92
collection_version : { name, namespace, version, description } ,
93
+ repository,
78
94
} = item ;
79
95
80
96
return (
81
- < tr onClick = { ( ) => setSelected ( item ) } key = { index } >
97
+ < tr
98
+ onClick = { ( ) =>
99
+ setSelected (
100
+ RepositoriesUtils . pushToOrFilterOutCollections ( item , selected ) ,
101
+ )
102
+ }
103
+ key = { index }
104
+ >
82
105
< td >
83
- < Radio
106
+ < Checkbox
84
107
aria-label = { `${ namespace } .${ name } v${ version } ` }
85
108
id = { `collection-${ index } ` }
86
- isChecked = { selected === item }
109
+ isChecked = { selected . includes ( item ) }
87
110
name = { `collection-${ index } ` }
88
111
/>
89
112
</ td >
90
113
< td >
91
114
{ namespace } .{ name } v{ version }
92
115
</ td >
93
116
< td > { description } </ td >
117
+ < td > { repository . name } </ td >
94
118
</ tr >
95
119
) ;
96
120
} ;
@@ -138,6 +162,10 @@ const AddCollectionVersionModal = ({
138
162
id : 'namespace' ,
139
163
title : t `Namespace` ,
140
164
} ,
165
+ {
166
+ id : 'repository_name' ,
167
+ title : t `Repository` ,
168
+ } ,
141
169
] }
142
170
noDataDescription = { t `Collection versions will appear once a collection is uploaded.` }
143
171
noDataTitle = { t `No collection versions yet` }
@@ -159,6 +187,11 @@ const AddCollectionVersionModal = ({
159
187
type : 'none' ,
160
188
id : 'col2' ,
161
189
} ,
190
+ {
191
+ title : t `Repository` ,
192
+ type : 'none' ,
193
+ id : 'col3' ,
194
+ } ,
162
195
] }
163
196
title = { t `Collection versions` }
164
197
/>
@@ -178,13 +211,13 @@ export const ansibleRepositoryCollectionVersionAddAction = Action({
178
211
modal : ( { addAlert, state, setState, query } ) =>
179
212
state . addCollectionVersionModal ? (
180
213
< AddCollectionVersionModal
181
- addAction = { ( collection ) =>
182
- add ( state . addCollectionVersionModal , collection . collection_version , {
214
+ addAction = { ( collections : CollectionVersionSearch [ ] ) => {
215
+ add ( state . addCollectionVersionModal , collections , {
183
216
addAlert,
184
217
setState,
185
218
query,
186
- } )
187
- }
219
+ } ) ;
220
+ } }
188
221
closeAction = { ( ) =>
189
222
setState ( ( ms ) => ( { ...ms , addCollectionVersionModal : null } ) )
190
223
}
0 commit comments