@@ -11,6 +11,7 @@ import {
11
11
Select ,
12
12
SelectOption ,
13
13
SelectVariant ,
14
+ Spinner ,
14
15
Text ,
15
16
} from '@patternfly/react-core' ;
16
17
import { ExternalLinkAltIcon } from '@patternfly/react-icons' ;
@@ -20,6 +21,7 @@ import { Navigate } from 'react-router-dom';
20
21
import {
21
22
CertificateUploadAPI ,
22
23
CollectionAPI ,
24
+ CollectionVersionAPI ,
23
25
CollectionVersionContentType ,
24
26
CollectionVersionSearch ,
25
27
MyNamespaceAPI ,
@@ -81,9 +83,10 @@ interface IState {
81
83
isOpenVersionsModal : boolean ;
82
84
isOpenSignModal : boolean ;
83
85
isOpenSignAllModal : boolean ;
86
+ modalCollections : CollectionVersionSearch [ ] ;
84
87
modalPagination : {
85
88
page : number ;
86
- pageSize : number ;
89
+ page_size : number ;
87
90
} ;
88
91
deleteCollection : CollectionVersionSearch ;
89
92
collectionVersion : string | null ;
@@ -111,9 +114,10 @@ export class CollectionHeader extends React.Component<IProps, IState> {
111
114
isOpenVersionsModal : false ,
112
115
isOpenSignModal : false ,
113
116
isOpenSignAllModal : false ,
117
+ modalCollections : null ,
114
118
modalPagination : {
115
119
page : 1 ,
116
- pageSize : Constants . DEFAULT_PAGINATION_OPTIONS [ 1 ] ,
120
+ page_size : Constants . DEFAULT_PAGINATION_OPTIONS [ 0 ] ,
117
121
} ,
118
122
deleteCollection : null ,
119
123
collectionVersion : null ,
@@ -141,6 +145,14 @@ export class CollectionHeader extends React.Component<IProps, IState> {
141
145
} ) . then ( ( { data } ) => {
142
146
this . setState ( { namespace : data } ) ;
143
147
} ) ;
148
+
149
+ this . setState ( { modalCollections : this . props . collections } ) ;
150
+ }
151
+
152
+ componentDidUpdate ( prevProps ) {
153
+ if ( this . props . collections !== prevProps . collections ) {
154
+ this . setState ( { modalCollections : this . props . collections } ) ;
155
+ }
144
156
}
145
157
146
158
render ( ) {
@@ -157,6 +169,7 @@ export class CollectionHeader extends React.Component<IProps, IState> {
157
169
} = this . props ;
158
170
159
171
const {
172
+ modalCollections,
160
173
modalPagination,
161
174
isOpenVersionsModal,
162
175
isOpenVersionsSelect,
@@ -328,16 +341,13 @@ export class CollectionHeader extends React.Component<IProps, IState> {
328
341
< Text > { t `${ collectionName } 's versions.` } </ Text >
329
342
< Pagination
330
343
isTop
331
- params = { {
332
- page : modalPagination . page ,
333
- page_size : modalPagination . pageSize ,
334
- } }
344
+ params = { modalPagination }
335
345
updateParams = { this . updatePaginationParams }
336
346
count = { collectionsCount }
337
347
/>
338
348
</ div >
339
- { this . paginateVersions ( collections ) . map (
340
- ( { collection_version } , i ) => (
349
+ { modalCollections ? (
350
+ modalCollections . map ( ( { collection_version } , i ) => (
341
351
< ListItem key = { i } >
342
352
< Button
343
353
variant = 'link'
@@ -357,14 +367,13 @@ export class CollectionHeader extends React.Component<IProps, IState> {
357
367
</ Button > { ' ' }
358
368
{ t `updated ${ isLatestVersion ( collection_version ) } ` }
359
369
</ ListItem >
360
- ) ,
370
+ ) )
371
+ ) : (
372
+ < Spinner />
361
373
) }
362
374
</ List >
363
375
< Pagination
364
- params = { {
365
- page : modalPagination . page ,
366
- page_size : modalPagination . pageSize ,
367
- } }
376
+ params = { modalPagination }
368
377
updateParams = { this . updatePaginationParams }
369
378
count = { collectionsCount }
370
379
/>
@@ -675,21 +684,33 @@ export class CollectionHeader extends React.Component<IProps, IState> {
675
684
} ) ;
676
685
}
677
686
678
- private paginateVersions ( versions ) {
679
- const { modalPagination } = this . state ;
680
- return versions . slice (
681
- modalPagination . pageSize * ( modalPagination . page - 1 ) ,
682
- modalPagination . pageSize * modalPagination . page ,
683
- ) ;
684
- }
685
-
686
687
private updatePaginationParams = ( { page, page_size } ) => {
687
- this . setState ( {
688
- modalPagination : {
689
- page : page ,
690
- pageSize : page_size ,
691
- } ,
692
- } ) ;
688
+ const modalPagination = {
689
+ page,
690
+ page_size,
691
+ } ;
692
+
693
+ this . setState ( { modalPagination, modalCollections : null } ) ;
694
+
695
+ const { namespace, name } = this . props . collection . collection_version ;
696
+ const repository = this . props . collection . repository ;
697
+ const requestParams = {
698
+ ...( repository ? { repository_name : repository . name } : { } ) ,
699
+ namespace,
700
+ name,
701
+ } ;
702
+
703
+ // loadCollections provides initial data, pagination needs extra requests
704
+ CollectionVersionAPI . list ( {
705
+ ...requestParams ,
706
+ order_by : '-version' ,
707
+ ...modalPagination ,
708
+ } )
709
+ . then ( ( { data } ) => data )
710
+ . catch ( ( ) => ( { data : [ ] } ) )
711
+ . then ( ( { data : modalCollections } ) =>
712
+ this . setState ( { modalCollections } ) ,
713
+ ) ;
693
714
} ;
694
715
695
716
private signCollection = ( ) => {
0 commit comments