Skip to content

Commit

Permalink
add collectionversionsearch
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaiahWren committed Jul 17, 2023
1 parent df9c030 commit 0a249fd
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 12 deletions.
94 changes: 94 additions & 0 deletions frontend/hub/collections/hooks/useCollectionVersionColumns.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { Label } from '@patternfly/react-core';
import {
AnsibleTowerIcon,
CheckCircleIcon,
ExclamationTriangleIcon,
} from '@patternfly/react-icons';
import { useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { ITableColumn, TextCell } from '../../../../framework';
import { RouteObj } from '../../../Routes';
import { CollectionVersionSearch } from '../CollectionVersionSearch';

export function useCollectionVersionColumns(_options?: {
disableSort?: boolean;
disableLinks?: boolean;
}) {
const { t } = useTranslation();
return useMemo<ITableColumn<CollectionVersionSearch>[]>(
() => [
{
header: t('Name'),
value: (collection) => collection.collection_version.name,
cell: (collection) => (
<TextCell
text={collection.collection_version.name}
to={RouteObj.CollectionDetails.replace(':id', collection.collection_version.name)}
/>
),
card: 'name',
list: 'name',
icon: () => <AnsibleTowerIcon />,
},
{
header: t('Repository'),
type: 'text',
value: (collection) => collection.repository.name,
},
{
header: t('Namespace'),
type: 'text',
value: (collection) => collection.collection_version.namespace,
},
{
header: t('Description'),
type: 'description',
value: (collection) => collection.collection_version.description,
card: 'description',
list: 'description',
},
{
header: t('Modules'),
type: 'count',
value: (collection) =>
collection.collection_version.contents.filter((c) => c.content_type === 'module').length,
},
{
header: t('Updated'),
type: 'datetime',
value: (collection) => collection.collection_version.pulp_created,
card: 'hidden',
list: 'secondary',
},
{
header: t('Version'),
type: 'text',
value: (collection) => collection.collection_version.version,
card: 'hidden',
list: 'secondary',
},
{
header: t('Signed state'),
cell: (collection) => {
switch (collection.is_signed) {
case true:
return (
<Label icon={<CheckCircleIcon />} variant="outline" color="green">
{t('Signed')}
</Label>
);
case false:
return (
<Label icon={<ExclamationTriangleIcon />} variant="outline" color="orange">
{t('Unsigned')}
</Label>
);
}
},
list: 'secondary',
value: (collection) => collection.is_signed,
},
],
[t]
);
}
18 changes: 6 additions & 12 deletions frontend/hub/namespaces/HubNamespaceDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@ import { useHubView } from '../useHubView';
import { useHubNamespaceActions } from './hooks/useHubNamespaceActions';
import { useHubNamespacesColumns } from './hooks/useHubNamespacesColumns';
import { useCollectionFilters } from '../collections/hooks/useCollectionFilters';
import { useCollectionsActions } from '../collections/hooks/useCollectionsActions';
import { useCollectionColumns } from '../collections/hooks/useCollectionColumns';
import { useCollectionActions } from '../collections/hooks/useCollectionActions';
import { useCollectionVersionColumns } from '../collections/hooks/useCollectionVersionColumns';
import { CollectionVersionSearch } from '../collections/CollectionVersionSearch';
import { hubAPI, idKeyFn } from '../api';

import { hubAPI } from '../api';
import { DropdownPosition } from '@patternfly/react-core';

export function NamespaceDetails() {
Expand Down Expand Up @@ -65,31 +62,28 @@ export function NamespaceDetails() {

function NamespaceDetailsTab(props: { namespace?: HubNamespace }) {
const { namespace } = props;
// eslint-disable-next-line no-console
const tableColumns = useHubNamespacesColumns();
return <PageDetailsFromColumns item={namespace} columns={tableColumns} />;
}

function CollectionsTab(props: { namespace?: HubNamespace }) {
const { t } = useTranslation();
const toolbarFilters = useCollectionFilters();
const tableColumns = useCollectionColumns();
const tableColumns = useCollectionVersionColumns();
const view = useHubView<CollectionVersionSearch>({
url: hubAPI`/_ui/v1/repo/published/`,
keyFn: idKeyFn,
url: hubAPI`/v3/plugin/ansible/search/collection-versions/`,
keyFn: (item) => item.collection_version.pulp_href + ':' + item.repository.name,
tableColumns,
queryParams: { namespace: props?.namespace?.name },
});
const toolbarActions = useCollectionsActions(view.unselectItemsAndRefresh);
const rowActions = useCollectionActions(view.unselectItemsAndRefresh);
const navigate = useNavigate();

return (
<PageLayout>
<PageTable<CollectionVersionSearch>
toolbarFilters={toolbarFilters}
toolbarActions={toolbarActions}
tableColumns={tableColumns}
rowActions={rowActions}
errorStateTitle={t('Error loading collections')}
emptyStateTitle={t('No collections yet')}
emptyStateDescription={t('To get started, upload a collection.')}
Expand Down

0 comments on commit 0a249fd

Please sign in to comment.