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 9aa7176a9..b8da16762 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 { concernFilter } from './utils/filters/concernFilter'; +import { concernFilter, OvirtHostFiler } from './utils/filters'; import { ProviderVirtualMachinesList, VmData } from './components'; import { OVirtVirtualMachinesCells } from './OVirtVirtualMachinesRow'; import { ProviderVirtualMachinesProps } from './ProviderVirtualMachines'; @@ -47,11 +47,8 @@ export const oVirtVmFieldsMetadataFactory: ResourceFieldFactory = (t) => [ label: t('Host'), isVisible: true, isIdentity: false, - filter: { - type: 'freetext', - placeholderLabel: t('Filter by host'), - }, sortable: true, + filter: OvirtHostFiler(t), }, { resourceFieldId: 'path', 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 71c0d2eea..f1bde2e04 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 @@ -3,7 +3,7 @@ import React from 'react'; import { EnumToTuple, ResourceFieldFactory } from '@kubev2v/common'; import { VSphereVM } from '@kubev2v/types'; -import { concernFilter, hostFilter } from './utils/filters'; +import { concernFilter, VsphereHostFilter } from './utils/filters'; import { ProviderVirtualMachinesList, VmData } from './components'; import { ProviderVirtualMachinesProps } from './ProviderVirtualMachines'; import { getVmPowerState, useVSphereInventoryVms } from './utils'; @@ -45,7 +45,7 @@ export const vSphereVmFieldsMetadataFactory: ResourceFieldFactory = (t) => [ isVisible: true, isIdentity: false, sortable: true, - filter: hostFilter(t), + filter: VsphereHostFilter(t), }, { resourceFieldId: 'folder', diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/filters/OvirtHostFilter.ts b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/filters/OvirtHostFilter.ts new file mode 100644 index 000000000..1b3806e0f --- /dev/null +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/filters/OvirtHostFilter.ts @@ -0,0 +1,22 @@ +import { EnumValue } from '@kubev2v/common'; + +const labelToFilterItem = (label: string): EnumValue => + label !== '' ? { id: label, label } : { id: label, label: 'Undefined' }; + +/** + * This component enables filtering the oVirt virtual machines + * by the hostname that they are running on. + */ +export const OvirtHostFiler = (t: (string) => string) => { + return { + type: 'host', + primary: true, + placeholderLabel: t('Host'), + dynamicFilter: (items: { vm: { host: string } }[]) => ({ + values: [ + ...Array.from(new Set(items.map((item) => item.vm.host))) // at this point the list contains unique strings that can be used as ID + .map(labelToFilterItem), + ], + }), + }; +}; diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/filters/hostFilter.ts b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/filters/VsphereHostFilter.ts similarity index 67% rename from packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/filters/hostFilter.ts rename to packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/filters/VsphereHostFilter.ts index 780b9daf5..c7ba78748 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/filters/hostFilter.ts +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/filters/VsphereHostFilter.ts @@ -1,10 +1,13 @@ import { EnumValue } from '@kubev2v/common'; +const labelToFilterItem = (label: string): EnumValue => + label !== '' ? { id: label, label } : { id: label, label: 'Undefined' }; + /** * This component enables filtering the VMware's virtual machines * by the hostname that they are running on. */ -export const hostFilter = (t: (string) => string) => { +export const VsphereHostFilter = (t: (string) => string) => { return { type: 'host', primary: true, @@ -12,7 +15,7 @@ export const hostFilter = (t: (string) => string) => { dynamicFilter: (items: { hostName: string }[]) => ({ values: [ ...Array.from(new Set(items.map((item) => item.hostName))) // at this point the list contains unique strings that can be used as ID - .map((label: string): EnumValue => ({ id: label, label })), + .map(labelToFilterItem), ], }), }; diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/filters/index.ts b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/filters/index.ts index 035249727..c588dbc5d 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/filters/index.ts +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/filters/index.ts @@ -1,4 +1,5 @@ // @index(['./*', /style/g], f => `export * from '${f.path}';`) export * from './concernFilter'; -export * from './hostFilter'; +export * from './OvirtHostFilter'; +export * from './VsphereHostFilter'; // @endindex