Skip to content

Commit

Permalink
frontend: Handle large list of ports
Browse files Browse the repository at this point in the history
  • Loading branch information
ashu8912 committed Jun 13, 2024
1 parent 8e8f58c commit fc3b1a0
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions frontend/src/components/common/Resource/Resource.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Icon } from '@iconify/react';
import Editor from '@monaco-editor/react';
import { InputLabel } from '@mui/material';
import { Button, InputLabel } from '@mui/material';
import Box from '@mui/material/Box';
import Divider from '@mui/material/Divider';
import Grid, { GridProps, GridSize } from '@mui/material/Grid';
Expand Down Expand Up @@ -644,7 +644,8 @@ export interface ContainerInfoProps {
export function ContainerInfo(props: ContainerInfoProps) {
const { container, status, resource } = props;
const { t } = useTranslation(['glossary', 'translation']);

const [maxPortsToShow, setMaxPortsToShow] = React.useState(5);
const portsToShow = container.ports?.slice(0, 5 * maxPortsToShow);
const [startedDate, finishDate, lastStateStartedDate, lastStateFinishDate] = React.useMemo(() => {
function getStartedDate(state?: KubeContainerStatus['state']) {
let startedDate = state?.running?.startedAt || state?.terminated?.startedAt || '';
Expand Down Expand Up @@ -738,7 +739,6 @@ export function ContainerInfo(props: ContainerInfoProps) {
}) {
const { rows } = props;
const id = useId('status-value-');

const rowsToDisplay = React.useMemo(() => {
return rows.filter(({ hide }) => !hide);
}, [rows]);
Expand Down Expand Up @@ -904,7 +904,7 @@ export function ContainerInfo(props: ContainerInfoProps) {
name: t('Ports'),
value: (
<Grid container>
{container.ports?.map(({ containerPort, protocol }, index) => (
{portsToShow?.map(({ containerPort, protocol }, index) => (
<>
<Grid item xs={12} key={`port_line_${index}`}>
<Box display="flex" alignItems={'center'}>
Expand All @@ -917,7 +917,7 @@ export function ContainerInfo(props: ContainerInfoProps) {
)}
</Box>
</Grid>
{index < container.ports!.length - 1 && (
{index < portsToShow!.length - 1 && (
<Grid item xs={12}>
<Box mt={2} mb={2}>
<Divider />
Expand All @@ -926,6 +926,18 @@ export function ContainerInfo(props: ContainerInfoProps) {
)}
</>
))}
{container.ports?.length! > 5 &&
portsToShow &&
container.ports &&
portsToShow.length < container.ports.length && (
<Grid item xs={12}>
<Box display="flex" mt={2}>
<Button onClick={() => setMaxPortsToShow(prev => prev * 2)}>
{t('translation|Show More')}
</Button>
</Box>
</Grid>
)}
</Grid>
),
hide: _.isEmpty(container.ports),
Expand Down

0 comments on commit fc3b1a0

Please sign in to comment.