-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix collection detail vs list path mixup * RPM: create a package list screen LazyRPMRepository - show repo in package list
- Loading branch information
Showing
12 changed files
with
220 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters