Skip to content

Commit

Permalink
Merge pull request #708 from rszwajko/providersVm
Browse files Browse the repository at this point in the history
Display more columns in Providers VM table
  • Loading branch information
yaacov authored Sep 7, 2023
2 parents c67b7c3 + 8074173 commit 6f97ee5
Show file tree
Hide file tree
Showing 16 changed files with 821 additions and 136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"Clear all filters": "Clear all filters",
"Click the update credentials button to save your changes, button is disabled until a change is detected.": "Click the update credentials button to save your changes, button is disabled until a change is detected.",
"Close": "Close",
"Cluster": "Cluster",
"Clusters": "Clusters",
"Concerns": "Concerns",
"Conditions": "Conditions",
Expand Down Expand Up @@ -113,17 +114,27 @@
"Error: VDDK init image must be valid.": "Error: VDDK init image must be valid.",
"Failed": "Failed",
"False": "False",
"Filter by cluster": "Filter by cluster",
"Filter by endpoint": "Filter by endpoint",
"Filter by flavor": "Filter by flavor",
"Filter by host": "Filter by host",
"Filter by image": "Filter by image",
"Filter by name": "Filter by name",
"Filter by namespace": "Filter by namespace",
"Filter by network": "Filter by network",
"Filter by path": "Filter by path",
"Filter by status": "Filter by status",
"Filter by tenant": "Filter by tenant",
"Flavor": "Flavor",
"From": "From",
"Hide values": "Hide values",
"Hooks for virtualization": "Hooks for virtualization",
"Host": "Host",
"Host cluster": "Host cluster",
"Hosts": "Hosts",
"If true, the provider's REST API TLS certificate won't be validated.": "If true, the provider's REST API TLS certificate won't be validated.",
"If true, the provider's TLS certificate won't be validated.": "If true, the provider's TLS certificate won't be validated.",
"Image": "Image",
"Invalid application credential ID.": "Invalid application credential ID.",
"Invalid application credential name.": "Invalid application credential name.",
"Invalid application credential secret.": "Invalid application credential secret.",
Expand Down Expand Up @@ -234,9 +245,11 @@
"OpenStack REST API user name.": "OpenStack REST API user name.",
"Operator": "Operator",
"Operator conditions define the current state of the controller": "Operator conditions define the current state of the controller",
"OvaPath": "OvaPath",
"Overview": "Overview",
"Owner": "Owner",
"Password": "Password",
"Path": "Path",
"Plans": "Plans",
"Plans for virtualization": "Plans for virtualization",
"Please choose a NetworkAttachmentDefinition for default data transfer.": "Please choose a NetworkAttachmentDefinition for default data transfer.",
Expand Down Expand Up @@ -320,6 +333,8 @@
"Succeeded": "Succeeded",
"Target and Source": "Target and Source",
"Target provider": "Target provider",
"Template": "Template",
"Tenant": "Tenant",
"The CA certificate is the /etc/pki/ovirt-engine/apache-ca.pem file on the Manager machine.": "The CA certificate is the /etc/pki/ovirt-engine/apache-ca.pem file on the Manager machine.",
"The interval in minutes for precopy. Default value is 60.": "The interval in minutes for precopy. Default value is 60.",
"The interval in seconds for snapshot pooling. Default value is 10.": "The interval in seconds for snapshot pooling. Default value is 10.",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import React from 'react';

import { EnumToTuple, ResourceFieldFactory } from '@kubev2v/common';

import { ProviderVirtualMachinesList } from './components/ProviderVirtualMachinesList';
import { OVirtVirtualMachinesRow } from './OVirtVirtualMachinesRow';
import { ProviderVirtualMachinesProps } from './ProviderVirtualMachines';

export const oVirtVmFieldsMetadataFactory: ResourceFieldFactory = (t) => [
{
resourceFieldId: 'name',
jsonPath: '$.name',
label: t('Name'),
isVisible: true,
isIdentity: true, // Name is sufficient ID when Namespace is pre-selected
filter: {
type: 'freetext',
placeholderLabel: t('Filter by name'),
},
sortable: true,
},
{
resourceFieldId: 'concerns',
jsonPath: '$.concerns',
label: t('Concerns'),
isVisible: true,
sortable: true,
filter: {
type: 'enum',
primary: true,
placeholderLabel: t('Concerns'),
values: EnumToTuple({ Critical: 'Critical', Warning: 'Warning', Information: 'Information' }),
},
},
{
resourceFieldId: 'cluster',
jsonPath: '$.vm.cluster',
label: t('Cluster'),
isVisible: true,
isIdentity: false,
filter: {
type: 'freetext',
placeholderLabel: t('Filter by cluster'),
},
sortable: true,
},
{
resourceFieldId: 'host',
jsonPath: '$.vm.host',
label: t('Host'),
isVisible: true,
isIdentity: false,
filter: {
type: 'freetext',
placeholderLabel: t('Filter by host'),
},
sortable: true,
},
{
resourceFieldId: 'path',
jsonPath: '$.vm.path',
label: t('Path'),
isVisible: true,
isIdentity: false,
filter: {
type: 'freetext',
placeholderLabel: t('Filter by path'),
},
sortable: true,
},
{
resourceFieldId: 'status',
jsonPath: '$.vm.status',
label: t('Status'),
isVisible: true,
isIdentity: false,
filter: {
type: 'freetext',
placeholderLabel: t('Filter by status'),
},
sortable: true,
},
{
resourceFieldId: 'description',
jsonPath: '$.vm.description',
label: t('Description'),
isVisible: true,
isIdentity: false,
sortable: false,
},
];

export const OVirtVirtualMachinesList: React.FC<ProviderVirtualMachinesProps> = ({
obj,
loaded,
loadError,
}) => (
<ProviderVirtualMachinesList
obj={obj}
loaded={loaded}
loadError={loadError}
rowMapper={OVirtVirtualMachinesRow}
fieldsMetadataFactory={oVirtVmFieldsMetadataFactory}
pageId="OVirtVirtualMachinesList"
/>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React from 'react';
import { TableCell } from 'src/modules/Providers/utils';

import { ResourceField, RowProps } from '@kubev2v/common';
import { OVirtVM } from '@kubev2v/types';
import { Td, Tr } from '@patternfly/react-table';

import { VMCellProps, VMConcernsCellRenderer, VMNameCellRenderer } from './components';

export interface VmData {
vm: OVirtVM;
name: string;
concerns: string;
}

const renderTd = ({ resourceData, resourceFieldId, resourceFields }: RenderTdProps) => {
const fieldId = resourceFieldId;

const CellRenderer = cellRenderers?.[fieldId] ?? (() => <></>);
return (
<Td key={fieldId} dataLabel={fieldId}>
<CellRenderer data={resourceData} fieldId={fieldId} fields={resourceFields} />
</Td>
);
};

interface RenderTdProps {
resourceData: VmData;
resourceFieldId: string;
resourceFields: ResourceField[];
}

const cellRenderers: Record<string, React.FC<VMCellProps>> = {
name: VMNameCellRenderer,
concerns: VMConcernsCellRenderer,
host: ({ data }) => <TableCell>{(data?.vm as OVirtVM)?.host}</TableCell>,
cluster: ({ data }) => <TableCell>{(data?.vm as OVirtVM)?.cluster}</TableCell>,
path: ({ data }) => <TableCell>{(data?.vm as OVirtVM)?.path}</TableCell>,
status: ({ data }) => <TableCell>{(data?.vm as OVirtVM)?.status}</TableCell>,
description: ({ data }) => <TableCell>{(data?.vm as OVirtVM)?.description}</TableCell>,
};

export const OVirtVirtualMachinesRow: React.FC<RowProps<VmData>> = ({
resourceFields,
resourceData,
}) => {
return (
<Tr>
{resourceFields?.map(({ resourceFieldId }) =>
renderTd({ resourceData, resourceFieldId, resourceFields }),
)}
</Tr>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React from 'react';

import { EnumToTuple, ResourceFieldFactory } from '@kubev2v/common';

import { ProviderVirtualMachinesList } from './components/ProviderVirtualMachinesList';
import { OpenShiftVirtualMachinesRow } from './OpenShiftVirtualMachinesRow';
import { ProviderVirtualMachinesProps } from './ProviderVirtualMachines';

const openShiftVmFieldsMetadataFactory: ResourceFieldFactory = (t) => [
{
resourceFieldId: 'name',
jsonPath: '$.name',
label: t('Name'),
isVisible: true,
isIdentity: true, // Name is sufficient ID when Namespace is pre-selected
filter: {
type: 'freetext',
placeholderLabel: t('Filter by name'),
},
sortable: true,
},
{
resourceFieldId: 'concerns',
jsonPath: '$.concerns',
label: t('Concerns'),
isVisible: true,
sortable: true,
filter: {
type: 'enum',
primary: true,
placeholderLabel: t('Concerns'),
values: EnumToTuple({ Critical: 'Critical', Warning: 'Warning', Information: 'Information' }),
},
},
];

export const OpenShiftVirtualMachinesList: React.FC<ProviderVirtualMachinesProps> = ({
obj,
loaded,
loadError,
}) => (
<ProviderVirtualMachinesList
obj={obj}
loaded={loaded}
loadError={loadError}
rowMapper={OpenShiftVirtualMachinesRow}
fieldsMetadataFactory={openShiftVmFieldsMetadataFactory}
pageId="OpenShiftVirtualMachinesList"
/>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from 'react';

import { ResourceField, RowProps } from '@kubev2v/common';
import { Td, Tr } from '@patternfly/react-table';

import { VMCellProps, VMConcernsCellRenderer, VmData, VMNameCellRenderer } from './components';

const cellRenderers: Record<string, React.FC<VMCellProps>> = {
name: VMNameCellRenderer,
concerns: VMConcernsCellRenderer,
};

const renderTd = ({ resourceData, resourceFieldId, resourceFields }: RenderTdProps) => {
const fieldId = resourceFieldId;

const CellRenderer = cellRenderers?.[fieldId] ?? (() => <></>);
return (
<Td key={fieldId} dataLabel={fieldId}>
<CellRenderer data={resourceData} fieldId={fieldId} fields={resourceFields} />
</Td>
);
};

interface RenderTdProps {
resourceData: VmData;
resourceFieldId: string;
resourceFields: ResourceField[];
}

export const OpenShiftVirtualMachinesRow: React.FC<RowProps<VmData>> = ({
resourceFields,
resourceData,
}) => {
return (
<Tr>
{resourceFields?.map(({ resourceFieldId }) =>
renderTd({ resourceData, resourceFieldId, resourceFields }),
)}
</Tr>
);
};
Loading

0 comments on commit 6f97ee5

Please sign in to comment.