Skip to content

Commit

Permalink
fix collections versions list api
Browse files Browse the repository at this point in the history
  • Loading branch information
himdel committed Oct 24, 2024
1 parent 4a841f8 commit f6b840b
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 78 deletions.
19 changes: 1 addition & 18 deletions src/actions/ansible-repository-collection-version-add.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,24 +94,7 @@ const AddCollectionVersionModal = ({
};

// @ts-expect-error: TS2525: Initializer provides no value for this binding element and the binding element has no default value.
const query = ({ params } = {}) => {
const newParams = { ...params };
newParams.ordering = newParams.sort;
delete newParams.sort;

return CollectionVersionAPI.list({
...newParams,
}).then(
({
data: {
meta: { count },
data: results,
},
}) => ({
data: { count, results },
}),
);
};
const query = ({ params } = {}) => CollectionVersionAPI.list(params);

const [modalState, setModalState] = useState({});

Expand Down
8 changes: 4 additions & 4 deletions src/api/collection-version.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { PulpAPI } from './pulp';

const base = new PulpAPI();
base.sortParam = 'order_by'; // FIXME

// FIXME HubAPI
export const CollectionVersionAPI = {
copy: (
namespace: string,
Expand All @@ -12,6 +10,7 @@ export const CollectionVersionAPI = {
source_base_path: string,
destination_base_path: string,
) =>
// FIXME HubAPI
base.http.post(
`v3/collections/${namespace}/${name}/versions/${version}/copy/${source_base_path}/${destination_base_path}/`,
{},
Expand All @@ -21,13 +20,13 @@ export const CollectionVersionAPI = {
base.http.get(`content/ansible/collection_versions/${id}/`),

getUsedDependenciesByCollection: (namespace, collection, params = {}) =>
// FIXME HubAPI
base.list(
`v3/plugin/ansible/search/collection-versions/?dependency=${namespace}.${collection}`,
params,
),

list: (params?) =>
base.list(`v3/plugin/ansible/search/collection-versions/`, params),
list: (params?) => base.list(`content/ansible/collection_versions/`, params),

move: (
namespace: string,
Expand All @@ -36,6 +35,7 @@ export const CollectionVersionAPI = {
source_base_path: string,
destination_base_path: string,
) =>
// FIXME HubAPI
base.http.post(
`v3/collections/${namespace}/${name}/versions/${version}/move/${source_base_path}/${destination_base_path}/`,
{},
Expand Down
4 changes: 3 additions & 1 deletion src/api/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export const CollectionAPI = {
),

getContent: (namespace, name, version) =>
base.list(`pulp/api/v3/content/ansible/collection_versions/`, {
// pulp
base.list(`content/ansible/collection_versions/`, {
namespace,
name,
version,
Expand Down Expand Up @@ -77,6 +78,7 @@ export const CollectionAPI = {
}: CollectionVersionSearch): Promise<{ data: { task: string } }> =>
repositoryBasePath(repository.name, repository.pulp_href).then(
(distroBasePath) =>
// FIXME content/ansible/collection_deprecations/...
base.http.patch(
`v3/plugin/ansible/content/${distroBasePath}/collections/index/${namespace}/${name}/`,
{
Expand Down
4 changes: 2 additions & 2 deletions src/components/collection-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -653,8 +653,8 @@ export const CollectionHeader = ({
...modalPagination,
})
.then(({ data }) => data)
.catch(() => ({ data: [] }))
.then(({ data: modalCollections }) =>
.catch(() => ({ results: [] }))
.then(({ results: modalCollections }) =>
setModalCollections(modalCollections),
);
}
Expand Down
25 changes: 9 additions & 16 deletions src/components/multi-repo-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,15 @@ export const MultiRepoModal = ({
page_size: 100,
...(pipeline ? { repository_label: pipeline } : {}),
})
.then(
({
data: {
data,
meta: { count },
},
}) => {
setDisabledRepos(data.map(({ repository: { name } }) => name));
if (count > 100) {
addAlert({
variant: 'warning',
title: t`The collection exists in too many repositories. Some repositories may not be disabled and preselected correctly.`,
});
}
},
)
.then(({ data: { results: data, count } }) => {
setDisabledRepos(data.map(({ repository: { name } }) => name));
if (count > 100) {
addAlert({
variant: 'warning',
title: t`The collection exists in too many repositories. Some repositories may not be disabled and preselected correctly.`,
});
}
})
.catch(() =>
addAlert({
variant: 'danger',
Expand Down
13 changes: 3 additions & 10 deletions src/containers/ansible-repository/tab-collection-versions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,9 @@ export const CollectionVersionsTab = ({
return CollectionVersionAPI.list({
repository,
...newParams,
}).then(
({
data: {
meta: { count },
data: results,
},
}) => ({
data: { count, results },
}),
);
}).then(({ data: { count, results } }) => ({
data: { count, results },
}));
};

const [modalState, setModalState] = useState({ repository: item });
Expand Down
6 changes: 3 additions & 3 deletions src/containers/approvals/approvals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ class Approvals extends Component<RouteProps, IState> {
repository: parsePulpIDFromURL(repositories.rejected.pulp_href),
version,
})
.then((result) => !!result.data.meta.count)
.then((result) => !!result.data.count)
.catch(() => false);
}

Expand All @@ -587,8 +587,8 @@ class Approvals extends Component<RouteProps, IState> {
return CollectionVersionAPI.list(updatedParams)
.then((result) => {
this.setState({
versions: result.data.data,
itemCount: result.data.meta.count,
versions: result.data.results,
itemCount: result.data.count,
});
if (handleLoading) {
this.setState({
Expand Down
11 changes: 4 additions & 7 deletions src/containers/collection-detail/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ export function loadCollection({
const currentVersion = (
version
? CollectionVersionAPI.list({ ...requestParams, version })
: CollectionVersionAPI.list({ ...requestParams, is_highest: true })
).then(({ data }) => data.data[0]);
: CollectionVersionAPI.list({ ...requestParams /* is_highest: true */ })
).then(({ data }) => data.results[0]);

const content = currentVersion
.then((collection) =>
Expand All @@ -97,7 +97,7 @@ export function loadCollection({
page_size: 10,
})
.then(({ data }) => data)
.catch(() => ({ data: [], meta: { count: 0 } }));
.catch(() => ({ results: [], count: 0 }));

const actuallyCollection = repositoryBasePath(repo)
.then((basePath) => CollectionAPI.getDetail(basePath, namespace, name))
Expand All @@ -110,10 +110,7 @@ export function loadCollection({
actuallyCollection,
]).then(
([
{
data: collections,
meta: { count: collectionsCount },
},
{ results: collections, count: collectionsCount },
collection,
content,
actuallyCollection,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ class CollectionDependencies extends Component<RouteProps, IState> {
page_size: 1,
})
.then((result) => {
const [collection] = result.data.data;
const [collection] = result.data.results;

dependency_repo.repo = collection.repository.name;
dependency_repo.path = formatPath(Paths.ansible.collection.detail, {
Expand Down
4 changes: 2 additions & 2 deletions src/containers/my-imports/my-imports.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,9 @@ class MyImports extends Component<RouteProps, IState> {
version,
})
.then((result) => {
if (result.data.meta.count === 1) {
if (result.data.count === 1) {
this.setState({
collection: result.data.data[0],
collection: result.data.results[0],
});
}
})
Expand Down
12 changes: 5 additions & 7 deletions src/containers/namespace-detail/namespace-detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -766,9 +766,9 @@ export class NamespaceDetail extends Component<RouteProps, IState> {
private loadAllCollections(params) {
return CollectionVersionAPI.list({
...params,
is_highest: true,
//is_highest: true,
namespace: this.props.routeParams.namespace,
repository_label: '!hide_from_search',
//repository_label: '!hide_from_search',
});
}

Expand All @@ -777,8 +777,8 @@ export class NamespaceDetail extends Component<RouteProps, IState> {
ParamHelper.getReduced(this.state.params, ['tab', 'group', 'user']),
).then((result) => {
this.setState({
collections: result.data.data,
filteredCount: result.data.meta.count,
collections: result.data.results,
filteredCount: result.data.count,
});
});
}
Expand Down Expand Up @@ -806,9 +806,7 @@ export class NamespaceDetail extends Component<RouteProps, IState> {
([
_collections,
{
data: {
meta: { count: unfilteredCount },
},
data: { count: unfilteredCount },
},
{ data: namespace },
//myNamespace,
Expand Down
4 changes: 2 additions & 2 deletions src/containers/search/multi-search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ const MultiSearch = (props: RouteProps) => {
const shared = { page_size: 10 };

setCollections(loading);
CollectionVersionAPI.list({ ...shared, keywords, is_highest: true })
.then(({ data: { data } }) => setCollections(data || []))
CollectionVersionAPI.list({ ...shared, keywords /* is_highest: true */ })
.then(({ data: { results } }) => setCollections(results || []))
.catch(
handleHttpError(
t`Failed to search collections (${keywords})`,
Expand Down
10 changes: 5 additions & 5 deletions src/containers/search/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -476,13 +476,13 @@ class Search extends Component<RouteProps, IState> {
this.setState({ loading: true }, () => {
CollectionVersionAPI.list({
...ParamHelper.getReduced(this.state.params, ['view_type']),
is_deprecated: false,
repository_label: '!hide_from_search',
is_highest: true,
//is_deprecated: false,
//repository_label: '!hide_from_search',
//is_highest: true,
}).then((result) => {
this.setState({
collections: result.data.data,
count: result.data.meta.count,
collections: result.data.results,
count: result.data.count,
loading: false,
});
});
Expand Down

0 comments on commit f6b840b

Please sign in to comment.