Skip to content

Commit d1c3060

Browse files
committed
UI updates for server rows to show current status
1 parent 2a42ef5 commit d1c3060

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

resources/scripts/components/dashboard/ServerRow.tsx

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
33
import { faEthernet, faHdd, faMemory, faMicrochip, faServer } from '@fortawesome/free-solid-svg-icons';
44
import { Link } from 'react-router-dom';
55
import { Server } from '@/api/server/getServer';
6-
import getServerResourceUsage, { ServerStats } from '@/api/server/getServerResourceUsage';
6+
import getServerResourceUsage, { ServerPowerState, ServerStats } from '@/api/server/getServerResourceUsage';
77
import { bytesToHuman, megabytesToHuman } from '@/helpers';
88
import tw from 'twin.macro';
99
import GreyRowBox from '@/components/elements/GreyRowBox';
@@ -24,6 +24,21 @@ const IconDescription = styled.p<{ $alarm: boolean }>`
2424
${props => props.$alarm ? tw`text-white` : tw`text-neutral-400`};
2525
`;
2626

27+
const StatusIndicatorBox = styled(GreyRowBox)<{ $status: ServerPowerState | undefined }>`
28+
${tw`grid grid-cols-12 gap-4 relative`};
29+
30+
& .status-bar {
31+
${tw`w-2 bg-red-500 absolute right-0 z-20 rounded-full m-1 opacity-50 transition-all duration-150`};
32+
height: calc(100% - 0.5rem);
33+
34+
${({ $status }) => (!$status || $status === 'offline') ? tw`bg-red-500` : ($status === 'running' ? tw`bg-green-500` : tw`bg-yellow-500`)};
35+
}
36+
37+
&:hover .status-bar {
38+
${tw`opacity-75`};
39+
}
40+
`;
41+
2742
export default ({ server, className }: { server: Server; className?: string }) => {
2843
const interval = useRef<number>(null);
2944
const [ stats, setStats ] = useState<ServerStats | null>(null);
@@ -61,15 +76,15 @@ export default ({ server, className }: { server: Server; className?: string }) =
6176
const memorylimit = server.limits.memory !== 0 ? megabytesToHuman(server.limits.memory) : 'Unlimited';
6277

6378
return (
64-
<GreyRowBox as={Link} to={`/server/${server.id}`} className={className} css={tw`grid grid-cols-12 gap-4`}>
65-
<div css={tw`flex items-center col-span-11 sm:col-span-5 lg:col-span-6`}>
79+
<StatusIndicatorBox as={Link} to={`/server/${server.id}`} className={className} $status={stats?.status}>
80+
<div css={tw`flex items-center col-span-12 sm:col-span-5 lg:col-span-6`}>
6681
<div className={'icon'} css={tw`mr-4`}>
6782
<FontAwesomeIcon icon={faServer}/>
6883
</div>
6984
<div>
7085
<p css={tw`text-lg break-words`}>{server.name}</p>
7186
{!!server.description &&
72-
<p css={tw`text-sm text-neutral-300 break-all`}>{server.description}</p>
87+
<p css={tw`text-sm text-neutral-300 break-words`}>{server.description}</p>
7388
}
7489
</div>
7590
</div>
@@ -131,16 +146,7 @@ export default ({ server, className }: { server: Server; className?: string }) =
131146
</React.Fragment>
132147
}
133148
</div>
134-
<div css={tw`col-span-1 sm:hidden flex justify-end`}>
135-
<div
136-
css={[
137-
tw`w-3 h-3 rounded-full`,
138-
(!stats?.status || stats?.status === 'offline')
139-
? tw`bg-red-500`
140-
: (stats?.status === 'running' ? tw`bg-green-500` : tw`bg-yellow-500`),
141-
]}
142-
/>
143-
</div>
144-
</GreyRowBox>
149+
<div className={'status-bar'}/>
150+
</StatusIndicatorBox>
145151
);
146152
};

0 commit comments

Comments
 (0)