From 581dda9025b3f51c4aa1f9c1ceed22715f10fed5 Mon Sep 17 00:00:00 2001 From: suomiy Date: Wed, 19 Jun 2019 13:38:23 +0200 Subject: [PATCH 1/2] kubevirt: port VM list to PF4 Table --- .../kubevirt-plugin/src/components/vms/vm.tsx | 170 +++++++++--------- 1 file changed, 89 insertions(+), 81 deletions(-) diff --git a/frontend/packages/kubevirt-plugin/src/components/vms/vm.tsx b/frontend/packages/kubevirt-plugin/src/components/vms/vm.tsx index 7c227e7968a..6791174df5c 100644 --- a/frontend/packages/kubevirt-plugin/src/components/vms/vm.tsx +++ b/frontend/packages/kubevirt-plugin/src/components/vms/vm.tsx @@ -1,101 +1,91 @@ import * as React from 'react'; +import * as classNames from 'classnames'; import { - getName, - getNamespace, + getResource, // VmStatus, // getSimpleVmStatus, // VM_SIMPLE_STATUS_ALL, // VM_SIMPLE_STATUS_TO_TEXT, - // getResource, // DASHES, } from 'kubevirt-web-ui-components'; +import { getName, getNamespace, getUid } from '@console/shared'; + import { NamespaceModel } from '@console/internal/models'; -import { - ListHeader, - ColHead, - List, - ListPage, - ResourceRow, -} from '@console/internal/components/factory'; -import { ResourceLink } from '@console/internal/components/utils'; +import { Table, MultiListPage, TableRow, TableData } from '@console/internal/components/factory'; +import { Kebab, ResourceLink } from '@console/internal/components/utils'; // import { actions } from '../../module/okdk8s'; +import { sortable } from '@patternfly/react-table'; import { VirtualMachineModel, // VirtualMachineInstanceModel, // VirtualMachineInstanceMigrationModel, } from '../../models'; +import {VMKind} from "./types"; // import { openCreateVmWizard } from '../modals/create-vm-modal'; // import { menuActions } from './menu-actions'; -// import { WithResources } from '../utils/withResources'; - -const mainRowSize = 'col-lg-4 col-md-4 col-sm-6 col-xs-6'; -const otherRowSize = 'col-lg-4 col-md-4 hidden-sm hidden-xs'; - -const VMHeader: React.FC = (props) => ( - - - Name - - - Namespace - - {/* TODO(mlibra): migrate VM status in a follow-up - State - */} - -); -const VMRow = ({ obj: vm }: React.ComponentProps) => { +const tableColumnClasses = [ + classNames('col-lg-4', 'col-md-4', 'col-sm-6', 'col-xs-6'), + classNames('col-lg-4', 'col-md-4', 'hidden-sm', 'hidden-xs'), + classNames('col-lg-4', 'col-md-4', 'col-sm-6', 'col-xs-6'), + Kebab.columnClass, +]; + +const VMHeader = () => [ + { + title: 'Name', + sortField: 'metadata.name', + transforms: [sortable], + props: { className: tableColumnClasses[0] }, + }, + { + title: 'Namespace', + sortField: 'metadata.namespace', + transforms: [sortable], + props: { className: tableColumnClasses[1] }, + }, + // { + // title: 'Status', + // props: { className: tableColumnClasses[2] }, + // }, + // { + // title: '', + // props: { className: Kebab.columnClass, props: { className: tableColumnClasses[3] } }, + // }, +]; + +const VMRow: React.FC = ({ obj: vm, index, key, style }) => { const name = getName(vm); const namespace = getNamespace(vm); - /* - TODO(mlibra) To keep recent PR minimal, relations to other objects will be migrated as a next step. - Keeping the code here for reference. - const migrationResources = getResource(VirtualMachineInstanceMigrationModel, {namespace}); - const resourceMap = { - pods: { - resource: getResource(PodModel, { namespace }), - }, - migrations: { - resource: migrationResources, - }, - }; - */ - return ( - -
+ + -
-
+ + -
- {/* TODO(mlibra): migrate VM status in a follow-up -
- DASHES}> - - -
- */} - {/* TODO(mlibra): migrate actions in a follow-up -
- -
- */} -
+ + {/* TODO(mlibra): migrate VM status in a follow-up */} + {/* TODO(mlibra): migrate actions in a follow-up */} + ); }; -const VMList: React.FC = (props) => ; +const VMList: React.FC & VMListProps> = (props) => ( + +); + VMList.displayName = 'VMList'; const filters = undefined; @@ -113,10 +103,6 @@ const filters = [{ }]; */ -type VirtualMachinesPageProps = { - namespace: string; -}; - const getCreateProps = (namespace: string) => ({ items: { // wizard: 'Create with Wizard', TODO(mlibra): migrate Create VM Dialog @@ -135,13 +121,35 @@ const getCreateProps = (namespace: string) => ({ */ }); -export const VirtualMachinesPage = (props: VirtualMachinesPageProps) => ( - -); +export const VirtualMachinesPage: React.FC = (props) => { + const { namespace } = props; + const flatten = ({ vms: { data: vmsData, loaded, loadError } }) => loaded && !loadError ? vmsData : []; + + return ( + + ); +}; + +type VMRowProps = { + obj: VMKind; + index: number; + key: string; + style: object; +}; + +type VMListProps = { + data: VMKind[]; +}; + +type VirtualMachinesPageProps = { + namespace: string; +}; From c66a7500a3c279ce40c41c00b48c2375b5638587 Mon Sep 17 00:00:00 2001 From: suomiy Date: Thu, 20 Jun 2019 17:13:12 +0200 Subject: [PATCH 2/2] kubevirt: move types to a standalone dir --- .../kubevirt-plugin/src/components/vms/vm-details.tsx | 2 +- .../kubevirt-plugin/src/components/vms/vm-resource.tsx | 2 +- frontend/packages/kubevirt-plugin/src/components/vms/vm.tsx | 6 +++--- frontend/packages/kubevirt-plugin/src/types/index.ts | 1 + .../src/{components/vms/types.ts => types/vm/index.ts} | 0 5 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 frontend/packages/kubevirt-plugin/src/types/index.ts rename frontend/packages/kubevirt-plugin/src/{components/vms/types.ts => types/vm/index.ts} (100%) diff --git a/frontend/packages/kubevirt-plugin/src/components/vms/vm-details.tsx b/frontend/packages/kubevirt-plugin/src/components/vms/vm-details.tsx index 2e8c87ee079..40848acbb12 100644 --- a/frontend/packages/kubevirt-plugin/src/components/vms/vm-details.tsx +++ b/frontend/packages/kubevirt-plugin/src/components/vms/vm-details.tsx @@ -14,7 +14,7 @@ import { PodKind } from '@console/internal/module/k8s'; import { PodModel, ServiceModel } from '@console/internal/models'; import { ServicesList } from '@console/internal/components/service'; -import { VMKind, VMIKind } from './types'; +import { VMKind, VMIKind } from '../../types'; import { VirtualMachineInstanceModel, VirtualMachineInstanceMigrationModel } from '../../models'; import { VMResourceSummary, VMDetailsList } from './vm-resource'; diff --git a/frontend/packages/kubevirt-plugin/src/components/vms/vm-resource.tsx b/frontend/packages/kubevirt-plugin/src/components/vms/vm-resource.tsx index 02660e0d614..06a95ddde4e 100644 --- a/frontend/packages/kubevirt-plugin/src/components/vms/vm-resource.tsx +++ b/frontend/packages/kubevirt-plugin/src/components/vms/vm-resource.tsx @@ -22,7 +22,7 @@ import { PodKind } from '@console/internal/module/k8s'; import { getName, getNamespace, DASH } from '@console/shared'; import { PodModel } from '@console/internal/models'; -import { VMKind, VMIKind } from './types'; +import { VMKind, VMIKind } from '../../types'; export const VMResourceSummary = ({ vm }: VMResourceSummaryProps) => { const template = getVmTemplate(vm); diff --git a/frontend/packages/kubevirt-plugin/src/components/vms/vm.tsx b/frontend/packages/kubevirt-plugin/src/components/vms/vm.tsx index 6791174df5c..8e9f421c615 100644 --- a/frontend/packages/kubevirt-plugin/src/components/vms/vm.tsx +++ b/frontend/packages/kubevirt-plugin/src/components/vms/vm.tsx @@ -11,7 +11,6 @@ import { } from 'kubevirt-web-ui-components'; import { getName, getNamespace, getUid } from '@console/shared'; - import { NamespaceModel } from '@console/internal/models'; import { Table, MultiListPage, TableRow, TableData } from '@console/internal/components/factory'; import { Kebab, ResourceLink } from '@console/internal/components/utils'; @@ -23,7 +22,7 @@ import { // VirtualMachineInstanceModel, // VirtualMachineInstanceMigrationModel, } from '../../models'; -import {VMKind} from "./types"; +import { VMKind } from '../../types'; // import { openCreateVmWizard } from '../modals/create-vm-modal'; // import { menuActions } from './menu-actions'; @@ -123,7 +122,8 @@ const getCreateProps = (namespace: string) => ({ export const VirtualMachinesPage: React.FC = (props) => { const { namespace } = props; - const flatten = ({ vms: { data: vmsData, loaded, loadError } }) => loaded && !loadError ? vmsData : []; + const flatten = ({ vms: { data: vmsData, loaded, loadError } }) => + loaded && !loadError ? vmsData : []; return (