mirror of
https://github.com/ansible/awx.git
synced 2026-03-07 19:51:08 -03:30
Adds message for unsynced projects for copy to clipboard button
This commit is contained in:
@@ -40,7 +40,13 @@ class ClipboardCopyButton extends React.Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { clickTip, entryDelay, exitDelay, hoverTip } = this.props;
|
const {
|
||||||
|
clickTip,
|
||||||
|
entryDelay,
|
||||||
|
exitDelay,
|
||||||
|
hoverTip,
|
||||||
|
isDisabled,
|
||||||
|
} = this.props;
|
||||||
const { copied } = this.state;
|
const { copied } = this.state;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -51,6 +57,7 @@ class ClipboardCopyButton extends React.Component {
|
|||||||
content={copied ? clickTip : hoverTip}
|
content={copied ? clickTip : hoverTip}
|
||||||
>
|
>
|
||||||
<Button
|
<Button
|
||||||
|
isDisabled={isDisabled}
|
||||||
variant="plain"
|
variant="plain"
|
||||||
onClick={this.handleCopyClick}
|
onClick={this.handleCopyClick}
|
||||||
aria-label={hoverTip}
|
aria-label={hoverTip}
|
||||||
@@ -69,6 +76,7 @@ ClipboardCopyButton.propTypes = {
|
|||||||
hoverTip: PropTypes.string.isRequired,
|
hoverTip: 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 to activate`)}
|
||||||
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}
|
||||||
|
hoverTip={i18n._(t`Copy full revision to clipboard.`)}
|
||||||
|
clickTip={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 to activate');
|
||||||
|
expect(wrapper.find('ClipboardCopyButton').prop('isDisabled')).toBe(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user