Skip to content

Commit

Permalink
format and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrewgdewar committed Jan 10, 2025
1 parent d1a4bad commit 0b125f2
Show file tree
Hide file tree
Showing 7 changed files with 361 additions and 322 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable quotes */
import {
Button,
Flex,
Expand Down
8 changes: 4 additions & 4 deletions src/Pages/Templates/TemplateDetails/TemplateDetails.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {fireEvent, render} from '@testing-library/react';
import { fireEvent, render } from '@testing-library/react';
import TemplateDetails from './TemplateDetails';
import { defaultTemplateItem } from 'testingHelpers';

Expand Down Expand Up @@ -41,15 +41,15 @@ it('expect UseTemplateModal to render correctly', () => {
const useTemplate = getByLabelText('use-template-button') as Element;
expect(useTemplate).toBeInTheDocument();
fireEvent.click(useTemplate);
expect(queryByText('Assign the template to a system')).toBeInTheDocument()
expect(queryByText('Assign the template to a system')).toBeInTheDocument();

const curlTab = getByLabelText('curl-tab') as Element;
expect(curlTab).toBeInTheDocument();
fireEvent.click(curlTab);
expect(queryByText('Download the repo file')).toBeInTheDocument()
expect(queryByText('Download the repo file')).toBeInTheDocument();

const ansibleTab = getByLabelText('ansible-tab') as Element;
expect(ansibleTab).toBeInTheDocument();
fireEvent.click(ansibleTab);
expect(queryByText('Use this ansible playbook to download the repo file')).toBeInTheDocument()
expect(queryByText('Use this ansible playbook to download the repo file')).toBeInTheDocument();
});
9 changes: 6 additions & 3 deletions src/Pages/Templates/TemplateDetails/TemplateDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import {
LabelGroup,
Stack,
StackItem,
Title, Toolbar, ToolbarContent, ToolbarItem,
Title,
Toolbar,
ToolbarContent,
ToolbarItem,
} from '@patternfly/react-core';
import { Outlet, useNavigate, useParams } from 'react-router-dom';
import { createUseStyles } from 'react-jss';
Expand Down Expand Up @@ -117,10 +120,10 @@ export default function TemplateDetails() {
<Toolbar>
<ToolbarContent>
<ToolbarItem>
<UseTemplateModal/>
<UseTemplateModal />
</ToolbarItem>
<ToolbarItem>
<TemplateActionDropdown />
<TemplateActionDropdown />
</ToolbarItem>
</ToolbarContent>
</Toolbar>
Expand Down
216 changes: 114 additions & 102 deletions src/Pages/Templates/TemplateDetails/components/UseTemplate/AnsibleTab.tsx
Original file line number Diff line number Diff line change
@@ -1,130 +1,142 @@
import {
Alert,
ClipboardCopy,
ClipboardCopyButton,
ClipboardCopyVariant, CodeBlock, CodeBlockAction, CodeBlockCode,
TabContent,
Text, TextContent,
TextList,
TextListItem,
TextVariants
Alert,
ClipboardCopy,
ClipboardCopyButton,
ClipboardCopyVariant,
CodeBlock,
CodeBlockAction,
CodeBlockCode,
TabContent,
Text,
TextContent,
TextList,
TextListItem,
TextVariants,
} from '@patternfly/react-core';
import React from 'react';
import {createUseStyles} from 'react-jss';
import {useParams} from 'react-router-dom';
import {ExternalLinkAltIcon} from "@patternfly/react-icons";
import { createUseStyles } from 'react-jss';
import { useParams } from 'react-router-dom';
import { ExternalLinkAltIcon } from '@patternfly/react-icons';

export const ANSIBLE_TAB = 'ansible'
export const ANSIBLE_TAB = 'ansible';

const useStyles = createUseStyles({
textGroup: {
paddingTop: '8px',
},
})
textGroup: {
paddingTop: '8px',
},
});

type Props = {
tabContentRef: React.RefObject<HTMLElement>
}
tabContentRef: React.RefObject<HTMLElement>;
};

const playbook1 = `---
- hosts: all
tasks:
- name: Download template.repo
ansible.builtin.get_url:
url: https://console.redhat.com/api/content-sources/v1/templates/`
url: https://console.redhat.com/api/content-sources/v1/templates/`;
const playbook2 = `/config.repo
dest: /etc/yum.repos.d/template.repo
mode: '0444'
client_cert: /etc/pki/consumer/cert.pem
client_key: /etc/pki/consumer/cert.key
`
`;

const AnsibleTab = ({ tabContentRef }: Props) => {
const classes = useStyles();
const { templateUUID } = useParams();
const [copied, setCopied] = React.useState(false);
const classes = useStyles();
const { templateUUID } = useParams();
const [copied, setCopied] = React.useState(false);

const clipboardCopyFunc = (event, text) => {
navigator.clipboard.writeText(text.toString());
};
const clipboardCopyFunc = (event, text) => {
navigator.clipboard.writeText(text.toString());
};

const onClick = (event, text) => {
clipboardCopyFunc(event, text);
setCopied(true);
};
const onClick = (event, text) => {
clipboardCopyFunc(event, text);
setCopied(true);
};

const actions = (
<React.Fragment>
<CodeBlockAction>
<ClipboardCopyButton
id="basic-copy-button"
textId="code-content"
aria-label="Copy to clipboard"
onClick={(e) => onClick(e, playbook1+`${templateUUID}`+playbook2)}
exitDelay={copied ? 1500 : 600}
maxWidth="110px"
variant="plain"
onTooltipHidden={() => setCopied(false)}
>
{copied ? 'Successfully copied to clipboard!' : 'Copy to clipboard'}
</ClipboardCopyButton>
</CodeBlockAction>
</React.Fragment>
);
const actions = (
<React.Fragment>
<CodeBlockAction>
<ClipboardCopyButton
id='basic-copy-button'
textId='code-content'
aria-label='Copy to clipboard'
onClick={(e) => onClick(e, playbook1 + `${templateUUID}` + playbook2)}
exitDelay={copied ? 1500 : 600}
maxWidth='110px'
variant='plain'
onTooltipHidden={() => setCopied(false)}
>
{copied ? 'Successfully copied to clipboard!' : 'Copy to clipboard'}
</ClipboardCopyButton>
</CodeBlockAction>
</React.Fragment>
);

return (
<TabContent eventKey={ANSIBLE_TAB} id={ANSIBLE_TAB} ref={tabContentRef} hidden>
<div className={classes.textGroup}>
<Alert
variant='warning'
title='Consuming a template in this way will result in the system not reporting applicable errata properly within Insights.'
isInline
>
System advisory information will not be available via {' '}
<a href="insights/patch/systems/" rel='noreferrer' target='_blank'>
Systems <ExternalLinkAltIcon/>
</a>
</Alert>
</div>
<TextContent className={classes.textGroup}>
<Text component={TextVariants.h2}>Register for subscriptions</Text>
<TextList isPlain>
<TextListItem>
<Text component="h6">Register with rhc</Text>
<ClipboardCopy isReadOnly hoverTip="Copy" clickTip="Copied"
variant={ClipboardCopyVariant.expansion}>
rhc connect
</ClipboardCopy>
</TextListItem>
<TextListItem>
<Text component="h6">Or register with subscription manager</Text>
<ClipboardCopy isReadOnly hoverTip="Copy" clickTip="Copied"
variant={ClipboardCopyVariant.expansion}>
subscription-manager register
</ClipboardCopy>
</TextListItem>
</TextList>
<TextList isPlain>
<TextListItem>
<Text component={TextVariants.h2}>Use this ansible playbook to download the repo file</Text>
<CodeBlock actions={actions}>
<CodeBlockCode>
{playbook1 + `${templateUUID}` + playbook2}
</CodeBlockCode>
</CodeBlock>
</TextListItem>
</TextList>
</TextContent>
<div className={classes.textGroup}>
<Alert
variant='info'
title='Adding or removing a repository from the template will not be reflected on the
return (
<TabContent eventKey={ANSIBLE_TAB} id={ANSIBLE_TAB} ref={tabContentRef} hidden>
<div className={classes.textGroup}>
<Alert
variant='warning'
title='Consuming a template in this way will result in the system not reporting applicable errata properly within Insights.'
isInline
>
System advisory information will not be available via{' '}
<a href='insights/patch/systems/' rel='noreferrer' target='_blank'>
Systems <ExternalLinkAltIcon />
</a>
</Alert>
</div>
<TextContent className={classes.textGroup}>
<Text component={TextVariants.h2}>Register for subscriptions</Text>
<TextList isPlain>
<TextListItem>
<Text component='h6'>Register with rhc</Text>
<ClipboardCopy
isReadOnly
hoverTip='Copy'
clickTip='Copied'
variant={ClipboardCopyVariant.expansion}
>
rhc connect
</ClipboardCopy>
</TextListItem>
<TextListItem>
<Text component='h6'>Or register with subscription manager</Text>
<ClipboardCopy
isReadOnly
hoverTip='Copy'
clickTip='Copied'
variant={ClipboardCopyVariant.expansion}
>
subscription-manager register
</ClipboardCopy>
</TextListItem>
</TextList>
<TextList isPlain>
<TextListItem>
<Text component={TextVariants.h2}>
Use this ansible playbook to download the repo file
</Text>
<CodeBlock actions={actions}>
<CodeBlockCode>{playbook1 + `${templateUUID}` + playbook2}</CodeBlockCode>
</CodeBlock>
</TextListItem>
</TextList>
</TextContent>
<div className={classes.textGroup}>
<Alert
variant='info'
title='Adding or removing a repository from the template will not be reflected on the
client until the repo file is re-downloaded.'
isInline
/>
</div>
</TabContent>
)
}
isInline
/>
</div>
</TabContent>
);
};

export default AnsibleTab;
Loading

0 comments on commit 0b125f2

Please sign in to comment.