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:
softwarefactory-project-zuul[bot] 2020-06-05 23:59:33 +00:00 committed by GitHub
commit e603cfd7ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 72 additions and 12 deletions

View File

@ -40,7 +40,13 @@ class ClipboardCopyButton extends React.Component {
};
render() {
const { clickTip, entryDelay, exitDelay, hoverTip } = this.props;
const {
copyTip,
entryDelay,
exitDelay,
copiedSuccessTip,
isDisabled,
} = this.props;
const { copied } = this.state;
return (
@ -48,12 +54,13 @@ class ClipboardCopyButton extends React.Component {
entryDelay={entryDelay}
exitDelay={exitDelay}
trigger="mouseenter focus click"
content={copied ? clickTip : hoverTip}
content={copied ? copiedSuccessTip : copyTip}
>
<Button
isDisabled={isDisabled}
variant="plain"
onClick={this.handleCopyClick}
aria-label={hoverTip}
aria-label={copyTip}
>
<CopyIcon />
</Button>
@ -63,12 +70,13 @@ class ClipboardCopyButton extends React.Component {
}
ClipboardCopyButton.propTypes = {
clickTip: PropTypes.string.isRequired,
copyTip: PropTypes.string.isRequired,
entryDelay: PropTypes.number,
exitDelay: PropTypes.number,
hoverTip: PropTypes.string.isRequired,
copiedSuccessTip: PropTypes.string.isRequired,
stringToCopy: PropTypes.string.isRequired,
switchDelay: PropTypes.number,
isDisabled: PropTypes.bool.isRequired,
};
ClipboardCopyButton.defaultProps = {

View File

@ -13,6 +13,7 @@ describe('ClipboardCopyButton', () => {
clickTip="foo"
hoverTip="bar"
stringToCopy="foobar!"
isDisabled={false}
/>
);
expect(wrapper).toHaveLength(1);
@ -23,6 +24,7 @@ describe('ClipboardCopyButton', () => {
clickTip="foo"
hoverTip="bar"
stringToCopy="foobar!"
isDisabled={false}
/>
).find('ClipboardCopyButton');
expect(wrapper.state('copied')).toBe(false);
@ -33,4 +35,15 @@ describe('ClipboardCopyButton', () => {
wrapper.update();
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);
});
});

View File

@ -32,6 +32,11 @@ const DataListAction = styled(_DataListAction)`
grid-gap: 16px;
grid-template-columns: repeat(3, 40px);
`;
const Label = styled.span`
color: var(--pf-global--disabled-color--100);
`;
function ProjectListItem({
project,
isSelected,
@ -121,13 +126,17 @@ function ProjectListItem({
</DataListCell>,
<DataListCell key="revision">
{project.scm_revision.substring(0, 7)}
{project.scm_revision ? (
<ClipboardCopyButton
stringToCopy={project.scm_revision}
hoverTip={i18n._(t`Copy full revision to clipboard.`)}
clickTip={i18n._(t`Successfully copied to clipboard!`)}
/>
) : null}
{!project.scm_revision && (
<Label aria-label={i18n._(t`copy to clipboard disabled`)}>
{i18n._(t`Sync for revision`)}
</Label>
)}
<ClipboardCopyButton
isDisabled={!project.scm_revision}
stringToCopy={project.scm_revision}
copyTip={i18n._(t`Copy full revision to clipboard.`)}
copiedSuccessTip={i18n._(t`Successfully copied to clipboard!`)}
/>
</DataListCell>,
]}
/>

View File

@ -218,4 +218,34 @@ describe('<ProjectsListItem />', () => {
);
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);
});
});