Skip to content

Commit

Permalink
community Sync - disable without a requirements file .. on the detail…
Browse files Browse the repository at this point in the history
… screen (#4385)

make it possible to disable the Sync action based on the repository's remote
..only on the detail screen

Issue: AAH-2360
(cherry picked from commit 53130f2)
  • Loading branch information
himdel authored and patchback[bot] committed Oct 10, 2023
1 parent 56dab62 commit 05fd635
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 41 deletions.
1 change: 1 addition & 0 deletions CHANGES/2360.bug
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
community Sync - disable without a requirements file .. on the detail screen
18 changes: 6 additions & 12 deletions src/actions/action.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
import { MessageDescriptor, i18n } from '@lingui/core';
import { Button, DropdownItem } from '@patternfly/react-core';
import React from 'react';
import React, { ReactNode } from 'react';
import { Tooltip } from 'src/components';
import { type PermissionContextType } from 'src/permissions';

type ModalType = ({
addAlert,
listQuery,
query,
setState,
state,
}) => React.ReactNode;
type ModalType = ({ addAlert, listQuery, query, setState, state }) => ReactNode;

interface ActionParams {
buttonVariant?: 'primary' | 'secondary';
condition?: PermissionContextType;
disabled?: (item, actionContext) => string | null;
disabled?: (item, actionContext) => string | ReactNode | null;
modal?: ModalType;
onClick: (item, actionContext) => void;
title: MessageDescriptor;
visible?: (item, actionContext) => boolean;
}

export class ActionType {
button: (item, actionContext) => React.ReactNode | null;
disabled: (item, actionContext) => string | null;
dropdownItem: (item, actionContext) => React.ReactNode | null;
button: (item, actionContext) => ReactNode | null;
disabled: (item, actionContext) => string | ReactNode | null;
dropdownItem: (item, actionContext) => ReactNode | null;
modal?: ModalType;
title: string;
visible: (item, actionContext) => boolean;
Expand Down
21 changes: 20 additions & 1 deletion src/actions/ansible-repository-sync.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { msg, t } from '@lingui/macro';
import { Trans, msg, t } from '@lingui/macro';
import {
Button,
FormGroup,
Expand All @@ -7,8 +7,10 @@ import {
Switch,
} from '@patternfly/react-core';
import React, { useEffect, useState } from 'react';
import { Link } from 'react-router-dom';
import { AnsibleRepositoryAPI } from 'src/api';
import { HelperText } from 'src/components';
import { Paths, formatPath } from 'src/paths';
import { canSyncAnsibleRepository } from 'src/permissions';
import { handleHttpError, parsePulpIDFromURL, taskAlert } from 'src/utilities';
import { Action } from './action';
Expand Down Expand Up @@ -132,6 +134,23 @@ export const ansibleRepositorySyncAction = Action({
return t`Sync task is already queued.`;
}

// only available on detail screen; list will have remote: string, so no .url
if (
remote &&
remote.url === 'https://galaxy.ansible.com/api/' &&
!remote.requirements_file
) {
const name = remote.name;
const url = formatPath(Paths.ansibleRemoteEdit, { name });

return (
<Trans>
YAML requirements are required to sync from Galaxy - you can{' '}
<Link to={url}>edit the {name} remote</Link> to add requirements.
</Trans>
);
}

return null;
},
});
Expand Down
6 changes: 3 additions & 3 deletions src/components/patternfly-wrappers/tooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Tooltip as PFTooltip } from '@patternfly/react-core';
import React from 'react';
import React, { ReactNode } from 'react';

interface IProps {
children: React.ReactNode;
content: string;
children: ReactNode;
content: string | ReactNode;
}

export const Tooltip = ({ content, children }: IProps) => (
Expand Down
19 changes: 16 additions & 3 deletions src/containers/ansible-repository/detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import {
ansibleRepositoryEditAction,
ansibleRepositorySyncAction,
} from 'src/actions';
import { AnsibleRepositoryAPI, AnsibleRepositoryType } from 'src/api';
import {
AnsibleRemoteAPI,
AnsibleRemoteType,
AnsibleRepositoryAPI,
AnsibleRepositoryType,
} from 'src/api';
import { PageWithTabs } from 'src/components';
import { Paths, formatPath } from 'src/paths';
import { canViewAnsibleRepositories } from 'src/permissions';
Expand All @@ -24,7 +29,9 @@ const tabs = [
{ id: 'repository-versions', name: msg`Versions` },
];

const AnsibleRepositoryDetail = PageWithTabs<AnsibleRepositoryType>({
const AnsibleRepositoryDetail = PageWithTabs<
AnsibleRepositoryType & { remote?: AnsibleRemoteType }
>({
breadcrumbs: ({ name, tab, params: { repositoryVersion, group } }) =>
[
{ url: formatPath(Paths.ansibleRepositories), name: t`Repositories` },
Expand Down Expand Up @@ -89,10 +96,16 @@ const AnsibleRepositoryDetail = PageWithTabs<AnsibleRepositoryType>({
)
.then(({ data: { permissions } }) => permissions)
.catch(err([])),
]).then(([distroBasePath, my_permissions]) => ({
repository.remote
? AnsibleRemoteAPI.get(parsePulpIDFromURL(repository.remote))
.then(({ data }) => data)
.catch(() => null)
: null,
]).then(([distroBasePath, my_permissions, remote]) => ({
...repository,
distroBasePath,
my_permissions,
remote,
}));
});
},
Expand Down
34 changes: 12 additions & 22 deletions src/containers/ansible-repository/tab-details.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,25 @@
import { t } from '@lingui/macro';
import React, { useEffect, useState } from 'react';
import React from 'react';
import { Link } from 'react-router-dom';
import {
AnsibleRemoteAPI,
AnsibleRemoteType,
AnsibleRepositoryType,
} from 'src/api';
import { AnsibleRemoteType, AnsibleRepositoryType } from 'src/api';
import {
CopyURL,
Details,
LazyDistributions,
PulpLabels,
} from 'src/components';
import { Paths, formatPath } from 'src/paths';
import { getRepoURL, parsePulpIDFromURL } from 'src/utilities';
import { getRepoURL } from 'src/utilities';

interface TabProps {
item: AnsibleRepositoryType & { distroBasePath?: string };
item: AnsibleRepositoryType & {
distroBasePath?: string;
remote?: AnsibleRemoteType;
};
actionContext: { addAlert: (alert) => void; state: { params } };
}

export const DetailsTab = ({ item }: TabProps) => {
const [remote, setRemote] = useState<AnsibleRemoteType>(null);

useEffect(() => {
const pk = item.remote && parsePulpIDFromURL(item.remote);
if (pk) {
AnsibleRemoteAPI.get(pk).then(({ data }) => setRemote(data));
} else {
setRemote(null);
}
}, [item.remote]);

return (
<Details
fields={[
Expand Down Expand Up @@ -63,11 +51,13 @@ export const DetailsTab = ({ item }: TabProps) => {
},
{
label: t`Remote`,
value: remote ? (
value: item?.remote ? (
<Link
to={formatPath(Paths.ansibleRemoteDetail, { name: remote.name })}
to={formatPath(Paths.ansibleRemoteDetail, {
name: item?.remote.name,
})}
>
{remote.name}
{item?.remote.name}
</Link>
) : (
t`None`
Expand Down

0 comments on commit 05fd635

Please sign in to comment.