Skip to content

Commit

Permalink
Merge pull request #2282 from avivtur/vm-tree-view-2
Browse files Browse the repository at this point in the history
CNV-45822: Vm tree view 2
  • Loading branch information
openshift-merge-bot[bot] authored Nov 28, 2024
2 parents 8fc8e19 + b76d373 commit 34b244d
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 19 deletions.
2 changes: 2 additions & 0 deletions locales/en/plugin__kubevirt-plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -1393,6 +1393,8 @@
"VirtIO": "VirtIO",
"Virtual machine is not running": "Virtual machine is not running",
"Virtual Machines": "Virtual Machines",
"Virtual Machines ({{count}})_one": "Virtual Machines ({{count}})",
"Virtual Machines ({{count}})_other": "Virtual Machines ({{count}})",
"Virtualization": "Virtualization",
"Virtualization Alerts": "Virtualization Alerts",
"Virtualization Alerts donut chart": "Virtualization Alerts donut chart",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@ import './VMStatusesCard.scss';
type VMStatusItemProps = {
count: number;
namespace?: string;
onFilterChange?: () => void;
status: string;
};

const VMStatusItem: React.FC<VMStatusItemProps> = ({ count, namespace, status }) => {
const VMStatusItem: React.FC<VMStatusItemProps> = ({
count,
namespace,
onFilterChange,
status,
}) => {
const Icon = vmStatusIcon[status];
const path = `/k8s/${
isAllNamespaces(namespace) ? ALL_NAMESPACES : `ns/${namespace}`
Expand All @@ -28,7 +34,14 @@ const VMStatusItem: React.FC<VMStatusItemProps> = ({ count, namespace, status })
<div className="vm-statuses-card__status-item--count">
<span className="vm-statuses-card__status-item--icon">{Icon && <Icon />}</span>
<span className="vm-statuses-card__status-item--value">
<Link to={path}>{count.toString()}</Link>
<Link
onClick={() => {
onFilterChange?.();
}}
to={path}
>
{count.toString()}
</Link>
</span>
</div>
<div className="vm-statuses-card__status-item--status">{status}</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ const VMStatusesCard: React.FC = () => {
status={VM_STATUS.Running}
/>
<VMStatusItem
count={primaryStatuses.Paused}
count={primaryStatuses.Stopped}
namespace={activeNamespace}
status={VM_STATUS.Paused}
status={VM_STATUS.Stopped}
/>
<VMStatusItem
count={primaryStatuses.Migrating}
count={primaryStatuses.Paused}
namespace={activeNamespace}
status={VM_STATUS.Migrating}
status={VM_STATUS.Paused}
/>
</Grid>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { V1VirtualMachine } from '@kubevirt-ui/kubevirt-api/kubevirt';
import { getVMStatus } from '@kubevirt-utils/resources/shared';
import { VM_STATUS } from '@kubevirt-utils/resources/vm/utils/vmStatus';
import { RedExclamationCircleIcon } from '@openshift-console/dynamic-plugin-sdk';
import { InProgressIcon, PausedIcon, SyncAltIcon } from '@patternfly/react-icons';
import { InProgressIcon, OffIcon, PausedIcon, SyncAltIcon } from '@patternfly/react-icons';

import { ERROR } from './constants';

const PRIMARY_STATUSES = [VM_STATUS.Running, VM_STATUS.Paused, VM_STATUS.Migrating, ERROR];
const PRIMARY_STATUSES = [VM_STATUS.Running, VM_STATUS.Stopped, VM_STATUS.Paused, ERROR];

const ERROR_STATUSES = [
VM_STATUS.CrashLoopBackOff,
Expand All @@ -30,7 +30,7 @@ export const vmStatusIcon = {
Provisioning: Fragment,
Running: SyncAltIcon,
Starting: Fragment,
Stopped: Fragment,
Stopped: OffIcon,
Stopping: Fragment,
Terminating: Fragment,
};
Expand Down
6 changes: 6 additions & 0 deletions src/views/virtualmachines/list/VirtualMachinesList.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@
max-width: 50px;
}
}

.vm-list-page-header {
h1.co-m-pane__heading {
font-size: var(--pf-v5-global--FontSize--lg);
}
}
29 changes: 19 additions & 10 deletions src/views/virtualmachines/list/VirtualMachinesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { useVMListFilters } from '../utils';

import VirtualMachineActionButton from './components/VirtualMachineActionButton';
import VirtualMachineEmptyState from './components/VirtualMachineEmptyState/VirtualMachineEmptyState';
import VirtualMachineListSummary from './components/VirtualMachineListSummary/VirtualMachineListSummary';
import VirtualMachineRow from './components/VirtualMachineRow/VirtualMachineRow';
import VirtualMachinesCreateButton from './components/VirtualMachinesCreateButton/VirtualMachinesCreateButton';
import useSelectedFilters from './hooks/useSelectedFilters';
Expand Down Expand Up @@ -165,6 +166,11 @@ const VirtualMachinesList: FC<VirtualMachinesListProps> = ({ kind, namespace })
if (loaded && noVMs) {
return (
<VirtualMachineTreeView>
<VirtualMachineListSummary
namespace={namespace}
onFilterChange={onFilterChange}
vms={data}
/>
<VirtualMachineEmptyState catalogURL={catalogURL} namespace={namespace} />
</VirtualMachineTreeView>
);
Expand All @@ -173,16 +179,19 @@ const VirtualMachinesList: FC<VirtualMachinesListProps> = ({ kind, namespace })
return (
/* All of this table and components should be replaced to our own fitted components */
<VirtualMachineTreeView onFilterChange={onFilterChange}>
<ListPageHeader title={t('VirtualMachines')}>
<Flex>
<FlexItem>
<VirtualMachineActionButton />
</FlexItem>
<FlexItem>
<VirtualMachinesCreateButton namespace={namespace} />
</FlexItem>
</Flex>
</ListPageHeader>
<VirtualMachineListSummary namespace={namespace} onFilterChange={onFilterChange} vms={data} />
<div className="vm-list-page-header">
<ListPageHeader title={t('VirtualMachines')}>
<Flex>
<FlexItem>
<VirtualMachineActionButton />
</FlexItem>
<FlexItem>
<VirtualMachinesCreateButton namespace={namespace} />
</FlexItem>
</Flex>
</ListPageHeader>
</div>
<ListPageBody>
<div className="vm-listpagebody">
<div className="list-managment-group">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.vm-list-summary {
&__expand-section {
margin: var(--pf-global--spacer--lg);

&-toggle {
color: var(--pf-v5-global--Color--100);
margin: 0;

&-icon {
margin-right: var(--pf-global--spacer--sm);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import React, { FC, useState } from 'react';

import { V1VirtualMachine } from '@kubevirt-ui/kubevirt-api/kubevirt';
import { ALL_PROJECTS } from '@kubevirt-utils/hooks/constants';
import { useKubevirtTranslation } from '@kubevirt-utils/hooks/useKubevirtTranslation';
import { VM_STATUS } from '@kubevirt-utils/resources/vm/utils/vmStatus';
import { FilterValue } from '@openshift-console/dynamic-plugin-sdk';
import { ERROR } from '@overview/OverviewTab/vm-statuses-card/utils/constants';
import { getVMStatuses } from '@overview/OverviewTab/vm-statuses-card/utils/utils';
import VMStatusItem from '@overview/OverviewTab/vm-statuses-card/VMStatusItem';
import {
Card,
CardHeader,
CardTitle,
Divider,
ExpandableSection,
Grid,
Text,
} from '@patternfly/react-core';
import { ProjectDiagramIcon } from '@patternfly/react-icons';

import './VirtualMachineListSummary.scss';

type VirtualMachineListSummaryProps = {
namespace: string;
onFilterChange?: (type: string, value: FilterValue) => void;
vms: V1VirtualMachine[];
};

const VirtualMachineListSummary: FC<VirtualMachineListSummaryProps> = ({
namespace,
onFilterChange,
vms,
}) => {
const { t } = useKubevirtTranslation();
const [isExpanded, setIsExpanded] = useState<boolean>(true);

const { primaryStatuses } = getVMStatuses(vms || []);

return (
<ExpandableSection
toggleContent={
<Text className="vm-list-summary__expand-section-toggle" component="h3">
<ProjectDiagramIcon className="vm-list-summary__expand-section-toggle-icon" />{' '}
{namespace ?? ALL_PROJECTS}
</Text>
}
className="vm-list-summary__expand-section"
isExpanded={isExpanded}
onToggle={() => setIsExpanded((prev) => !prev)}
>
<Card className="vm-list-summary__card" data-test-id="vm-list-summary">
<CardHeader className="vm-statuses-card__header">
<CardTitle component="h5">
{t('Virtual Machines ({{count}})', { count: vms?.length })}
</CardTitle>
</CardHeader>
<div className="vm-statuses-card__body">
<Grid hasGutter>
<VMStatusItem
count={primaryStatuses.Error}
namespace={namespace}
onFilterChange={() => onFilterChange('status', { selected: [ERROR] })}
status={ERROR}
/>
<VMStatusItem
count={primaryStatuses.Running}
namespace={namespace}
onFilterChange={() => onFilterChange('status', { selected: [VM_STATUS.Running] })}
status={VM_STATUS.Running}
/>
<VMStatusItem
count={primaryStatuses.Stopped}
namespace={namespace}
onFilterChange={() => onFilterChange('status', { selected: [VM_STATUS.Stopped] })}
status={VM_STATUS.Stopped}
/>
<VMStatusItem
count={primaryStatuses.Paused}
namespace={namespace}
onFilterChange={() => onFilterChange('status', { selected: [VM_STATUS.Paused] })}
status={VM_STATUS.Paused}
/>
</Grid>
</div>
<Divider />
</Card>
</ExpandableSection>
);
};

export default VirtualMachineListSummary;
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@catalog/*": ["src/views/catalog/*"],
"@kubevirt-utils": ["src/utils"],
"@kubevirt-utils/*": ["src/utils/*"],
"@overview/*": ["src/views/clusteroverview/*"],
"@virtualmachines/*": ["src/views/virtualmachines/*"],
"react": ["./node_modules/react", "./node_modules/@types/react"]
},
Expand Down

0 comments on commit 34b244d

Please sign in to comment.