Skip to content

Commit 5c18fd1

Browse files
committed
Show allocated ports on settings page
1 parent 7b5139b commit 5c18fd1

File tree

5 files changed

+75
-10
lines changed

5 files changed

+75
-10
lines changed

resources/scripts/api/server/getServer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export interface Allocation {
44
ip: string;
55
alias: string | null;
66
port: number;
7-
default: boolean;
7+
isDefault: boolean;
88
}
99

1010
export interface Server {
@@ -49,7 +49,7 @@ export const rawDataToServerObject = (data: any): Server => ({
4949
ip: datum.ip,
5050
alias: datum.ip_alias,
5151
port: datum.port,
52-
default: datum.is_default,
52+
isDefault: datum.is_default,
5353
})),
5454
limits: { ...data.limits },
5555
featureLimits: { ...data.feature_limits },

resources/scripts/components/dashboard/ServerRow.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export default ({ server }: { server: Server }) => {
6565
<FontAwesomeIcon icon={faEthernet} css={tw`text-neutral-500`}/>
6666
<p css={tw`text-sm text-neutral-400 ml-2`}>
6767
{
68-
server.allocations.filter(alloc => alloc.default).map(allocation => (
68+
server.allocations.filter(alloc => alloc.isDefault).map(allocation => (
6969
<span key={allocation.ip + allocation.port.toString()}>{allocation.alias || allocation.ip}:{allocation.port}</span>
7070
))
7171
}

resources/scripts/components/dashboard/search/SearchModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export default ({ ...props }: Props) => {
112112
<p css={tw`text-sm`}>{server.name}</p>
113113
<p css={tw`mt-1 text-xs text-neutral-400`}>
114114
{
115-
server.allocations.filter(alloc => alloc.default).map(allocation => (
115+
server.allocations.filter(alloc => alloc.isDefault).map(allocation => (
116116
<span key={allocation.ip + allocation.port.toString()}>{allocation.alias || allocation.ip}:{allocation.port}</span>
117117
))
118118
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import React from 'react';
2+
import TitledGreyBox from '@/components/elements/TitledGreyBox';
3+
import { ServerContext } from '@/state/server';
4+
import tw from 'twin.macro';
5+
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
6+
import { faNetworkWired } from '@fortawesome/free-solid-svg-icons';
7+
import styled from 'styled-components/macro';
8+
9+
const Code = styled.code`${tw`font-mono py-1 px-2 bg-neutral-900 rounded text-sm block`}`;
10+
const Label = styled.label`${tw`uppercase text-xs mt-1 text-neutral-400 block px-1 select-none transition-colors duration-150`}`;
11+
12+
const Row = styled.div`
13+
${tw`flex items-center py-2 pl-4 pr-5 border-l-4 border-transparent transition-colors duration-150`};
14+
15+
& svg {
16+
${tw`transition-colors duration-150`};
17+
}
18+
19+
&:hover {
20+
${tw`border-cyan-400`};
21+
22+
svg {
23+
${tw`text-neutral-100`};
24+
}
25+
26+
${Label} {
27+
${tw`text-neutral-200`};
28+
}
29+
}
30+
`;
31+
32+
export default () => {
33+
const allocations = ServerContext.useStoreState(state => state.server.data!.allocations);
34+
35+
return (
36+
<TitledGreyBox title={'Allocated Ports'}>
37+
{allocations.map(({ ip, port, alias, isDefault }, index) => (
38+
<Row key={`${ip}:${port}`} css={index > 0 ? tw`mt-2` : undefined}>
39+
<div css={tw`mr-4 text-neutral-400`}>
40+
<FontAwesomeIcon icon={faNetworkWired}/>
41+
</div>
42+
<div css={tw`mr-4`}>
43+
<Code>{alias || ip}</Code>
44+
<Label>IP Address</Label>
45+
</div>
46+
<div>
47+
<Code>:{port}</Code>
48+
<Label>Port</Label>
49+
</div>
50+
<div css={tw`flex-1 text-right`}>
51+
{isDefault ?
52+
<span css={tw`bg-green-500 py-1 px-2 rounded text-green-50 text-xs`}>
53+
Default
54+
</span>
55+
:
56+
null
57+
}
58+
</div>
59+
</Row>
60+
))}
61+
</TitledGreyBox>
62+
);
63+
};

resources/scripts/components/server/settings/SettingsContainer.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import tw from 'twin.macro';
1313
import Input from '@/components/elements/Input';
1414
import Label from '@/components/elements/Label';
1515
import { LinkButton } from '@/components/elements/Button';
16+
import ServerAllocationsContainer from '@/components/server/settings/ServerAllocationsContainer';
1617

1718
export default () => {
1819
const user = useStoreState<ApplicationStore, UserData>(state => state.user.data!);
@@ -22,9 +23,9 @@ export default () => {
2223
<PageContentBlock>
2324
<FlashMessageRender byKey={'settings'} css={tw`mb-4`}/>
2425
<div css={tw`md:flex`}>
25-
<Can action={'file.sftp'}>
26-
<div css={tw`w-full md:flex-1 md:mr-10`}>
27-
<TitledGreyBox title={'SFTP Details'}>
26+
<div css={tw`w-full md:flex-1 md:mr-10`}>
27+
<Can action={'file.sftp'}>
28+
<TitledGreyBox title={'SFTP Details'} css={tw`mb-6 md:mb-10`}>
2829
<div>
2930
<Label>Server Address</Label>
3031
<Input
@@ -59,9 +60,7 @@ export default () => {
5960
</div>
6061
</div>
6162
</TitledGreyBox>
62-
</div>
63-
</Can>
64-
<div css={tw`w-full mt-6 md:flex-1 md:mt-0`}>
63+
</Can>
6564
<Can action={'settings.rename'}>
6665
<div css={tw`mb-6 md:mb-10`}>
6766
<RenameServerBox/>
@@ -71,6 +70,9 @@ export default () => {
7170
<ReinstallServerBox/>
7271
</Can>
7372
</div>
73+
<div css={tw`w-full mt-6 md:flex-1 md:mt-0`}>
74+
<ServerAllocationsContainer/>
75+
</div>
7476
</div>
7577
</PageContentBlock>
7678
);

0 commit comments

Comments
 (0)