Skip to content

Commit e9f1b2c

Browse files
author
Peter Bengtsson
authored
Merge pull request #84 from peterbe/83-help-to-add-whatsdeployed-badge-lacks-things
Help to add Whatsdeployed badge lacks things
2 parents dceb7b6 + cf5193e commit e9f1b2c

File tree

3 files changed

+71
-14
lines changed

3 files changed

+71
-14
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"classnames": "2.2.6",
88
"ky": "0.9.0",
99
"react": "16.8.6",
10+
"react-copy-to-clipboard": "5.0.1",
1011
"react-dom": "16.8.6",
1112
"react-router-dom": "5.0.0",
1213
"react-scripts": "2.1.8",

src/DeployPage.js

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import ky from 'ky/umd';
44
import TimeAgo from 'react-timeago';
55
import classNames from 'classnames';
66
import { Link } from 'react-router-dom';
7+
import { CopyToClipboard } from 'react-copy-to-clipboard';
78

89
import AutoProgressBar from './AutoProgressBar';
910
import shortUrls from './shortUrls';
@@ -358,7 +359,12 @@ class DeployTable extends React.Component {
358359
Use the links below to compare directly on GitHub.
359360
</div>
360361
)}
361-
<BadgesAndUrls deployInfo={deployInfo} shortUrl={shortUrl} />
362+
<BadgesAndUrls
363+
deployInfo={deployInfo}
364+
shortUrl={shortUrl}
365+
owner={owner}
366+
repo={repo}
367+
/>
362368
</div>
363369
</>
364370
);
@@ -679,19 +685,51 @@ class Culprits extends React.PureComponent {
679685

680686
class BadgesAndUrls extends React.Component {
681687
state = {
682-
showHelp: false
688+
showHelp: false,
689+
textCopied: ''
683690
};
684691

692+
componentWillUnmount() {
693+
this.dismounted = true;
694+
}
695+
685696
toggleHelp = () => {
686697
this.setState(state => ({ showHelp: !state.showHelp }));
687698
};
688699

700+
copiedText = textCopied => {
701+
this.setState({ textCopied }, () => {
702+
window.setTimeout(() => {
703+
if (!this.dismounted) {
704+
this.setState({ textCopied: '' });
705+
}
706+
}, 4 * 1000);
707+
});
708+
};
709+
710+
showCopyToClipboard = text => {
711+
return (
712+
<CopyToClipboard text={text} onCopy={() => this.copiedText(text)}>
713+
<small>
714+
<button
715+
className="btn btn-outline-secondary btn-sm"
716+
disabled={text === this.state.textCopied}
717+
>
718+
{text === this.state.textCopied
719+
? 'Copied to clipboard'
720+
: 'Copy to clipboard'}
721+
</button>
722+
</small>
723+
</CopyToClipboard>
724+
);
725+
};
726+
689727
render() {
690-
const { deployInfo, shortUrl } = this.props;
728+
const { deployInfo, shortUrl, owner, repo } = this.props;
691729
const { showHelp } = this.state;
692730

693731
const { protocol, host } = window.location;
694-
const fullUrl = `${protocol}//${host}${shortUrl}`;
732+
const fullUrl = `${protocol}//${host}${shortUrl}/${owner}/${repo}`;
695733
const envs = deployInfo.map(deploy => deploy.name.toLowerCase()).join(',');
696734
const badgeUrl = `https://img.shields.io/badge/whatsdeployed-${envs}-green.svg`;
697735
const badgeAlt = `What's deployed on ${envs}?`;
@@ -720,21 +758,19 @@ class BadgesAndUrls extends React.Component {
720758
<div>
721759
<h3>Badge Help</h3>
722760
<dl>
723-
<dt>Image URL</dt>
761+
<dt>Image URL {this.showCopyToClipboard(badgeUrl)}</dt>
724762
<dd>
725-
<code>{badgeUrl}</code>
763+
<pre>{badgeUrl}</pre>
726764
</dd>
727-
<dt>Markdown</dt>
765+
<dt>Markdown {this.showCopyToClipboard(markdown)}</dt>
728766
<dd>
729-
<pre>
730-
<code>{markdown}</code>
731-
</pre>
767+
<pre>{markdown}</pre>
732768
</dd>
733-
<dt>ReStructuredText</dt>
769+
<dt>
770+
ReStructuredText {this.showCopyToClipboard(restructuredText)}
771+
</dt>
734772
<dd>
735-
<pre>
736-
<code>{restructuredText}</code>
737-
</pre>
773+
<pre>{restructuredText}</pre>
738774
</dd>
739775
</dl>
740776
</div>

yarn.lock

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2485,6 +2485,13 @@ copy-descriptor@^0.1.0:
24852485
resolved "https://registry.yarnpkg.com/copy-descriptor/-/copy-descriptor-0.1.1.tgz#676f6eb3c39997c2ee1ac3a924fd6124748f578d"
24862486
integrity sha1-Z29us8OZl8LuGsOpJP1hJHSPV40=
24872487

2488+
copy-to-clipboard@^3:
2489+
version "3.0.8"
2490+
resolved "https://registry.yarnpkg.com/copy-to-clipboard/-/copy-to-clipboard-3.0.8.tgz#f4e82f4a8830dce4666b7eb8ded0c9bcc313aba9"
2491+
integrity sha512-c3GdeY8qxCHGezVb1EFQfHYK/8NZRemgcTIzPq7PuxjHAf/raKibn2QdhHPb/y6q74PMgH6yizaDZlRmw6QyKw==
2492+
dependencies:
2493+
toggle-selection "^1.0.3"
2494+
24882495
24892496
version "2.6.4"
24902497
resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.6.4.tgz#b8897c062c4d769dd30a0ac5c73976c47f92ea0d"
@@ -7993,6 +8000,14 @@ react-app-polyfill@^0.2.2:
79938000
raf "3.4.1"
79948001
whatwg-fetch "3.0.0"
79958002

8003+
8004+
version "5.0.1"
8005+
resolved "https://registry.yarnpkg.com/react-copy-to-clipboard/-/react-copy-to-clipboard-5.0.1.tgz#8eae107bb400be73132ed3b6a7b4fb156090208e"
8006+
integrity sha512-ELKq31/E3zjFs5rDWNCfFL4NvNFQvGRoJdAKReD/rUPA+xxiLPQmZBZBvy2vgH7V0GE9isIQpT9WXbwIVErYdA==
8007+
dependencies:
8008+
copy-to-clipboard "^3"
8009+
prop-types "^15.5.8"
8010+
79968011
react-dev-utils@^8.0.0:
79978012
version "8.0.0"
79988013
resolved "https://registry.yarnpkg.com/react-dev-utils/-/react-dev-utils-8.0.0.tgz#7c5b227a45a32ea8ff7fbc318f336cf9e2c6e34c"
@@ -9471,6 +9486,11 @@ to-regex@^3.0.1, to-regex@^3.0.2:
94719486
regex-not "^1.0.2"
94729487
safe-regex "^1.1.0"
94739488

9489+
toggle-selection@^1.0.3:
9490+
version "1.0.6"
9491+
resolved "https://registry.yarnpkg.com/toggle-selection/-/toggle-selection-1.0.6.tgz#6e45b1263f2017fa0acc7d89d78b15b8bf77da32"
9492+
integrity sha1-bkWxJj8gF/oKzH2J14sVuL932jI=
9493+
94749494
94759495
version "2.0.2"
94769496
resolved "https://registry.yarnpkg.com/topo/-/topo-2.0.2.tgz#cd5615752539057c0dc0491a621c3bc6fbe1d182"

0 commit comments

Comments
 (0)