Skip to content

Commit

Permalink
RPM list (#72)
Browse files Browse the repository at this point in the history
* fix collection detail vs list path mixup

* RPM: create a package list screen

LazyRPMRepository - show repo in package list
  • Loading branch information
himdel authored Oct 7, 2024
1 parent 105e1ca commit 60a2ce9
Show file tree
Hide file tree
Showing 12 changed files with 220 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ export {
} from './response-types/user';
export { WriteOnlyFieldType } from './response-types/write-only-field';
export { RoleAPI } from './role';
export { RPMPackageAPI } from './rpm-package';
export { RPMRepositoryAPI } from './rpm-repository';
export { SettingsAPI } from './settings';
export { SignCollectionAPI } from './sign-collections';
export { SignContainersAPI } from './sign-containers';
Expand Down
9 changes: 9 additions & 0 deletions src/api/rpm-package.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { PulpAPI } from './pulp';

class API extends PulpAPI {
apiPath = 'content/rpm/packages/';

// list(params?)
}

export const RPMPackageAPI = new API();
9 changes: 9 additions & 0 deletions src/api/rpm-repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { PulpAPI } from './pulp';

class API extends PulpAPI {
apiPath = 'repositories/rpm/rpm/';

// list(params?)
}

export const RPMRepositoryAPI = new API();
5 changes: 3 additions & 2 deletions src/app-routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
NotFound,
Partners,
PulpStatus,
RPMPackageList,
RoleCreate,
RoleList,
Search,
Expand Down Expand Up @@ -189,13 +190,13 @@ export class AppRoutes extends Component {
path: Paths.ansible.collection.dependencies,
},
{ component: CollectionDetail, path: Paths.ansible.collection.detail },
{ component: Search, path: Paths.ansible.collection.detail },
{ component: Search, path: Paths.ansible.collection.list },
{ component: MyImports, path: Paths.ansible.imports },
{ component: NamespaceDetail, path: Paths.ansible.namespace.detail },
{ component: Search, path: Paths.ansible.collection.detail },
{ component: PulpStatus, path: Paths.core.status, noAuth: true },
{ component: MultiSearch, path: Paths.meta.search },
{ component: AboutProject, path: Paths.meta.about, noAuth: true },
{ component: RPMPackageList, path: Paths.rpm.package.list },
];
}

Expand Down
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export { ImportModal } from './import-modal';
export { LanguageSwitcher } from './language-switcher';
export { LazyDistributions } from './lazy-distributions';
export { LazyRepositories } from './lazy-repositories';
export { LazyRPMRepository } from './lazy-rpm-repository';
export { LinkTabs, type LinkTabsProps } from './link-tabs';
export { ListItemActions } from './list-item-actions';
export {
Expand Down
106 changes: 106 additions & 0 deletions src/components/lazy-rpm-repository.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import { t } from '@lingui/macro';
import { Button } from '@patternfly/react-core';
import ExclamationCircleIcon from '@patternfly/react-icons/dist/esm/icons/exclamation-circle-icon';
import React, { useEffect, useState } from 'react';
// import { Link } from 'react-router-dom';
import { RPMRepositoryAPI } from 'src/api';
import { Spinner, Tooltip } from 'src/components';
// import { Paths, formatPath } from 'src/paths';
import { errorMessage } from 'src/utilities';

// FIXME: merge with LazyRepositories, parametrize api, query, link
export const LazyRPMRepository = ({
content_href,
}: {
content_href: string;
}) => {
const [repositories, setRepositories] = useState([]);
const [count, setCount] = useState(null);
const [page, setPage] = useState(1);
const [error, setError] = useState(null);
const [loading, setLoading] = useState(true);

const query = (prepend?) => {
RPMRepositoryAPI.list({ with_content: content_href, page, page_size: 10 })
.then(({ data: { count, results } }) => {
setRepositories(prepend ? [...prepend, ...results] : results);
setCount(count);
setError(null);
setLoading(false);
})
.catch((e) => {
const { status, statusText } = e.response;
setRepositories(prepend || []);
setCount(null);
setError(errorMessage(status, statusText));
setLoading(false);
});
};

useEffect(() => {
if (!content_href) {
setRepositories([]);
setCount(null);
setPage(1);
setError(null);
setLoading(false);
return;
}

setRepositories([]);
setCount(null);
setPage(1);
setError(null);
setLoading(true);

query();
}, [content_href]);

// support pagination, but page == 1 is handled above
useEffect(() => {
if (page === 1) {
return;
}

query(repositories);
}, [page]);

const errorElement = error && (
<Tooltip content={t`Failed to load repositories: ${error}`} key='empty'>
<Button variant='plain'>
<ExclamationCircleIcon />
</Button>
</Tooltip>
);

const loadMore = () => {
setPage((page) => page + 1);
};

return loading ? (
<Spinner size='sm' />
) : error ? (
errorElement
) : (
<>
{repositories?.map?.(({ name }, index) => (
<>
{index ? ', ' : ''}
{name}
{/* FIXME: ansible -> rpm
<Link to={formatPath(Paths.ansible.repository.detail, { name })}>
{name}
</Link>
*/}
</>
))}
{!repositories?.length ? '?' : null}
{count > repositories?.length ? (
<>
{' '}
<a onClick={loadMore}>{t`(more)`}</a>
</>
) : null}
</>
);
};
4 changes: 2 additions & 2 deletions src/containers/ansible-repository/detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ const AnsibleRepositoryDetail = PageWithTabs<
collections: (
<Navigate
to={formatPath(
Paths.ansible.collection.detail,
Paths.ansible.collection.list,
{},
{ repository_name: item?.name },
)}
Expand Down Expand Up @@ -181,7 +181,7 @@ const AnsibleRepositoryDetail = PageWithTabs<
title: t`Collections`,
icon: <ArrowRightIcon />,
link: formatPath(
Paths.ansible.collection.detail,
Paths.ansible.collection.list,
{},
{ repository_name: name },
),
Expand Down
1 change: 1 addition & 0 deletions src/containers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export { default as PulpStatus } from './pulp-status';
export { default as RoleCreate } from './role-management/role-create';
export { default as EditRole } from './role-management/role-edit';
export { default as RoleList } from './role-management/role-list';
export { default as RPMPackageList } from './rpm/package-list';
export { default as MultiSearch } from './search/multi-search';
export { default as Search } from './search/search';
export { default as UserProfile } from './settings/user-profile';
Expand Down
77 changes: 77 additions & 0 deletions src/containers/rpm/package-list.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { msg, t } from '@lingui/macro';
import { Td, Tr } from '@patternfly/react-table';
import React from 'react';
import { RPMPackageAPI } from 'src/api';
import { LazyRPMRepository, ListItemActions, ListPage } from 'src/components';

interface RPMPackage {
name: string;
version;
arch;
pulp_href;
}

const listItemActions = [];

const RPMPackageList = ListPage<RPMPackage>({
defaultPageSize: 10,
defaultSort: '-name',
displayName: 'RPMPackageList',
errorTitle: msg`Packages could not be displayed.`,
filterConfig: (_) => [
{
id: 'name__contains',
title: t`Package name`,
},
],
headerActions: [],
listItemActions,
noDataDescription: msg`Packages will appear once created.`,
noDataTitle: msg`No packages yet`,
query: ({ params }) => RPMPackageAPI.list(params),
renderTableRow(item: RPMPackage, index: number, _actionContext) {
const { name, version, arch, pulp_href } = item;

// TODO download rpm
const kebabItems = []; /* listItemActions.map((action) =>
action.dropdownItem({ ...item, id }, actionContext),
); */

return (
<Tr key={index}>
<Td>{name}</Td>
<Td>{version}</Td>
<Td>{arch}</Td>
<Td>
<LazyRPMRepository content_href={pulp_href} />
</Td>
<ListItemActions kebabItems={kebabItems} />
</Tr>
);
},
sortHeaders: [
{
title: msg`Package name`,
type: 'alpha',
id: 'name',
},
{
title: msg`Version`,
type: 'none',
id: 'version',
},
{
title: msg`Arch`,
type: 'none',
id: 'arch',
},
{
title: msg`Repository`,
type: 'none',
id: 'repository',
},
],
title: msg`Packages`,
});

export default RPMPackageList;
4 changes: 2 additions & 2 deletions src/containers/search/multi-search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,12 @@ const MultiSearch = (props: RouteProps) => {
title={t`Collections`}
showAllLink={
<Link
to={formatPath(Paths.ansible.collection.detail)}
to={formatPath(Paths.ansible.collection.list)}
>{t`Show all collections`}</Link>
}
showMoreLink={
<Link
to={formatPath(Paths.ansible.collection.detail, {}, { keywords })}
to={formatPath(Paths.ansible.collection.list, {}, { keywords })}
>{t`Show more collections`}</Link>
}
>
Expand Down
5 changes: 5 additions & 0 deletions src/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ function standaloneMenu() {
}),
],
),
menuSection('Pulp RPM', { condition: and(loggedIn, hasPlugin('rpm')) }, [
menuItem(t`RPMs`, {
url: formatPath(Paths.rpm.package.list),
}),
]),
menuItem(t`Task Management`, {
url: formatPath(Paths.core.task.list),
alternativeUrls: [altPath(Paths.core.task.detail)],
Expand Down
3 changes: 3 additions & 0 deletions src/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,7 @@ export const Paths = {
not_found: '/not-found', // FIXME: don't redirect
search: '/search',
},
rpm: {
package: { list: '/rpm/rpms' },
},
};

0 comments on commit 60a2ce9

Please sign in to comment.