From 92ba467f0f144ada17ae31c3e91595193ccacd89 Mon Sep 17 00:00:00 2001 From: yaacov Date: Thu, 23 May 2024 14:40:33 +0300 Subject: [PATCH] Show vm specific conditions in plan vm list Signed-off-by: yaacov --- .../Plan/PlanVirtualMachinesList.tsx | 48 ++++++++++++++++++- .../Plan/PlanVirtualMachinesRow.tsx | 3 +- .../components/ConditionsCellRenderer.tsx | 27 +++++++++++ .../tabs/VirtualMachines/components/index.ts | 1 + .../tabs/VirtualMachines/types/VMData.ts | 2 + 5 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/components/ConditionsCellRenderer.tsx diff --git a/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/Plan/PlanVirtualMachinesList.tsx b/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/Plan/PlanVirtualMachinesList.tsx index 4c432a906..1b67476d0 100644 --- a/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/Plan/PlanVirtualMachinesList.tsx +++ b/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/Plan/PlanVirtualMachinesList.tsx @@ -7,7 +7,11 @@ import { import { useForkliftTranslation } from 'src/utils/i18n'; import { loadUserSettings, ResourceFieldFactory } from '@kubev2v/common'; -import { V1beta1PlanSpecVms, V1beta1PlanStatusMigrationVms } from '@kubev2v/types'; +import { + V1beta1PlanSpecVms, + V1beta1PlanStatusConditions, + V1beta1PlanStatusMigrationVms, +} from '@kubev2v/types'; import { PlanVMsDeleteButton } from '../components'; import { PlanData, VMData } from '../types'; @@ -27,6 +31,15 @@ const fieldsMetadataFactory: ResourceFieldFactory = (t) => [ }, sortable: true, }, + { + resourceFieldId: 'conditions', + jsonPath: (obj: VMData) => { + return obj?.conditions?.[0]?.category; + }, + label: t('Conditions'), + isVisible: true, + sortable: true, + }, ]; const PageWithSelection = StandardPageWithSelection; @@ -48,12 +61,22 @@ export const PlanVirtualMachinesList: FC<{ obj: PlanData }> = ({ obj }) => { const vmDict: Record = {}; migrationVirtualMachines.forEach((m) => (vmDict[m.id] = m)); + const conditions = plan?.status?.conditions?.filter((c) => c?.items && c.items.length > 0); + const conditionsDict: Record = {}; + conditions?.forEach((c) => { + c.items.forEach((i) => { + const { id: vmID } = extractIdAndNameFromConditionItem(i); + conditionsDict[vmID] ? conditionsDict[vmID].push(c) : (conditionsDict[vmID] = [c]); + }); + }); + const vmData: VMData[] = virtualMachines.map((m) => ({ specVM: m, statusVM: vmDict[m.id], pods: [], jobs: [], pvcs: [], + conditions: conditionsDict[m.id], targetNamespace: plan?.spec?.targetNamespace, })); @@ -83,3 +106,26 @@ export const PlanVirtualMachinesList: FC<{ obj: PlanData }> = ({ obj }) => { return ; }; + +/** + * Extracts the ID and name from a condition item string. + * + * This function parses a string containing condition item details and extracts the ID and name. + * The string format expected is something like "id: name:''". + * + * @param {string} input - The string containing the condition item details. + * @returns {{ id: string; name: string }} An object containing the extracted ID and name. + */ +function extractIdAndNameFromConditionItem(input: string): { id: string; name: string } { + const idMatch = /id:([^ ]+)/.exec(input); + const nameMatch = /name:'([^']+)'/.exec(input); + + if (!idMatch || !nameMatch) { + return { id: '', name: '' }; + } + + return { + id: idMatch[1], + name: nameMatch[1], + }; +} diff --git a/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/Plan/PlanVirtualMachinesRow.tsx b/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/Plan/PlanVirtualMachinesRow.tsx index caeb49d83..3bd3b81b3 100644 --- a/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/Plan/PlanVirtualMachinesRow.tsx +++ b/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/Plan/PlanVirtualMachinesRow.tsx @@ -3,7 +3,7 @@ import React from 'react'; import { ResourceField, RowProps } from '@kubev2v/common'; import { Td } from '@kubev2v/common'; -import { PlanVMsCellProps } from '../components'; +import { ConditionsCellRenderer, PlanVMsCellProps } from '../components'; import { NameCellRenderer } from '../components/NameCellRenderer'; import { VMData } from '../types'; @@ -33,6 +33,7 @@ const renderTd = ({ resourceData, resourceFieldId, resourceFields }: RenderTdPro const cellRenderers: Record> = { name: NameCellRenderer, + conditions: ConditionsCellRenderer, }; interface RenderTdProps { diff --git a/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/components/ConditionsCellRenderer.tsx b/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/components/ConditionsCellRenderer.tsx new file mode 100644 index 000000000..316d2338e --- /dev/null +++ b/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/components/ConditionsCellRenderer.tsx @@ -0,0 +1,27 @@ +import React from 'react'; +import { TableCell } from 'src/modules/Providers/utils'; + +import { YellowExclamationTriangleIcon } from '@openshift-console/dynamic-plugin-sdk'; +import { Label, Level, LevelItem } from '@patternfly/react-core'; + +import { PlanVMsCellProps } from './PlanVMsCellProps'; + +export const ConditionsCellRenderer: React.FC = ({ data }) => { + const condition = data?.conditions?.[0]; + if (!condition) { + return <>; + } + + return ( + + + + + + {condition.message} + + + ); +}; diff --git a/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/components/index.ts b/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/components/index.ts index 9595f520c..db0547464 100644 --- a/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/components/index.ts +++ b/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/components/index.ts @@ -1,4 +1,5 @@ // @index(['./*', /style/g], f => `export * from '${f.path}';`) +export * from './ConditionsCellRenderer'; export * from './MigrationVMsCancelButton'; export * from './NameCellRenderer'; export * from './PlanVMsCellProps'; diff --git a/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/types/VMData.ts b/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/types/VMData.ts index a88b890a4..0754125fc 100644 --- a/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/types/VMData.ts +++ b/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/types/VMData.ts @@ -3,6 +3,7 @@ import { IoK8sApiCoreV1PersistentVolumeClaim, IoK8sApiCoreV1Pod, V1beta1PlanSpecVms, + V1beta1PlanStatusConditions, V1beta1PlanStatusMigrationVms, } from '@kubev2v/types'; @@ -12,5 +13,6 @@ export type VMData = { pods: IoK8sApiCoreV1Pod[]; jobs: IoK8sApiBatchV1Job[]; pvcs: IoK8sApiCoreV1PersistentVolumeClaim[]; + conditions?: V1beta1PlanStatusConditions[]; targetNamespace: string; };