Skip to content

Commit 394cd81

Browse files
Network tab changes
Allows address feild to be copied to the clipboard when clicked If alias is used changes it to hostname instead of ip address ( might just make it say address as that would cover both? ) Fixed overflow for allocations with a long alias
1 parent ff64220 commit 394cd81

File tree

4 files changed

+98
-4
lines changed

4 files changed

+98
-4
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"@fortawesome/fontawesome-svg-core": "^1.2.32",
55
"@fortawesome/free-solid-svg-icons": "^5.15.1",
66
"@fortawesome/react-fontawesome": "^0.1.11",
7+
"@types/react-copy-to-clipboard": "^4.3.0",
78
"axios": "^0.19.2",
89
"chart.js": "^2.8.0",
910
"codemirror": "^5.57.0",
@@ -21,6 +22,7 @@
2122
"path": "^0.12.7",
2223
"query-string": "^6.7.0",
2324
"react": "^16.13.1",
25+
"react-copy-to-clipboard": "^5.0.2",
2426
"react-dom": "npm:@hot-loader/react-dom",
2527
"react-fast-compare": "^3.2.0",
2628
"react-ga": "^3.1.2",
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import React, { useCallback, useEffect, useState } from 'react';
2+
import CopyToClipboard from 'react-copy-to-clipboard';
3+
import tw from 'twin.macro';
4+
import styled, { keyframes } from 'styled-components/macro';
5+
import Fade from '@/components/elements/Fade';
6+
import { SwitchTransition } from 'react-transition-group';
7+
8+
const fade = keyframes`
9+
from { opacity: 0 }
10+
to { opacity: 1 }
11+
`;
12+
13+
const Toast = styled.div`
14+
${tw`fixed z-50 bottom-0 left-0 mb-4 w-full flex justify-end pr-4`};
15+
animation: ${fade} 250ms linear;
16+
17+
& > div {
18+
${tw`rounded px-4 py-2 text-white bg-neutral-800 border border-neutral-900`};
19+
}
20+
`;
21+
22+
const CopyOnClick: React.FC<{ text: string }> = ({ text, children }) => {
23+
const [ copied, setCopied ] = useState(false);
24+
25+
useEffect(() => {
26+
if (!copied) return;
27+
28+
const timeout = setTimeout(() => {
29+
setCopied(false);
30+
}, 2500);
31+
32+
return () => {
33+
clearTimeout(timeout);
34+
};
35+
}, [ copied ]);
36+
37+
const onCopy = useCallback(() => {
38+
setCopied(true);
39+
}, []);
40+
41+
return (
42+
<>
43+
<SwitchTransition>
44+
<Fade timeout={250} key={copied ? 'visible' : 'invisible'}>
45+
{copied ?
46+
<Toast>
47+
<div>
48+
<p>Copied &quot;{text}&quot; to clipboard.</p>
49+
</div>
50+
</Toast>
51+
:
52+
<></>
53+
}
54+
</Fade>
55+
</SwitchTransition>
56+
<CopyToClipboard onCopy={onCopy} text={text} options={{ debug: true }}>
57+
{children}
58+
</CopyToClipboard>
59+
</>
60+
);
61+
};
62+
63+
export default CopyOnClick;

resources/scripts/components/server/network/AllocationRow.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { debounce } from 'debounce';
1414
import setServerAllocationNotes from '@/api/server/network/setServerAllocationNotes';
1515
import useFlash from '@/plugins/useFlash';
1616
import { ServerContext } from '@/state/server';
17+
import CopyOnClick from '@/components/elements/CopyOnClick';
1718

1819
const Code = styled.code`${tw`font-mono py-1 px-2 bg-neutral-900 rounded text-sm inline-block`}`;
1920
const Label = styled.label`${tw`uppercase text-xs mt-1 text-neutral-400 block px-1 select-none transition-colors duration-150`}`;
@@ -43,11 +44,12 @@ const AllocationRow = ({ allocation, onSetPrimary, onNotesChanged }: Props) => {
4344
<GreyRowBox $hoverable={false} css={tw`flex-wrap md:flex-no-wrap mt-2`}>
4445
<div css={tw`flex items-center w-full md:w-auto`}>
4546
<div css={tw`pl-4 pr-6 text-neutral-400`}>
46-
<FontAwesomeIcon icon={faNetworkWired}/>
47+
<FontAwesomeIcon icon={faNetworkWired} />
4748
</div>
4849
<div css={tw`mr-4 flex-1 md:w-40`}>
49-
<Code>{allocation.alias || allocation.ip}</Code>
50-
<Label>IP Address</Label>
50+
{allocation.alias ? <CopyOnClick text={allocation.alias}><Code css={tw`w-40 truncate`}>{allocation.alias}</Code></CopyOnClick> :
51+
<CopyOnClick text={allocation.ip}><Code>{allocation.ip}</Code></CopyOnClick>}
52+
<Label>{allocation.alias ? 'Hostname' : 'IP Address'}</Label>
5153
</div>
5254
<div css={tw`w-16 md:w-24 overflow-hidden`}>
5355
<Code>{allocation.port}</Code>

yarn.lock

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,13 @@
12011201
dependencies:
12021202
query-string "*"
12031203

1204+
"@types/react-copy-to-clipboard@^4.3.0":
1205+
version "4.3.0"
1206+
resolved "https://registry.yarnpkg.com/@types/react-copy-to-clipboard/-/react-copy-to-clipboard-4.3.0.tgz#8e07becb4f11cfced4bd36038cb5bdf5c2658be5"
1207+
integrity sha512-iideNPRyroENqsOFh1i2Dv3zkviYS9r/9qD9Uh3Z9NNoAAqqa2x53i7iGndGNnJFIo20wIu7Hgh77tx1io8bgw==
1208+
dependencies:
1209+
"@types/react" "*"
1210+
12041211
"@types/react-dom@^16.9.8":
12051212
version "16.9.8"
12061213
resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-16.9.8.tgz#fe4c1e11dfc67155733dfa6aa65108b4971cb423"
@@ -2460,6 +2467,13 @@ copy-descriptor@^0.1.0:
24602467
version "0.1.1"
24612468
resolved "https://registry.yarnpkg.com/copy-descriptor/-/copy-descriptor-0.1.1.tgz#676f6eb3c39997c2ee1ac3a924fd6124748f578d"
24622469

2470+
copy-to-clipboard@^3:
2471+
version "3.3.1"
2472+
resolved "https://registry.yarnpkg.com/copy-to-clipboard/-/copy-to-clipboard-3.3.1.tgz#115aa1a9998ffab6196f93076ad6da3b913662ae"
2473+
integrity sha512-i13qo6kIHTTpCm8/Wup+0b1mVWETvu2kIMzKoK8FpkLkFxlt0znUAHcMzox+T8sPlqtZXq3CulEjQHsYiGFJUw==
2474+
dependencies:
2475+
toggle-selection "^1.0.6"
2476+
24632477
core-js-compat@^3.6.2:
24642478
version "3.6.5"
24652479
resolved "https://registry.yarnpkg.com/core-js-compat/-/core-js-compat-3.6.5.tgz#2a51d9a4e25dfd6e690251aa81f99e3c05481f1c"
@@ -5650,7 +5664,7 @@ promise-inflight@^1.0.1:
56505664
version "1.0.1"
56515665
resolved "https://registry.yarnpkg.com/promise-inflight/-/promise-inflight-1.0.1.tgz#98472870bf228132fcbdd868129bad12c3c029e3"
56525666

5653-
prop-types@^15.5.0, prop-types@^15.6.1, prop-types@^15.6.2, prop-types@^15.7.2:
5667+
prop-types@^15.5.0, prop-types@^15.5.8, prop-types@^15.6.1, prop-types@^15.6.2, prop-types@^15.7.2:
56545668
version "15.7.2"
56555669
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5"
56565670
integrity sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==
@@ -5802,6 +5816,14 @@ react-async-script@^1.1.1:
58025816
hoist-non-react-statics "^3.3.0"
58035817
prop-types "^15.5.0"
58045818

5819+
react-copy-to-clipboard@^5.0.2:
5820+
version "5.0.2"
5821+
resolved "https://registry.yarnpkg.com/react-copy-to-clipboard/-/react-copy-to-clipboard-5.0.2.tgz#d82a437e081e68dfca3761fbd57dbf2abdda1316"
5822+
integrity sha512-/2t5mLMMPuN5GmdXo6TebFa8IoFxZ+KTDDqYhcDm0PhkgEzSxVvIX26G20s1EB02A4h2UZgwtfymZ3lGJm0OLg==
5823+
dependencies:
5824+
copy-to-clipboard "^3"
5825+
prop-types "^15.5.8"
5826+
58055827
"react-dom@npm:@hot-loader/react-dom":
58065828
version "16.11.0"
58075829
resolved "https://registry.yarnpkg.com/@hot-loader/react-dom/-/react-dom-16.11.0.tgz#c0b483923b289db5431516f56ee2a69448ebf9bd"
@@ -7027,6 +7049,11 @@ to-regex@^3.0.1, to-regex@^3.0.2:
70277049
regex-not "^1.0.2"
70287050
safe-regex "^1.1.0"
70297051

7052+
toggle-selection@^1.0.6:
7053+
version "1.0.6"
7054+
resolved "https://registry.yarnpkg.com/toggle-selection/-/toggle-selection-1.0.6.tgz#6e45b1263f2017fa0acc7d89d78b15b8bf77da32"
7055+
integrity sha1-bkWxJj8gF/oKzH2J14sVuL932jI=
7056+
70307057
toidentifier@1.0.0:
70317058
version "1.0.0"
70327059
resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.0.tgz#7e1be3470f1e77948bc43d94a3c8f4d7752ba553"

0 commit comments

Comments
 (0)