From 1111a5536a5bea110118cfec4fd428590b874107 Mon Sep 17 00:00:00 2001 From: Radoslaw Szwajkowski Date: Thu, 28 Sep 2023 17:22:16 +0200 Subject: [PATCH] Filter by all concerns present in the VM Before only the most severe concern was used for filtering. Signed-off-by: Radoslaw Szwajkowski --- .../OVirtVirtualMachinesList.tsx | 6 ++--- .../OpenShiftVirtualMachinesList.tsx | 3 +-- .../OpenStackVirtualMachinesList.tsx | 6 ++--- .../OvaVirtualMachinesList.tsx | 6 ++--- .../VSphereVirtualMachinesList.tsx | 6 ++--- .../ProviderVirtualMachinesList.tsx | 26 ++++++++++++++----- .../VirtualMachines/components/VMCellProps.ts | 1 - .../tabs/VirtualMachines/components/index.ts | 1 + .../helpers/getHighestPriorityConcern.ts | 23 ---------------- .../VirtualMachines/utils/helpers/index.ts | 1 - .../VirtualMachines/utils/useInventoryVms.tsx | 3 --- 11 files changed, 33 insertions(+), 49 deletions(-) delete mode 100644 packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/helpers/getHighestPriorityConcern.ts diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OVirtVirtualMachinesList.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OVirtVirtualMachinesList.tsx index a3c48759c..5afc2ff85 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OVirtVirtualMachinesList.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OVirtVirtualMachinesList.tsx @@ -2,7 +2,7 @@ import React from 'react'; import { EnumToTuple, ResourceFieldFactory } from '@kubev2v/common'; -import { ProviderVirtualMachinesList, VmData } from './components/ProviderVirtualMachinesList'; +import { ProviderVirtualMachinesList, VmData } from './components'; import { OVirtVirtualMachinesRow } from './OVirtVirtualMachinesRow'; import { ProviderVirtualMachinesProps } from './ProviderVirtualMachines'; import { getVmPowerState } from './utils'; @@ -22,12 +22,12 @@ export const oVirtVmFieldsMetadataFactory: ResourceFieldFactory = (t) => [ }, { resourceFieldId: 'concerns', - jsonPath: '$.concerns', + jsonPath: (data: VmData) => (data.vm.providerType === 'ovirt' ? data?.vm?.concerns : []), label: t('Concerns'), isVisible: true, sortable: true, filter: { - type: 'enum', + type: 'concerns', primary: true, placeholderLabel: t('Concerns'), values: EnumToTuple({ Critical: 'Critical', Warning: 'Warning', Information: 'Information' }), diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OpenShiftVirtualMachinesList.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OpenShiftVirtualMachinesList.tsx index b278e8391..a3fb05daa 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OpenShiftVirtualMachinesList.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OpenShiftVirtualMachinesList.tsx @@ -2,8 +2,7 @@ import React from 'react'; import { EnumToTuple, ResourceFieldFactory } from '@kubev2v/common'; -import { ProviderVirtualMachinesList } from './components/ProviderVirtualMachinesList'; -import { VmData } from './components'; +import { ProviderVirtualMachinesList, VmData } from './components'; import { OpenShiftVirtualMachinesRow } from './OpenShiftVirtualMachinesRow'; import { ProviderVirtualMachinesProps } from './ProviderVirtualMachines'; import { getVmPowerState } from './utils'; diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OpenStackVirtualMachinesList.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OpenStackVirtualMachinesList.tsx index 28d5eeb9b..11ceec0ca 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OpenStackVirtualMachinesList.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OpenStackVirtualMachinesList.tsx @@ -2,8 +2,8 @@ import React from 'react'; import { EnumToTuple, ResourceFieldFactory } from '@kubev2v/common'; -import { ProviderVirtualMachinesList, VmData } from './components/ProviderVirtualMachinesList'; import { getVmPowerState } from './utils/helpers/getVmPowerState'; +import { ProviderVirtualMachinesList, VmData } from './components'; import { OpenStackVirtualMachinesRow } from './OpenStackVirtualMachinesRow'; import { ProviderVirtualMachinesProps } from './ProviderVirtualMachines'; @@ -22,12 +22,12 @@ export const openStackVmFieldsMetadataFactory: ResourceFieldFactory = (t) => [ }, { resourceFieldId: 'concerns', - jsonPath: '$.concerns', + jsonPath: (data: VmData) => (data.vm.providerType === 'openstack' ? data?.vm?.concerns : []), label: t('Concerns'), isVisible: true, sortable: true, filter: { - type: 'enum', + type: 'concerns', primary: true, placeholderLabel: t('Concerns'), values: EnumToTuple({ Critical: 'Critical', Warning: 'Warning', Information: 'Information' }), diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OvaVirtualMachinesList.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OvaVirtualMachinesList.tsx index 2c9cdfbd9..2f542b65d 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OvaVirtualMachinesList.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OvaVirtualMachinesList.tsx @@ -2,7 +2,7 @@ import React from 'react'; import { EnumToTuple, ResourceFieldFactory } from '@kubev2v/common'; -import { ProviderVirtualMachinesList } from './components/ProviderVirtualMachinesList'; +import { ProviderVirtualMachinesList, VmData } from './components'; import { OvaVirtualMachinesRow } from './OvaVirtualMachinesRow'; import { ProviderVirtualMachinesProps } from './ProviderVirtualMachines'; @@ -21,12 +21,12 @@ export const ovaVmFieldsMetadataFactory: ResourceFieldFactory = (t) => [ }, { resourceFieldId: 'concerns', - jsonPath: '$.concerns', + jsonPath: (data: VmData) => (data.vm.providerType === 'ova' ? data?.vm?.concerns : []), label: t('Concerns'), isVisible: true, sortable: true, filter: { - type: 'enum', + type: 'concerns', primary: true, placeholderLabel: t('Concerns'), values: EnumToTuple({ Critical: 'Critical', Warning: 'Warning', Information: 'Information' }), diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/VSphereVirtualMachinesList.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/VSphereVirtualMachinesList.tsx index 433944b2d..ace8d7558 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/VSphereVirtualMachinesList.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/VSphereVirtualMachinesList.tsx @@ -2,7 +2,7 @@ import React from 'react'; import { EnumToTuple, ResourceFieldFactory } from '@kubev2v/common'; -import { ProviderVirtualMachinesList, VmData } from './components/ProviderVirtualMachinesList'; +import { ProviderVirtualMachinesList, VmData } from './components'; import { ProviderVirtualMachinesProps } from './ProviderVirtualMachines'; import { getVmPowerState } from './utils'; import { VSphereVirtualMachinesRow } from './VSphereVirtualMachinesRow'; @@ -22,12 +22,12 @@ export const vSphereVmFieldsMetadataFactory: ResourceFieldFactory = (t) => [ }, { resourceFieldId: 'concerns', - jsonPath: '$.concerns', + jsonPath: (data: VmData) => (data.vm.providerType === 'vsphere' ? data?.vm?.concerns : []), label: t('Concerns'), isVisible: true, sortable: true, filter: { - type: 'enum', + type: 'concerns', primary: true, placeholderLabel: t('Concerns'), values: EnumToTuple({ Critical: 'Critical', Warning: 'Warning', Information: 'Information' }), diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/components/ProviderVirtualMachinesList.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/components/ProviderVirtualMachinesList.tsx index d43c047bc..60632ec67 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/components/ProviderVirtualMachinesList.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/components/ProviderVirtualMachinesList.tsx @@ -4,16 +4,18 @@ import StandardPage from 'src/components/page/StandardPage'; import { ProviderData } from 'src/modules/Providers/utils'; import { useForkliftTranslation } from 'src/utils/i18n'; -import { loadUserSettings, ResourceFieldFactory, RowProps } from '@kubev2v/common'; -import { ProviderVirtualMachine } from '@kubev2v/types'; +import { + EnumFilter, + loadUserSettings, + ResourceFieldFactory, + RowProps, + ValueMatcher, +} from '@kubev2v/common'; +import { Concern } from '@kubev2v/types'; import { useInventoryVms } from '../utils/useInventoryVms'; -export interface VmData { - vm: ProviderVirtualMachine; - name: string; - concerns: string; -} +import { VmData } from './VMCellProps'; export interface ProviderVirtualMachinesListProps extends RouteComponentProps { obj: ProviderData; @@ -49,6 +51,16 @@ export const ProviderVirtualMachinesList: React.FC ); }; + +const concernsMatcher: ValueMatcher = { + filterType: 'concerns', + matchValue: (concerns: Concern[]) => (filter: string) => + concerns.some(({ category }) => category === filter), +}; diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/components/VMCellProps.ts b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/components/VMCellProps.ts index c0a6492ee..3b4c73a10 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/components/VMCellProps.ts +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/components/VMCellProps.ts @@ -4,7 +4,6 @@ import { ProviderVirtualMachine } from '@kubev2v/types'; export interface VmData { vm: ProviderVirtualMachine; name: string; - concerns: string; } export interface VMCellProps { diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/components/index.ts b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/components/index.ts index f374d52b9..7ff5972ec 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/components/index.ts +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/components/index.ts @@ -1,5 +1,6 @@ // @index(['./*', /style/g], f => `export * from '${f.path}';`) export * from './PowerStateCellRenderer'; +export * from './ProviderVirtualMachinesList'; export * from './VMCellProps'; export * from './VMConcernsCellRenderer'; export * from './VMNameCellRenderer'; diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/helpers/getHighestPriorityConcern.ts b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/helpers/getHighestPriorityConcern.ts deleted file mode 100644 index 4af0dd64c..000000000 --- a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/helpers/getHighestPriorityConcern.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { ProviderVirtualMachine } from '@kubev2v/types'; - -type ConcernCategory = 'Critical' | 'Warning' | 'Information'; - -export const getHighestPriorityConcern = (vm: ProviderVirtualMachine): ConcernCategory => { - if (vm?.providerType === 'openshift' || !vm?.concerns) { - return undefined; - } - - if (vm.concerns.some((c) => c.category === 'Critical')) { - return 'Critical'; - } - - if (vm.concerns.some((c) => c.category === 'Warning')) { - return 'Warning'; - } - - if (vm.concerns.some((c) => c.category === 'Information')) { - return 'Information'; - } - - return undefined; -}; diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/helpers/index.ts b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/helpers/index.ts index 066775fe2..aa2d06682 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/helpers/index.ts +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/helpers/index.ts @@ -1,5 +1,4 @@ // @index(['./*', /style/g], f => `export * from '${f.path}';`) -export * from './getHighestPriorityConcern'; export * from './getVmPowerState'; export * from './vmProps'; // @endindex diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/useInventoryVms.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/useInventoryVms.tsx index 75bd72197..978afe1b2 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/useInventoryVms.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/useInventoryVms.tsx @@ -5,8 +5,6 @@ import { ProviderVirtualMachine } from '@kubev2v/types'; import { VmData } from '../components'; -import { getHighestPriorityConcern } from './helpers'; - /** * A hook for retrieving VMs from the inventory. * Adds providerType property to each VM. @@ -46,7 +44,6 @@ export const useInventoryVms = ( providerType: provider?.spec?.type, } as ProviderVirtualMachine, name: vm.name, - concerns: getHighestPriorityConcern(vm), })) : [];