Skip to content

Commit 0e0054b

Browse files
himdelpatchback[bot]
authored andcommitted
Fix version modal - load data on pagination (#3648)
Follows #3595 the version selector modal still operates under the assumption that collections contains all the versions, not just the first page making the modal query the api on pagination, have a loading spinner, default page size to 10, not 20 to match the loadCollections request No-Issue (cherry picked from commit 8e99d29)
1 parent 99c257d commit 0e0054b

File tree

2 files changed

+50
-27
lines changed

2 files changed

+50
-27
lines changed

src/components/headers/collection-header.tsx

+48-27
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
Select,
1212
SelectOption,
1313
SelectVariant,
14+
Spinner,
1415
Text,
1516
} from '@patternfly/react-core';
1617
import { ExternalLinkAltIcon } from '@patternfly/react-icons';
@@ -20,6 +21,7 @@ import { Navigate } from 'react-router-dom';
2021
import {
2122
CertificateUploadAPI,
2223
CollectionAPI,
24+
CollectionVersionAPI,
2325
CollectionVersionContentType,
2426
CollectionVersionSearch,
2527
MyNamespaceAPI,
@@ -81,9 +83,10 @@ interface IState {
8183
isOpenVersionsModal: boolean;
8284
isOpenSignModal: boolean;
8385
isOpenSignAllModal: boolean;
86+
modalCollections: CollectionVersionSearch[];
8487
modalPagination: {
8588
page: number;
86-
pageSize: number;
89+
page_size: number;
8790
};
8891
deleteCollection: CollectionVersionSearch;
8992
collectionVersion: string | null;
@@ -111,9 +114,10 @@ export class CollectionHeader extends React.Component<IProps, IState> {
111114
isOpenVersionsModal: false,
112115
isOpenSignModal: false,
113116
isOpenSignAllModal: false,
117+
modalCollections: null,
114118
modalPagination: {
115119
page: 1,
116-
pageSize: Constants.DEFAULT_PAGINATION_OPTIONS[1],
120+
page_size: Constants.DEFAULT_PAGINATION_OPTIONS[0],
117121
},
118122
deleteCollection: null,
119123
collectionVersion: null,
@@ -141,6 +145,14 @@ export class CollectionHeader extends React.Component<IProps, IState> {
141145
}).then(({ data }) => {
142146
this.setState({ namespace: data });
143147
});
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+
}
144156
}
145157

146158
render() {
@@ -157,6 +169,7 @@ export class CollectionHeader extends React.Component<IProps, IState> {
157169
} = this.props;
158170

159171
const {
172+
modalCollections,
160173
modalPagination,
161174
isOpenVersionsModal,
162175
isOpenVersionsSelect,
@@ -328,16 +341,13 @@ export class CollectionHeader extends React.Component<IProps, IState> {
328341
<Text>{t`${collectionName}'s versions.`}</Text>
329342
<Pagination
330343
isTop
331-
params={{
332-
page: modalPagination.page,
333-
page_size: modalPagination.pageSize,
334-
}}
344+
params={modalPagination}
335345
updateParams={this.updatePaginationParams}
336346
count={collectionsCount}
337347
/>
338348
</div>
339-
{this.paginateVersions(collections).map(
340-
({ collection_version }, i) => (
349+
{modalCollections ? (
350+
modalCollections.map(({ collection_version }, i) => (
341351
<ListItem key={i}>
342352
<Button
343353
variant='link'
@@ -357,14 +367,13 @@ export class CollectionHeader extends React.Component<IProps, IState> {
357367
</Button>{' '}
358368
{t`updated ${isLatestVersion(collection_version)}`}
359369
</ListItem>
360-
),
370+
))
371+
) : (
372+
<Spinner />
361373
)}
362374
</List>
363375
<Pagination
364-
params={{
365-
page: modalPagination.page,
366-
page_size: modalPagination.pageSize,
367-
}}
376+
params={modalPagination}
368377
updateParams={this.updatePaginationParams}
369378
count={collectionsCount}
370379
/>
@@ -675,21 +684,33 @@ export class CollectionHeader extends React.Component<IProps, IState> {
675684
});
676685
}
677686

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-
686687
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+
);
693714
};
694715

695716
private signCollection = () => {

src/containers/collection-detail/base.ts

+2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ export function loadCollection({
8484
.then(({ data: { results } }) => results[0])
8585
.catch(() => navigate(formatPath(Paths.notFound)));
8686

87+
// Note: this only provides the first page - containing the latest version, and all items for the version *selector*,
88+
// but the version *modal* is using a separate call, in CollectionHeader updatePaginationParams
8789
const versions = CollectionVersionAPI.list({
8890
...requestParams,
8991
order_by: '-version',

0 commit comments

Comments
 (0)