mirror of
https://github.com/ansible/awx.git
synced 2026-03-02 01:08:48 -03:30
Merge pull request #7239 from AlexSCorey/6863-CopyProjectsAndInventories
Adds ux for unsynced projects Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
@@ -40,7 +40,13 @@ class ClipboardCopyButton extends React.Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { clickTip, entryDelay, exitDelay, hoverTip } = this.props;
|
const {
|
||||||
|
copyTip,
|
||||||
|
entryDelay,
|
||||||
|
exitDelay,
|
||||||
|
copiedSuccessTip,
|
||||||
|
isDisabled,
|
||||||
|
} = this.props;
|
||||||
const { copied } = this.state;
|
const { copied } = this.state;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -48,12 +54,13 @@ class ClipboardCopyButton extends React.Component {
|
|||||||
entryDelay={entryDelay}
|
entryDelay={entryDelay}
|
||||||
exitDelay={exitDelay}
|
exitDelay={exitDelay}
|
||||||
trigger="mouseenter focus click"
|
trigger="mouseenter focus click"
|
||||||
content={copied ? clickTip : hoverTip}
|
content={copied ? copiedSuccessTip : copyTip}
|
||||||
>
|
>
|
||||||
<Button
|
<Button
|
||||||
|
isDisabled={isDisabled}
|
||||||
variant="plain"
|
variant="plain"
|
||||||
onClick={this.handleCopyClick}
|
onClick={this.handleCopyClick}
|
||||||
aria-label={hoverTip}
|
aria-label={copyTip}
|
||||||
>
|
>
|
||||||
<CopyIcon />
|
<CopyIcon />
|
||||||
</Button>
|
</Button>
|
||||||
@@ -63,12 +70,13 @@ class ClipboardCopyButton extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ClipboardCopyButton.propTypes = {
|
ClipboardCopyButton.propTypes = {
|
||||||
clickTip: PropTypes.string.isRequired,
|
copyTip: PropTypes.string.isRequired,
|
||||||
entryDelay: PropTypes.number,
|
entryDelay: PropTypes.number,
|
||||||
exitDelay: PropTypes.number,
|
exitDelay: PropTypes.number,
|
||||||
hoverTip: PropTypes.string.isRequired,
|
copiedSuccessTip: PropTypes.string.isRequired,
|
||||||
stringToCopy: PropTypes.string.isRequired,
|
stringToCopy: PropTypes.string.isRequired,
|
||||||
switchDelay: PropTypes.number,
|
switchDelay: PropTypes.number,
|
||||||
|
isDisabled: PropTypes.bool.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
ClipboardCopyButton.defaultProps = {
|
ClipboardCopyButton.defaultProps = {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ describe('ClipboardCopyButton', () => {
|
|||||||
clickTip="foo"
|
clickTip="foo"
|
||||||
hoverTip="bar"
|
hoverTip="bar"
|
||||||
stringToCopy="foobar!"
|
stringToCopy="foobar!"
|
||||||
|
isDisabled={false}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
expect(wrapper).toHaveLength(1);
|
expect(wrapper).toHaveLength(1);
|
||||||
@@ -23,6 +24,7 @@ describe('ClipboardCopyButton', () => {
|
|||||||
clickTip="foo"
|
clickTip="foo"
|
||||||
hoverTip="bar"
|
hoverTip="bar"
|
||||||
stringToCopy="foobar!"
|
stringToCopy="foobar!"
|
||||||
|
isDisabled={false}
|
||||||
/>
|
/>
|
||||||
).find('ClipboardCopyButton');
|
).find('ClipboardCopyButton');
|
||||||
expect(wrapper.state('copied')).toBe(false);
|
expect(wrapper.state('copied')).toBe(false);
|
||||||
@@ -33,4 +35,15 @@ describe('ClipboardCopyButton', () => {
|
|||||||
wrapper.update();
|
wrapper.update();
|
||||||
expect(wrapper.state('copied')).toBe(false);
|
expect(wrapper.state('copied')).toBe(false);
|
||||||
});
|
});
|
||||||
|
test('should render disabled button', () => {
|
||||||
|
const wrapper = mountWithContexts(
|
||||||
|
<ClipboardCopyButton
|
||||||
|
clickTip="foo"
|
||||||
|
hoverTip="bar"
|
||||||
|
stringToCopy="foobar!"
|
||||||
|
isDisabled
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
expect(wrapper.find('Button').prop('isDisabled')).toBe(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -32,6 +32,11 @@ const DataListAction = styled(_DataListAction)`
|
|||||||
grid-gap: 16px;
|
grid-gap: 16px;
|
||||||
grid-template-columns: repeat(3, 40px);
|
grid-template-columns: repeat(3, 40px);
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
const Label = styled.span`
|
||||||
|
color: var(--pf-global--disabled-color--100);
|
||||||
|
`;
|
||||||
|
|
||||||
function ProjectListItem({
|
function ProjectListItem({
|
||||||
project,
|
project,
|
||||||
isSelected,
|
isSelected,
|
||||||
@@ -121,13 +126,17 @@ function ProjectListItem({
|
|||||||
</DataListCell>,
|
</DataListCell>,
|
||||||
<DataListCell key="revision">
|
<DataListCell key="revision">
|
||||||
{project.scm_revision.substring(0, 7)}
|
{project.scm_revision.substring(0, 7)}
|
||||||
{project.scm_revision ? (
|
{!project.scm_revision && (
|
||||||
<ClipboardCopyButton
|
<Label aria-label={i18n._(t`copy to clipboard disabled`)}>
|
||||||
stringToCopy={project.scm_revision}
|
{i18n._(t`Sync for revision`)}
|
||||||
hoverTip={i18n._(t`Copy full revision to clipboard.`)}
|
</Label>
|
||||||
clickTip={i18n._(t`Successfully copied to clipboard!`)}
|
)}
|
||||||
/>
|
<ClipboardCopyButton
|
||||||
) : null}
|
isDisabled={!project.scm_revision}
|
||||||
|
stringToCopy={project.scm_revision}
|
||||||
|
copyTip={i18n._(t`Copy full revision to clipboard.`)}
|
||||||
|
copiedSuccessTip={i18n._(t`Successfully copied to clipboard!`)}
|
||||||
|
/>
|
||||||
</DataListCell>,
|
</DataListCell>,
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -218,4 +218,34 @@ describe('<ProjectsListItem />', () => {
|
|||||||
);
|
);
|
||||||
expect(wrapper.find('CopyButton').length).toBe(0);
|
expect(wrapper.find('CopyButton').length).toBe(0);
|
||||||
});
|
});
|
||||||
|
test('should render disabled copy to clipboard button', () => {
|
||||||
|
const wrapper = mountWithContexts(
|
||||||
|
<ProjectsListItem
|
||||||
|
isSelected={false}
|
||||||
|
detailUrl="/project/1"
|
||||||
|
onSelect={() => {}}
|
||||||
|
project={{
|
||||||
|
id: 1,
|
||||||
|
name: 'Project 1',
|
||||||
|
url: '/api/v2/projects/1',
|
||||||
|
type: 'project',
|
||||||
|
scm_type: 'git',
|
||||||
|
scm_revision: '',
|
||||||
|
summary_fields: {
|
||||||
|
last_job: {
|
||||||
|
id: 9000,
|
||||||
|
status: 'successful',
|
||||||
|
},
|
||||||
|
user_capabilities: {
|
||||||
|
edit: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
wrapper.find('span[aria-label="copy to clipboard disabled"]').text()
|
||||||
|
).toBe('Sync for revision');
|
||||||
|
expect(wrapper.find('ClipboardCopyButton').prop('isDisabled')).toBe(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user